// options that may be set up below.
Messager.preRegister(context,
messager.programName,
messager.errWriter, messager.warnWriter, messager.noticeWriter);
Options compOpts = Options.instance(context);
boolean docClasses = false;
// Parse arguments
for (int i = 0 ; i < argv.length ; i++) {
String arg = argv[i];
if (arg.equals("-subpackages")) {
oneArg(argv, i++);
addToList(subPackages, argv[i]);
} else if (arg.equals("-exclude")){
oneArg(argv, i++);
addToList(excludedPackages, argv[i]);
} else if (arg.equals("-verbose")) {
setOption(arg);
compOpts.put("-verbose", "");
} else if (arg.equals("-encoding")) {
oneArg(argv, i++);
encoding = argv[i];
compOpts.put("-encoding", argv[i]);
} else if (arg.equals("-breakiterator")) {
breakiterator = true;
setOption("-breakiterator");
} else if (arg.equals("-quiet")) {
quiet = true;
setOption("-quiet");
} else if (arg.equals("-help")) {
usage();
exit();
} else if (arg.equals("-Xclasses")) {
setOption(arg);
docClasses = true;
} else if (arg.equals("-Xwerror")) {
setOption(arg);
rejectWarnings = true;
} else if (arg.equals("-private")) {
setOption(arg);
setFilter(ModifierFilter.ALL_ACCESS);
} else if (arg.equals("-package")) {
setOption(arg);
setFilter(PUBLIC | PROTECTED |
ModifierFilter.PACKAGE );
} else if (arg.equals("-protected")) {
setOption(arg);
setFilter(PUBLIC | PROTECTED );
} else if (arg.equals("-public")) {
setOption(arg);
setFilter(PUBLIC);
} else if (arg.equals("-source")) {
oneArg(argv, i++);
if (compOpts.get("-source") != null) {
usageError("main.option.already.seen", arg);
}
compOpts.put("-source", argv[i]);
} else if (arg.equals("-prompt")) {
compOpts.put("-prompt", "-prompt");
messager.promptOnError = true;
} else if (arg.equals("-sourcepath")) {
oneArg(argv, i++);
if (compOpts.get("-sourcepath") != null) {
usageError("main.option.already.seen", arg);
}
compOpts.put("-sourcepath", argv[i]);
} else if (arg.equals("-classpath")) {
oneArg(argv, i++);
if (compOpts.get("-classpath") != null) {
usageError("main.option.already.seen", arg);
}
compOpts.put("-classpath", argv[i]);
} else if (arg.equals("-sysclasspath")) {
oneArg(argv, i++);
if (compOpts.get("-bootclasspath") != null) {
usageError("main.option.already.seen", arg);
}
compOpts.put("-bootclasspath", argv[i]);
} else if (arg.equals("-bootclasspath")) {
oneArg(argv, i++);
if (compOpts.get("-bootclasspath") != null) {
usageError("main.option.already.seen", arg);
}
compOpts.put("-bootclasspath", argv[i]);
} else if (arg.equals("-extdirs")) {
oneArg(argv, i++);
if (compOpts.get("-extdirs") != null) {
usageError("main.option.already.seen", arg);
}
compOpts.put("-extdirs", argv[i]);
} else if (arg.equals("-overview")) {
oneArg(argv, i++);
} else if (arg.equals("-doclet")) {
i++; // handled in setDocletInvoker
} else if (arg.equals("-docletpath")) {
i++; // handled in setDocletInvoker
} else if (arg.equals("-locale")) {
if (i != 0)
usageError("main.locale_first");
oneArg(argv, i++);
docLocale = argv[i];
} else if (arg.equals("-Xmaxerrs") || arg.equals("-Xmaxwarns")) {
oneArg(argv, i++);
if (compOpts.get(arg) != null) {
usageError("main.option.already.seen", arg);
}
compOpts.put(arg, argv[i]);
} else if (arg.equals("-X")) {
Xusage();
exit();
} else if (arg.startsWith("-XD")) {
String s = arg.substring("-XD".length());
int eq = s.indexOf('=');
String key = (eq < 0) ? s : s.substring(0, eq);
String value = (eq < 0) ? s : s.substring(eq+1);
compOpts.put(key, value);
}
// call doclet for its options
// other arg starts with - is invalid
else if ( arg.startsWith("-") ) {
int optionLength;
optionLength = docletInvoker.optionLength(arg);
if (optionLength < 0) {
// error already displayed
exit();
} else if (optionLength == 0) {
// option not found
usageError("main.invalid_flag", arg);
} else {
// doclet added option
if ((i + optionLength) > argv.length) {
usageError("main.requires_argument", arg);
}
ListBuffer<String> args = new ListBuffer<String>();
for (int j = 0; j < optionLength-1; ++j) {
args.append(argv[++i]);
}
setOption(arg, args.toList());
}
} else {
javaNames.append(arg);
}
}
if (javaNames.isEmpty() && subPackages.isEmpty()) {
usageError("main.No_packages_or_classes_specified");
}
if (!docletInvoker.validOptions(options.toList())) {
// error message already displayed
exit();
}
JavadocTool comp = JavadocTool.make0(context);
if (comp == null) return false;
if (showAccess == null) {
setFilter(defaultFilter);
}
LanguageVersion languageVersion = docletInvoker.languageVersion();
RootDocImpl root = comp.getRootDocImpl(
docLocale, encoding, showAccess,
javaNames.toList(), options.toList(), breakiterator,
subPackages.toList(), excludedPackages.toList(),
docClasses,
// legacy?
languageVersion == null || languageVersion == LanguageVersion.JAVA_1_1, quiet);
// pass off control to the doclet
boolean ok = root != null;
if (ok) ok = docletInvoker.start(root);
Messager docletMessager = Messager.instance0(context);
messager.nwarnings += docletMessager.nwarnings;
messager.nerrors += docletMessager.nerrors;
// We're done.
if (compOpts.get("-verbose") != null) {
tm = System.currentTimeMillis() - tm;
messager.notice("main.done_in", Long.toString(tm));
}
return ok;