Merge branch '1.3.x'

This commit is contained in:
Andy Wilkinson
2016-04-07 17:51:17 +01:00
2 changed files with 92 additions and 3 deletions

View File

@@ -17,19 +17,27 @@
package org.springframework.boot.devtools.restart;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.jar.Attributes;
import java.util.jar.JarOutputStream;
import java.util.jar.Manifest;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.springframework.util.StringUtils;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Tests for {@link ChangeableUrls}.
*
* @author Phillip Webb
* @author Andy Wilkinson
*/
public class ChangeableUrlsTests {
@@ -63,6 +71,16 @@ public class ChangeableUrlsTests {
assertThat(urls.size()).isEqualTo(0);
}
@Test
public void urlsFromJarClassPathAreConsidered() throws Exception {
URL projectCore = makeUrl("project-core");
URL projectWeb = makeUrl("project-web");
ChangeableUrls urls = ChangeableUrls.fromUrlClassLoader(new URLClassLoader(
new URL[] { makeJarFileWithUrlsInManifestClassPath(projectCore,
projectWeb) }));
assertThat(urls.toList()).containsExactly(projectCore, projectWeb);
}
private URL makeUrl(String name) throws IOException {
File file = this.temporaryFolder.newFolder();
file = new File(file, name);
@@ -72,4 +90,15 @@ public class ChangeableUrlsTests {
return file.toURI().toURL();
}
private URL makeJarFileWithUrlsInManifestClassPath(URL... urls) throws Exception {
File classpathJar = this.temporaryFolder.newFile("classpath.jar");
Manifest manifest = new Manifest();
manifest.getMainAttributes().putValue(Attributes.Name.MANIFEST_VERSION.toString(),
"1.0");
manifest.getMainAttributes().putValue(Attributes.Name.CLASS_PATH.toString(),
StringUtils.arrayToDelimitedString(urls, " "));
new JarOutputStream(new FileOutputStream(classpathJar), manifest).close();
return classpathJar.toURI().toURL();
}
}