From 1947de3334827e90b84c6f7951a52f7747221083 Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Sun, 21 Sep 2014 10:54:05 -0700 Subject: [PATCH] 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 --- .../PathMatchingResourcePatternResolver.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/spring-core/src/main/java/org/springframework/core/io/support/PathMatchingResourcePatternResolver.java b/spring-core/src/main/java/org/springframework/core/io/support/PathMatchingResourcePatternResolver.java index be2bcb9e1e..bbb87e250e 100644 --- a/spring-core/src/main/java/org/springframework/core/io/support/PathMatchingResourcePatternResolver.java +++ b/spring-core/src/main/java/org/springframework/core/io/support/PathMatchingResourcePatternResolver.java @@ -35,7 +35,6 @@ import java.util.jar.JarFile; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; - import org.springframework.core.io.DefaultResourceLoader; import org.springframework.core.io.FileSystemResource; import org.springframework.core.io.Resource; @@ -317,9 +316,19 @@ public class PathMatchingResourcePatternResolver implements ResourcePatternResol // We need to have pointers to each of the jar files on the classpath as well... addAllClassLoaderJarRoots(cl, result); } + postProcessFindAllClassPathResourcesResult(location, result); return result.toArray(new Resource[result.size()]); } + /** + * Subclass hook allowing for post processing of a + * {@link #findAllClassPathResources(String) findAllClassPathResources} result. + * @param location the absolute path within the classpath + * @param result a mutable set of the results which can be post processed + */ + protected void postProcessFindAllClassPathResourcesResult(String location, Set result) { + } + /** * Convert the given URL as returned from the ClassLoader into a {@link Resource}. *

The default implementation simply creates a {@link UrlResource} instance. @@ -338,7 +347,7 @@ public class PathMatchingResourcePatternResolver implements ResourcePatternResol * @param classLoader the ClassLoader to search (including its ancestors) * @param result the set of resources to add jar roots to */ - private void addAllClassLoaderJarRoots(ClassLoader classLoader, Set result) { + protected void addAllClassLoaderJarRoots(ClassLoader classLoader, Set result) { if (classLoader instanceof URLClassLoader) { try { for (URL url : ((URLClassLoader) classLoader).getURLs()) {