Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
b3e46a1
fix DocumentName issues
Claudenw Jun 9, 2026
51064da
checkpoint
Claudenw Jun 16, 2026
805b423
Fixed several parsing errors in DocumentName.Builder
Claudenw Jun 18, 2026
57124fc
initial changes
Claudenw May 10, 2026
84a4079
created testhelper and updated tests
Claudenw May 10, 2026
e61bcdd
fixed tests
Claudenw May 10, 2026
90a12f8
Change to Reporter.Output usage
Claudenw May 24, 2026
b9e9955
updated javadoc
Claudenw May 24, 2026
fc99411
updated UI strategy
Claudenw May 31, 2026
1a9e1bc
Remove ArchiveEntryDocument and clean up ArchiveWalker.
Claudenw Jun 1, 2026
3355412
Change ArgumentContext to build from Options and arguments rather tha…
Claudenw Jun 1, 2026
b028db2
Switch to UnmodifiableSets for licences
Claudenw Jun 1, 2026
9b90121
Switch to UnmodifiableSets for licences
Claudenw Jun 1, 2026
462ed9b
Use MutableInt in ClaimValidator
Claudenw Jun 1, 2026
bc8cf42
fix case statement
Claudenw Jun 1, 2026
73cef38
fix spotbugs issues
Claudenw Jun 1, 2026
2c73194
fix spotbugs issues
Claudenw Jun 1, 2026
86eac78
fix spotbugs issues
Claudenw Jun 1, 2026
e886cf8
created TempDir replacement to support Windows
Claudenw Jun 1, 2026
f576ae2
Fixed issues with DocumentName and DocumentNameBuilder.
Claudenw Jun 5, 2026
ac06009
fixes for DocumentName errors
Claudenw Jun 9, 2026
a8478ad
fixed rebasing issues
Claudenw Jun 22, 2026
2605ddd
fix DocumentName issues
Claudenw Jun 9, 2026
862a8ad
checkpoint
Claudenw Jun 16, 2026
febe704
Fixed several parsing errors in DocumentName.Builder
Claudenw Jun 18, 2026
8917531
RAT-559: Refactor during review
ottlinger Jun 23, 2026
d9896be
RAT-559: Shorten tests
ottlinger Jun 23, 2026
f3fd02e
fixed merge issues
Claudenw Jun 24, 2026
c484029
fixed rebase issues
Claudenw Jun 25, 2026
b15b06b
fix some sonarqube issues
Claudenw Jun 25, 2026
f4939c2
cleaned up sonar issues
Claudenw Jun 26, 2026
42aeae6
fixed sonar issues
Claudenw Jun 26, 2026
cfa48bb
fixed checkstyle issues
Claudenw Jun 26, 2026
f8e968c
fixes for SonarQube results
Claudenw Jun 27, 2026
3a47cd2
cleaned up checkstyle issues
Claudenw Jun 27, 2026
0b664d6
cleaned up SonarQube issues
Claudenw Jun 27, 2026
0170189
Merge branch 'master' into RAT-541_create-testhelper_data-package
Claudenw Jun 28, 2026
154a741
Merge branch 'master' into RAT-541_create-testhelper_data-package
Claudenw Jun 29, 2026
9871e78
fixed tests
Claudenw Jun 29, 2026
1baa31b
Merge branch 'master' into RAT-541_create-testhelper_data-package
Claudenw Jul 1, 2026
0d154e6
Merge branch 'master' into RAT-541_create-testhelper_data-package
Claudenw Jul 5, 2026
1ad5ba6
merged main branch
Claudenw Jul 5, 2026
75a518e
cleaned up implementation
Claudenw Jul 6, 2026
90dd8c5
initial code
Claudenw Jul 6, 2026
a99e12a
added tests
Claudenw Jul 6, 2026
30707d2
fixed some style issues
Claudenw Jul 6, 2026
046c1be
fixes sonarqube issues
Claudenw Jul 6, 2026
2ad3adc
fix sonarqube issues
Claudenw Jul 7, 2026
0fcd7da
cleaned up code
Claudenw Jul 7, 2026
e4df18a
Merge branch 'create-output-object' into RAT-541_create-testhelper_da…
Claudenw Jul 8, 2026
efedd1e
cleaned up sonarqube
Claudenw Jul 9, 2026
75d80ca
fixed checkstyle
Claudenw Jul 9, 2026
97a8d8c
fixed new line issue
Claudenw Jul 9, 2026
7ba796d
Merge branch 'create-output-object' into RAT-541_create-testhelper_da…
Claudenw Jul 9, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions apache-rat-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -263,5 +263,10 @@
<artifactId>jimfs</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.xmlunit</groupId>
<artifactId>xmlunit-assertj3</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
15 changes: 9 additions & 6 deletions apache-rat-core/src/it/java/org/apache/rat/ReportTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,15 @@
* associated with the exception.</li>
* </ul>
*/
public class ReportTest {
class ReportTest {

private String[] asArgs(final List<String> argsList) {
return argsList.toArray(new String[0]);
}

@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();

Expand Down Expand Up @@ -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));
}
Expand All @@ -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);
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Issues with UNAPPROVED
Issues with LICENSE_CATEGORIES, LICENSE_NAMES, STANDARDS
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
--licenses-denied
DOJO
--
18 changes: 6 additions & 12 deletions apache-rat-core/src/main/java/org/apache/rat/OptionCollection.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -132,27 +131,22 @@ public static ReportConfiguration parseCommands(final File workingDirectory, fin
final Consumer<Options> 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;
}
Expand Down Expand Up @@ -184,8 +178,8 @@ public static ReportConfiguration createConfiguration(final ArgumentContext argu
Optional<Option> dirOpt = CLIOptionCollection.INSTANCE.getSelected(Arg.DIR);
if (dirOpt.isPresent()) {
try {
configuration.addSource(getReportable(commandLine.getParsedOptionValue(
dirOpt.get()), configuration));
DocumentName directoryName = commandLine.getParsedOptionValue(dirOpt.get());
configuration.addSource(getReportable(directoryName.asFile(), configuration));
} catch (ParseException e) {
throw new ConfigurationException("Unable to set parse " + dirOpt.get(), e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
import org.apache.commons.lang3.StringUtils;
import org.apache.rat.api.RatException;
import org.apache.rat.commandline.Arg;
import org.apache.rat.commandline.ArgumentContext;
import org.apache.rat.help.Licenses;
Expand Down Expand Up @@ -62,11 +63,10 @@ public OptionCollectionParser(final UIOptionCollection<?> optionCollection) {
* @param workingDirectory The directory to resolve relative file names against.
* @param args the arguments to parse
* @return the ArgumentContext for the process.
* @throws IOException on error.
* @throws ParseException on option parsing error.
* @throws RatException on error.
*/
public ArgumentContext parseCommands(final File workingDirectory, final String[] args)
throws IOException, ParseException {
throws RatException {
return parseCommands(workingDirectory, args, uiOptionCollection.getOptions());
}

Expand All @@ -77,8 +77,7 @@ public ArgumentContext parseCommands(final File workingDirectory, final String[]
* @return the CommandLine
* @throws ParseException on option parsing error.
*/
//@VisibleForTesting
CommandLine parseCommandLine(final Options opts, final String[] args) throws ParseException {
public static CommandLine parseCommandLine(final Options opts, final String[] args) throws ParseException {
try {
return DefaultParser.builder().setDeprecatedHandler(DeprecationReporter.getLogReporter())
.setAllowPartialMatching(true).build().parse(opts, args);
Expand All @@ -89,29 +88,37 @@ CommandLine parseCommandLine(final Options opts, final String[] args) throws Par
}
}

private void printHelp(final ArgumentContext argumentContext) throws RatException {
try {
new Licenses(argumentContext.getConfiguration(),
new PrintWriter(argumentContext.getConfiguration().getOutput().get(),
false, StandardCharsets.UTF_8)).printHelp();
} catch (IOException e) {
throw new RatException("Unable to print help: " + e.getMessage(), e);
}
}
/**
* Parses the standard options to create a ReportConfiguration.
*
* @param workingDirectory The directory to resolve relative file names against.
* @param args the arguments to parse.
* @param options An Options object containing Apache command line options.
* @return the ArgumentContext for the process.
* @throws IOException on error.
* @throws ParseException on option parsing error.
* @throws RatException on error.
*/
private ArgumentContext parseCommands(final File workingDirectory, final String[] args,
final Options options) throws IOException, ParseException {
CommandLine commandLine = parseCommandLine(options, args);
ArgumentContext argumentContext = new ArgumentContext(workingDirectory, commandLine);
Arg.processLogLevel(argumentContext, uiOptionCollection);
populateConfiguration(argumentContext);
if (uiOptionCollection.isSelected(Arg.HELP_LICENSES)) {
new Licenses(argumentContext.getConfiguration(),
new PrintWriter(argumentContext.getConfiguration().getOutput().get(),
false, StandardCharsets.UTF_8)).printHelp();
final Options options) throws RatException {
try {
ArgumentContext argumentContext = new ArgumentContext(workingDirectory, options, args);
Arg.processLogLevel(argumentContext, uiOptionCollection);
populateConfiguration(argumentContext);
if (uiOptionCollection.isSelected(Arg.HELP_LICENSES)) {
printHelp(argumentContext);
}
return argumentContext;
} catch (ParseException e) {
throw new RatException("Unable to parse command line: " + e.getMessage(), e);
}

return argumentContext;
}

/**
Expand Down
64 changes: 51 additions & 13 deletions apache-rat-core/src/main/java/org/apache/rat/Report.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,15 @@
package org.apache.rat;

import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.nio.charset.StandardCharsets;

import org.apache.commons.cli.Options;
import org.apache.commons.io.function.IOSupplier;
import org.apache.rat.api.RatException;
import org.apache.rat.commandline.ArgumentContext;
import org.apache.rat.document.RatDocumentAnalysisException;
import org.apache.rat.help.Help;
import org.apache.rat.utils.DefaultLog;
Expand Down Expand Up @@ -48,28 +55,59 @@ public static void main(final String[] args) throws Exception {
System.exit(0);
}

ReportConfiguration configuration = OptionCollection.parseCommands(new File("."), args, Report::printUsage);
if (configuration != null) {
configuration.validate(DefaultLog.getInstance()::error);
Reporter reporter = new Reporter(configuration);
reporter.output();
reporter.writeSummary(DefaultLog.getInstance().asWriter());
Reporter.Output result = generateReport(CLIOptionCollection.INSTANCE, new File("."), args);
if (result != null) {
result.writeSummary(DefaultLog.getInstance().asWriter());

if (configuration.getClaimValidator().hasErrors()) {
configuration.getClaimValidator().logIssues(reporter.getClaimsStatistic());
if (result.getConfiguration().getClaimValidator().hasErrors()) {
result.getConfiguration().getClaimValidator().logIssues(result.getStatistic());
throw new RatDocumentAnalysisException(format("Issues with %s",
String.join(", ",
configuration.getClaimValidator().listIssues(reporter.getClaimsStatistic()))));
result.getConfiguration().getClaimValidator().listIssues(result.getStatistic()))));
}
}
}

/**
* Prints the usage message on {@code System.out}.
* @param opts The defined options.
* Prints the usage message on the specified output stream.
* @param out The OutputStream supplier
*/
private static void printUsage(final Options options, final IOSupplier<OutputStream> out) {
try (OutputStream stream = out.get();
PrintWriter writer = new PrintWriter(stream, false, StandardCharsets.UTF_8)) {
new Help(writer).printUsage(options);
} catch (IOException e) {
throw new RuntimeException(e);
}
}

/**
* Generates the report
* @param workingDirectory the directory that we are executing in
* @param args the arguments from the command line.
* @return The Client output.
* @throws Exception on error.
*/
private static void printUsage(final Options opts) {
new Help(System.out).printUsage(opts);
static Reporter.Output generateReport(final CLIOptionCollection optionCollection, final File workingDirectory, final String[] args) throws RatException {
Reporter.Output output = null;
OptionCollectionParser optionParser = new OptionCollectionParser(optionCollection);
ArgumentContext argumentContext = optionParser.parseCommands(workingDirectory, args);
ReportConfiguration configuration = argumentContext.getConfiguration();
if (configuration != null) {
if (argumentContext.getCommandLine().hasOption(CLIOptionCollection.HELP)) {
printUsage(optionCollection.getOptions(), argumentContext.getConfiguration().getOutput());
} else if (!configuration.hasSource()) {
String msg = "No directories or files specified for scanning. Did you forget to close a multi-argument option?";
DefaultLog.getInstance().error(msg);
printUsage(optionCollection.getOptions(), argumentContext.getConfiguration().getOutput());
} else {
configuration.validate();
Reporter reporter = new Reporter(configuration);
output = reporter.execute();
output.format(configuration);
}
}
return output;
}

private Report() {
Expand Down
Loading
Loading