Skip to content

Commit ae2354a

Browse files
committed
Added a FileFilterUtils.makeSVNAware() taking the makeCVSAware() as a template.
git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/io/trunk@201606 13f79535-47bb-0310-9956-ffa450edef68
1 parent 4e1a5df commit ae2354a

2 files changed

Lines changed: 53 additions & 2 deletions

File tree

src/java/org/apache/commons/io/filefilter/FileFilterUtils.java

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2004 The Apache Software Foundation.
2+
* Copyright 2002-2005 The Apache Software Foundation.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -159,6 +159,9 @@ public static IOFileFilter asFileFilter(FilenameFilter filter) {
159159
/* Constructed on demand and then cached */
160160
private static IOFileFilter cvsFilter;
161161

162+
/* Constructed on demand and then cached */
163+
private static IOFileFilter svnFilter;
164+
162165
/**
163166
* Returns an IOFileFilter that ignores CVS directories. You may optionally
164167
* pass in an existing IOFileFilter in which case it is extended to exclude
@@ -180,4 +183,25 @@ public static IOFileFilter makeCVSAware(IOFileFilter filter) {
180183
}
181184
}
182185

186+
/**
187+
* Returns an IOFileFilter that ignores SVN directories. You may optionally
188+
* pass in an existing IOFileFilter in which case it is extended to exclude
189+
* SVN directories.
190+
* @param filter IOFileFilter to wrap, null if a new IOFileFilter
191+
* should be created
192+
* @return the requested (combined) filter
193+
* @since 1.1
194+
*/
195+
public static IOFileFilter makeSVNAware(IOFileFilter filter) {
196+
if (svnFilter == null) {
197+
svnFilter = notFileFilter(
198+
andFileFilter(directoryFileFilter(), nameFileFilter(".svn")));
199+
}
200+
if (filter == null) {
201+
return svnFilter;
202+
} else {
203+
return andFileFilter(filter, svnFilter);
204+
}
205+
}
206+
183207
}

src/test/org/apache/commons/io/filefilter/FileFilterTestCase.java

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2004 The Apache Software Foundation.
2+
* Copyright 2002-2005 The Apache Software Foundation.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -257,5 +257,32 @@ public void testMakeCVSAware() throws Exception {
257257
assertFiltering(filter2, file, false);
258258
}
259259

260+
public void testMakeSVNAware() throws Exception {
261+
IOFileFilter filter1 = FileFilterUtils.makeSVNAware(null);
262+
IOFileFilter filter2 = FileFilterUtils.makeSVNAware(FileFilterUtils
263+
.nameFileFilter("test-file1.txt"));
264+
265+
File file = new File(getTestDirectory(), ".svn");
266+
file.mkdirs();
267+
assertFiltering(filter1, file, false);
268+
assertFiltering(filter2, file, false);
269+
FileUtils.deleteDirectory(file);
270+
271+
file = new File(getTestDirectory(), "test-file1.txt");
272+
createFile(file, 0);
273+
assertFiltering(filter1, file, true);
274+
assertFiltering(filter2, file, true);
275+
276+
file = new File(getTestDirectory(), "test-file2.log");
277+
createFile(file, 0);
278+
assertFiltering(filter1, file, true);
279+
assertFiltering(filter2, file, false);
280+
281+
file = new File(getTestDirectory(), ".svn");
282+
createFile(file, 0);
283+
assertFiltering(filter1, file, true);
284+
assertFiltering(filter2, file, false);
285+
}
286+
260287
}
261288

0 commit comments

Comments
 (0)