Skip to content

Commit

Permalink
removed special handling for *.json, fixed path issues on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
Claudenw committed Apr 29, 2024
1 parent 9aedf3c commit d8c999e
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 24 deletions.
3 changes: 2 additions & 1 deletion apache-rat-core/src/main/java/org/apache/rat/Defaults.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.util.TreeSet;

import org.apache.commons.io.IOCase;
import org.apache.commons.io.filefilter.FalseFileFilter;
import org.apache.commons.io.filefilter.IOFileFilter;
import org.apache.commons.io.filefilter.WildcardFileFilter;
import org.apache.commons.io.function.IOSupplier;
Expand Down Expand Up @@ -66,7 +67,7 @@ public class Defaults {

private final LicenseSetFactory setFactory;

private static final FilenameFilter FILES_TO_IGNORE = WildcardFileFilter.builder().setWildcards("*.json").setIoCase(IOCase.INSENSITIVE).get();
private static final FilenameFilter FILES_TO_IGNORE = FalseFileFilter.FALSE;

private static final IOFileFilter DIRECTORIES_TO_IGNORE = NameBasedHiddenFileFilter.HIDDEN;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,6 @@ public class TikaProcessor {
documentTypeMap.put("image/svg+xml", Document.Type.STANDARD);
// org.apache.tika.parser.xml.FictionBookParser
documentTypeMap.put("application/x-fictionbook+xml", Document.Type.STANDARD);

documentTypeMap.put("application/json", Document.Type.STANDARD);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ public void filesToIgnoreTest() {

underTest.setFrom(Defaults.builder().build(DefaultLog.INSTANCE));
assertThat(underTest.getFilesToIgnore()).isNotNull();
assertThat(underTest.getFilesToIgnore()).isExactlyInstanceOf(WildcardFileFilter.class);
assertThat(underTest.getFilesToIgnore()).isExactlyInstanceOf(FalseFileFilter.class);

FilenameFilter filter = mock(FilenameFilter.class);
underTest.setFilesToIgnore(filter);
Expand Down Expand Up @@ -562,7 +562,7 @@ public static void validateDefault(ReportConfiguration config) {
assertThat(config.isAddingLicenses()).isFalse();
assertThat(config.isAddingLicensesForced()).isFalse();
assertThat(config.getCopyrightMessage()).isNull();
assertThat(config.getFilesToIgnore().toString()).isEqualTo(WildcardFileFilter.builder().setWildcards("*.json").setIoCase(IOCase.INSENSITIVE).get().toString());
assertThat(config.getFilesToIgnore()).isExactlyInstanceOf(FalseFileFilter.class);
assertThat(config.isStyleReport()).isTrue();
assertThat(config.getStyleSheet()).isNotNull().withFailMessage("Stylesheet should not be null");
assertThat(config.getDirectoriesToIgnore()).isNotNull().withFailMessage("Directory filter should not be null");
Expand Down
4 changes: 2 additions & 2 deletions apache-rat-core/src/test/java/org/apache/rat/ReportTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public void testDefaultOutput() throws Exception {
assertTrue(output.exists());
String content = FileUtils.readFileToString(output, StandardCharsets.UTF_8);
TextUtils.assertPatternInOutput("Notes: 2$", content);
TextUtils.assertPatternInOutput("Binaries: 1$", content);
TextUtils.assertPatternInOutput("Binaries: 2$", content);
TextUtils.assertPatternInOutput("Archives: 1$", content);
TextUtils.assertPatternInOutput("Standards: 8$", content);
TextUtils.assertPatternInOutput("Apache Licensed: 5$", content);
Expand Down Expand Up @@ -156,7 +156,7 @@ public void testXMLOutput() throws Exception {
assertEquals(1, nodeList.getLength());

nodeList = XmlUtils.getNodeList(doc, xPath, "/rat-report/resource[@type='BINARY']");
assertEquals(1, nodeList.getLength());
assertEquals(2, nodeList.getLength());

nodeList = XmlUtils.getNodeList(doc, xPath, "/rat-report/resource[@type='GENERATED']");
assertEquals(1, nodeList.getLength());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public void xmlReportTest() throws Exception {
checkNode(doc, xPath, "src/test/resources/elements/generated.txt", new LicenseInfo("GEN", true, true),
"GENERATED", false);
NodeList nodeList = (NodeList) xPath.compile("/rat-report/resource").evaluate(doc, XPathConstants.NODESET);
assertEquals(13, nodeList.getLength());
assertEquals(14, nodeList.getLength());
}

private static final String NL = System.lineSeparator();
Expand Down Expand Up @@ -161,7 +161,7 @@ public void plainReportTest() throws Exception {
assertTrue(document.startsWith(HEADER), "'Generated at' is not present in " + document);

TextUtils.assertPatternInOutput("^Notes: 2$", document);
TextUtils.assertPatternInOutput("^Binaries: 1$", document);
TextUtils.assertPatternInOutput("^Binaries: 2$", document);
TextUtils.assertPatternInOutput("^Archives: 1$", document);
TextUtils.assertPatternInOutput("^Standards: 8$", document);
TextUtils.assertPatternInOutput("^Apache Licensed: 5$", document);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public void testTikaFiles() throws RatDocumentAnalysisException, IOException {
for (File file : Objects.requireNonNull(typeDir.listFiles())) {
Document doc = new FileDocument(file);
String mimeType = TikaProcessor.process(DefaultLog.INSTANCE, doc);
assertEquals( docType, doc.getMetaData().getDocumentType());
assertEquals( docType, doc.getMetaData().getDocumentType(), () -> "Wrong type for "+file.toString());
unseenMime.remove(mimeType);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public void standardReport() throws Exception {
"Preamble and document element are OK");

assertTrue(XmlUtils.isWellFormedXml(output), "Is well formed");
assertEquals(1, statistic.getCounter(Document.Type.BINARY), "Binary files");
assertEquals(2, statistic.getCounter(Document.Type.BINARY), "Binary files");
assertEquals(2, statistic.getCounter(Document.Type.NOTICE), "Notice files");
assertEquals(8, statistic.getCounter(Document.Type.STANDARD), "Standard files");
assertEquals(1, statistic.getCounter(Document.Type.ARCHIVE), "Archives");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;

Expand Down Expand Up @@ -70,18 +71,20 @@ public static void setUp(@TempDir File dir) throws Exception {
fileWriter(hidden, ".hiddenFile", "hidden file");
}

private String expectedName(String name) {
return toWalk.toString()+name;
private String expectedName(String[] name) {
return toWalk.toString()+File.separator+name[0]+File.separator+name[1];
}



@Test
public void noFiltersTest() throws IOException, RatException {
DirectoryWalker walker = new DirectoryWalker(toWalk, null,null);
List<String> scanned = new ArrayList<>();
walker.run(new TestRatReport(scanned));
String[] expected = {"/regular/regularFile", "/regular/.hiddenFile", "/.hidden/regularFile", "/.hidden/.hiddenFile"};
String[][] expected = {{"regular", "regularFile"}, {"regular", ".hiddenFile"}, {".hidden", "regularFile"}, {".hidden", ".hiddenFile"}};
assertEquals(4, scanned.size());
for (String ex : expected) {
for (String[] ex : expected) {
assertTrue(scanned.contains(expectedName(ex)), ()-> String.format("Missing %s (%s)",ex, expectedName(ex)));
}
}
Expand All @@ -91,10 +94,10 @@ public void noHiddenFileFiltersTest() throws IOException, RatException {
DirectoryWalker walker = new DirectoryWalker(toWalk, NameBasedHiddenFileFilter.HIDDEN,null);
List<String> scanned = new ArrayList<>();
walker.run(new TestRatReport(scanned));
String[] expected = {"/regular/regularFile", "/.hidden/regularFile"};
String[][] expected = {{"regular", "regularFile"}, {".hidden", "regularFile"}};
assertEquals(2, scanned.size());
for (String ex : expected) {
assertTrue(scanned.contains(expectedName(ex)), ()-> String.format("Missing %s (%s)",ex, expectedName(ex)));
for (String ex[] : expected) {
assertTrue(scanned.contains(expectedName(ex)), ()-> String.format("Missing %s", expectedName(ex)));
}
}

Expand All @@ -103,10 +106,10 @@ public void noHiddenDirectoryFiltersTest() throws IOException, RatException {
DirectoryWalker walker = new DirectoryWalker(toWalk, null, NameBasedHiddenFileFilter.HIDDEN);
List<String> scanned = new ArrayList<>();
walker.run(new TestRatReport(scanned));
String[] expected = {"/regular/regularFile", "/regular/.hiddenFile"};
String[][] expected = {{"regular", "regularFile"}, {"regular", ".hiddenFile"}};
assertEquals(2, scanned.size());
for (String ex : expected) {
assertTrue(scanned.contains(expectedName(ex)), ()-> String.format("Missing %s (%s)",ex, expectedName(ex)));
for (String[] ex : expected) {
assertTrue(scanned.contains(expectedName(ex)), ()-> String.format("Missing %s", expectedName(ex)));
}
}

Expand All @@ -115,10 +118,10 @@ public void noHiddenDirectoryAndNoHiddenFileFiltersTest() throws IOException, Ra
DirectoryWalker walker = new DirectoryWalker(toWalk, NameBasedHiddenFileFilter.HIDDEN, NameBasedHiddenFileFilter.HIDDEN);
List<String> scanned = new ArrayList<>();
walker.run(new TestRatReport(scanned));
String[] expected = {"/regular/regularFile"};
String[][] expected = {{"regular", "regularFile"}};
assertEquals(1, scanned.size());
for (String ex : expected) {
assertTrue(scanned.contains(expectedName(ex)), ()-> String.format("Missing %s (%s)",ex, expectedName(ex)));
for (String[] ex : expected) {
assertTrue(scanned.contains(expectedName(ex)), ()-> String.format("Missing %s", expectedName(ex)));
}
}

Expand Down

0 comments on commit d8c999e

Please sign in to comment.