{
private Builder() {
- super(CLIOption::new);
+ super(CLIOption.CLIBuilder::new);
}
}
}
diff --git a/apache-rat-core/src/main/java/org/apache/rat/OptionCollection.java b/apache-rat-core/src/main/java/org/apache/rat/OptionCollection.java
index ccf5b40fe..3ecd24f28 100644
--- a/apache-rat-core/src/main/java/org/apache/rat/OptionCollection.java
+++ b/apache-rat-core/src/main/java/org/apache/rat/OptionCollection.java
@@ -51,6 +51,9 @@
import org.apache.rat.license.LicenseSetFactory;
import org.apache.rat.report.Reportable;
import org.apache.rat.report.claim.ClaimStatistic;
+import org.apache.rat.ui.ArgumentTracker;
+import org.apache.rat.ui.UIOption;
+import org.apache.rat.ui.UIOptionCollection;
import org.apache.rat.utils.DefaultLog;
import org.apache.rat.utils.Log.Level;
import org.apache.rat.walker.ArchiveWalker;
@@ -68,6 +71,11 @@ private OptionCollection() {
// do not instantiate
}
+ /**
+ * The collection of UI Options.
+ */
+ private static final UIOptionCollection extends UIOption>> BASE_OPTION_COLLECTION = new CLIOptionCollection();
+
/**
* The Option comparator to sort the help.
*/
@@ -122,8 +130,8 @@ public static ReportConfiguration parseCommands(final File workingDirectory, fin
* Parses the standard options to create a ReportConfiguration.
*
* This method is {@code synchronized} because it uses shared mutable state:
- * the {@link Arg} enum's {@code OptionGroup} instances (whose {@code selected}
- * field is mutated by {@link DefaultParser#parse}), and
+ * the {@link #BASE_OPTION_COLLECTION}'s {@code OptionGroup} instances (whose {@code selected}
+ * field is mutated by {@link DefaultParser#parse(Options, String[])}), and
* {@link org.apache.rat.commandline.Converters#FILE_CONVERTER} (whose
* {@code workingDirectory} field is set during argument processing).
* Without synchronization, parallel Maven reactor threads (e.g. {@code mvn -T4})
@@ -140,29 +148,23 @@ public static ReportConfiguration parseCommands(final File workingDirectory, fin
*/
public static synchronized ReportConfiguration parseCommands(final File workingDirectory, final String[] args,
final Consumer helpCmd, final boolean noArgs) throws IOException {
-
Options opts = buildOptions();
- CommandLine commandLine;
+ ArgumentContext argumentContext;
try {
- commandLine = DefaultParser.builder().setDeprecatedHandler(DeprecationReporter.getLogReporter())
- .setAllowPartialMatching(true).build().parse(opts, args);
+ argumentContext = new ArgumentContext(workingDirectory, opts, args);
} catch (ParseException e) {
- DefaultLog.getInstance().error(e.getMessage());
- DefaultLog.getInstance().error("Please use the \"--help\" option to see a list of valid commands and options.", e);
System.exit(1);
return null; // dummy return (won't be reached) to avoid Eclipse complaint about possible NPE
// for "commandLine"
}
+ Arg.processLogLevel(argumentContext, BASE_OPTION_COLLECTION);
- ArgumentContext argumentContext = new ArgumentContext(workingDirectory, commandLine);
- Arg.processLogLevel(argumentContext, CLIOptionCollection.INSTANCE);
-
- if (commandLine.hasOption(HELP)) {
+ if (argumentContext.getCommandLine().hasOption(HELP)) {
helpCmd.accept(opts);
return null;
}
- if (commandLine.hasOption(Arg.HELP_LICENSES.option())) {
+ if (argumentContext.getCommandLine().hasOption(Arg.HELP_LICENSES.option())) {
new Licenses(createConfiguration(argumentContext), new PrintWriter(System.out, false, StandardCharsets.UTF_8)).printHelp();
return null;
}
@@ -180,33 +182,46 @@ public static synchronized ReportConfiguration parseCommands(final File workingD
/**
* Create the report configuration.
- * Note: this method is package private for testing.
- * You probably want one of the {@code ParseCommands} methods.
+ * Note: this method is visible for testing.
+ * You probably want one of the {@code parseCommands(...)} methods instead.
* @param argumentContext The context to execute in.
* @return a ReportConfiguration
* @see #parseCommands(File, String[], Consumer)
* @see #parseCommands(File, String[], Consumer, boolean)
*/
public static ReportConfiguration createConfiguration(final ArgumentContext argumentContext) {
- argumentContext.processArgs(CLIOptionCollection.INSTANCE);
- final ReportConfiguration configuration = argumentContext.getConfiguration();
- final CommandLine commandLine = argumentContext.getCommandLine();
- Optional