Handle relative URLs in jar's Class-Path when getting changeable URLs

5e0ba6ea added support for reading a jar manifest's Class-Path
attribute when resolving changeable URLs from a URLClassLoader,
however it did not handle relative URLs, i.e. URLs without a protocol,
correctly.

This commit updates ChangeableUrls so that it uses the URL of the
JAR that contains the manifest as the base for any new URLs that
are created. When the Class-Path entry is relative, this base will
be used. When the Class-Path entry is absolutee, URL's constructor
will ignore the supplied base.

Closes gh-5665
This commit is contained in:
Andy Wilkinson
2016-04-12 13:47:58 +01:00
parent af2483816b
commit 1412eaa0e0
2 changed files with 8 additions and 6 deletions

View File

@@ -77,10 +77,12 @@ public class ChangeableUrlsTests {
public void urlsFromJarClassPathAreConsidered() throws Exception {
URL projectCore = makeUrl("project-core");
URL projectWeb = makeUrl("project-web");
File relative = this.temporaryFolder.newFolder();
ChangeableUrls urls = ChangeableUrls.fromUrlClassLoader(new URLClassLoader(
new URL[] { makeJarFileWithUrlsInManifestClassPath(projectCore,
projectWeb) }));
assertThat(urls.toList(), contains(projectCore, projectWeb));
projectWeb, relative.getName() + "/") }));
assertThat(urls.toList(),
contains(projectCore, projectWeb, relative.toURI().toURL()));
}
private URL makeUrl(String name) throws IOException {
@@ -92,7 +94,7 @@ public class ChangeableUrlsTests {
return file.toURI().toURL();
}
private URL makeJarFileWithUrlsInManifestClassPath(URL... urls) throws Exception {
private URL makeJarFileWithUrlsInManifestClassPath(Object... urls) throws Exception {
File classpathJar = this.temporaryFolder.newFile("classpath.jar");
Manifest manifest = new Manifest();
manifest.getMainAttributes().putValue(Attributes.Name.MANIFEST_VERSION.toString(),