|
41 | 41 |
|
42 | 42 | import java.io.File; |
43 | 43 | import java.io.FileInputStream; |
44 | | -import java.io.FileNotFoundException; |
45 | 44 | import java.io.FileOutputStream; |
46 | 45 | import java.io.FileWriter; |
47 | 46 | import java.io.IOException; |
|
67 | 66 | public class ApiXmlDocWriter { |
68 | 67 | public static final Logger s_logger = Logger.getLogger(ApiXmlDocWriter.class.getName()); |
69 | 68 |
|
70 | | - private static final short DOMAIN_ADMIN_COMMAND = 4; |
71 | | - private static final short USER_COMMAND = 8; |
| 69 | + private static String s_dirName = ""; |
72 | 70 | private static Map<String, Class<?>> s_apiNameCmdClassMap = new HashMap<String, Class<?>>(); |
73 | 71 | private static LinkedHashMap<Object, String> s_allApiCommands = new LinkedHashMap<Object, String>(); |
74 | | - private static LinkedHashMap<Object, String> s_domainAdminApiCommands = new LinkedHashMap<Object, String>(); |
75 | | - private static LinkedHashMap<Object, String> s_regularUserApiCommands = new LinkedHashMap<Object, String>(); |
76 | 72 | private static TreeMap<Object, String> s_allApiCommandsSorted = new TreeMap<Object, String>(); |
77 | | - private static TreeMap<Object, String> s_domainAdminApiCommandsSorted = new TreeMap<Object, String>(); |
78 | | - private static TreeMap<Object, String> s_regularUserApiCommandsSorted = new TreeMap<Object, String>(); |
79 | | - private static String s_dirName = ""; |
80 | 73 | private static final List<String> AsyncResponses = setAsyncResponses(); |
81 | 74 |
|
82 | 75 | private static List<String> setAsyncResponses() { |
@@ -123,155 +116,61 @@ public static void main(String[] args) { |
123 | 116 | s_apiNameCmdClassMap.put(apiName, cmdClass); |
124 | 117 | } |
125 | 118 | } |
126 | | - |
127 | | - LinkedProperties preProcessedCommands = new LinkedProperties(); |
128 | | - String[] fileNames = null; |
129 | | - |
| 119 | + System.out.printf("Scanned and found %d APIs\n", s_apiNameCmdClassMap.size()); |
130 | 120 | List<String> argsList = Arrays.asList(args); |
131 | 121 | Iterator<String> iter = argsList.iterator(); |
132 | 122 | while (iter.hasNext()) { |
133 | 123 | String arg = iter.next(); |
134 | | - // populate the file names |
135 | | - if (arg.equals("-f")) { |
136 | | - fileNames = iter.next().split(","); |
137 | | - } |
138 | 124 | if (arg.equals("-d")) { |
139 | 125 | s_dirName = iter.next(); |
140 | 126 | } |
141 | 127 | } |
142 | 128 |
|
143 | | - if ((fileNames == null) || (fileNames.length == 0)) { |
144 | | - System.out.println("Please specify input file(s) separated by coma using -f option"); |
145 | | - System.exit(2); |
146 | | - } |
147 | | - |
148 | | - for (String fileName : fileNames) { |
149 | | - try(FileInputStream in = new FileInputStream(fileName);) { |
150 | | - preProcessedCommands.load(in); |
151 | | - } catch (FileNotFoundException ex) { |
152 | | - System.out.println("Can't find file " + fileName); |
153 | | - System.exit(2); |
154 | | - } catch (IOException ex1) { |
155 | | - System.out.println("Error reading from file " + ex1); |
156 | | - System.exit(2); |
157 | | - } |
158 | | - } |
159 | | - |
160 | | - Iterator<?> propertiesIterator = preProcessedCommands.keys.iterator(); |
161 | | - // Get command classes and response object classes |
162 | | - while (propertiesIterator.hasNext()) { |
163 | | - String key = (String)propertiesIterator.next(); |
164 | | - String preProcessedCommand = preProcessedCommands.getProperty(key); |
165 | | - int splitIndex = preProcessedCommand.lastIndexOf(";"); |
166 | | - String commandRoleMask = preProcessedCommand.substring(splitIndex + 1); |
167 | | - Class<?> cmdClass = s_apiNameCmdClassMap.get(key); |
168 | | - if (cmdClass == null) { |
169 | | - System.out.println("Check, is this api part of another build profile? Null value for key: " + key + " preProcessedCommand=" + preProcessedCommand); |
170 | | - continue; |
171 | | - } |
172 | | - String commandName = cmdClass.getName(); |
173 | | - s_allApiCommands.put(key, commandName); |
174 | | - |
175 | | - short cmdPermissions = 1; |
176 | | - if (commandRoleMask != null) { |
177 | | - cmdPermissions = Short.parseShort(commandRoleMask); |
178 | | - } |
179 | | - |
180 | | - if ((cmdPermissions & DOMAIN_ADMIN_COMMAND) != 0) { |
181 | | - s_domainAdminApiCommands.put(key, commandName); |
182 | | - } |
183 | | - if ((cmdPermissions & USER_COMMAND) != 0) { |
184 | | - s_regularUserApiCommands.put(key, commandName); |
185 | | - } |
| 129 | + for (Map.Entry<String, Class<?>> entry: s_apiNameCmdClassMap.entrySet()) { |
| 130 | + Class<?> cls = entry.getValue(); |
| 131 | + s_allApiCommands.put(entry.getKey(), cls.getName()); |
186 | 132 | } |
187 | 133 |
|
188 | 134 | s_allApiCommandsSorted.putAll(s_allApiCommands); |
189 | | - s_domainAdminApiCommandsSorted.putAll(s_domainAdminApiCommands); |
190 | | - s_regularUserApiCommandsSorted.putAll(s_regularUserApiCommands); |
191 | 135 |
|
192 | 136 | try { |
193 | 137 | // Create object writer |
194 | 138 | XStream xs = new XStream(); |
195 | 139 | xs.alias("command", Command.class); |
196 | 140 | xs.alias("arg", Argument.class); |
197 | 141 | String xmlDocDir = s_dirName + "/xmldoc"; |
198 | | - String rootAdminDirName = xmlDocDir + "/root_admin"; |
199 | | - String domainAdminDirName = xmlDocDir + "/domain_admin"; |
200 | | - String regularUserDirName = xmlDocDir + "/regular_user"; |
| 142 | + String rootAdminDirName = xmlDocDir + "/apis"; |
201 | 143 | (new File(rootAdminDirName)).mkdirs(); |
202 | | - (new File(domainAdminDirName)).mkdirs(); |
203 | | - (new File(regularUserDirName)).mkdirs(); |
204 | 144 |
|
205 | 145 | ObjectOutputStream out = xs.createObjectOutputStream(new FileWriter(s_dirName + "/commands.xml"), "commands"); |
206 | | - ObjectOutputStream rootAdmin = xs.createObjectOutputStream(new FileWriter(rootAdminDirName + "/" + "rootAdminSummary.xml"), "commands"); |
207 | | - ObjectOutputStream rootAdminSorted = xs.createObjectOutputStream(new FileWriter(rootAdminDirName + "/" + "rootAdminSummarySorted.xml"), "commands"); |
208 | | - ObjectOutputStream domainAdmin = xs.createObjectOutputStream(new FileWriter(domainAdminDirName + "/" + "domainAdminSummary.xml"), "commands"); |
209 | | - ObjectOutputStream outDomainAdminSorted = xs.createObjectOutputStream(new FileWriter(domainAdminDirName + "/" + "domainAdminSummarySorted.xml"), "commands"); |
210 | | - ObjectOutputStream regularUser = xs.createObjectOutputStream(new FileWriter(regularUserDirName + "/regularUserSummary.xml"), "commands"); |
211 | | - ObjectOutputStream regularUserSorted = xs.createObjectOutputStream(new FileWriter(regularUserDirName + "/regularUserSummarySorted.xml"), "commands"); |
212 | | - |
213 | | - // Write commands in the order they are represented in commands.properties.in file |
| 146 | + ObjectOutputStream rootAdmin = xs.createObjectOutputStream(new FileWriter(rootAdminDirName + "/" + "apiSummary.xml"), "commands"); |
| 147 | + ObjectOutputStream rootAdminSorted = xs.createObjectOutputStream(new FileWriter(rootAdminDirName + "/" + "apiSummarySorted.xml"), "commands"); |
| 148 | + |
214 | 149 | Iterator<?> it = s_allApiCommands.keySet().iterator(); |
215 | 150 | while (it.hasNext()) { |
216 | 151 | String key = (String)it.next(); |
217 | | - |
218 | 152 | // Write admin commands |
219 | 153 | writeCommand(out, key); |
220 | 154 | writeCommand(rootAdmin, key); |
221 | | - |
222 | 155 | // Write single commands to separate xml files |
223 | 156 | ObjectOutputStream singleRootAdminCommandOs = xs.createObjectOutputStream(new FileWriter(rootAdminDirName + "/" + key + ".xml"), "command"); |
224 | 157 | writeCommand(singleRootAdminCommandOs, key); |
225 | 158 | singleRootAdminCommandOs.close(); |
226 | | - |
227 | | - if (s_domainAdminApiCommands.containsKey(key)) { |
228 | | - writeCommand(domainAdmin, key); |
229 | | - ObjectOutputStream singleDomainAdminCommandOs = xs.createObjectOutputStream(new FileWriter(domainAdminDirName + "/" + key + ".xml"), "command"); |
230 | | - writeCommand(singleDomainAdminCommandOs, key); |
231 | | - singleDomainAdminCommandOs.close(); |
232 | | - } |
233 | | - |
234 | | - if (s_regularUserApiCommands.containsKey(key)) { |
235 | | - writeCommand(regularUser, key); |
236 | | - ObjectOutputStream singleRegularUserCommandOs = xs.createObjectOutputStream(new FileWriter(regularUserDirName + "/" + key + ".xml"), "command"); |
237 | | - writeCommand(singleRegularUserCommandOs, key); |
238 | | - singleRegularUserCommandOs.close(); |
239 | | - } |
240 | 159 | } |
241 | 160 |
|
242 | 161 | // Write sorted commands |
243 | 162 | it = s_allApiCommandsSorted.keySet().iterator(); |
244 | 163 | while (it.hasNext()) { |
245 | 164 | String key = (String)it.next(); |
246 | | - |
247 | 165 | writeCommand(rootAdminSorted, key); |
248 | | - |
249 | | - if (s_domainAdminApiCommands.containsKey(key)) { |
250 | | - writeCommand(outDomainAdminSorted, key); |
251 | | - } |
252 | | - |
253 | | - if (s_regularUserApiCommands.containsKey(key)) { |
254 | | - writeCommand(regularUserSorted, key); |
255 | | - } |
256 | 166 | } |
257 | 167 |
|
258 | 168 | out.close(); |
259 | 169 | rootAdmin.close(); |
260 | 170 | rootAdminSorted.close(); |
261 | | - domainAdmin.close(); |
262 | | - outDomainAdminSorted.close(); |
263 | | - regularUser.close(); |
264 | | - regularUserSorted.close(); |
265 | 171 |
|
266 | 172 | // write alerttypes to xml |
267 | 173 | writeAlertTypes(xmlDocDir); |
268 | | - |
269 | | - // gzip directory with xml doc |
270 | | - // zipDir(dirName + "xmldoc.zip", xmlDocDir); |
271 | | - |
272 | | - // Delete directory |
273 | | - // deleteDir(new File(xmlDocDir)); |
274 | | - |
275 | 174 | } catch (Exception ex) { |
276 | 175 | ex.printStackTrace(); |
277 | 176 | System.exit(2); |
@@ -537,5 +436,4 @@ public Object put(Object key, Object value) { |
537 | 436 | return super.put(key, value); |
538 | 437 | } |
539 | 438 | } |
540 | | - |
541 | 439 | } |
0 commit comments