@@ -100,13 +100,94 @@ void usingClasspathStarProtocol() {
100
100
}
101
101
102
102
@ Test
103
- void usingFileProtocol () {
103
+ void usingClasspathStarProtocolWithWildcardInPatternAndNotEndingInSlash () throws Exception {
104
+ String pattern = "classpath*:org/springframework/core/io/sup*" ;
105
+ String pathPrefix = ".+org/springframework/core/io/" ;
106
+
107
+ List <String > actualSubPaths = getSubPathsIgnoringClassFiles (pattern , pathPrefix );
108
+
109
+ // We DO find "support" if the pattern does NOT end with a slash.
110
+ assertThat (actualSubPaths ).containsExactly ("support" );
111
+ }
112
+
113
+ @ Test
114
+ void usingFileProtocolWithWildcardInPatternAndNotEndingInSlash () throws Exception {
115
+ Path testResourcesDir = Paths .get ("src/test/resources" ).toAbsolutePath ();
116
+ String pattern = String .format ("file:%s/org/springframework/core/io/sup*" , testResourcesDir );
117
+ String pathPrefix = ".+org/springframework/core/io/" ;
118
+
119
+ List <String > actualSubPaths = getSubPathsIgnoringClassFiles (pattern , pathPrefix );
120
+
121
+ // We DO find "support" if the pattern does NOT end with a slash.
122
+ assertThat (actualSubPaths ).containsExactly ("support" );
123
+ }
124
+
125
+ @ Test
126
+ void usingClasspathStarProtocolWithWildcardInPatternAndEndingInSlash () throws Exception {
127
+ String pattern = "classpath*:org/springframework/core/io/sup*/" ;
128
+ String pathPrefix = ".+org/springframework/core/io/" ;
129
+
130
+ List <String > actualSubPaths = getSubPathsIgnoringClassFiles (pattern , pathPrefix );
131
+
132
+ // We do NOT find "support" if the pattern ENDS with a slash.
133
+ assertThat (actualSubPaths ).isEmpty ();
134
+ }
135
+
136
+ @ Test
137
+ void usingFileProtocolWithWildcardInPatternAndEndingInSlash () throws Exception {
138
+ Path testResourcesDir = Paths .get ("src/test/resources" ).toAbsolutePath ();
139
+ String pattern = String .format ("file:%s/org/springframework/core/io/sup*/" , testResourcesDir );
140
+ String pathPrefix = ".+org/springframework/core/io/" ;
141
+
142
+ List <String > actualSubPaths = getSubPathsIgnoringClassFiles (pattern , pathPrefix );
143
+
144
+ // We do NOT find "support" if the pattern ENDS with a slash.
145
+ assertThat (actualSubPaths ).isEmpty ();
146
+ }
147
+
148
+ @ Test
149
+ void usingClasspathStarProtocolWithWildcardInPatternAndEndingWithSlashStarStar () throws Exception {
150
+ String pattern = "classpath*:org/springframework/core/io/sup*/**" ;
151
+ String pathPrefix = ".+org/springframework/core/io/" ;
152
+
153
+ List <String > actualSubPaths = getSubPathsIgnoringClassFiles (pattern , pathPrefix );
154
+
155
+ // We DO find "support" if the pattern ENDS with "/**".
156
+ assertThat (actualSubPaths )
157
+ .containsExactlyInAnyOrder ("support" , "support/resource#test1.txt" , "support/resource#test2.txt" );
158
+ }
159
+
160
+ private List <String > getSubPathsIgnoringClassFiles (String pattern , String pathPrefix ) throws IOException {
161
+ return Arrays .stream (resolver .getResources (pattern ))
162
+ .map (resource -> getPath (resource ).replaceFirst (pathPrefix , "" ))
163
+ .filter (name -> !name .endsWith (".class" ))
164
+ .distinct ()
165
+ .sorted ()
166
+ .collect (Collectors .toList ());
167
+ }
168
+
169
+ @ Test
170
+ void usingFileProtocolWithoutWildcardInPatternAndEndingInSlashStarStar () throws Exception {
104
171
Path testResourcesDir = Paths .get ("src/test/resources" ).toAbsolutePath ();
105
172
String pattern = String .format ("file:%s/scanned-resources/**" , testResourcesDir );
106
- String pathPrefix = ".+scanned- resources/" ;
173
+ String pathPrefix = ".+? resources/" ;
107
174
175
+ // We do NOT find "scanned-resources" if the pattern ENDS with "/**" AND does NOT otherwise contain a wildcard.
108
176
assertExactFilenames (pattern , "resource#test1.txt" , "resource#test2.txt" );
109
- assertExactSubPaths (pattern , pathPrefix , "resource#test1.txt" , "resource#test2.txt" );
177
+ assertExactSubPaths (pattern , pathPrefix , "scanned-resources/resource#test1.txt" ,
178
+ "scanned-resources/resource#test2.txt" );
179
+ }
180
+
181
+ @ Test
182
+ void usingFileProtocolWithWildcardInPatternAndEndingInSlashStarStar () throws Exception {
183
+ Path testResourcesDir = Paths .get ("src/test/resources" ).toAbsolutePath ();
184
+ String pattern = String .format ("file:%s/scanned*resources/**" , testResourcesDir );
185
+ String pathPrefix = ".+?resources/" ;
186
+
187
+ // We DO find "scanned-resources" if the pattern ENDS with "/**" AND DOES otherwise contain a wildcard.
188
+ assertExactFilenames (pattern , "scanned-resources" , "resource#test1.txt" , "resource#test2.txt" );
189
+ assertExactSubPaths (pattern , pathPrefix , "scanned-resources" , "scanned-resources/resource#test1.txt" ,
190
+ "scanned-resources/resource#test2.txt" );
110
191
}
111
192
112
193
@ Test
0 commit comments