Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
75 commits
Select commit Hold shift + click to select a range
67363a6
fix DocumentName issues
Claudenw Jun 9, 2026
eeccf97
checkpoint
Claudenw Jun 16, 2026
7795c26
Fixed several parsing errors in DocumentName.Builder
Claudenw Jun 18, 2026
b4106b7
initial changes
Claudenw May 10, 2026
fb945eb
created testhelper and updated tests
Claudenw May 10, 2026
1312f27
fixed tests
Claudenw May 10, 2026
b1e37cb
Change to Reporter.Output usage
Claudenw May 24, 2026
a756ca1
updated javadoc
Claudenw May 24, 2026
0a31f12
updated UI strategy
Claudenw May 31, 2026
f4219bb
Remove ArchiveEntryDocument and clean up ArchiveWalker.
Claudenw Jun 1, 2026
11dc8cb
Switch to UnmodifiableSets for licences
Claudenw Jun 1, 2026
1f87473
fix spotbugs issues
Claudenw Jun 1, 2026
9e48d83
fix spotbugs issues
Claudenw Jun 1, 2026
7758b79
fix spotbugs issues
Claudenw Jun 1, 2026
3b90180
created TempDir replacement to support Windows
Claudenw Jun 1, 2026
fcb5436
Fixed issues with DocumentName and DocumentNameBuilder.
Claudenw Jun 5, 2026
c7d4356
fixes for DocumentName errors
Claudenw Jun 9, 2026
775052f
fixed rebasing issues
Claudenw Jun 22, 2026
59f76e4
fix DocumentName issues
Claudenw Jun 9, 2026
316d889
checkpoint
Claudenw Jun 16, 2026
2a254d6
Fixed several parsing errors in DocumentName.Builder
Claudenw Jun 18, 2026
ec4b88a
RAT-559: Refactor during review
ottlinger Jun 23, 2026
6d29904
RAT-559: Shorten tests
ottlinger Jun 23, 2026
8da423a
fixed merge issues
Claudenw Jun 24, 2026
88d10f7
fixed rebase issues
Claudenw Jun 25, 2026
e233611
fix some sonarqube issues
Claudenw Jun 25, 2026
8212c3a
fixed sonar issues
Claudenw Jun 26, 2026
ff0b849
fixes for SonarQube results
Claudenw Jun 27, 2026
2a35b97
cleaned up checkstyle issues
Claudenw Jun 27, 2026
703359c
cleaned up SonarQube issues
Claudenw Jun 27, 2026
23e8aa1
fixed tests
Claudenw Jun 29, 2026
2a5d7c4
merged main branch
Claudenw Jul 5, 2026
8d87ac4
fixup from rebase
Claudenw Jul 23, 2026
dd08261
fixed some sonarcloud issues
Claudenw Jul 25, 2026
d6efe92
fixed some sonarcloud issues
Claudenw Jul 26, 2026
da4120c
fixed bad comments
Claudenw Jul 26, 2026
c652f74
Fixed UIOption build issues
Claudenw Aug 3, 2026
612a835
removed dead code
Claudenw Aug 3, 2026
a866f76
merged from main
Claudenw Sep 15, 2026
f5d9fe7
rebased
Claudenw Sep 16, 2026
0374d18
removed unnecessary check
Claudenw Sep 16, 2026
e101a8f
cleaned up test code
Claudenw Sep 16, 2026
5950358
fixed tests
Claudenw Sep 20, 2026
98538d2
updated javadocs etc.
Claudenw Sep 20, 2026
6bbe470
Merge branch 'master' into RAT-541_create-testhelper_data-package
Claudenw Sep 20, 2026
9d23746
fixed encoding name and bad override annotation
Claudenw Sep 20, 2026
dda69ce
fixed sonarcloud issues
Claudenw Sep 21, 2026
2d4506c
fixed sonarcloud issues
Claudenw Sep 21, 2026
343a0b6
RAT-541: Minor changes during review
ottlinger Sep 27, 2026
9cc7302
RAT-541: Minor changes during review, adapt RAT HTML5 xslt
ottlinger Sep 27, 2026
f949063
RAT-541: Try to get rid of deprecated ArgType processing - fails in M…
ottlinger Sep 27, 2026
bb39248
RAT-541: Fix IDE warnings in test code
ottlinger Sep 27, 2026
974623f
RAT-541: Fix IDE warning
ottlinger Sep 27, 2026
316bc21
RAT-541: Replace with non-deprecated jUnit5 method
ottlinger Sep 27, 2026
1fe0d1b
RAT-541: Review docs
ottlinger Sep 27, 2026
1321357
RAT-541: Fix warning
ottlinger Sep 27, 2026
d9fc2ce
RAT-541: Remove redundant escape character
ottlinger Sep 27, 2026
dbe51d9
RAT-541: Simplify data creation
ottlinger Sep 27, 2026
3e74b5c
RAT-541: Cleanup Ant Javadoc
ottlinger Sep 27, 2026
8f6adb8
RAT-541: Fix SonarCloud issue
ottlinger Sep 27, 2026
6a73a93
RAT-541: Raise test coverage
ottlinger Sep 27, 2026
31c50b6
RAT-541: Raise test coverage, add tests for delete()
ottlinger Sep 27, 2026
acf5721
RAT-541: Remove empty line
ottlinger Sep 27, 2026
be2f9ca
fixed regex escaped string
Claudenw Oct 1, 2026
480b380
RAT-541: Fix warning
ottlinger Oct 1, 2026
87d36c2
RAT-541: Replace String.format by regular String
ottlinger Oct 1, 2026
765ceaa
Reformat during review
ottlinger Oct 1, 2026
9353e7f
Remove redundant escape in RegExp
ottlinger Oct 1, 2026
b04a253
RAT-541: Review changes
ottlinger Oct 1, 2026
c29eea3
RAT-541: Try to raise test coverage
ottlinger Oct 2, 2026
0795a1f
RAT-541: Apply sonar warning and simplify lambda
ottlinger Oct 2, 2026
f9d8d50
RAT-541: Apply sonar warning and simplify lambda
ottlinger Oct 2, 2026
024bdbf
RAT-541: Raise coverage and fix sonarcloud issues
ottlinger Oct 2, 2026
52186d2
fixed deprecated usage code in MavenGenerator
Claudenw Oct 2, 2026
64d2653
Merge remote-tracking branch 'origin/RAT-541_create-testhelper_data-p…
Claudenw Oct 2, 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
69 changes: 47 additions & 22 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,27 @@
* associated with the exception.</li>
* </ul>
*/
public class ReportTest {
class ReportTest {

/**
* Converts an argument lists to an argument array.
* @param argsList the list to convert.
* @return the array of arguments.
*/
private String[] asArgs(final List<String> argsList) {
return argsList.toArray(new String[0]);
}

/**
* Runs the commands specified by the `commandLine.txt` file in the `resources/ReportTest/*` directories
* and validates the results using the {@code verify.groovy} file in the test directory.
* @param testName the name of the test based on the directory the test was found in.
* @param commandLineDoc the document that is the command line.
* @throws Exception on execution error.
*/
@ParameterizedTest(name = "{index} {0}")
@MethodSource("args")
public void integrationTest(String testName, Document commandLineDoc) throws Exception {
@MethodSource("integrationTestData")
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 +131,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,15 +156,21 @@ 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(testName + ": " + value);
}
} catch (AssertionError e) {
throw new AssertionError(String.format("%s: %s", testName, e.getMessage()), e);
throw new AssertionError(testName + ": " + e.getMessage(), e);
}
}
}

