RAT-240: Unify handling of exclusion parsing
* Use same method from exclusionFile and as parameter to define excludes
git-svn-id: https://svn.apache.org/repos/asf/creadur/rat/trunk@1811509 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/apache-rat-core/src/main/java/org/apache/rat/Report.java b/apache-rat-core/src/main/java/org/apache/rat/Report.java
index ec610c8..47b606c 100644
--- a/apache-rat-core/src/main/java/org/apache/rat/Report.java
+++ b/apache-rat-core/src/main/java/org/apache/rat/Report.java
@@ -33,6 +33,7 @@
import javax.xml.transform.TransformerConfigurationException;
import java.io.*;
+import java.util.Arrays;
import java.util.List;
import java.util.regex.PatternSyntaxException;
@@ -78,7 +79,7 @@
if (cl.hasOption(EXCLUDE_CLI)) {
String[] excludes = cl.getOptionValues(EXCLUDE_CLI);
if (excludes != null) {
- final FilenameFilter filter = new NotFileFilter(new WildcardFileFilter(excludes));
+ final FilenameFilter filter = parseExclusions(Arrays.asList(excludes));
report.setInputFileFilter(filter);
}
} else if (cl.hasOption(EXCLUDE_FILE_CLI)) {
@@ -114,7 +115,7 @@
}
}
- private static FilenameFilter parseExclusions(List<String> excludes) throws IOException {
+ static FilenameFilter parseExclusions(List<String> excludes) throws IOException {
final OrFileFilter orFilter = new OrFileFilter();
for (String exclude : excludes) {
try {
@@ -216,7 +217,7 @@
return opts;
}
- private static final void printUsage(Options opts) {
+ private static void printUsage(Options opts) {
HelpFormatter f = new HelpFormatter();
String header = "Options";
@@ -244,15 +245,6 @@
}
/**
- * Gets the current filter used to select files.
- *
- * @return current file filter, or null when no filter has been set
- */
- public FilenameFilter getInputFileFilter() {
- return inputFileFilter;
- }
-
- /**
* Sets the current filter used to select files.
*
* @param inputFileFilter filter, or null when no filter has been set
diff --git a/apache-rat-core/src/test/java/org/apache/rat/ReportTest.java b/apache-rat-core/src/test/java/org/apache/rat/ReportTest.java
index bccab10..8468a8e 100644
--- a/apache-rat-core/src/test/java/org/apache/rat/ReportTest.java
+++ b/apache-rat-core/src/test/java/org/apache/rat/ReportTest.java
@@ -24,9 +24,13 @@
import org.junit.Test;
import java.io.File;
+import java.io.FilenameFilter;
+import java.io.IOException;
import java.io.StringWriter;
+import java.util.Arrays;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
public class ReportTest {
@@ -130,4 +134,10 @@
elementsReports,
result.substring(generatedAtLineEnd + NL.length()));
}
+
+ @Test
+ public void parseExclusionsForCLIUsage() throws IOException {
+ final FilenameFilter filter = Report.parseExclusions(Arrays.asList("foo", "foo/bar"));
+ assertNotNull(filter);
+ }
}