Commit 1fbd43bd authored by Andy Wilkinson's avatar Andy Wilkinson

Tolerate jar files with no manifest in ChangeableUrls

Closes gh-5704
parent a2f482b7
...@@ -119,19 +119,23 @@ final class ChangeableUrls implements Iterable<URL> { ...@@ -119,19 +119,23 @@ final class ChangeableUrls implements Iterable<URL> {
} }
private static List<URL> getUrlsFromClassPathAttribute(URL base, Manifest manifest) { private static List<URL> getUrlsFromClassPathAttribute(URL base, Manifest manifest) {
List<URL> urls = new ArrayList<URL>(); if (manifest == null) {
return Collections.<URL>emptyList();
}
String classPathAttribute = manifest.getMainAttributes() String classPathAttribute = manifest.getMainAttributes()
.getValue(Attributes.Name.CLASS_PATH); .getValue(Attributes.Name.CLASS_PATH);
if (StringUtils.hasText(classPathAttribute)) { if (!StringUtils.hasText(classPathAttribute)) {
for (String entry : StringUtils.delimitedListToStringArray(classPathAttribute, return Collections.<URL>emptyList();
" ")) { }
try { List<URL> urls = new ArrayList<URL>();
urls.add(new URL(base, entry)); for (String entry : StringUtils.delimitedListToStringArray(classPathAttribute,
} " ")) {
catch (MalformedURLException ex) { try {
throw new IllegalStateException( urls.add(new URL(base, entry));
"Class-Path attribute contains malformed URL", ex); }
} catch (MalformedURLException ex) {
throw new IllegalStateException(
"Class-Path attribute contains malformed URL", ex);
} }
} }
return urls; return urls;
......
...@@ -24,6 +24,7 @@ import java.net.URLClassLoader; ...@@ -24,6 +24,7 @@ import java.net.URLClassLoader;
import java.util.jar.Attributes; import java.util.jar.Attributes;
import java.util.jar.JarOutputStream; import java.util.jar.JarOutputStream;
import java.util.jar.Manifest; import java.util.jar.Manifest;
import java.util.zip.ZipOutputStream;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
...@@ -80,7 +81,7 @@ public class ChangeableUrlsTests { ...@@ -80,7 +81,7 @@ public class ChangeableUrlsTests {
File relative = this.temporaryFolder.newFolder(); File relative = this.temporaryFolder.newFolder();
ChangeableUrls urls = ChangeableUrls.fromUrlClassLoader(new URLClassLoader( ChangeableUrls urls = ChangeableUrls.fromUrlClassLoader(new URLClassLoader(
new URL[] { makeJarFileWithUrlsInManifestClassPath(projectCore, new URL[] { makeJarFileWithUrlsInManifestClassPath(projectCore,
projectWeb, relative.getName() + "/") })); projectWeb, relative.getName() + "/"), makeJarFileWithNoManifest() }));
assertThat(urls.toList(), assertThat(urls.toList(),
contains(projectCore, projectWeb, relative.toURI().toURL())); contains(projectCore, projectWeb, relative.toURI().toURL()));
} }
...@@ -105,4 +106,10 @@ public class ChangeableUrlsTests { ...@@ -105,4 +106,10 @@ public class ChangeableUrlsTests {
return classpathJar.toURI().toURL(); return classpathJar.toURI().toURL();
} }
private URL makeJarFileWithNoManifest() throws Exception {
File classpathJar = this.temporaryFolder.newFile("no-manifest.jar");
new ZipOutputStream(new FileOutputStream(classpathJar)).close();
return classpathJar.toURI().toURL();
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment