Merge branch '1.5.x' into 2.0.x

pull/13061/head
Andy Wilkinson 7 years ago
commit 49089546f8

@ -279,9 +279,9 @@ public class JettyServletWebServerFactory extends AbstractServletWebServerFactor
} }
} }
private Resource createResource(URL url) throws IOException { private Resource createResource(URL url) throws Exception {
if ("file".equals(url.getProtocol())) { if ("file".equals(url.getProtocol())) {
File file = new File(getDecodedFile(url)); File file = new File(url.toURI());
if (file.isFile()) { if (file.isFile()) {
return Resource.newResource("jar:" + url + "!/META-INF/resources"); return Resource.newResource("jar:" + url + "!/META-INF/resources");
} }

@ -674,8 +674,8 @@ public class TomcatServletWebServerFactory extends AbstractServletWebServerFacto
private void addResourceJars(List<URL> resourceJarUrls) { private void addResourceJars(List<URL> resourceJarUrls) {
for (URL url : resourceJarUrls) { for (URL url : resourceJarUrls) {
String file = getDecodedFile(url); String path = url.getPath();
if (file.endsWith(".jar") || file.endsWith(".jar!/")) { if (path.endsWith(".jar") || path.endsWith(".jar!/")) {
String jar = url.toString(); String jar = url.toString();
if (!jar.startsWith("jar:")) { if (!jar.startsWith("jar:")) {
// A jar file in the file system. Convert to Jar URL. // A jar file in the file system. Convert to Jar URL.

@ -361,18 +361,18 @@ public class UndertowServletWebServerFactory extends AbstractServletWebServerFac
: new LoaderHidingResourceManager(rootResourceManager)); : new LoaderHidingResourceManager(rootResourceManager));
for (URL url : metaInfResourceUrls) { for (URL url : metaInfResourceUrls) {
if ("file".equals(url.getProtocol())) { if ("file".equals(url.getProtocol())) {
File file = new File(getDecodedFile(url)); try {
if (file.isFile()) { File file = new File(url.toURI());
try { if (file.isFile()) {
resourceJarUrls.add(new URL("jar:" + url + "!/")); resourceJarUrls.add(new URL("jar:" + url + "!/"));
} }
catch (MalformedURLException ex) { else {
throw new RuntimeException(ex); resourceManagers.add(new FileResourceManager(
new File(file, "META-INF/resources"), 0));
} }
} }
else { catch (Exception ex) {
resourceManagers.add(new FileResourceManager( throw new RuntimeException(ex);
new File(file, "META-INF/resources"), 0));
} }
} }
else { else {

@ -282,6 +282,14 @@ public abstract class AbstractServletWebServerFactory
return this.staticResourceJars.getUrls(); return this.staticResourceJars.getUrls();
} }
/**
* Converts the given {@code url} into a decoded file path.
*
* @param url the url to convert
* @return the file path
* @deprecated Since 2.0.2 in favor of {@link File#File(java.net.URI)}
*/
@Deprecated
protected final String getDecodedFile(URL url) { protected final String getDecodedFile(URL url) {
try { try {
return URLDecoder.decode(url.getFile(), "UTF-8"); return URLDecoder.decode(url.getFile(), "UTF-8");

@ -18,14 +18,13 @@ package org.springframework.boot.web.servlet.server;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.lang.management.ManagementFactory; import java.lang.management.ManagementFactory;
import java.net.JarURLConnection; import java.net.JarURLConnection;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URISyntaxException;
import java.net.URL; import java.net.URL;
import java.net.URLClassLoader; import java.net.URLClassLoader;
import java.net.URLConnection; import java.net.URLConnection;
import java.net.URLDecoder;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.jar.JarFile; import java.util.jar.JarFile;
@ -71,10 +70,20 @@ class StaticResourceJars {
} }
} }
private File toFile(URL url) {
try {
return new File(url.toURI());
}
catch (URISyntaxException ex) {
throw new IllegalStateException(
"Failed to create File from URL '" + url + "'");
}
}
private void addUrl(List<URL> urls, URL url) { private void addUrl(List<URL> urls, URL url) {
try { try {
if ("file".equals(url.getProtocol())) { if ("file".equals(url.getProtocol())) {
addUrlFile(urls, url, new File(getDecodedFile(url))); addUrlFile(urls, url, toFile(url));
} }
else { else {
addUrlConnection(urls, url, url.openConnection()); addUrlConnection(urls, url, url.openConnection());
@ -85,16 +94,6 @@ class StaticResourceJars {
} }
} }
private String getDecodedFile(URL url) {
try {
return URLDecoder.decode(url.getFile(), "UTF-8");
}
catch (UnsupportedEncodingException ex) {
throw new IllegalStateException(
"Failed to decode '" + url.getFile() + "' using UTF-8");
}
}
private void addUrlFile(List<URL> urls, URL url, File file) { private void addUrlFile(List<URL> urls, URL url, File file) {
if ((file.isDirectory() && new File(file, "META-INF/resources").isDirectory()) if ((file.isDirectory() && new File(file, "META-INF/resources").isDirectory())
|| isResourcesJar(file)) { || isResourcesJar(file)) {

@ -58,6 +58,14 @@ public class StaticResourceJarsTests {
assertThat(staticResourceJarUrls).hasSize(1); assertThat(staticResourceJarUrls).hasSize(1);
} }
@Test
public void includeJarWithStaticResourcesWithPlusInItsPath() throws Exception {
File jarFile = createResourcesJar("test + resources.jar");
List<URL> staticResourceJarUrls = new StaticResourceJars()
.getUrlsFrom(jarFile.toURI().toURL());
assertThat(staticResourceJarUrls).hasSize(1);
}
@Test @Test
public void excludeJarWithoutStaticResources() throws Exception { public void excludeJarWithoutStaticResources() throws Exception {
File jarFile = createJar("dependency.jar"); File jarFile = createJar("dependency.jar");

@ -40,7 +40,7 @@ import org.springframework.util.StringUtils;
*/ */
class IdeApplicationLauncher extends AbstractApplicationLauncher { class IdeApplicationLauncher extends AbstractApplicationLauncher {
private final File exploded = new File("target/ide application"); private final File exploded = new File("target/the+ide application");
IdeApplicationLauncher(ApplicationBuilder applicationBuilder) { IdeApplicationLauncher(ApplicationBuilder applicationBuilder) {
super(applicationBuilder); super(applicationBuilder);

Loading…
Cancel
Save