This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-io.git


The following commit(s) were added to refs/heads/master by this push:
     new d6ca819  Add SymbolicLinkFileFilter.
d6ca819 is described below

commit d6ca8197ce8a3c7b5947ca4ac50a474995d66d76
Author: Gary Gregory <garydgreg...@gmail.com>
AuthorDate: Wed Jun 30 09:22:18 2021 -0400

    Add SymbolicLinkFileFilter.
    
    Next release is 2.11.0 due to semantic versioning.
---
 pom.xml                                            |   8 +-
 src/changes/changes.xml                            |  13 ++-
 .../io/filefilter/SymbolicLinkFileFilter.java      | 100 +++++++++++++++++++++
 .../io/filefilter/SymbolicLinkFileFilterTest.java  |  37 ++++++++
 4 files changed, 150 insertions(+), 8 deletions(-)

diff --git a/pom.xml b/pom.xml
index 9f89f63..2448f15 100644
--- a/pom.xml
+++ b/pom.xml
@@ -24,7 +24,7 @@
   <modelVersion>4.0.0</modelVersion>
   <groupId>commons-io</groupId>
   <artifactId>commons-io</artifactId>
-  <version>2.10.1-SNAPSHOT</version>
+  <version>2.11.0-SNAPSHOT</version>
   <name>Apache Commons IO</name>
 
   <inceptionYear>2002</inceptionYear>
@@ -52,7 +52,7 @@ file comparators, endian transformation classes, and much 
more.
     
<connection>scm:git:https://gitbox.apache.org/repos/asf/commons-io.git</connection>
     
<developerConnection>scm:git:https://gitbox.apache.org/repos/asf/commons-io.git</developerConnection>
     <url>https://gitbox.apache.org/repos/asf?p=commons-io.git</url>
-    <tag>rel/commons-io-2.10.0</tag>
+    <tag>rel/commons-io-2.11.0</tag>
   </scm>
 
   <developers>
@@ -291,8 +291,8 @@ file comparators, endian transformation classes, and much 
more.
     <commons.componentid>io</commons.componentid>
     <commons.module.name>org.apache.commons.io</commons.module.name>
     <commons.rc.version>RC1</commons.rc.version>
-    <commons.bc.version>2.9.0</commons.bc.version>
-    <commons.release.version>2.10.0</commons.release.version>
+    <commons.bc.version>2.10.0</commons.bc.version>
+    <commons.release.version>2.11.0</commons.release.version>
     <commons.release.desc>(requires Java 8)</commons.release.desc>
     <commons.jira.id>IO</commons.jira.id>
     <commons.jira.pid>12310477</commons.jira.pid>
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 505aaa9..1c10cc3 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -45,17 +45,22 @@ The <action> type attribute can be add,update,fix,remove.
   </properties>
 
   <body>
-    <release version="2.10.1" date="2021-MM-DD" description="Java 8 required.">
+    <release version="2.11.0" date="2021-MM-DD" description="Java 8 required.">
       <!-- FIX -->
       <action dev="ggregory" type="fix" due-to="Arturo Bernal">
         Minor changes #243.
       </action>
+      <action issue="IO-724" dev="ggregory" type="fix" due-to="liran2000">
+        FileUtils#deleteDirectory(File) exception Javadoc inaccurate update 
#245.
+      </action>
+      <!-- ADD -->
+      <action dev="ggregory" type="update" due-to="Gary Gregory">
+        Add SymbolicLinkFileFilter. 
+      </action>
+      <!-- UPDATE -->
       <action dev="ggregory" type="update" due-to="Dependabot">
         Bump mockito-inline from 3.11.0 to 3.11.2 #247. 
       </action>
-      <action issue="IO-724" dev="ggregory" type="update" due-to="liran2000">
-        FileUtils#deleteDirectory(File) exception Javadoc inaccurate update 
#245.
-      </action>
     </release>
     <!-- The release date is the date RC is cut -->
     <release version="2.10.0" date="2021-06-10" description="Java 8 required.">
