https://issues.apache.org/jira/browse/TENTACLES-1
Enhanced license and notice filters to not work on directories (thanks to Andy Gumbrecht) by factoring out a new super class.
Added UK/US-notion of license/licence to the LicenseFilter.
git-svn-id: https://svn.apache.org/repos/asf/creadur/tentacles/trunk@1614184 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/src/main/java/org/apache/creadur/tentacles/filter/LicenseFilter.java b/src/main/java/org/apache/creadur/tentacles/filter/LicenseFilter.java
index d8b35b3..eb8bf65 100644
--- a/src/main/java/org/apache/creadur/tentacles/filter/LicenseFilter.java
+++ b/src/main/java/org/apache/creadur/tentacles/filter/LicenseFilter.java
@@ -18,21 +18,8 @@
*/
package org.apache.creadur.tentacles.filter;
-import java.io.File;
-import java.io.FileFilter;
-
-final class LicenseFilter implements FileFilter {
- @Override
- public boolean accept(final File pathname) {
- final String name = pathname.getName().toLowerCase();
-
- if (name.equals("license")) {
- return true;
- }
- if (name.equals("license.txt")) {
- return true;
- }
-
- return false;
- }
+final class LicenseFilter extends ListOfFilesFilter {
+ LicenseFilter() {
+ super("license", "license.txt", "licence", "licence.txt");
+ }
}
\ No newline at end of file
diff --git a/src/main/java/org/apache/creadur/tentacles/filter/ListOfFilesFilter.java b/src/main/java/org/apache/creadur/tentacles/filter/ListOfFilesFilter.java
new file mode 100644
index 0000000..9f4f774
--- /dev/null
+++ b/src/main/java/org/apache/creadur/tentacles/filter/ListOfFilesFilter.java
@@ -0,0 +1,60 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.creadur.tentacles.filter;
+
+import java.io.File;
+import java.io.FileFilter;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+public class ListOfFilesFilter implements FileFilter {
+
+ private List<String> listOfFiles;
+
+ ListOfFilesFilter(String... files) {
+ listOfFiles = Arrays.asList(files);
+ }
+
+ @Override
+ public boolean accept(File pathname) {
+ if (pathname.isDirectory()) {
+ return false;
+ }
+
+ return listOfFiles.contains(pathname.getName().toLowerCase());
+ }
+
+ /**
+ * @return an unmodifiable list of the files to filter for.
+ */
+ public List<String> getListOfFiles() {
+ return Collections.unmodifiableList(listOfFiles);
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder builder = new StringBuilder();
+ builder.append("Filtering for one of the following file names [");
+ builder.append(listOfFiles);
+ builder.append("]");
+ return builder.toString();
+ }
+
+}
diff --git a/src/main/java/org/apache/creadur/tentacles/filter/NoticeFilter.java b/src/main/java/org/apache/creadur/tentacles/filter/NoticeFilter.java
index a3ff6e3..0333a9e 100644
--- a/src/main/java/org/apache/creadur/tentacles/filter/NoticeFilter.java
+++ b/src/main/java/org/apache/creadur/tentacles/filter/NoticeFilter.java
@@ -18,21 +18,8 @@
*/
package org.apache.creadur.tentacles.filter;
-import java.io.File;
-import java.io.FileFilter;
-
-final class NoticeFilter implements FileFilter {
- @Override
- public boolean accept(final File pathname) {
- final String name = pathname.getName().toLowerCase();
-
- if (name.equals("notice")) {
- return true;
- }
- if (name.equals("notice.txt")) {
- return true;
- }
-
- return false;
- }
+final class NoticeFilter extends ListOfFilesFilter {
+ public NoticeFilter() {
+ super("notice", "notice.txt");
+ }
}
\ No newline at end of file
diff --git a/src/test/java/org/apache/creadur/tentacles/filter/ListOfFilesFilterTest.java b/src/test/java/org/apache/creadur/tentacles/filter/ListOfFilesFilterTest.java
new file mode 100644
index 0000000..767ee30
--- /dev/null
+++ b/src/test/java/org/apache/creadur/tentacles/filter/ListOfFilesFilterTest.java
@@ -0,0 +1,16 @@
+package org.apache.creadur.tentacles.filter;
+
+import static org.junit.Assert.*;
+
+import org.junit.Test;
+
+public class ListOfFilesFilterTest {
+ @Test
+ public void testCreationAndToString() {
+ ListOfFilesFilter filter = new ListOfFilesFilter("a12", "b23", "c34");
+ String toString = filter.toString();
+ assertTrue(toString.contains("a12"));
+ assertTrue(toString.contains("b23"));
+ assertTrue(toString.contains("c34"));
+ }
+}