Skip to content

Commit 155d550

Browse files
committed
Merge branch '1.4.x' into 1.5.x
2 parents c55bfb0 + 47de05b commit 155d550

File tree

2 files changed

+28
-13
lines changed

2 files changed

+28
-13
lines changed

spring-boot-devtools/src/main/java/org/springframework/boot/devtools/restart/ChangeableUrls.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2016 the original author or authors.
2+
* Copyright 2012-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -104,7 +104,7 @@ private static List<URL> getUrlsFromClassPathOfJarManifestIfPossible(URL url) {
104104
return Collections.<URL>emptyList();
105105
}
106106
try {
107-
return getUrlsFromClassPathAttribute(url, jarFile.getManifest());
107+
return getUrlsFromManifestClassPathAttribute(jarFile);
108108
}
109109
catch (IOException ex) {
110110
throw new IllegalStateException(
@@ -126,7 +126,9 @@ private static JarFile getJarFileIfPossible(URL url) {
126126
return null;
127127
}
128128

129-
private static List<URL> getUrlsFromClassPathAttribute(URL base, Manifest manifest) {
129+
private static List<URL> getUrlsFromManifestClassPathAttribute(JarFile jarFile)
130+
throws IOException {
131+
Manifest manifest = jarFile.getManifest();
130132
if (manifest == null) {
131133
return Collections.<URL>emptyList();
132134
}
@@ -137,9 +139,18 @@ private static List<URL> getUrlsFromClassPathAttribute(URL base, Manifest manife
137139
}
138140
String[] entries = StringUtils.delimitedListToStringArray(classPath, " ");
139141
List<URL> urls = new ArrayList<URL>(entries.length);
142+
File parent = new File(jarFile.getName()).getParentFile();
140143
for (String entry : entries) {
141144
try {
142-
urls.add(new URL(base, entry));
145+
File referenced = new File(parent, entry);
146+
if (referenced.exists()) {
147+
urls.add(referenced.toURI().toURL());
148+
}
149+
else {
150+
System.err.println("Ignoring Class-Path entry " + entry + " found in"
151+
+ jarFile.getName() + " as " + referenced
152+
+ " does not exist");
153+
}
143154
}
144155
catch (MalformedURLException ex) {
145156
throw new IllegalStateException(

spring-boot-devtools/src/test/java/org/springframework/boot/devtools/restart/ChangeableUrlsTests.java

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2016 the original author or authors.
2+
* Copyright 2012-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -74,15 +74,19 @@ public void skipsUrls() throws Exception {
7474

7575
@Test
7676
public void urlsFromJarClassPathAreConsidered() throws Exception {
77-
URL projectCore = makeUrl("project-core");
78-
URL projectWeb = makeUrl("project-web");
7977
File relative = this.temporaryFolder.newFolder();
78+
File jarWithClassPath = makeJarFileWithUrlsInManifestClassPath(
79+
"project-core/target/classes/", "project-web/target/classes/",
80+
"does-not-exist/target/classes", relative.getName() + "/");
81+
new File(jarWithClassPath.getParentFile(), "project-core/target/classes")
82+
.mkdirs();
83+
new File(jarWithClassPath.getParentFile(), "project-web/target/classes").mkdirs();
8084
ChangeableUrls urls = ChangeableUrls
8185
.fromUrlClassLoader(new URLClassLoader(new URL[] {
82-
makeJarFileWithUrlsInManifestClassPath(projectCore, projectWeb,
83-
relative.getName() + "/"),
84-
makeJarFileWithNoManifest() }));
85-
assertThat(urls.toList()).containsExactly(projectCore, projectWeb,
86+
jarWithClassPath.toURI().toURL(), makeJarFileWithNoManifest() }));
87+
assertThat(urls.toList()).containsExactly(
88+
new URL(jarWithClassPath.toURI().toURL(), "project-core/target/classes/"),
89+
new URL(jarWithClassPath.toURI().toURL(), "project-web/target/classes/"),
8690
relative.toURI().toURL());
8791
}
8892

@@ -95,15 +99,15 @@ private URL makeUrl(String name) throws IOException {
9599
return file.toURI().toURL();
96100
}
97101

98-
private URL makeJarFileWithUrlsInManifestClassPath(Object... urls) throws Exception {
102+
private File makeJarFileWithUrlsInManifestClassPath(Object... urls) throws Exception {
99103
File classpathJar = this.temporaryFolder.newFile("classpath.jar");
100104
Manifest manifest = new Manifest();
101105
manifest.getMainAttributes().putValue(Attributes.Name.MANIFEST_VERSION.toString(),
102106
"1.0");
103107
manifest.getMainAttributes().putValue(Attributes.Name.CLASS_PATH.toString(),
104108
StringUtils.arrayToDelimitedString(urls, " "));
105109
new JarOutputStream(new FileOutputStream(classpathJar), manifest).close();
106-
return classpathJar.toURI().toURL();
110+
return classpathJar;
107111
}
108112

109113
private URL makeJarFileWithNoManifest() throws Exception {

0 commit comments

Comments
 (0)