1 package jdiff; 2 3 import java.io.*; 4 import java.util.*; 5 import com.sun.javadoc.*; 6 7 13 public class Options { 14 15 16 public Options() { 17 } 18 19 35 public static int optionLength(String option) { 36 String opt = option.toLowerCase(); 37 38 if (opt.equals("-authorid")) return 2; 40 if (opt.equals("-versionid")) return 2; 41 if (opt.equals("-d")) return 2; 42 if (opt.equals("-classlist")) return 1; 43 if (opt.equals("-title")) return 2; 44 if (opt.equals("-docletid")) return 1; 45 if (opt.equals("-evident")) return 2; 46 if (opt.equals("-skippkg")) return 2; 47 if (opt.equals("-skipclass")) return 2; 48 if (opt.equals("-execdepth")) return 2; 49 if (opt.equals("-help")) return 1; 50 if (opt.equals("-version")) return 1; 51 if (opt.equals("-package")) return 1; 52 if (opt.equals("-protected")) return 1; 53 if (opt.equals("-public")) return 1; 54 if (opt.equals("-private")) return 1; 55 if (opt.equals("-sourcepath")) return 2; 56 57 if (opt.equals("-apiname")) return 2; 59 if (opt.equals("-oldapi")) return 2; 60 if (opt.equals("-newapi")) return 2; 61 62 if (opt.equals("-apidir")) return 2; 64 if (opt.equals("-oldapidir")) return 2; 65 if (opt.equals("-newapidir")) return 2; 66 67 if (opt.equals("-excludeclass")) return 2; 69 if (opt.equals("-excludemember")) return 2; 70 71 if (opt.equals("-firstsentence")) return 1; 72 if (opt.equals("-docchanges")) return 1; 73 if (opt.equals("-packagesonly")) return 1; 74 if (opt.equals("-showallchanges")) return 1; 75 76 if (opt.equals("-javadocnew")) return 2; 79 if (opt.equals("-javadocold")) return 2; 82 83 if (opt.equals("-baseuri")) return 2; 84 85 if (opt.equals("-nosuggest")) return 2; 87 88 if (opt.equals("-checkcomments")) return 1; 90 if (opt.equals("-retainnonprinting")) return 1; 92 if (opt.equals("-excludetag")) return 2; 94 if (opt.equals("-stats")) return 1; 96 97 if (opt.equals("-windowtitle")) return 2; 99 if (opt.equals("-doctitle")) return 2; 101 102 return 0; 103 } 105 134 public static boolean validOptions(String [][] options, 135 DocErrorReporter reporter) { 136 final DocErrorReporter errOut = reporter; 137 138 class ErrorHandler { 142 boolean noErrorsFound = true; 143 void msg(String msg) { 144 noErrorsFound = false; 145 errOut.printError(msg); 146 } 147 } 148 149 ErrorHandler err = new ErrorHandler(); 150 if (trace) 151 System.out.println("Command line arguments: "); 152 for (int i = 0; i < options.length; i++) { 153 for (int j = 0; j < options[i].length; j++) { 154 Options.cmdOptions += " " + options[i][j]; 155 if (trace) 156 System.out.print(" " + options[i][j]); 157 } 158 } 159 if (trace) 160 System.out.println(); 161 162 for (int i = 0; i < options.length; i++) { 163 if (options[i][0].toLowerCase().equals("-apiname")) { 164 if (options[i].length < 2) { 165 err.msg("No version identifier specified after -apiname option."); 166 } else if (JDiff.compareAPIs) { 167 err.msg("Use the -apiname option, or the -oldapi and -newapi options, but not both."); 168 } else { 169 String filename = options[i][1]; 170 RootDocToXML.apiIdentifier = filename; 171 filename = filename.replace(' ', '_'); 172 RootDocToXML.outputFileName = filename + ".xml"; 173 JDiff.writeXML = true; 174 JDiff.compareAPIs = false; 175 } 176 continue; 177 } 178 if (options[i][0].toLowerCase().equals("-apidir")) { 179 if (options[i].length < 2) { 180 err.msg("No directory specified after -apidir option."); 181 } else { 182 RootDocToXML.outputDirectory = options[i][1]; 183 } 184 continue; 185 } 186 if (options[i][0].toLowerCase().equals("-oldapi")) { 187 if (options[i].length < 2) { 188 err.msg("No version identifier specified after -oldapi option."); 189 } else if (JDiff.writeXML) { 190 err.msg("Use the -apiname or -oldapi option, but not both."); 191 } else { 192 String filename = options[i][1]; 193 filename = filename.replace(' ', '_'); 194 JDiff.oldFileName = filename + ".xml"; 195 JDiff.writeXML = false; 196 JDiff.compareAPIs = true; 197 } 198 continue; 199 } 200 if (options[i][0].toLowerCase().equals("-oldapidir")) { 201 if (options[i].length < 2) { 202 err.msg("No directory specified after -oldapidir option."); 203 } else { 204 JDiff.oldDirectory = options[i][1]; 205 } 206 continue; 207 } 208 if (options[i][0].toLowerCase().equals("-newapi")) { 209 if (options[i].length < 2) { 210 err.msg("No version identifier specified after -newapi option."); 211 } else if (JDiff.writeXML) { 212 err.msg("Use the -apiname or -newapi option, but not both."); 213 } else { 214 String filename = options[i][1]; 215 filename = filename.replace(' ', '_'); 216 JDiff.newFileName = filename + ".xml"; 217 JDiff.writeXML = false; 218 JDiff.compareAPIs = true; 219 } 220 continue; 221 } 222 if (options[i][0].toLowerCase().equals("-newapidir")) { 223 if (options[i].length < 2) { 224 err.msg("No directory specified after -newapidir option."); 225 } else { 226 JDiff.newDirectory = options[i][1]; 227 } 228 continue; 229 } 230 if (options[i][0].toLowerCase().equals("-d")) { 231 if (options[i].length < 2) { 232 err.msg("No directory specified after -d option."); 233 } else { 234 HTMLReportGenerator.outputDir = options[i][1]; 235 } 236 continue; 237 } 238 if (options[i][0].toLowerCase().equals("-javadocnew")) { 239 if (options[i].length < 2) { 240 err.msg("No location specified after -javadocnew option."); 241 } else { 242 HTMLReportGenerator.newDocPrefix = options[i][1]; 243 } 244 continue; 245 } 246 if (options[i][0].toLowerCase().equals("-javadocold")) { 247 if (options[i].length < 2) { 248 err.msg("No location specified after -javadocold option."); 249 } else { 250 HTMLReportGenerator.oldDocPrefix = options[i][1]; 251 } 252 continue; 253 } 254 if (options[i][0].toLowerCase().equals("-baseuri")) { 255 if (options[i].length < 2) { 256 err.msg("No base location specified after -baseURI option."); 257 } else { 258 RootDocToXML.baseURI = options[i][1]; 259 } 260 continue; 261 } 262 if (options[i][0].toLowerCase().equals("-excludeclass")) { 263 if (options[i].length < 2) { 264 err.msg("No level (public|protected|package|private) specified after -excludeclass option."); 265 } else { 266 String level = options[i][1]; 267 if (level.compareTo("public") != 0 && 268 level.compareTo("protected") != 0 && 269 level.compareTo("package") != 0 && 270 level.compareTo("private") != 0) { 271 err.msg("Level specified after -excludeclass option must be one of (public|protected|package|private)."); 272 } else { 273 RootDocToXML.classVisibilityLevel = level; 274 } 275 } 276 continue; 277 } 278 if (options[i][0].toLowerCase().equals("-excludemember")) { 279 if (options[i].length < 2) { 280 err.msg("No level (public|protected|package|private) specified after -excludemember option."); 281 } else { 282 String level = options[i][1]; 283 if (level.compareTo("public") != 0 && 284 level.compareTo("protected") != 0 && 285 level.compareTo("package") != 0 && 286 level.compareTo("private") != 0) { 287 err.msg("Level specified after -excludemember option must be one of (public|protected|package|private)."); 288 } else { 289 RootDocToXML.memberVisibilityLevel = level; 290 } 291 } 292 continue; 293 } 294 if (options[i][0].toLowerCase().equals("-firstsentence")) { 295 RootDocToXML.saveAllDocs = false; 296 continue; 297 } 298 if (options[i][0].toLowerCase().equals("-docchanges")) { 299 HTMLReportGenerator.reportDocChanges = true; 300 Diff.noDocDiffs = false; 301 continue; 302 } 303 if (options[i][0].toLowerCase().equals("-packagesonly")) { 304 RootDocToXML.packagesOnly = true; 305 continue; 306 } 307 if (options[i][0].toLowerCase().equals("-showallchanges")) { 308 Diff.showAllChanges = true; 309 continue; 310 } 311 if (options[i][0].toLowerCase().equals("-nosuggest")) { 312 if (options[i].length < 2) { 313 err.msg("No level (all|remove|add|change) specified after -nosuggest option."); 314 } else { 315 String level = options[i][1]; 316 if (level.compareTo("all") != 0 && 317 level.compareTo("remove") != 0 && 318 level.compareTo("add") != 0 && 319 level.compareTo("change") != 0) { 320 err.msg("Level specified after -nosuggest option must be one of (all|remove|add|change)."); 321 } else { 322 if (level.compareTo("removal") == 0) 323 HTMLReportGenerator.noCommentsOnRemovals = true; 324 else if (level.compareTo("add") == 0) 325 HTMLReportGenerator.noCommentsOnAdditions = true; 326 else if (level.compareTo("change") == 0) 327 HTMLReportGenerator.noCommentsOnChanges = true; 328 else if (level.compareTo("all") == 0) { 329 HTMLReportGenerator.noCommentsOnRemovals = true; 330 HTMLReportGenerator.noCommentsOnAdditions = true; 331 HTMLReportGenerator.noCommentsOnChanges = true; 332 } 333 } 334 } 335 continue; 336 } 337 if (options[i][0].toLowerCase().equals("-checkcomments")) { 338 APIHandler.checkIsSentence = true; 339 continue; 340 } 341 if (options[i][0].toLowerCase().equals("-retainnonprinting")) { 342 RootDocToXML.stripNonPrintables = false; 343 continue; 344 } 345 if (options[i][0].toLowerCase().equals("-excludetag")) { 346 if (options[i].length < 2) { 347 err.msg("No exclude tag specified after -excludetag option."); 348 } else { 349 RootDocToXML.excludeTag = options[i][1]; 350 RootDocToXML.excludeTag = RootDocToXML.excludeTag.trim(); 351 RootDocToXML.doExclude = true; 352 } 353 continue; 354 } 355 if (options[i][0].toLowerCase().equals("-stats")) { 356 HTMLReportGenerator.doStats = true; 357 continue; 358 } 359 if (options[i][0].toLowerCase().equals("-doctitle")) { 360 if (options[i].length < 2) { 361 err.msg("No HTML text specified after -doctitle option."); 362 } else { 363 HTMLReportGenerator.docTitle = options[i][1]; 364 } 365 continue; 366 } 367 if (options[i][0].toLowerCase().equals("-windowtitle")) { 368 if (options[i].length < 2) { 369 err.msg("No text specified after -windowtitle option."); 370 } else { 371 HTMLReportGenerator.windowTitle = options[i][1]; 372 } 373 continue; 374 } 375 if (options[i][0].toLowerCase().equals("-version")) { 376 System.out.println("JDiff version: " + JDiff.version); 377 System.exit(0); 378 } 379 if (options[i][0].toLowerCase().equals("-help")) { 380 usage(); 381 System.exit(0); 382 } 383 } if (!JDiff.writeXML && !JDiff.compareAPIs) { 385 err.msg("First use the -apiname option to generate an XML file for one API."); 386 err.msg("Then use the -apiname option again to generate another XML file for a different version of the API."); 387 err.msg("Finally use the -oldapi option and -newapi option to generate a report about how the APIs differ."); 388 } 389 return err.noErrorsFound; 390 } 392 393 public static void usage() { 394 System.err.println("JDiff version: " + JDiff.version); 395 System.err.println(""); 396 System.err.println("Valid JDiff arguments:"); 397 System.err.println(""); 398 System.err.println(" -apiname <Name of a version>"); 399 System.err.println(" -oldapi <Name of a version>"); 400 System.err.println(" -newapi <Name of a version>"); 401 402 System.err.println(" Optional Arguments"); 403 System.err.println(); 404 System.err.println(" -d <directory> Destination directory for output HTML files"); 405 System.err.println(" -apidir <directory> Destination directory for the XML file generated with the '-apiname' argument."); 406 System.err.println(" -oldapidir <directory> Location of the XML file for the old API"); 407 System.err.println(" -newapidir <directory> Location of the XML file for the new API"); 408 System.err.println(" -sourcepath <location of Java source files>"); 409 System.err.println(" -javadocnew <location of existing Javadoc files for the new API>"); 410 System.err.println(" -javadocold <location of existing Javadoc files for the old API>"); 411 412 System.err.println(" -baseURI <base> Use \"base\" as the base location of the various DTDs and Schemas used by JDiff"); 413 System.err.println(" -excludeclass [public|protected|package|private] Exclude classes which are not public, protected etc"); 414 System.err.println(" -excludemember [public|protected|package|private] Exclude members which are not public, protected etc"); 415 416 System.err.println(" -firstsentence Save only the first sentence of each comment block with the API."); 417 System.err.println(" -docchanges Report changes in Javadoc comments between the APIs"); 418 System.err.println(" -nosuggest [all|remove|add|change] Do not add suggested comments to all, or the removed, added or chabged sections"); 419 System.err.println(" -checkcomments Check that comments are sentences"); 420 System.err.println(" -stripnonprinting Remove non-printable characters from comments."); 421 System.err.println(" -excludetag <tag> Define the Javadoc tag which implies exclusion"); 422 System.err.println(" -stats Generate statistical output"); 423 System.err.println(" -help (generates this output)"); 424 System.err.println(""); 425 System.err.println("For more help, see jdiff.html"); 426 } 427 428 429 public static String cmdOptions = ""; 430 431 432 private static boolean trace = false; 433 } 434 | Popular Tags |