diff --git a/apache-rat-core/pom.xml b/apache-rat-core/pom.xml index 21f0c583c..061670044 100644 --- a/apache-rat-core/pom.xml +++ b/apache-rat-core/pom.xml @@ -263,5 +263,10 @@ jimfs test + + org.xmlunit + xmlunit-assertj3 + test + diff --git a/apache-rat-core/src/it/java/org/apache/rat/ReportTest.java b/apache-rat-core/src/it/java/org/apache/rat/ReportTest.java index b695134a6..34cf3909d 100644 --- a/apache-rat-core/src/it/java/org/apache/rat/ReportTest.java +++ b/apache-rat-core/src/it/java/org/apache/rat/ReportTest.java @@ -80,7 +80,7 @@ * associated with the exception. * */ -public class ReportTest { +class ReportTest { private String[] asArgs(final List argsList) { return argsList.toArray(new String[0]); @@ -88,7 +88,7 @@ private String[] asArgs(final List argsList) { @ParameterizedTest(name = "{index} {0}") @MethodSource("args") - public void integrationTest(String testName, Document commandLineDoc) throws Exception { + void integrationTest(String testName, Document commandLineDoc) throws Exception { DefaultLog.getInstance().log(Log.Level.INFO, "Running test for " + testName); File baseDir = new File(commandLineDoc.getName().getName()).getParentFile(); @@ -119,9 +119,11 @@ public void integrationTest(String testName, Document commandLineDoc) throws Exc File expectedMsg = new File(baseDir, "expected-message.txt"); if (expectedMsg.exists()) { - String msg = IOUtils.readLines(new FileReader(expectedMsg)).get(0).trim(); - assertThrows(RatDocumentAnalysisException.class, () -> Report.main(asArgs(argsList)), - msg); + try (FileReader fr = new FileReader(expectedMsg)) { + String msg = IOUtils.readLines(fr).get(0).trim(); + assertThrows(RatDocumentAnalysisException.class, () -> Report.main(asArgs(argsList)), + msg); + } } else { Report.main(asArgs(argsList)); } @@ -142,7 +144,7 @@ public void integrationTest(String testName, Document commandLineDoc) throws Exc try { Object value = shell.run(groovyScript, new String[]{outputFile.getAbsolutePath(), logFile.getAbsolutePath()}); if (value != null) { - fail(String.format("%s", value)); + fail(String.format("%s: %s", testName, value)); } } catch (AssertionError e) { throw new AssertionError(String.format("%s: %s", testName, e.getMessage()), e); @@ -204,6 +206,7 @@ public static class FileLog implements Log { * * @param level the level to use when writing messages. */ + @Override public void setLevel(final Level level) { this.level = level; } diff --git a/apache-rat-core/src/it/resources/ReportTest/RAT_14/verify.groovy b/apache-rat-core/src/it/resources/ReportTest/RAT_14/verify.groovy index 226394df0..c0027ba13 100644 --- a/apache-rat-core/src/it/resources/ReportTest/RAT_14/verify.groovy +++ b/apache-rat-core/src/it/resources/ReportTest/RAT_14/verify.groovy @@ -66,9 +66,9 @@ myArgs[3] = src.getAbsolutePath() ReportConfiguration configuration = OptionCollection.parseCommands(src, myArgs, { opts -> }) assertNotNull(configuration) -configuration.validate(DefaultLog.getInstance().&error) +configuration.validate() Reporter reporter = new Reporter(configuration) -ClaimStatistic statistic = reporter.execute() +ClaimStatistic statistic = reporter.execute().getStatistic() assertEquals(3, statistic.getCounter(ClaimStatistic.Counter.APPROVED)) assertEquals(2, statistic.getCounter(ClaimStatistic.Counter.ARCHIVES)) diff --git a/apache-rat-core/src/it/resources/ReportTest/RAT_362/expected-message.txt b/apache-rat-core/src/it/resources/ReportTest/RAT_362/expected-message.txt index bea4ba545..7e187ea8d 100644 --- a/apache-rat-core/src/it/resources/ReportTest/RAT_362/expected-message.txt +++ b/apache-rat-core/src/it/resources/ReportTest/RAT_362/expected-message.txt @@ -1 +1 @@ -Issues with UNAPPROVED +Issues with LICENSE_CATEGORIES, LICENSE_NAMES, STANDARDS diff --git a/apache-rat-core/src/it/resources/ReportTest/RAT_406/commandLine.txt b/apache-rat-core/src/it/resources/ReportTest/RAT_406/commandLine.txt index 0d6433f57..cec3b5e30 100644 --- a/apache-rat-core/src/it/resources/ReportTest/RAT_406/commandLine.txt +++ b/apache-rat-core/src/it/resources/ReportTest/RAT_406/commandLine.txt @@ -1,2 +1,3 @@ --licenses-denied DOJO +-- 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 2d4bdd636..9a6066b6f 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 @@ -35,7 +35,6 @@ import java.util.stream.Collectors; import org.apache.commons.cli.CommandLine; -import org.apache.commons.cli.DefaultParser; import org.apache.commons.cli.Option; import org.apache.commons.cli.Options; import org.apache.commons.cli.ParseException; @@ -132,27 +131,22 @@ public static ReportConfiguration parseCommands(final File workingDirectory, fin 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" } - - 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; } @@ -184,8 +178,8 @@ public static ReportConfiguration createConfiguration(final ArgumentContext argu Optional