static Stream<Arguments> args() throws RatException {
/**
* Reads each directory under the ReportTest directory in the test resources and creates a test from it.
* The {@code commandLine.txt} file is parsed to create the command line to execute the tests.
* @return a stream of arguments for each test case.
* @throws RatException on parsing error.
*/
static Stream<Arguments> integrationTestData() throws RatException {
List<Arguments> results = new ArrayList<>();
URL url = ReportTest.class.getResource("/ReportTest");

Expand All @@ -170,11 +190,11 @@ static Stream<Arguments> args() throws RatException {
DirectoryWalker walker = new DirectoryWalker(document);
RatReport report = new RatReport() {
@Override
public void report(Document document) {
if (!document.isIgnored()) {
String[] tokens = DocumentName.FSInfo.getDefault().tokenize(document.getName().localized());
results.add(Arguments.of(tokens[1], document));
}
public void report(Document document) {
if (!document.isIgnored()) {
String[] tokens = DocumentName.FSInfo.getDefault().tokenize(document.getName().localized());
results.add(Arguments.of(tokens[1], document));
}
}
};
walker.run(report);
Expand All @@ -185,25 +205,27 @@ public void report(Document document) {
* Log that captures output for later review.
*/
public static class FileLog implements Log {

/**
* The output from the log.
*/
private final PrintStream logFile;

/**
* The level at which we will write messages
* The level at which we will write messages.
*/
private Level level;

/**
* Constructor to write at level {@code INFO}.
* @param logFile the file to write to.
* @throws IOException on error.
*/
FileLog(File logFile) throws IOException {
this.logFile = new PrintStream(logFile);
level = Level.INFO;
}

/**
* Sets the level.Log messages below the specified level will
* not be written to the log.
*
* @param level the level to use when writing messages.
*/
@Override
public void setLevel(final Level level) {
this.level = level;
}
Expand All @@ -220,6 +242,9 @@ public void log(Level level, String msg) {
}
}

/**
* Closes the log file.
*/
public void close() {
logFile.close();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
--licenses-denied
DOJO
--
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ public enum Processing {
*/
private final String description;

/**
* Constructor.
* @param description the description for this processing strategy
*/
Processing(final String description) {
this.description = description;
}
Expand Down Expand Up @@ -139,7 +143,7 @@ public String desc() {
/**
* The IODescriptor that provides the output stream to write the report to.
*/
private IODescriptor<OutputStream> out;
private IODescriptor<OutputStream> outputDescriptor;

/**
* The IODescriptor that provides the stylesheet to style the XML output.
Expand Down Expand Up @@ -205,6 +209,10 @@ public ReportConfiguration() {
reportables = new ArrayList<>();
}

/**
* A serializer/deserializer for a ReportConfiguration.
* @return the serializer/deserializer for a ReportConfiguration.
*/
public SerDes serDes() {
return new SerDes();
}
Expand All @@ -227,21 +235,29 @@ public void reportExclusions(final Appendable appendable) {
* File within the file must be in linux format with a
* {@code "/"} file separator.
* @param file the file to process.
* @throws ConfigurationException if the file is {@code null}.
*/
public void addSource(final File file) {
notNull(file, "File may not be null.");
sources.add(file);
}

private void notNull(final Object o, final String msg) {
if (o == null) {
/**
* Throws ConfigurationException if the object is {@code null}.
* @param object the object to test.
* @param msg the message to create the exception with.
* @throws ConfigurationException if the object is {@code null}.
*/
private void notNull(final Object object, final String msg) {
if (object == null) {
throw new ConfigurationException(msg);
}
}

/**
* Adds a Reportable as a source of files to scan.
* @param reportable the reportable to process.
* @throws ConfigurationException if the reportable is {@code null}.
*/
public void addSource(final Reportable reportable) {
notNull(reportable, "Reportable may not be null.");
Expand All @@ -257,8 +273,8 @@ public boolean hasSource() {
}

/**
* Gets a builder initialized with any files specified as sources.
* @return a configured builder.
* Gets a ReportListWalker.Builder initialized with any files specified as sources.
* @return a configured ReportListWalker.Builder.
*/
public ReportableListWalker.Builder getSources() {
DocumentName name = DocumentName.builder(new File(".")).build();
Expand Down Expand Up @@ -527,7 +543,7 @@ public void setStyleSheet(final IODescriptor<InputStream> styleSheet) {
*/
public void setFrom(final Defaults defaults) {
licenseSetFactory.add(defaults.getLicenseSetFactory());
if (getStyleSheet() == null) {
if (getStyleSheetDescriptor() == null) {
setStyleSheet(StyleSheets.PLAIN.getStyleSheet());
}
defaults.getStandardExclusion().forEach(this::addExcludedCollection);
Expand Down Expand Up @@ -571,22 +587,22 @@ public void setStyleSheet(final URL styleSheet) {
* times to provide the stream. Suppliers should prepare streams that are
* appended to and that can be closed. If an {@code OutputStream} should not be
* closed consider wrapping it in a {@code CloseShieldOutputStream}
* @param out the OutputStream supplier that provides the output stream to write
* @param outputDescriptor the OutputStream supplier that provides the output stream to write.
* the report to. A {@code null} value will use {@code System.out}.
* @see CloseShieldOutputStream
*/
public void setOut(final IODescriptor<OutputStream> out) {
this.out = out;
public void setOutput(final IODescriptor<OutputStream> outputDescriptor) {
this.outputDescriptor = outputDescriptor;
}

/**
* Sets the OutputStream supplier to use the specified file. The file may be
* opened and closed several times. File is deleted first and then may be
* repeatedly opened in append mode.
* @see #setOut(IODescriptor)
* @see #setOutput(IODescriptor)
* @param file The file to create the supplier with.
*/
public void setOut(final File file) {
public void setOutput(final File file) {
Objects.requireNonNull(file, "output file should not be null");
if (file.exists()) {
try {
Expand All @@ -600,7 +616,7 @@ public void setOut(final File file) {
if (!parent.mkdirs() && !parent.isDirectory()) {
DefaultLog.getInstance().warn("Unable to create directory: " + file.getParentFile());
}
setOut(IODescriptor.output(file));
setOutput(IODescriptor.output(file));
}

/**
Expand All @@ -618,7 +634,7 @@ public IOSupplier<OutputStream> getOutput() {
* @return the IODescriptor of the output stream to write the report to.
*/
public IODescriptor<OutputStream> getOutputDescriptor() {
return out == null ? SYSTEM_OUT : out;
return outputDescriptor == null ? SYSTEM_OUT : outputDescriptor;
}

/**
Expand Down Expand Up @@ -982,7 +998,7 @@ public void serialize(final Appendable appendable) throws IOException {
.attribute("archiveProcessing", getArchiveProcessing().name())
.attribute("standardProcessing", getStandardProcessing().name())
.attribute("stylesheet", styleSheet.name())
.attribute("output", out.name());
.attribute("output", outputDescriptor.name());
if (StringUtils.isNotEmpty(copyrightMessage)) {
writer.startElement("copyrightMessage").content(copyrightMessage).closeElement();
}
Expand Down Expand Up @@ -1015,6 +1031,13 @@ public void serialize(final Appendable appendable) throws IOException {
}
}

/**
* Reads an input stream as an XML document and parses the report configuration from that.
* <em>Note:</em> The reportable objects (Files) in a deserialized ReportConfigurations are not executable.
* @param inputStreamSupplier The XML document written by {@link #serialize(Appendable)}
* @param workingDirectory the directory to resolve short XSLT and output names from.
* @throws IOException on parse error.
*/
public void deserialize(final IOSupplier<InputStream> inputStreamSupplier, final DocumentName workingDirectory) throws IOException {
org.w3c.dom.Document document;
try (InputStream stream = inputStreamSupplier.get()) {
Expand All @@ -1036,14 +1059,14 @@ public void deserialize(final IOSupplier<InputStream> inputStreamSupplier, final
standardProcessing = Processing.valueOf(attributes.get("standardProcessing"));
String styleName = attributes.get("stylesheet");
if (styleName != null) {
styleSheet = StyleSheets.getStyleSheet(styleName);
styleSheet = StyleSheets.getStyleSheet(styleName, workingDirectory);
}
String outputName = attributes.get("output");
if (outputName != null) {
if (outputName.equals(ReportConfiguration.SYSTEM_OUT.name())) {
out = ReportConfiguration.SYSTEM_OUT;
outputDescriptor = ReportConfiguration.SYSTEM_OUT;
} else {
out = IODescriptor.output(outputName, workingDirectory);
outputDescriptor = IODescriptor.output(outputName, workingDirectory);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@ public enum Arg {
.build()),
(context, selected) ->
context.getConfiguration().addApprovedLicenseIds(context.getParsedOptionValue(selected))

),

/**
Expand Down Expand Up @@ -515,14 +514,14 @@ public enum Arg {
if ("x".equals(key)) {
// display deprecated message.
context.hasOption("x");
context.getConfiguration().setStyleSheet(StyleSheets.getStyleSheet("xml"));
context.getConfiguration().setStyleSheet(StyleSheets.getStyleSheet("xml", context.getWorkingDirectory()));
} else {
List<String> style = context.getOptionValues(selected);
if (style.size() != 1) {
DefaultLog.getInstance().error("Please specify a single stylesheet");
throw new ConfigurationException("Please specify a single stylesheet");
}
context.getConfiguration().setStyleSheet(StyleSheets.getStyleSheet(style.get(0)));
context.getConfiguration().setStyleSheet(StyleSheets.getStyleSheet(style.get(0), context.getWorkingDirectory()));
}
}),

Expand Down Expand Up @@ -597,7 +596,7 @@ public enum Arg {
.build()),
(context, selected) -> {
DocumentName documentName = context.getParsedOptionValue(selected, () -> {
context.getConfiguration().setOut(ReportConfiguration.SYSTEM_OUT);
context.getConfiguration().setOutput(ReportConfiguration.SYSTEM_OUT);
return null;
});
if (documentName != null) {
Expand All @@ -606,7 +605,7 @@ public enum Arg {
if (!parent.mkdirs() && !parent.isDirectory()) {
DefaultLog.getInstance().error("Could not create report parent directory " + documentName);
}
context.getConfiguration().setOut(document);
context.getConfiguration().setOutput(document);
}
}),

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ private Converters() {
}

/**
* Creates a File with fully qualified name.
* Creates a file with fully qualified name.
*/
public static final FileConverter FILE_CONVERTER = new FileConverter();

/**
* Converts the Converter pattern into a Converter, count pair.
* Converts the converter pattern into a pair of Converter and count.
*/
public static final Converter<Pair<ClaimStatistic.Counter, Integer>, ConfigurationException> COUNTER_CONVERTER = arg -> {
String[] parts = arg.split(":");
Expand Down Expand Up @@ -98,7 +98,7 @@ public void setWorkingDirectory(final DocumentName workingDirectory) {
* Applies the conversion function to the specified file name.
* @param fileName the file name to create a file from.
* @return the DocumentName
* @throws NullPointerException if {@code fileName} is null.
* @throws NullPointerException if given {@code fileName} is null.
*/
public DocumentName apply(final String fileName) throws NullPointerException {
DocumentName.FSInfo fsInfo = workingDirectory.fsInfo();
Expand All @@ -117,7 +117,7 @@ public DocumentName apply(final String fileName) throws NullPointerException {
} else {
builder.setBaseName(workingDirectory);
}
return builder.setName(normalizedFileName).build();
return builder.setName(normalizedFileName).build();
}
}
}
Loading
Loading