Skip to content

Commit 1947de3

Browse files
committed
Provide subclass hooks in path matching resolver
Update PathMatchingResourcePatternResolver to include additional protected methods that can be used by subclasses to optimize which JARs are searched. Issue: SPR-12231
1 parent 4aa97f8 commit 1947de3

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

spring-core/src/main/java/org/springframework/core/io/support/PathMatchingResourcePatternResolver.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535

3636
import org.apache.commons.logging.Log;
3737
import org.apache.commons.logging.LogFactory;
38-
3938
import org.springframework.core.io.DefaultResourceLoader;
4039
import org.springframework.core.io.FileSystemResource;
4140
import org.springframework.core.io.Resource;
@@ -317,9 +316,19 @@ protected Resource[] findAllClassPathResources(String location) throws IOExcepti
317316
// We need to have pointers to each of the jar files on the classpath as well...
318317
addAllClassLoaderJarRoots(cl, result);
319318
}
319+
postProcessFindAllClassPathResourcesResult(location, result);
320320
return result.toArray(new Resource[result.size()]);
321321
}
322322

323+
/**
324+
* Subclass hook allowing for post processing of a
325+
* {@link #findAllClassPathResources(String) findAllClassPathResources} result.
326+
* @param location the absolute path within the classpath
327+
* @param result a mutable set of the results which can be post processed
328+
*/
329+
protected void postProcessFindAllClassPathResourcesResult(String location, Set<Resource> result) {
330+
}
331+
323332
/**
324333
* Convert the given URL as returned from the ClassLoader into a {@link Resource}.
325334
* <p>The default implementation simply creates a {@link UrlResource} instance.
@@ -338,7 +347,7 @@ protected Resource convertClassLoaderURL(URL url) {
338347
* @param classLoader the ClassLoader to search (including its ancestors)
339348
* @param result the set of resources to add jar roots to
340349
*/
341-
private void addAllClassLoaderJarRoots(ClassLoader classLoader, Set<Resource> result) {
350+
protected void addAllClassLoaderJarRoots(ClassLoader classLoader, Set<Resource> result) {
342351
if (classLoader instanceof URLClassLoader) {
343352
try {
344353
for (URL url : ((URLClassLoader) classLoader).getURLs()) {

0 commit comments

Comments
 (0)