Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 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
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
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
@@ -1,2 +1,3 @@
--licenses-denied
DOJO
--
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,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
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
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,11 @@ public enum StyleSheets {
/**
* The pretty-printed XML style sheet.
*/
XML("xml", "Produces output in pretty-printed XML.");

XML("xml", "Produces output in pretty-printed XML."),
/**
* Official HTML5 stylesheet.
*/
XHTML5("xhtml5", "Produces a HTML5 report");
/**
* The name of the style sheet. Must map to bundled resource XSLT file
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,9 @@ private void resetLastMatcher() {
*/
public ExclusionProcessor addIncludedPatterns(final Iterable<String> patterns) {
if (patterns != null) {
DefaultLog.getInstance().debug(format("Including patterns: %s", String.join(", ", patterns)));
patterns.forEach(includedPatterns::add);
resetLastMatcher();
DefaultLog.getInstance().debug(format("Including patterns: %s", String.join(", ", patterns)));
patterns.forEach(includedPatterns::add);
resetLastMatcher();
}
return this;
}
Expand Down Expand Up @@ -193,9 +193,9 @@ public ExclusionProcessor addIncludedCollection(final StandardCollection collect
*/
public ExclusionProcessor addExcludedPatterns(final Iterable<String> patterns) {
if (patterns != null) {
DefaultLog.getInstance().debug(format("Excluding patterns: %s", String.join(", ", patterns)));
patterns.forEach(excludedPatterns::add);
resetLastMatcher();
DefaultLog.getInstance().debug(format("Excluding patterns: %s", String.join(", ", patterns)));
patterns.forEach(excludedPatterns::add);
resetLastMatcher();
}
return this;
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,42 +16,46 @@
* specific language governing permissions and limitations *
* under the License. *
*/
package org.apache.rat.testhelpers;
package org.apache.rat.utils;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.nio.file.Files;
import java.util.Arrays;
import java.util.Collections;

import static org.assertj.core.api.Fail.fail;

public class FileUtils {
public final class FileUtils {
private FileUtils() {
// do not instantiate
}

/**
* Creates a directory if it does not exist.
* @param dir the directory to make.
*/
public static void mkDir(File dir) {
public static void mkDir(final File dir) {
boolean ignored = dir.mkdirs();
}

/**
* Deletes a file if it exists.
* @param file the file to delete.
*/
public static void delete(File file) {
public static void delete(final File file) {
if (file.exists()) {
if (file.isDirectory()) {
try {
try {
if (file.isDirectory()) {
org.apache.commons.io.FileUtils.deleteDirectory(file);
} catch (IOException ignore) {
//
} else {
Files.delete(file.toPath());
}
} else {
boolean ignored = file.delete();
} catch (IOException ignore) {
//
}

}
}

Expand All @@ -62,15 +66,16 @@ public static void delete(File file) {
* @param lines the lines to write into the file.
* @return the new File.
*/
static public File writeFile(File dir, final String name, final Iterable<String> lines) {
public static File writeFile(final File dir, final String name, final Iterable<String> lines) {
if (dir == null) {
fail("base directory not specified");
throw new IllegalArgumentException("base directory not specified");
}
mkDir(dir);
File file = new File(dir, name);
try (PrintWriter writer = new PrintWriter(new FileWriter(file))) {
lines.forEach(writer::println);
} catch (IOException e) {
fail(e.getMessage());
throw new RuntimeException(e.getMessage(), e);
}
return file;
}
Expand All @@ -82,7 +87,7 @@ static public File writeFile(File dir, final String name, final Iterable<String>
* @param lines the lines to write into the file.
* @return the new File.
*/
static public File writeFile(File dir, final String name, final String... lines) {
public static File writeFile(final File dir, final String name, final String... lines) {
return writeFile(dir, name, Arrays.asList(lines));
}

Expand All @@ -92,7 +97,7 @@ static public File writeFile(File dir, final String name, final String... lines)
* @param name the name of the file.
* @return the new file.
*/
public static File writeFile(File dir, String name) {
public static File writeFile(final File dir, final String name) {
return writeFile(dir, name, Collections.singletonList(name));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,15 @@
package org.apache.rat.walker;

import java.io.BufferedInputStream;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.SortedSet;

import org.apache.commons.compress.archivers.ArchiveEntry;
import org.apache.commons.compress.archivers.ArchiveException;
Expand All @@ -34,9 +37,9 @@
import org.apache.commons.io.IOUtils;
import org.apache.rat.api.Document;
import org.apache.rat.api.RatException;
import org.apache.rat.document.ArchiveEntryDocument;
import org.apache.rat.document.ArchiveEntryName;
import org.apache.rat.document.DocumentName;
import org.apache.rat.document.DocumentNameMatcher;
import org.apache.rat.report.RatReport;
import org.apache.rat.utils.DefaultLog;

Expand Down Expand Up @@ -87,13 +90,29 @@ public Collection<Document> getDocuments() throws RatException {
ArchiveEntry entry;
while ((entry = input.getNextEntry()) != null) {
if (!entry.isDirectory() && input.canReadEntryData(entry)) {
DocumentName innerName = DocumentName.builder().setName(entry.getName())
final DocumentName innerName = DocumentName.builder().setName(entry.getName())
.setBaseName(".").build();
if (this.getDocument().getNameMatcher().matches(innerName)) {
final DocumentNameMatcher documentNameMatcher = getDocument().getNameMatcher();
if (documentNameMatcher.matches(innerName)) {
ArchiveEntryName entryName = new ArchiveEntryName(getDocument().getName(), entry.getName());
ByteArrayOutputStream baos = new ByteArrayOutputStream();
IOUtils.copy(input, baos);
ArchiveEntryName entryName = new ArchiveEntryName(getDocument().getName(), entry.getName());
result.add(new ArchiveEntryDocument(entryName, baos.toByteArray(), getDocument().getNameMatcher()));
result.add(new Document(entryName, documentNameMatcher) {
@Override
public InputStream inputStream() {
return new ByteArrayInputStream(baos.toByteArray());
}

@Override
public boolean isDirectory() {
return false;
}

@Override
public SortedSet<Document> listChildren() {
return Collections.emptySortedSet();
}
});
}
}
}
Expand Down
Loading
Loading