Merge branch '1.1.x'
This commit is contained in:
@@ -16,10 +16,12 @@ given the ability to merge pull requests.
|
||||
None of these is essential for a pull request, but they will all help. They can also be
|
||||
added after the original pull request but before a merge.
|
||||
|
||||
* Use the Spring Framework code format conventions. Import `eclipse-code-formatter.xml`
|
||||
from the `eclipse` folder of the project if you are using Eclipse. If using IntelliJ,
|
||||
copy `spring-intellij-code-style.xml` to `~/.IntelliJIdea*/config/codestyles` and select
|
||||
spring-intellij-code-style from Settings -> Code Styles.
|
||||
* Use the Spring Framework code format conventions. If you use Eclipse and you follow
|
||||
the ``Importing into eclipse'' instructions below you should get project specific
|
||||
formatting automatically. You can also import formatter settings using the
|
||||
`eclipse-code-formatter.xml` file from the `eclipse` folder. If using IntelliJ, you can
|
||||
use the [Eclipse Code Formatter Plugin](http://plugins.jetbrains.com/plugin/6546)
|
||||
to import the same file.
|
||||
* Make sure all new `.java` files to have a simple Javadoc class comment with at least an
|
||||
`@author` tag identifying you, and preferably at least a paragraph on what the class is
|
||||
for.
|
||||
|
||||
@@ -17,6 +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;
|
||||
@@ -40,8 +41,10 @@ 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;
|
||||
@@ -146,6 +149,10 @@ public class MessageSourceAutoConfiguration {
|
||||
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);
|
||||
}
|
||||
@@ -160,35 +167,54 @@ public class MessageSourceAutoConfiguration {
|
||||
if ("".equals(path)) {
|
||||
Set<Resource> result = new LinkedHashSet<Resource>(16);
|
||||
result.addAll(Arrays.asList(super.findAllClassPathResources(location)));
|
||||
addAllClassLoaderJarUrls(getClassLoader(), result);
|
||||
addAllClassLoaderJarRoots(getClassLoader(), result);
|
||||
return result.toArray(new Resource[result.size()]);
|
||||
}
|
||||
return super.findAllClassPathResources(location);
|
||||
}
|
||||
|
||||
private void addAllClassLoaderJarUrls(ClassLoader classLoader,
|
||||
private void addAllClassLoaderJarRoots(ClassLoader classLoader,
|
||||
Set<Resource> result) {
|
||||
if (classLoader != null) {
|
||||
if (classLoader instanceof URLClassLoader) {
|
||||
addAllClassLoaderJarUrls(((URLClassLoader) classLoader).getURLs(),
|
||||
result);
|
||||
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);
|
||||
}
|
||||
}
|
||||
addAllClassLoaderJarUrls(classLoader.getParent(), result);
|
||||
}
|
||||
}
|
||||
|
||||
private void addAllClassLoaderJarUrls(URL[] urls, Set<Resource> result) {
|
||||
for (URL url : urls) {
|
||||
if ("file".equals(url.getProtocol())
|
||||
&& url.toString().toLowerCase().endsWith(".jar")) {
|
||||
if (isJarFileUrl(url)) {
|
||||
try {
|
||||
URL jarUrl = new URL("jar:" + url.toString() + "!/");
|
||||
jarUrl.openConnection();
|
||||
result.add(convertClassLoaderURL(jarUrl));
|
||||
UrlResource jarResource = new UrlResource(JAR_URL_PREFIX
|
||||
+ url.toString() + ResourceUtils.JAR_URL_SEPARATOR);
|
||||
if (jarResource.exists()) {
|
||||
result.add(jarResource);
|
||||
}
|
||||
}
|
||||
catch (Exception ex) {
|
||||
if (logger.isWarnEnabled()) {
|
||||
logger.warn("Cannot search for matching files underneath "
|
||||
catch (MalformedURLException ex) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Cannot search for matching files underneath "
|
||||
+ url + " because it cannot be accessed as a JAR", ex);
|
||||
}
|
||||
}
|
||||
@@ -196,6 +222,11 @@ public class MessageSourceAutoConfiguration {
|
||||
}
|
||||
}
|
||||
|
||||
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