Remove ExtendedPathMatchingResourcePatternResolver
Remove ExtendedPathMatchingResourcePatternResolver which is not required with Spring 4.1 Fixes gh-1420
This commit is contained in:
@@ -17,15 +17,7 @@
|
||||
package org.springframework.boot.autoconfigure;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.boot.autoconfigure.MessageSourceAutoConfiguration.ResourceBundleCondition;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionOutcome;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
@@ -41,10 +33,8 @@ import org.springframework.context.support.ResourceBundleMessageSource;
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.core.io.UrlResource;
|
||||
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
|
||||
import org.springframework.core.type.AnnotatedTypeMetadata;
|
||||
import org.springframework.util.ResourceUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import static org.springframework.util.StringUtils.commaDelimitedListToStringArray;
|
||||
@@ -128,7 +118,7 @@ public class MessageSourceAutoConfiguration {
|
||||
|
||||
private Resource[] getResources(ClassLoader classLoader, String name) {
|
||||
try {
|
||||
return new ExtendedPathMatchingResourcePatternResolver(classLoader)
|
||||
return new PathMatchingResourcePatternResolver(classLoader)
|
||||
.getResources("classpath*:" + name + "*.properties");
|
||||
}
|
||||
catch (IOException ex) {
|
||||
@@ -138,95 +128,4 @@ public class MessageSourceAutoConfiguration {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Extended version of {@link PathMatchingResourcePatternResolver} to deal with the
|
||||
* fact that "{@code classpath*:...*.properties}" patterns don't work with
|
||||
* {@link URLClassLoader}s.
|
||||
*/
|
||||
private static class ExtendedPathMatchingResourcePatternResolver extends
|
||||
PathMatchingResourcePatternResolver {
|
||||
|
||||
private static final Log logger = LogFactory
|
||||
.getLog(PathMatchingResourcePatternResolver.class);
|
||||
|
||||
private static final String JAR_FILE_EXTENSION = ".jar";
|
||||
|
||||
private static final String JAR_URL_PREFIX = "jar:";
|
||||
|
||||
public ExtendedPathMatchingResourcePatternResolver(ClassLoader classLoader) {
|
||||
super(classLoader);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Resource[] findAllClassPathResources(String location)
|
||||
throws IOException {
|
||||
String path = location;
|
||||
if (path.startsWith("/")) {
|
||||
path = path.substring(1);
|
||||
}
|
||||
if ("".equals(path)) {
|
||||
Set<Resource> result = new LinkedHashSet<Resource>(16);
|
||||
result.addAll(Arrays.asList(super.findAllClassPathResources(location)));
|
||||
addAllClassLoaderJarRoots(getClassLoader(), result);
|
||||
return result.toArray(new Resource[result.size()]);
|
||||
}
|
||||
return super.findAllClassPathResources(location);
|
||||
}
|
||||
|
||||
private void addAllClassLoaderJarRoots(ClassLoader classLoader,
|
||||
Set<Resource> result) {
|
||||
if (classLoader != null) {
|
||||
if (classLoader instanceof URLClassLoader) {
|
||||
try {
|
||||
addAllClassLoaderJarUrls(
|
||||
((URLClassLoader) classLoader).getURLs(), result);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Cannot introspect jar files since "
|
||||
+ "ClassLoader [" + classLoader
|
||||
+ "] does not support 'getURLs()': " + ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
try {
|
||||
addAllClassLoaderJarRoots(classLoader.getParent(), result);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Cannot introspect jar files in parent "
|
||||
+ "ClassLoader since [" + classLoader
|
||||
+ "] does not support 'getParent()': " + ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void addAllClassLoaderJarUrls(URL[] urls, Set<Resource> result) {
|
||||
for (URL url : urls) {
|
||||
if (isJarFileUrl(url)) {
|
||||
try {
|
||||
UrlResource jarResource = new UrlResource(JAR_URL_PREFIX
|
||||
+ url.toString() + ResourceUtils.JAR_URL_SEPARATOR);
|
||||
if (jarResource.exists()) {
|
||||
result.add(jarResource);
|
||||
}
|
||||
}
|
||||
catch (MalformedURLException ex) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Cannot search for matching files underneath "
|
||||
+ url + " because it cannot be accessed as a JAR", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isJarFileUrl(URL url) {
|
||||
return ResourceUtils.URL_PROTOCOL_FILE.equals(url.getProtocol())
|
||||
&& url.getPath().toLowerCase().endsWith(JAR_FILE_EXTENSION);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user