creadur-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pottlin...@apache.org
Subject svn commit: r1614184 - in /creadur/tentacles/trunk/src: main/java/org/apache/creadur/tentacles/filter/ test/ test/java/ test/java/org/ test/java/org/apache/ test/java/org/apache/creadur/ test/java/org/apache/creadur/tentacles/ test/java/org/apache/crea...
Date Mon, 28 Jul 2014 21:23:52 GMT
Author: pottlinger
Date: Mon Jul 28 21:23:51 2014
New Revision: 1614184

URL: http://svn.apache.org/r1614184
Log:
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.

Added:
    creadur/tentacles/trunk/src/main/java/org/apache/creadur/tentacles/filter/ListOfFilesFilter.java
    creadur/tentacles/trunk/src/test/
    creadur/tentacles/trunk/src/test/java/
    creadur/tentacles/trunk/src/test/java/org/
    creadur/tentacles/trunk/src/test/java/org/apache/
    creadur/tentacles/trunk/src/test/java/org/apache/creadur/
    creadur/tentacles/trunk/src/test/java/org/apache/creadur/tentacles/
    creadur/tentacles/trunk/src/test/java/org/apache/creadur/tentacles/filter/
    creadur/tentacles/trunk/src/test/java/org/apache/creadur/tentacles/filter/ListOfFilesFilterTest.java
Modified:
    creadur/tentacles/trunk/src/main/java/org/apache/creadur/tentacles/filter/LicenseFilter.java
    creadur/tentacles/trunk/src/main/java/org/apache/creadur/tentacles/filter/NoticeFilter.java

Modified: creadur/tentacles/trunk/src/main/java/org/apache/creadur/tentacles/filter/LicenseFilter.java
URL: http://svn.apache.org/viewvc/creadur/tentacles/trunk/src/main/java/org/apache/creadur/tentacles/filter/LicenseFilter.java?rev=1614184&r1=1614183&r2=1614184&view=diff
==============================================================================
--- creadur/tentacles/trunk/src/main/java/org/apache/creadur/tentacles/filter/LicenseFilter.java
(original)
+++ creadur/tentacles/trunk/src/main/java/org/apache/creadur/tentacles/filter/LicenseFilter.java
Mon Jul 28 21:23:51 2014
@@ -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

Added: creadur/tentacles/trunk/src/main/java/org/apache/creadur/tentacles/filter/ListOfFilesFilter.java
URL: http://svn.apache.org/viewvc/creadur/tentacles/trunk/src/main/java/org/apache/creadur/tentacles/filter/ListOfFilesFilter.java?rev=1614184&view=auto
==============================================================================
--- creadur/tentacles/trunk/src/main/java/org/apache/creadur/tentacles/filter/ListOfFilesFilter.java
(added)
+++ creadur/tentacles/trunk/src/main/java/org/apache/creadur/tentacles/filter/ListOfFilesFilter.java
Mon Jul 28 21:23:51 2014
@@ -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();
+	}
+
+}

Modified: creadur/tentacles/trunk/src/main/java/org/apache/creadur/tentacles/filter/NoticeFilter.java
URL: http://svn.apache.org/viewvc/creadur/tentacles/trunk/src/main/java/org/apache/creadur/tentacles/filter/NoticeFilter.java?rev=1614184&r1=1614183&r2=1614184&view=diff
==============================================================================
--- creadur/tentacles/trunk/src/main/java/org/apache/creadur/tentacles/filter/NoticeFilter.java
(original)
+++ creadur/tentacles/trunk/src/main/java/org/apache/creadur/tentacles/filter/NoticeFilter.java
Mon Jul 28 21:23:51 2014
@@ -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

Added: creadur/tentacles/trunk/src/test/java/org/apache/creadur/tentacles/filter/ListOfFilesFilterTest.java
URL: http://svn.apache.org/viewvc/creadur/tentacles/trunk/src/test/java/org/apache/creadur/tentacles/filter/ListOfFilesFilterTest.java?rev=1614184&view=auto
==============================================================================
--- creadur/tentacles/trunk/src/test/java/org/apache/creadur/tentacles/filter/ListOfFilesFilterTest.java
(added)
+++ creadur/tentacles/trunk/src/test/java/org/apache/creadur/tentacles/filter/ListOfFilesFilterTest.java
Mon Jul 28 21:23:51 2014
@@ -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"));
+	}
+}



Mime
View raw message