|
@@ -495,7 +495,12 @@ private Result parseAndExecute(List<String> argList, Iterable<? extends JavaFile |
|
|
arguments.allowEmpty(); |
|
|
|
|
|
doclet.init(locale, messager); |
|
|
parseArgs(argList, javaNames); |
|
|
int beforeCount = messager.nerrors; |
|
|
boolean success = parseArgs(argList, javaNames); |
|
|
int afterCount = messager.nerrors; |
|
|
if (!success && beforeCount == afterCount) { // if there were failures but they have not been reported |
|
|
return CMDERR; |
|
|
} |
|
|
|
|
|
if (!arguments.handleReleaseOptions(extra -> true)) { |
|
|
// Arguments does not always increase the error count in the |
|
@@ -579,8 +584,13 @@ boolean matches(Doclet.Option option, String arg) { |
|
|
} |
|
|
|
|
|
private Set<? extends Doclet.Option> docletOptions = null; |
|
|
int handleDocletOption(int idx, List<String> args, boolean isToolOption) |
|
|
throws OptionException { |
|
|
|
|
|
/* |
|
|
* Consumes an option along with its arguments. Returns an advanced index |
|
|
* modulo the sign. If the value is negative, it means there was a failure |
|
|
* processing one or more options. |
|
|
*/ |
|
|
int consumeDocletOption(int idx, List<String> args, boolean isToolOption) throws OptionException { |
|
|
if (docletOptions == null) { |
|
|
docletOptions = getSupportedOptionsOf(doclet); |
|
|
} |
|
@@ -594,6 +604,7 @@ int handleDocletOption(int idx, List<String> args, boolean isToolOption) |
|
|
argBase = arg; |
|
|
argVal = null; |
|
|
} |
|
|
int m = 1; |
|
|
String text = null; |
|
|
for (Doclet.Option opt : docletOptions) { |
|
|
if (matches(opt, argBase)) { |
|
@@ -603,29 +614,33 @@ int handleDocletOption(int idx, List<String> args, boolean isToolOption) |
|
|
text = messager.getText("main.unnecessary_arg_provided", argBase); |
|
|
throw new OptionException(ERROR, this::showUsage, text); |
|
|
case 1: |
|
|
opt.process(arg, Arrays.asList(argVal)); |
|
|
if (!opt.process(arg, Collections.singletonList(argVal))) { |
|
|
m = -1; |
|
|
} |
|
|
break; |
|
|
default: |
|
|
text = messager.getText("main.only_one_argument_with_equals", argBase); |
|
|
throw new OptionException(ERROR, this::showUsage, text); |
|
|
} |
|
|
} else { |
|
|
if (args.size() - idx -1 < opt.getArgumentCount()) { |
|
|
if (args.size() - idx - 1 < opt.getArgumentCount()) { |
|
|
text = messager.getText("main.requires_argument", arg); |
|
|
throw new OptionException(ERROR, this::showUsage, text); |
|
|
} |
|
|
opt.process(arg, args.subList(idx + 1, args.size())); |
|
|
if (!opt.process(arg, args.subList(idx + 1, idx + 1 + opt.getArgumentCount()))) { |
|
|
m = -1; |
|
|
} |
|
|
idx += opt.getArgumentCount(); |
|
|
} |
|
|
return idx; |
|
|
return m * idx; |
|
|
} |
|
|
} |
|
|
// check if arg is accepted by the tool before emitting error |
|
|
if (!isToolOption) { |
|
|
text = messager.getText("main.invalid_flag", arg); |
|
|
throw new OptionException(ERROR, this::showUsage, text); |
|
|
} |
|
|
return idx; |
|
|
return m * idx; |
|
|
} |
|
|
|
|
|
private static Set<? extends Option> getSupportedOptionsOf(Doclet doclet) { |
|
@@ -649,8 +664,7 @@ int handleDocletOption(int idx, List<String> args, boolean isToolOption) |
|
|
* @throws ToolException if an error occurs initializing the doclet |
|
|
* @throws OptionException if an error occurs while processing an option |
|
|
*/ |
|
|
private Doclet preprocess(List<String> argv) |
|
|
throws ToolException, OptionException { |
|
|
private Doclet preprocess(List<String> argv) throws ToolException, OptionException { |
|
|
// doclet specifying arguments |
|
|
String userDocletPath = null; |
|
|
String userDocletName = null; |
|
@@ -774,15 +788,19 @@ private Doclet preprocess(List<String> argv) |
|
|
} |
|
|
} |
|
|
|
|
|
private void parseArgs(List<String> args, List<String> javaNames) throws ToolException, |
|
|
OptionException, com.sun.tools.javac.main.Option.InvalidValueException { |
|
|
private boolean parseArgs(List<String> args, List<String> javaNames) |
|
|
throws OptionException, com.sun.tools.javac.main.Option.InvalidValueException |
|
|
{ |
|
|
boolean success = true; |
|
|
for (int i = 0; i < args.size(); i++) { |
|
|
String arg = args.get(i); |
|
|
ToolOption o = options.getOption(arg); |
|
|
if (o != null) { |
|
|
// handle a doclet argument that may be needed however |
|
|
// don't increment the index, and allow the tool to consume args |
|
|
handleDocletOption(i, args, true); |
|
|
if (consumeDocletOption(i, args, true) < 0) { |
|
|
success = false; |
|
|
} |
|
|
if (o.hasArg) { |
|
|
if (arg.startsWith("--") && arg.contains("=")) { |
|
|
o.process(arg.substring(arg.indexOf('=') + 1)); |
|
@@ -800,14 +818,19 @@ private void parseArgs(List<String> args, List<String> javaNames) throws ToolExc |
|
|
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); |
|
|
String value = (eq < 0) ? s : s.substring(eq + 1); |
|
|
options.compilerOptions().put(key, value); |
|
|
} else if (arg.startsWith("-")) { |
|
|
i = handleDocletOption(i, args, false); |
|
|
i = consumeDocletOption(i, args, false); |
|
|
if (i < 0) { |
|
|
i = -i; |
|
|
success = false; |
|
|
} |
|
|
} else { |
|
|
javaNames.add(arg); |
|
|
} |
|
|
} |
|
|
return success; |
|
|
} |
|
|
|
|
|
private <T> boolean isEmpty(Iterable<T> iter) { |
|
|