Skip to content

Commit d6ca819

Browse files
committed
Add SymbolicLinkFileFilter.
Next release is 2.11.0 due to semantic versioning.
1 parent 807b46a commit d6ca819

4 files changed

Lines changed: 150 additions & 8 deletions

File tree

pom.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
<modelVersion>4.0.0</modelVersion>
2525
<groupId>commons-io</groupId>
2626
<artifactId>commons-io</artifactId>
27-
<version>2.10.1-SNAPSHOT</version>
27+
<version>2.11.0-SNAPSHOT</version>
2828
<name>Apache Commons IO</name>
2929

3030
<inceptionYear>2002</inceptionYear>
@@ -52,7 +52,7 @@ file comparators, endian transformation classes, and much more.
5252
<connection>scm:git:https://gitbox.apache.org/repos/asf/commons-io.git</connection>
5353
<developerConnection>scm:git:https://gitbox.apache.org/repos/asf/commons-io.git</developerConnection>
5454
<url>https://gitbox.apache.org/repos/asf?p=commons-io.git</url>
55-
<tag>rel/commons-io-2.10.0</tag>
55+
<tag>rel/commons-io-2.11.0</tag>
5656
</scm>
5757

5858
<developers>
@@ -291,8 +291,8 @@ file comparators, endian transformation classes, and much more.
291291
<commons.componentid>io</commons.componentid>
292292
<commons.module.name>org.apache.commons.io</commons.module.name>
293293
<commons.rc.version>RC1</commons.rc.version>
294-
<commons.bc.version>2.9.0</commons.bc.version>
295-
<commons.release.version>2.10.0</commons.release.version>
294+
<commons.bc.version>2.10.0</commons.bc.version>
295+
<commons.release.version>2.11.0</commons.release.version>
296296
<commons.release.desc>(requires Java 8)</commons.release.desc>
297297
<commons.jira.id>IO</commons.jira.id>
298298
<commons.jira.pid>12310477</commons.jira.pid>

src/changes/changes.xml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,22 @@ The <action> type attribute can be add,update,fix,remove.
4545
</properties>
4646

4747
<body>
48-
<release version="2.10.1" date="2021-MM-DD" description="Java 8 required.">
48+
<release version="2.11.0" date="2021-MM-DD" description="Java 8 required.">
4949
<!-- FIX -->
5050
<action dev="ggregory" type="fix" due-to="Arturo Bernal">
5151
Minor changes #243.
5252
</action>
53+
<action issue="IO-724" dev="ggregory" type="fix" due-to="liran2000">
54+
FileUtils#deleteDirectory(File) exception Javadoc inaccurate update #245.
55+
</action>
56+
<!-- ADD -->
57+
<action dev="ggregory" type="update" due-to="Gary Gregory">
58+
Add SymbolicLinkFileFilter.
59+
</action>
60+
<!-- UPDATE -->
5361
<action dev="ggregory" type="update" due-to="Dependabot">
5462
Bump mockito-inline from 3.11.0 to 3.11.2 #247.
5563
</action>
56-
<action issue="IO-724" dev="ggregory" type="update" due-to="liran2000">
57-
FileUtils#deleteDirectory(File) exception Javadoc inaccurate update #245.
58-
</action>
5964
</release>
6065
<!-- The release date is the date RC is cut -->
6166
<release version="2.10.0" date="2021-06-10" description="Java 8 required.">
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.apache.commons.io.filefilter;
18+
19+
import java.io.File;
20+
import java.io.Serializable;
21+
import java.nio.file.FileVisitResult;
22+
import java.nio.file.Files;
23+
import java.nio.file.Path;
24+
import java.nio.file.attribute.BasicFileAttributes;
25+
26+
/**
27+
* This filter accepts {@code File}s that are symbolic links.
28+
* <p>
29+
* For example, here is how to print out a list of the real files
30+
* within the current directory:
31+
* </p>
32+
* <h2>Using Classic IO</h2>
33+
* <pre>
34+
* File dir = new File(".");
35+
* String[] files = dir.list(SymbolicLinkFileFilter.INSTANCE);
36+
* for (String file : files) {
37+
* System.out.println(file);
38+
* }
39+
* </pre>
40+
*
41+
* <h2>Using NIO</h2>
42+
* <pre>
43+
* final Path dir = Paths.get("");
44+
* final AccumulatorPathVisitor visitor = AccumulatorPathVisitor.withLongCounters(SymbolicLinkFileFilter.FILE);
45+
* //
46+
* // Walk one dir
47+
* Files.<b>walkFileTree</b>(dir, Collections.emptySet(), 1, visitor);
48+
* System.out.println(visitor.getPathCounters());
49+
* System.out.println(visitor.getFileList());
50+
* //
51+
* visitor.getPathCounters().reset();
52+
* //
53+
* // Walk dir tree
54+
* Files.<b>walkFileTree</b>(dir, visitor);
55+
* System.out.println(visitor.getPathCounters());
56+
* System.out.println(visitor.getDirList());
57+
* System.out.println(visitor.getFileList());
58+
* </pre>
59+
*
60+
* @since 2.11.0
61+
* @see FileFilterUtils#fileFileFilter()
62+
*/
63+
public class SymbolicLinkFileFilter extends AbstractFileFilter implements Serializable {
64+
65+
/**
66+
* Singleton instance of file filter.
67+
*/
68+
public static final SymbolicLinkFileFilter INSTANCE = new SymbolicLinkFileFilter();
69+
70+
private static final long serialVersionUID = 1L;
71+
72+
/**
73+
* Restrictive constructor.
74+
*/
75+
protected SymbolicLinkFileFilter() {
76+
}
77+
78+
/**
79+
* Checks to see if the file is a file.
80+
*
81+
* @param file the File to check
82+
* @return true if the file is a file
83+
*/
84+
@Override
85+
public boolean accept(final File file) {
86+
return file.isFile();
87+
}
88+
89+
/**
90+
* Checks to see if the file is a file.
91+
* @param file the File to check
92+
*
93+
* @return true if the file is a file
94+
*/
95+
@Override
96+
public FileVisitResult accept(final Path file, final BasicFileAttributes attributes) {
97+
return toFileVisitResult(Files.isSymbolicLink(file), file);
98+
}
99+
100+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.commons.io.filefilter;
19+
20+
import static org.junit.jupiter.api.Assertions.assertEquals;
21+
22+
import java.nio.file.FileVisitResult;
23+
24+
import org.apache.commons.io.file.PathUtils;
25+
import org.junit.jupiter.api.Test;
26+
27+
/**
28+
* Tests {@link SymbolicLinkFileFilter}.
29+
*/
30+
public class SymbolicLinkFileFilterTest {
31+
32+
@Test
33+
public void testSymbolicLinkFileFilter() {
34+
assertEquals(FileVisitResult.TERMINATE, SymbolicLinkFileFilter.INSTANCE.accept(PathUtils.current(), null));
35+
36+
}
37+
}

0 commit comments

Comments
 (0)