Skip to content

Commit

Permalink
#70 added filename comparator to Scanner and DirectoryScanner
Browse files Browse the repository at this point in the history
  • Loading branch information
hboutemy committed Aug 25, 2019
1 parent 6102699 commit 5e23866
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -26,7 +26,7 @@ limitations under the License.
</parent>

<artifactId>plexus-utils</artifactId>
<version>3.2.2-SNAPSHOT</version>
<version>3.3.0-SNAPSHOT</version>

<name>Plexus Common Utilities</name>
<description>A collection of various utility classes to ease working with strings, files, command lines, XML and
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/org/codehaus/plexus/util/AbstractScanner.java
Expand Up @@ -18,6 +18,7 @@

import java.io.File;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;

/**
Expand Down Expand Up @@ -119,6 +120,11 @@ public abstract class AbstractScanner
*/
protected boolean isCaseSensitive = true;

/**
* @since 3.3.0
*/
protected Comparator<String> filenameComparator;

/**
* Sets whether or not the file system should be regarded as case sensitive.
*
Expand Down Expand Up @@ -390,4 +396,10 @@ protected void setupMatchPatterns()
includesPatterns = MatchPatterns.from( includes );
excludesPatterns = MatchPatterns.from( excludes );
}

@Override
public void setFilenameComparator( Comparator<String> filenameComparator )
{
this.filenameComparator = filenameComparator;
}
}
6 changes: 6 additions & 0 deletions src/main/java/org/codehaus/plexus/util/DirectoryScanner.java
Expand Up @@ -57,6 +57,7 @@
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Vector;

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

if ( filenameComparator != null )
{
Arrays.sort( newfiles, filenameComparator );
}

for ( String newfile : newfiles )
{
String name = vpath + newfile;
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/org/codehaus/plexus/util/Scanner.java
Expand Up @@ -17,6 +17,7 @@
*/

import java.io.File;
import java.util.Comparator;

/**
* Scan a directory tree for files, with specified inclusions and exclusions.
Expand Down Expand Up @@ -83,4 +84,12 @@ public interface Scanner
* @return the base directory to be scanned
*/
File getBasedir();

/**
* Use a filename comparator in each directory when scanning.
*
* @param filenameComparator
* @since 3.3.0
*/
void setFilenameComparator( Comparator<String> filenameComparator );
}

0 comments on commit 5e23866

Please sign in to comment.