@@ -729,7 +729,7 @@ protected JarFile getJarFile(String jarFileUrl) throws IOException {
729
729
/**
730
730
* Find all resources in the file system of the supplied root directory that
731
731
* match the given location sub pattern via the Ant-style PathMatcher.
732
- * @param rootDirResource the root directory as Resource
732
+ * @param rootDirResource the root directory as a Resource
733
733
* @param subPattern the sub pattern to match (below the root directory)
734
734
* @return a mutable Set of matching Resource instances
735
735
* @throws IOException in case of I/O errors
@@ -738,50 +738,47 @@ protected JarFile getJarFile(String jarFileUrl) throws IOException {
738
738
protected Set <Resource > doFindPathMatchingFileResources (Resource rootDirResource , String subPattern )
739
739
throws IOException {
740
740
741
- Set <Resource > result = new HashSet <>();
741
+
742
+ URI rootDirUri = rootDirResource .getURI ();
743
+ String rootDir = rootDirUri .getRawPath ();
744
+ if (!"file" .equals (rootDirUri .getScheme ()) && rootDir .startsWith ("/" )) {
745
+ rootDir = stripLeadingSlash (rootDir );
746
+ rootDir = stripTrailingSlash (rootDir );
747
+ if (rootDir .isEmpty ()) {
748
+ rootDir = "/" ;
749
+ }
750
+ }
742
751
FileSystem fileSystem ;
743
752
try {
744
- fileSystem = FileSystems .getFileSystem (rootDirResource . getURI () .resolve ("/" ));
753
+ fileSystem = FileSystems .getFileSystem (rootDirUri .resolve ("/" ));
745
754
}
746
755
catch (Exception ex ) {
747
- fileSystem = FileSystems .newFileSystem (rootDirResource . getURI () .resolve ("/" ), Map .of (),
756
+ fileSystem = FileSystems .newFileSystem (rootDirUri .resolve ("/" ), Map .of (),
748
757
ClassUtils .getDefaultClassLoader ());
749
758
}
750
- String rootPath = rootDirResource .getURI ().getRawPath ();
751
- if (!("file" ).equals (rootDirResource .getURI ().getScheme ()) && rootPath .startsWith ("/" )) {
752
- rootPath = rootPath .substring (1 );
753
- if (rootPath .length ()==0 ) {
754
- return result ;
755
- }
756
- if (rootPath .endsWith ("/" )) {
757
- rootPath = rootPath .substring (0 , rootPath .length ()-1 );
758
- }
759
- if (rootPath .length ()==0 ) {
760
- return result ;
761
- }
762
- }
763
- Path path = fileSystem .getPath (rootPath );
764
- Path patternPath = path .resolve (subPattern );
765
- try (Stream <Path > files = Files .walk (path )) {
766
- files .forEach (file -> {
767
- if (getPathMatcher ().match (patternPath .toString (), file .toString ())) {
768
- try {
769
- result .add (convertToResource (file .toUri ()));
770
- }
771
- catch (Exception ex ) {
772
- // ignore
773
- }
759
+
760
+ Path rootPath = fileSystem .getPath (rootDir );
761
+ String resourcePattern = rootPath .resolve (subPattern ).toString ();
762
+ Predicate <Path > resourcePatternMatches = path -> getPathMatcher ().match (resourcePattern , path .toString ());
763
+ Set <Resource > result = new HashSet <>();
764
+ try (Stream <Path > files = Files .walk (rootPath )) {
765
+ files .filter (resourcePatternMatches ).sorted ().forEach (file -> {
766
+ try {
767
+ result .add (convertToResource (file .toUri ()));
768
+ }
769
+ catch (Exception ex ) {
770
+ // TODO Introduce logging
774
771
}
775
772
});
776
773
}
777
774
catch (NoSuchFileException ex ) {
778
- // ignore
775
+ // TODO Introduce logging
779
776
}
780
777
try {
781
778
fileSystem .close ();
782
779
}
783
780
catch (UnsupportedOperationException ex ) {
784
- // ignore
781
+ // TODO Introduce logging
785
782
}
786
783
return result ;
787
784
}
@@ -876,6 +873,10 @@ private static String stripLeadingSlash(String path) {
876
873
return (path .startsWith ("/" ) ? path .substring (1 ) : path );
877
874
}
878
875
876
+ private static String stripTrailingSlash (String path ) {
877
+ return (path .endsWith ("/" ) ? path .substring (0 , path .length () - 1 ) : path );
878
+ }
879
+
879
880
880
881
/**
881
882
* Inner delegate class, avoiding a hard JBoss VFS API dependency at runtime.
0 commit comments