Skip to content

Commit 5e23866

Browse files
committed
#70 added filename comparator to Scanner and DirectoryScanner
1 parent 6102699 commit 5e23866

File tree

4 files changed

+28
-1
lines changed

4 files changed

+28
-1
lines changed

pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ limitations under the License.
2626
</parent>
2727

2828
<artifactId>plexus-utils</artifactId>
29-
<version>3.2.2-SNAPSHOT</version>
29+
<version>3.3.0-SNAPSHOT</version>
3030

3131
<name>Plexus Common Utilities</name>
3232
<description>A collection of various utility classes to ease working with strings, files, command lines, XML and

src/main/java/org/codehaus/plexus/util/AbstractScanner.java

+12
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import java.io.File;
2020
import java.util.ArrayList;
21+
import java.util.Comparator;
2122
import java.util.List;
2223

2324
/**
@@ -119,6 +120,11 @@ public abstract class AbstractScanner
119120
*/
120121
protected boolean isCaseSensitive = true;
121122

123+
/**
124+
* @since 3.3.0
125+
*/
126+
protected Comparator<String> filenameComparator;
127+
122128
/**
123129
* Sets whether or not the file system should be regarded as case sensitive.
124130
*
@@ -390,4 +396,10 @@ protected void setupMatchPatterns()
390396
includesPatterns = MatchPatterns.from( includes );
391397
excludesPatterns = MatchPatterns.from( excludes );
392398
}
399+
400+
@Override
401+
public void setFilenameComparator( Comparator<String> filenameComparator )
402+
{
403+
this.filenameComparator = filenameComparator;
404+
}
393405
}

src/main/java/org/codehaus/plexus/util/DirectoryScanner.java

+6
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
import java.io.File;
5858
import java.io.IOException;
5959
import java.util.ArrayList;
60+
import java.util.Arrays;
6061
import java.util.Vector;
6162

6263
/**
@@ -436,6 +437,11 @@ protected void scandir( File dir, String vpath, boolean fast )
436437
newfiles = noLinks.toArray( new String[noLinks.size()] );
437438
}
438439

440+
if ( filenameComparator != null )
441+
{
442+
Arrays.sort( newfiles, filenameComparator );
443+
}
444+
439445
for ( String newfile : newfiles )
440446
{
441447
String name = vpath + newfile;

src/main/java/org/codehaus/plexus/util/Scanner.java

+9
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
*/
1818

1919
import java.io.File;
20+
import java.util.Comparator;
2021

2122
/**
2223
* Scan a directory tree for files, with specified inclusions and exclusions.
@@ -83,4 +84,12 @@ public interface Scanner
8384
* @return the base directory to be scanned
8485
*/
8586
File getBasedir();
87+
88+
/**
89+
* Use a filename comparator in each directory when scanning.
90+
*
91+
* @param filenameComparator
92+
* @since 3.3.0
93+
*/
94+
void setFilenameComparator( Comparator<String> filenameComparator );
8695
}

0 commit comments

Comments
 (0)