diff --git 
a/src/main/java/org/apache/commons/io/filefilter/SymbolicLinkFileFilter.java 
b/src/main/java/org/apache/commons/io/filefilter/SymbolicLinkFileFilter.java
new file mode 100644
index 0000000..3697766
--- /dev/null
+++ b/src/main/java/org/apache/commons/io/filefilter/SymbolicLinkFileFilter.java
@@ -0,0 +1,100 @@
+/*
+ * 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.commons.io.filefilter;
+
+import java.io.File;
+import java.io.Serializable;
+import java.nio.file.FileVisitResult;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.attribute.BasicFileAttributes;
+
+/**
+ * This filter accepts {@code File}s that are symbolic links.
+ * <p>
+ * For example, here is how to print out a list of the real files
+ * within the current directory:
+ * </p>
+ * <h2>Using Classic IO</h2>
+ * <pre>
+ * File dir = new File(".");
+ * String[] files = dir.list(SymbolicLinkFileFilter.INSTANCE);
+ * for (String file : files) {
+ *     System.out.println(file);
+ * }
+ * </pre>
+ *
+ * <h2>Using NIO</h2>
+ * <pre>
+ * final Path dir = Paths.get("");
+ * final AccumulatorPathVisitor visitor = 
AccumulatorPathVisitor.withLongCounters(SymbolicLinkFileFilter.FILE);
+ * //
+ * // Walk one dir
+ * Files.<b>walkFileTree</b>(dir, Collections.emptySet(), 1, visitor);
+ * System.out.println(visitor.getPathCounters());
+ * System.out.println(visitor.getFileList());
+ * //
+ * visitor.getPathCounters().reset();
+ * //
+ * // Walk dir tree
+ * Files.<b>walkFileTree</b>(dir, visitor);
+ * System.out.println(visitor.getPathCounters());
+ * System.out.println(visitor.getDirList());
+ * System.out.println(visitor.getFileList());
+ * </pre>
+ *
+ * @since 2.11.0
+ * @see FileFilterUtils#fileFileFilter()
+ */
+public class SymbolicLinkFileFilter extends AbstractFileFilter implements 
Serializable {
+
+    /**
+     * Singleton instance of file filter.
+     */
+    public static final SymbolicLinkFileFilter INSTANCE = new 
SymbolicLinkFileFilter();
+
+    private static final long serialVersionUID = 1L;
+
+    /**
+     * Restrictive constructor.
+     */
+    protected SymbolicLinkFileFilter() {
+    }
+
+    /**
+     * Checks to see if the file is a file.
+     *
+     * @param file  the File to check
+     * @return true if the file is a file
+     */
+    @Override
+    public boolean accept(final File file) {
+        return file.isFile();
+    }
+
+    /**
+     * Checks to see if the file is a file.
+     * @param file  the File to check
+     *
+     * @return true if the file is a file
+     */
+    @Override
+    public FileVisitResult accept(final Path file, final BasicFileAttributes 
attributes) {
+        return toFileVisitResult(Files.isSymbolicLink(file), file);
+    }
+
+}
diff --git 
a/src/test/java/org/apache/commons/io/filefilter/SymbolicLinkFileFilterTest.java
 
b/src/test/java/org/apache/commons/io/filefilter/SymbolicLinkFileFilterTest.java
new file mode 100644
index 0000000..786a952
--- /dev/null
+++ 
b/src/test/java/org/apache/commons/io/filefilter/SymbolicLinkFileFilterTest.java
@@ -0,0 +1,37 @@
+/*
+ * 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.commons.io.filefilter;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import java.nio.file.FileVisitResult;
+
+import org.apache.commons.io.file.PathUtils;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Tests {@link SymbolicLinkFileFilter}.
+ */
+public class SymbolicLinkFileFilterTest {
+
+    @Test
+    public void testSymbolicLinkFileFilter() {
+        assertEquals(FileVisitResult.TERMINATE, 
SymbolicLinkFileFilter.INSTANCE.accept(PathUtils.current(), null));
+
+    }
+}

Reply via email to