Merge branch '1.5.x'
This commit is contained in:
commit
f892363c0f
|
@ -104,7 +104,7 @@ final class ChangeableUrls implements Iterable<URL> {
|
||||||
return Collections.<URL>emptyList();
|
return Collections.<URL>emptyList();
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
return getUrlsFromClassPathAttribute(url, jarFile.getManifest());
|
return getUrlsFromManifestClassPathAttribute(jarFile);
|
||||||
}
|
}
|
||||||
catch (IOException ex) {
|
catch (IOException ex) {
|
||||||
throw new IllegalStateException(
|
throw new IllegalStateException(
|
||||||
|
@ -126,7 +126,9 @@ final class ChangeableUrls implements Iterable<URL> {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static List<URL> getUrlsFromClassPathAttribute(URL base, Manifest manifest) {
|
private static List<URL> getUrlsFromManifestClassPathAttribute(JarFile jarFile)
|
||||||
|
throws IOException {
|
||||||
|
Manifest manifest = jarFile.getManifest();
|
||||||
if (manifest == null) {
|
if (manifest == null) {
|
||||||
return Collections.<URL>emptyList();
|
return Collections.<URL>emptyList();
|
||||||
}
|
}
|
||||||
|
@ -137,9 +139,18 @@ final class ChangeableUrls implements Iterable<URL> {
|
||||||
}
|
}
|
||||||
String[] entries = StringUtils.delimitedListToStringArray(classPath, " ");
|
String[] entries = StringUtils.delimitedListToStringArray(classPath, " ");
|
||||||
List<URL> urls = new ArrayList<>(entries.length);
|
List<URL> urls = new ArrayList<>(entries.length);
|
||||||
|
File parent = new File(jarFile.getName()).getParentFile();
|
||||||
for (String entry : entries) {
|
for (String entry : entries) {
|
||||||
try {
|
try {
|
||||||
urls.add(new URL(base, entry));
|
File referenced = new File(parent, entry);
|
||||||
|
if (referenced.exists()) {
|
||||||
|
urls.add(referenced.toURI().toURL());
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
System.err.println("Ignoring Class-Path entry " + entry + " found in"
|
||||||
|
+ jarFile.getName() + " as " + referenced
|
||||||
|
+ " does not exist");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (MalformedURLException ex) {
|
catch (MalformedURLException ex) {
|
||||||
throw new IllegalStateException(
|
throw new IllegalStateException(
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2016 the original author or authors.
|
* Copyright 2012-2017 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -74,15 +74,19 @@ public class ChangeableUrlsTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void urlsFromJarClassPathAreConsidered() throws Exception {
|
public void urlsFromJarClassPathAreConsidered() throws Exception {
|
||||||
URL projectCore = makeUrl("project-core");
|
|
||||||
URL projectWeb = makeUrl("project-web");
|
|
||||||
File relative = this.temporaryFolder.newFolder();
|
File relative = this.temporaryFolder.newFolder();
|
||||||
|
File jarWithClassPath = makeJarFileWithUrlsInManifestClassPath(
|
||||||
|
"project-core/target/classes/", "project-web/target/classes/",
|
||||||
|
"does-not-exist/target/classes", relative.getName() + "/");
|
||||||
|
new File(jarWithClassPath.getParentFile(), "project-core/target/classes")
|
||||||
|
.mkdirs();
|
||||||
|
new File(jarWithClassPath.getParentFile(), "project-web/target/classes").mkdirs();
|
||||||
ChangeableUrls urls = ChangeableUrls
|
ChangeableUrls urls = ChangeableUrls
|
||||||
.fromUrlClassLoader(new URLClassLoader(new URL[] {
|
.fromUrlClassLoader(new URLClassLoader(new URL[] {
|
||||||
makeJarFileWithUrlsInManifestClassPath(projectCore, projectWeb,
|
jarWithClassPath.toURI().toURL(), makeJarFileWithNoManifest() }));
|
||||||
relative.getName() + "/"),
|
assertThat(urls.toList()).containsExactly(
|
||||||
makeJarFileWithNoManifest() }));
|
new URL(jarWithClassPath.toURI().toURL(), "project-core/target/classes/"),
|
||||||
assertThat(urls.toList()).containsExactly(projectCore, projectWeb,
|
new URL(jarWithClassPath.toURI().toURL(), "project-web/target/classes/"),
|
||||||
relative.toURI().toURL());
|
relative.toURI().toURL());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,7 +99,7 @@ public class ChangeableUrlsTests {
|
||||||
return file.toURI().toURL();
|
return file.toURI().toURL();
|
||||||
}
|
}
|
||||||
|
|
||||||
private URL makeJarFileWithUrlsInManifestClassPath(Object... urls) throws Exception {
|
private File makeJarFileWithUrlsInManifestClassPath(Object... urls) throws Exception {
|
||||||
File classpathJar = this.temporaryFolder.newFile("classpath.jar");
|
File classpathJar = this.temporaryFolder.newFile("classpath.jar");
|
||||||
Manifest manifest = new Manifest();
|
Manifest manifest = new Manifest();
|
||||||
manifest.getMainAttributes().putValue(Attributes.Name.MANIFEST_VERSION.toString(),
|
manifest.getMainAttributes().putValue(Attributes.Name.MANIFEST_VERSION.toString(),
|
||||||
|
@ -103,7 +107,7 @@ public class ChangeableUrlsTests {
|
||||||
manifest.getMainAttributes().putValue(Attributes.Name.CLASS_PATH.toString(),
|
manifest.getMainAttributes().putValue(Attributes.Name.CLASS_PATH.toString(),
|
||||||
StringUtils.arrayToDelimitedString(urls, " "));
|
StringUtils.arrayToDelimitedString(urls, " "));
|
||||||
new JarOutputStream(new FileOutputStream(classpathJar), manifest).close();
|
new JarOutputStream(new FileOutputStream(classpathJar), manifest).close();
|
||||||
return classpathJar.toURI().toURL();
|
return classpathJar;
|
||||||
}
|
}
|
||||||
|
|
||||||
private URL makeJarFileWithNoManifest() throws Exception {
|
private URL makeJarFileWithNoManifest() throws Exception {
|
||||||
|
|
Loading…
Reference in New Issue