4141import org .apache .logging .log4j .LogManager ;
4242
4343import java .io .File ;
44- import java .io .FileInputStream ;
45- import java .io .FileOutputStream ;
4644import java .io .FileWriter ;
4745import java .io .IOException ;
4846import java .io .ObjectOutputStream ;
4947import java .lang .reflect .Field ;
5048import java .util .ArrayList ;
5149import java .util .Arrays ;
5250import java .util .Collections ;
53- import java .util .Enumeration ;
5451import java .util .HashMap ;
5552import java .util .HashSet ;
5653import java .util .Iterator ;
5754import java .util .LinkedHashMap ;
58- import java .util .LinkedList ;
5955import java .util .List ;
6056import java .util .Map ;
61- import java .util .Properties ;
6257import java .util .Set ;
6358import java .util .TreeMap ;
64- import java .util .zip .ZipEntry ;
65- import java .util .zip .ZipOutputStream ;
6659
6760public class ApiXmlDocWriter {
6861 protected static Logger LOGGER = LogManager .getLogger (ApiXmlDocWriter .class );
@@ -93,8 +86,8 @@ public static void main(String[] args) {
9386 "org.apache.cloudstack.api.command.admin.zone" , "org.apache.cloudstack.network.contrail.api.command" });
9487
9588 for (Class <?> cmdClass : cmdClasses ) {
96- if (cmdClass .getAnnotation (APICommand .class )== null ){
97- System .out .println ("Warning, API Cmd class " + cmdClass .getName () + " has no APICommand annotation " );
89+ if (cmdClass .getAnnotation (APICommand .class ) == null ) {
90+ System .out .println ("Warning: API Cmd class " + cmdClass .getName () + " has no APICommand annotation " );
9891 continue ;
9992 }
10093 String apiName = cmdClass .getAnnotation (APICommand .class ).name ();
@@ -105,11 +98,9 @@ public static void main(String[] args) {
10598 // api_cmd map always keep the admin cmd class to get full response and parameters
10699 s_apiNameCmdClassMap .put (apiName , cmdClass );
107100 } else if (cmdClass .isAssignableFrom (curCmd )) {
108- // just skip this one without warning
109- continue ;
101+ System .out .println ("Info: API Cmd class " + cmdClass .getName () + " is assignable from " + curCmd .getName () + ", skip this one" );
110102 } else {
111- System .out .println ("Warning, API Cmd class " + cmdClass .getName () + " has non-unique apiname " + apiName );
112- continue ;
103+ System .out .println ("Warning: API Cmd class " + cmdClass .getName () + " has non-unique apiname " + apiName );
113104 }
114105 } else {
115106 s_apiNameCmdClassMap .put (apiName , cmdClass );
@@ -178,8 +169,6 @@ public static void main(String[] args) {
178169
179170 private static void writeCommand (ObjectOutputStream out , String command ) throws ClassNotFoundException , IOException {
180171 Class <?> clas = Class .forName (s_allApiCommands .get (command ));
181- ArrayList <Argument > request = new ArrayList <Argument >();
182- ArrayList <Argument > response = new ArrayList <Argument >();
183172
184173 // Create a new command, set name/description/usage
185174 Command apiCommand = new Command ();
@@ -220,19 +209,19 @@ private static void writeCommand(ObjectOutputStream out, String command) throws
220209
221210 Set <Field > fields = ReflectUtil .getAllFieldsForClass (clas , new Class <?>[] {BaseCmd .class , BaseAsyncCmd .class , BaseAsyncCreateCmd .class });
222211
223- request = setRequestFields (fields );
212+ ArrayList < Argument > request = setRequestFields (fields );
224213
225214 // Get response parameters
226215 Class <?> responseClas = impl .responseObject ();
227216 Field [] responseFields = responseClas .getDeclaredFields ();
228- response = setResponseFields (responseFields , responseClas );
217+ ArrayList < Argument > response = setResponseFields (responseFields , responseClas );
229218
230219 apiCommand .setRequest (request );
231220 apiCommand .setResponse (response );
232221
233222 out .writeObject (apiCommand );
234223 } else {
235- LOGGER .debug ("Command " + command + " is not exposed in api doc" );
224+ LOGGER .debug ("Command {} is not exposed in api doc" , command );
236225 }
237226 }
238227
@@ -361,49 +350,6 @@ private static ArrayList<Argument> setResponseFields(Field[] responseFields, Cla
361350 return arguments ;
362351 }
363352
364- private static void zipDir (String zipFileName , String dir ) throws Exception {
365- File dirObj = new File (dir );
366- ZipOutputStream out = new ZipOutputStream (new FileOutputStream (zipFileName ));
367- addDir (dirObj , out );
368- out .close ();
369- }
370-
371- static void addDir (File dirObj , ZipOutputStream out ) throws IOException {
372- File [] files = dirObj .listFiles ();
373- byte [] tmpBuf = new byte [1024 ];
374- String pathToDir = s_dirName ;
375-
376- for (int i = 0 ; i < files .length ; i ++) {
377- if (files [i ].isDirectory ()) {
378- addDir (files [i ], out );
379- continue ;
380- }
381- try (FileInputStream in = new FileInputStream (files [i ].getPath ());) {
382- out .putNextEntry (new ZipEntry (files [i ].getPath ().substring (pathToDir .length ())));
383- int len ;
384- while ((len = in .read (tmpBuf )) > 0 ) {
385- out .write (tmpBuf , 0 , len );
386- }
387- out .closeEntry ();
388- }catch (IOException ex )
389- {
390- LOGGER .error ("addDir:Exception:" + ex .getMessage (),ex );
391- }
392- }
393- }
394-
395- private static void deleteDir (File dir ) {
396- if (dir .isDirectory ()) {
397- String [] children = dir .list ();
398- if (children != null ) {
399- for (int i = 0 ; i < children .length ; i ++) {
400- deleteDir (new File (dir , children [i ]));
401- }
402- }
403- }
404- dir .delete ();
405- }
406-
407353 private static void writeAlertTypes (String dirName ) {
408354 XStream xs = new XStream ();
409355 xs .alias ("alert" , Alert .class );
@@ -421,20 +367,4 @@ private static void writeAlertTypes(String dirName) {
421367 LOGGER .error ("Failed to read alert fields " , e );
422368 }
423369 }
424-
425- private static class LinkedProperties extends Properties {
426- private final LinkedList <Object > keys = new LinkedList <Object >();
427-
428- @ Override
429- public Enumeration <Object > keys () {
430- return Collections .<Object > enumeration (keys );
431- }
432-
433- @ Override
434- public Object put (Object key , Object value ) {
435- // System.out.println("Adding key" + key);
436- keys .add (key );
437- return super .put (key , value );
438- }
439- }
440370}
0 commit comments