Merge branch '1.5.x' into 2.0.x

This commit is contained in:
Andy Wilkinson
2019-06-07 10:46:31 +01:00
2320 changed files with 23858 additions and 39476 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -170,8 +170,7 @@ public class DefaultLaunchScriptTests {
public void expandVariables() throws Exception {
File file = this.temporaryFolder.newFile();
FileCopyUtils.copy("h{{a}}ll{{b}}".getBytes(), file);
DefaultLaunchScript script = new DefaultLaunchScript(file,
createProperties("a:e", "b:o"));
DefaultLaunchScript script = new DefaultLaunchScript(file, createProperties("a:e", "b:o"));
String content = new String(script.toByteArray());
assertThat(content).isEqualTo("hello");
}
@@ -180,8 +179,7 @@ public class DefaultLaunchScriptTests {
public void expandVariablesMultiLine() throws Exception {
File file = this.temporaryFolder.newFile();
FileCopyUtils.copy("h{{a}}l\nl{{b}}".getBytes(), file);
DefaultLaunchScript script = new DefaultLaunchScript(file,
createProperties("a:e", "b:o"));
DefaultLaunchScript script = new DefaultLaunchScript(file, createProperties("a:e", "b:o"));
String content = new String(script.toByteArray());
assertThat(content).isEqualTo("hel\nlo");
}
@@ -208,8 +206,7 @@ public class DefaultLaunchScriptTests {
public void expandVariablesWithDefaultsOverride() throws Exception {
File file = this.temporaryFolder.newFile();
FileCopyUtils.copy("h{{a:e}}ll{{b:o}}".getBytes(), file);
DefaultLaunchScript script = new DefaultLaunchScript(file,
createProperties("a:a"));
DefaultLaunchScript script = new DefaultLaunchScript(file, createProperties("a:a"));
String content = new String(script.toByteArray());
assertThat(content).isEqualTo("hallo");
}
@@ -224,8 +221,7 @@ public class DefaultLaunchScriptTests {
}
private void assertThatPlaceholderCanBeReplaced(String placeholder) throws Exception {
DefaultLaunchScript script = new DefaultLaunchScript(null,
createProperties(placeholder + ":__test__"));
DefaultLaunchScript script = new DefaultLaunchScript(null, createProperties(placeholder + ":__test__"));
String content = new String(script.toByteArray());
assertThat(content).contains("__test__");
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -60,8 +60,7 @@ public class FileUtilsTests {
File file = new File(this.outputDirectory, "logback.xml");
file.createNewFile();
new File(this.originDirectory, "logback.xml").createNewFile();
FileUtils.removeDuplicatesFromOutputDirectory(this.outputDirectory,
this.originDirectory);
FileUtils.removeDuplicatesFromOutputDirectory(this.outputDirectory, this.originDirectory);
assertThat(file.exists()).isFalse();
}
@@ -72,8 +71,7 @@ public class FileUtilsTests {
File file = new File(this.outputDirectory, "sub/logback.xml");
file.createNewFile();
new File(this.originDirectory, "sub/logback.xml").createNewFile();
FileUtils.removeDuplicatesFromOutputDirectory(this.outputDirectory,
this.originDirectory);
FileUtils.removeDuplicatesFromOutputDirectory(this.outputDirectory, this.originDirectory);
assertThat(file.exists()).isFalse();
}
@@ -84,8 +82,7 @@ public class FileUtilsTests {
File file = new File(this.outputDirectory, "sub/logback.xml");
file.createNewFile();
new File(this.originDirectory, "sub/different.xml").createNewFile();
FileUtils.removeDuplicatesFromOutputDirectory(this.outputDirectory,
this.originDirectory);
FileUtils.removeDuplicatesFromOutputDirectory(this.outputDirectory, this.originDirectory);
assertThat(file.exists()).isTrue();
}
@@ -94,8 +91,7 @@ public class FileUtilsTests {
File file = new File(this.outputDirectory, "logback.xml");
file.createNewFile();
new File(this.originDirectory, "different.xml").createNewFile();
FileUtils.removeDuplicatesFromOutputDirectory(this.outputDirectory,
this.originDirectory);
FileUtils.removeDuplicatesFromOutputDirectory(this.outputDirectory, this.originDirectory);
assertThat(file.exists()).isTrue();
}
@@ -105,8 +101,7 @@ public class FileUtilsTests {
try (OutputStream outputStream = new FileOutputStream(file)) {
outputStream.write(new byte[] { 1, 2, 3 });
}
assertThat(FileUtils.sha1Hash(file))
.isEqualTo("7037807198c22a7d2b0807371d763779a84fdfcf");
assertThat(FileUtils.sha1Hash(file)).isEqualTo("7037807198c22a7d2b0807371d763779a84fdfcf");
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -40,8 +40,7 @@ public class LayoutsTests {
assertThat(Layouts.forFile(new File("test.jar"))).isInstanceOf(Layouts.Jar.class);
assertThat(Layouts.forFile(new File("test.JAR"))).isInstanceOf(Layouts.Jar.class);
assertThat(Layouts.forFile(new File("test.jAr"))).isInstanceOf(Layouts.Jar.class);
assertThat(Layouts.forFile(new File("te.st.jar")))
.isInstanceOf(Layouts.Jar.class);
assertThat(Layouts.forFile(new File("te.st.jar"))).isInstanceOf(Layouts.Jar.class);
}
@Test
@@ -49,8 +48,7 @@ public class LayoutsTests {
assertThat(Layouts.forFile(new File("test.war"))).isInstanceOf(Layouts.War.class);
assertThat(Layouts.forFile(new File("test.WAR"))).isInstanceOf(Layouts.War.class);
assertThat(Layouts.forFile(new File("test.wAr"))).isInstanceOf(Layouts.War.class);
assertThat(Layouts.forFile(new File("te.st.war")))
.isInstanceOf(Layouts.War.class);
assertThat(Layouts.forFile(new File("te.st.war"))).isInstanceOf(Layouts.War.class);
}
@Test
@@ -63,27 +61,19 @@ public class LayoutsTests {
@Test
public void jarLayout() {
Layout layout = new Layouts.Jar();
assertThat(layout.getLibraryDestination("lib.jar", LibraryScope.COMPILE))
.isEqualTo("BOOT-INF/lib/");
assertThat(layout.getLibraryDestination("lib.jar", LibraryScope.CUSTOM))
.isEqualTo("BOOT-INF/lib/");
assertThat(layout.getLibraryDestination("lib.jar", LibraryScope.PROVIDED))
.isEqualTo("BOOT-INF/lib/");
assertThat(layout.getLibraryDestination("lib.jar", LibraryScope.RUNTIME))
.isEqualTo("BOOT-INF/lib/");
assertThat(layout.getLibraryDestination("lib.jar", LibraryScope.COMPILE)).isEqualTo("BOOT-INF/lib/");
assertThat(layout.getLibraryDestination("lib.jar", LibraryScope.CUSTOM)).isEqualTo("BOOT-INF/lib/");
assertThat(layout.getLibraryDestination("lib.jar", LibraryScope.PROVIDED)).isEqualTo("BOOT-INF/lib/");
assertThat(layout.getLibraryDestination("lib.jar", LibraryScope.RUNTIME)).isEqualTo("BOOT-INF/lib/");
}
@Test
public void warLayout() {
Layout layout = new Layouts.War();
assertThat(layout.getLibraryDestination("lib.jar", LibraryScope.COMPILE))
.isEqualTo("WEB-INF/lib/");
assertThat(layout.getLibraryDestination("lib.jar", LibraryScope.CUSTOM))
.isEqualTo("WEB-INF/lib/");
assertThat(layout.getLibraryDestination("lib.jar", LibraryScope.PROVIDED))
.isEqualTo("WEB-INF/lib-provided/");
assertThat(layout.getLibraryDestination("lib.jar", LibraryScope.RUNTIME))
.isEqualTo("WEB-INF/lib/");
assertThat(layout.getLibraryDestination("lib.jar", LibraryScope.COMPILE)).isEqualTo("WEB-INF/lib/");
assertThat(layout.getLibraryDestination("lib.jar", LibraryScope.CUSTOM)).isEqualTo("WEB-INF/lib/");
assertThat(layout.getLibraryDestination("lib.jar", LibraryScope.PROVIDED)).isEqualTo("WEB-INF/lib-provided/");
assertThat(layout.getLibraryDestination("lib.jar", LibraryScope.RUNTIME)).isEqualTo("WEB-INF/lib/");
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -84,8 +84,8 @@ public class MainClassFinderTests {
this.testJarFile.addClass("a/B.class", ClassWithMainMethod.class);
this.testJarFile.addClass("a/b/c/E.class", ClassWithMainMethod.class);
this.thrown.expect(IllegalStateException.class);
this.thrown.expectMessage("Unable to find a single main class "
+ "from the following candidates [a.B, a.b.c.E]");
this.thrown
.expectMessage("Unable to find a single main class " + "from the following candidates [a.B, a.b.c.E]");
MainClassFinder.findSingleMainClass(this.testJarFile.getJarFile(), "");
}
@@ -93,8 +93,7 @@ public class MainClassFinderTests {
public void findSingleJarSearchPrefersAnnotatedMainClass() throws Exception {
this.testJarFile.addClass("a/B.class", ClassWithMainMethod.class);
this.testJarFile.addClass("a/b/c/E.class", AnnotatedClassWithMainMethod.class);
String mainClass = MainClassFinder.findSingleMainClass(
this.testJarFile.getJarFile(), "",
String mainClass = MainClassFinder.findSingleMainClass(this.testJarFile.getJarFile(), "",
"org.springframework.boot.loader.tools.sample.SomeApplication");
assertThat(mainClass).isEqualTo("a.b.c.E");
}
@@ -103,8 +102,7 @@ public class MainClassFinderTests {
public void findMainClassInJarSubLocation() throws Exception {
this.testJarFile.addClass("a/B.class", ClassWithMainMethod.class);
this.testJarFile.addClass("a/b/c/E.class", ClassWithMainMethod.class);
String actual = MainClassFinder.findMainClass(this.testJarFile.getJarFile(),
"a/");
String actual = MainClassFinder.findMainClass(this.testJarFile.getJarFile(), "a/");
assertThat(actual).isEqualTo("B");
}
@@ -139,8 +137,8 @@ public class MainClassFinderTests {
this.testJarFile.addClass("a/B.class", ClassWithMainMethod.class);
this.testJarFile.addClass("a/b/c/E.class", ClassWithMainMethod.class);
this.thrown.expect(IllegalStateException.class);
this.thrown.expectMessage("Unable to find a single main class "
+ "from the following candidates [a.B, a.b.c.E]");
this.thrown
.expectMessage("Unable to find a single main class " + "from the following candidates [a.B, a.b.c.E]");
MainClassFinder.findSingleMainClass(this.testJarFile.getJarSource());
}
@@ -148,8 +146,7 @@ public class MainClassFinderTests {
public void findSingleFolderSearchPrefersAnnotatedMainClass() throws Exception {
this.testJarFile.addClass("a/B.class", ClassWithMainMethod.class);
this.testJarFile.addClass("a/b/c/E.class", AnnotatedClassWithMainMethod.class);
String mainClass = MainClassFinder.findSingleMainClass(
this.testJarFile.getJarSource(),
String mainClass = MainClassFinder.findSingleMainClass(this.testJarFile.getJarSource(),
"org.springframework.boot.loader.tools.sample.SomeApplication");
assertThat(mainClass).isEqualTo("a.b.c.E");
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -119,8 +119,7 @@ public class RepackagerTests {
Manifest actualManifest = getManifest(file);
assertThat(actualManifest.getMainAttributes().getValue("Main-Class"))
.isEqualTo("org.springframework.boot.loader.JarLauncher");
assertThat(actualManifest.getMainAttributes().getValue("Start-Class"))
.isEqualTo("a.b.C");
assertThat(actualManifest.getMainAttributes().getValue("Start-Class")).isEqualTo("a.b.C");
assertThat(hasLauncherClasses(file)).isTrue();
}
@@ -137,8 +136,7 @@ public class RepackagerTests {
Manifest actualManifest = getManifest(file);
assertThat(actualManifest.getMainAttributes().getValue("Main-Class"))
.isEqualTo("org.springframework.boot.loader.JarLauncher");
assertThat(actualManifest.getMainAttributes().getValue("Start-Class"))
.isEqualTo("a.b.C");
assertThat(actualManifest.getMainAttributes().getValue("Start-Class")).isEqualTo("a.b.C");
assertThat(hasLauncherClasses(file)).isTrue();
}
@@ -151,8 +149,7 @@ public class RepackagerTests {
Manifest actualManifest = getManifest(file);
assertThat(actualManifest.getMainAttributes().getValue("Main-Class"))
.isEqualTo("org.springframework.boot.loader.JarLauncher");
assertThat(actualManifest.getMainAttributes().getValue("Start-Class"))
.isEqualTo("a.b.C");
assertThat(actualManifest.getMainAttributes().getValue("Start-Class")).isEqualTo("a.b.C");
assertThat(hasLauncherClasses(file)).isTrue();
}
@@ -166,8 +163,7 @@ public class RepackagerTests {
Manifest actualManifest = getManifest(file);
assertThat(actualManifest.getMainAttributes().getValue("Main-Class"))
.isEqualTo("org.springframework.boot.loader.JarLauncher");
assertThat(actualManifest.getMainAttributes().getValue("Start-Class"))
.isEqualTo("a.b.C");
assertThat(actualManifest.getMainAttributes().getValue("Start-Class")).isEqualTo("a.b.C");
assertThat(hasLauncherClasses(file)).isTrue();
}
@@ -178,8 +174,8 @@ public class RepackagerTests {
File file = this.testJarFile.getFile();
Repackager repackager = new Repackager(file);
this.thrown.expect(IllegalStateException.class);
this.thrown.expectMessage("Unable to find a single main class "
+ "from the following candidates [a.b.C, a.b.D]");
this.thrown
.expectMessage("Unable to find a single main class " + "from the following candidates [a.b.C, a.b.D]");
repackager.repackage(NO_LIBRARIES);
}
@@ -199,8 +195,7 @@ public class RepackagerTests {
repackager.setLayout(new Layouts.None());
repackager.repackage(file, NO_LIBRARIES);
Manifest actualManifest = getManifest(file);
assertThat(actualManifest.getMainAttributes().getValue("Main-Class"))
.isEqualTo("a.b.C");
assertThat(actualManifest.getMainAttributes().getValue("Main-Class")).isEqualTo("a.b.C");
assertThat(hasLauncherClasses(file)).isFalse();
}
@@ -233,8 +228,7 @@ public class RepackagerTests {
Repackager repackager = new Repackager(file);
repackager.setBackupSource(false);
repackager.repackage(NO_LIBRARIES);
assertThat(new File(file.getParent(), file.getName() + ".original"))
.doesNotExist();
assertThat(new File(file.getParent(), file.getName() + ".original")).doesNotExist();
assertThat(hasLauncherClasses(file)).isTrue();
}
@@ -245,8 +239,7 @@ public class RepackagerTests {
File dest = this.temporaryFolder.newFile("different.jar");
Repackager repackager = new Repackager(source);
repackager.repackage(dest, NO_LIBRARIES);
assertThat(new File(source.getParent(), source.getName() + ".original"))
.doesNotExist();
assertThat(new File(source.getParent(), source.getName() + ".original")).doesNotExist();
assertThat(hasLauncherClasses(source)).isFalse();
assertThat(hasLauncherClasses(dest)).isTrue();
}
@@ -298,8 +291,7 @@ public class RepackagerTests {
File libNonJarFile = this.temporaryFolder.newFile();
FileCopyUtils.copy(new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8 }, libNonJarFile);
this.testJarFile.addClass("a/b/C.class", ClassWithMainMethod.class);
this.testJarFile.addFile("BOOT-INF/lib/" + libJarFileToUnpack.getName(),
libJarFileToUnpack);
this.testJarFile.addFile("BOOT-INF/lib/" + libJarFileToUnpack.getName(), libJarFileToUnpack);
File file = this.testJarFile.getFile();
libJarFile.setLastModified(JAN_1_1980);
Repackager repackager = new Repackager(file);
@@ -309,8 +301,7 @@ public class RepackagerTests {
callback.library(new Library(libNonJarFile, LibraryScope.COMPILE));
});
assertThat(hasEntry(file, "BOOT-INF/lib/" + libJarFile.getName())).isTrue();
assertThat(hasEntry(file, "BOOT-INF/lib/" + libJarFileToUnpack.getName()))
.isTrue();
assertThat(hasEntry(file, "BOOT-INF/lib/" + libJarFileToUnpack.getName())).isTrue();
assertThat(hasEntry(file, "BOOT-INF/lib/" + libNonJarFile.getName())).isFalse();
JarEntry entry = getEntry(file, "BOOT-INF/lib/" + libJarFile.getName());
assertThat(entry.getTime()).isEqualTo(JAN_1_1985);
@@ -347,16 +338,12 @@ public class RepackagerTests {
LibraryScope scope = mock(LibraryScope.class);
given(layout.getLauncherClassName()).willReturn("testLauncher");
given(layout.getLibraryDestination(anyString(), eq(scope))).willReturn("test/");
given(layout.getLibraryDestination(anyString(), eq(LibraryScope.COMPILE)))
.willReturn("test-lib/");
given(layout.getLibraryDestination(anyString(), eq(LibraryScope.COMPILE))).willReturn("test-lib/");
repackager.setLayout(layout);
repackager.repackage(
(callback) -> callback.library(new Library(libJarFile, scope)));
repackager.repackage((callback) -> callback.library(new Library(libJarFile, scope)));
assertThat(hasEntry(file, "test/" + libJarFile.getName())).isTrue();
assertThat(getManifest(file).getMainAttributes().getValue("Spring-Boot-Lib"))
.isEqualTo("test-lib/");
assertThat(getManifest(file).getMainAttributes().getValue("Main-Class"))
.isEqualTo("testLauncher");
assertThat(getManifest(file).getMainAttributes().getValue("Spring-Boot-Lib")).isEqualTo("test-lib/");
assertThat(getManifest(file).getMainAttributes().getValue("Main-Class")).isEqualTo("testLauncher");
}
@Test
@@ -371,12 +358,9 @@ public class RepackagerTests {
LibraryScope scope = mock(LibraryScope.class);
given(layout.getLauncherClassName()).willReturn("testLauncher");
repackager.setLayout(layout);
repackager.repackage(
(callback) -> callback.library(new Library(libJarFile, scope)));
assertThat(getManifest(file).getMainAttributes().getValue("Spring-Boot-Lib"))
.isNull();
assertThat(getManifest(file).getMainAttributes().getValue("Main-Class"))
.isEqualTo("testLauncher");
repackager.repackage((callback) -> callback.library(new Library(libJarFile, scope)));
assertThat(getManifest(file).getMainAttributes().getValue("Spring-Boot-Lib")).isNull();
assertThat(getManifest(file).getMainAttributes().getValue("Main-Class")).isEqualTo("testLauncher");
}
@Test
@@ -386,8 +370,7 @@ public class RepackagerTests {
Repackager repackager = new Repackager(file);
repackager.repackage(NO_LIBRARIES);
Manifest actualManifest = getManifest(file);
assertThat(actualManifest.getMainAttributes())
.containsKey(new Attributes.Name("Spring-Boot-Version"));
assertThat(actualManifest.getMainAttributes()).containsKey(new Attributes.Name("Spring-Boot-Version"));
}
@Test
@@ -397,24 +380,23 @@ public class RepackagerTests {
Repackager repackager = new Repackager(file);
repackager.repackage(NO_LIBRARIES);
Manifest actualManifest = getManifest(file);
assertThat(actualManifest.getMainAttributes())
.containsEntry(new Attributes.Name("Spring-Boot-Lib"), "BOOT-INF/lib/");
assertThat(actualManifest.getMainAttributes()).containsEntry(
new Attributes.Name("Spring-Boot-Classes"), "BOOT-INF/classes/");
assertThat(actualManifest.getMainAttributes()).containsEntry(new Attributes.Name("Spring-Boot-Lib"),
"BOOT-INF/lib/");
assertThat(actualManifest.getMainAttributes()).containsEntry(new Attributes.Name("Spring-Boot-Classes"),
"BOOT-INF/classes/");
}
@Test
public void executableWarLayoutAttributes() throws Exception {
this.testJarFile.addClass("WEB-INF/classes/a/b/C.class",
ClassWithMainMethod.class);
this.testJarFile.addClass("WEB-INF/classes/a/b/C.class", ClassWithMainMethod.class);
File file = this.testJarFile.getFile("war");
Repackager repackager = new Repackager(file);
repackager.repackage(NO_LIBRARIES);
Manifest actualManifest = getManifest(file);
assertThat(actualManifest.getMainAttributes())
.containsEntry(new Attributes.Name("Spring-Boot-Lib"), "WEB-INF/lib/");
assertThat(actualManifest.getMainAttributes()).containsEntry(
new Attributes.Name("Spring-Boot-Classes"), "WEB-INF/classes/");
assertThat(actualManifest.getMainAttributes()).containsEntry(new Attributes.Name("Spring-Boot-Lib"),
"WEB-INF/lib/");
assertThat(actualManifest.getMainAttributes()).containsEntry(new Attributes.Name("Spring-Boot-Classes"),
"WEB-INF/classes/");
}
@Test
@@ -435,15 +417,11 @@ public class RepackagerTests {
this.testJarFile.addClass("A.class", ClassWithMainMethod.class);
File file = this.testJarFile.getFile();
Repackager repackager = new Repackager(file);
repackager.repackage((callback) -> callback
.library(new Library(nestedFile, LibraryScope.COMPILE)));
repackager.repackage((callback) -> callback.library(new Library(nestedFile, LibraryScope.COMPILE)));
try (JarFile jarFile = new JarFile(file)) {
assertThat(
jarFile.getEntry("BOOT-INF/lib/" + nestedFile.getName()).getMethod())
.isEqualTo(ZipEntry.STORED);
assertThat(jarFile.getEntry("BOOT-INF/classes/test/nested.jar").getMethod())
.isEqualTo(ZipEntry.STORED);
assertThat(jarFile.getEntry("BOOT-INF/lib/" + nestedFile.getName()).getMethod()).isEqualTo(ZipEntry.STORED);
assertThat(jarFile.getEntry("BOOT-INF/classes/test/nested.jar").getMethod()).isEqualTo(ZipEntry.STORED);
}
}
@@ -460,8 +438,7 @@ public class RepackagerTests {
assertThat(hasLauncherClasses(source)).isFalse();
assertThat(hasLauncherClasses(dest)).isTrue();
try {
assertThat(Files.getPosixFilePermissions(dest.toPath()))
.contains(PosixFilePermission.OWNER_EXECUTE);
assertThat(Files.getPosixFilePermissions(dest.toPath())).contains(PosixFilePermission.OWNER_EXECUTE);
}
catch (UnsupportedOperationException ex) {
// Probably running the test on Windows
@@ -469,8 +446,7 @@ public class RepackagerTests {
}
@Test
public void unpackLibrariesTakePrecedenceOverExistingSourceEntries()
throws Exception {
public void unpackLibrariesTakePrecedenceOverExistingSourceEntries() throws Exception {
TestJarFile nested = new TestJarFile(this.temporaryFolder);
nested.addClass("a/b/C.class", ClassWithoutMainMethod.class);
File nestedFile = nested.getFile();
@@ -479,21 +455,18 @@ public class RepackagerTests {
this.testJarFile.addClass("A.class", ClassWithMainMethod.class);
File file = this.testJarFile.getFile();
Repackager repackager = new Repackager(file);
repackager.repackage((callback) -> callback
.library(new Library(nestedFile, LibraryScope.COMPILE, true)));
repackager.repackage((callback) -> callback.library(new Library(nestedFile, LibraryScope.COMPILE, true)));
try (JarFile jarFile = new JarFile(file)) {
assertThat(jarFile.getEntry(name).getComment()).startsWith("UNPACK:");
}
}
@Test
public void existingSourceEntriesTakePrecedenceOverStandardLibraries()
throws Exception {
public void existingSourceEntriesTakePrecedenceOverStandardLibraries() throws Exception {
TestJarFile nested = new TestJarFile(this.temporaryFolder);
nested.addClass("a/b/C.class", ClassWithoutMainMethod.class);
File nestedFile = nested.getFile();
this.testJarFile.addFile("BOOT-INF/lib/" + nestedFile.getName(),
nested.getFile());
this.testJarFile.addFile("BOOT-INF/lib/" + nestedFile.getName(), nested.getFile());
this.testJarFile.addClass("A.class", ClassWithMainMethod.class);
File file = this.testJarFile.getFile();
Repackager repackager = new Repackager(file);
@@ -505,16 +478,14 @@ public class RepackagerTests {
callback.library(new Library(nestedFile, LibraryScope.COMPILE));
});
try (JarFile jarFile = new JarFile(file)) {
assertThat(jarFile.getEntry("BOOT-INF/lib/" + nestedFile.getName()).getSize())
.isEqualTo(sourceLength);
assertThat(jarFile.getEntry("BOOT-INF/lib/" + nestedFile.getName()).getSize()).isEqualTo(sourceLength);
}
}
@Test
public void metaInfIndexListIsRemovedFromRepackagedJar() throws Exception {
this.testJarFile.addClass("A.class", ClassWithMainMethod.class);
this.testJarFile.addFile("META-INF/INDEX.LIST",
this.temporaryFolder.newFile("INDEX.LIST"));
this.testJarFile.addFile("META-INF/INDEX.LIST", this.temporaryFolder.newFile("INDEX.LIST"));
File source = this.testJarFile.getFile();
File dest = this.temporaryFolder.newFile("dest.jar");
Repackager repackager = new Repackager(source);
@@ -548,11 +519,9 @@ public class RepackagerTests {
}
@Test
public void metaInfAopXmlIsMovedBeneathBootInfClassesWhenRepackaged()
throws Exception {
public void metaInfAopXmlIsMovedBeneathBootInfClassesWhenRepackaged() throws Exception {
this.testJarFile.addClass("A.class", ClassWithMainMethod.class);
this.testJarFile.addFile("META-INF/aop.xml",
this.temporaryFolder.newFile("aop.xml"));
this.testJarFile.addFile("META-INF/aop.xml", this.temporaryFolder.newFile("aop.xml"));
File source = this.testJarFile.getFile();
File dest = this.temporaryFolder.newFile("dest.jar");
Repackager repackager = new Repackager(source);
@@ -581,10 +550,8 @@ public class RepackagerTests {
}
@Test
public void loaderIsWrittenFirstThenApplicationClassesThenLibraries()
throws IOException {
this.testJarFile.addClass("com/example/Application.class",
ClassWithMainMethod.class);
public void loaderIsWrittenFirstThenApplicationClassesThenLibraries() throws IOException {
this.testJarFile.addClass("com/example/Application.class", ClassWithMainMethod.class);
File source = this.testJarFile.getFile();
File dest = this.temporaryFolder.newFile("dest.jar");
File libraryOne = createLibrary();
@@ -596,31 +563,23 @@ public class RepackagerTests {
callback.library(new Library(libraryTwo, LibraryScope.COMPILE, true));
callback.library(new Library(libraryThree, LibraryScope.COMPILE, false));
});
assertThat(getEntryNames(dest)).containsSubsequence(
"org/springframework/boot/loader/",
"BOOT-INF/classes/com/example/Application.class",
"BOOT-INF/lib/" + libraryOne.getName(),
"BOOT-INF/lib/" + libraryTwo.getName(),
"BOOT-INF/lib/" + libraryThree.getName());
assertThat(getEntryNames(dest)).containsSubsequence("org/springframework/boot/loader/",
"BOOT-INF/classes/com/example/Application.class", "BOOT-INF/lib/" + libraryOne.getName(),
"BOOT-INF/lib/" + libraryTwo.getName(), "BOOT-INF/lib/" + libraryThree.getName());
}
@Test
public void existingEntryThatMatchesUnpackLibraryIsMarkedForUnpack()
throws IOException {
public void existingEntryThatMatchesUnpackLibraryIsMarkedForUnpack() throws IOException {
File library = createLibrary();
this.testJarFile.addClass("WEB-INF/classes/com/example/Application.class",
ClassWithMainMethod.class);
this.testJarFile.addClass("WEB-INF/classes/com/example/Application.class", ClassWithMainMethod.class);
this.testJarFile.addFile("WEB-INF/lib/" + library.getName(), library);
File source = this.testJarFile.getFile("war");
File dest = this.temporaryFolder.newFile("dest.war");
Repackager repackager = new Repackager(source);
repackager.setLayout(new Layouts.War());
repackager.repackage(dest, (callback) -> callback
.library(new Library(library, LibraryScope.COMPILE, true)));
assertThat(getEntryNames(dest)).containsSubsequence(
"org/springframework/boot/loader/",
"WEB-INF/classes/com/example/Application.class",
"WEB-INF/lib/" + library.getName());
repackager.repackage(dest, (callback) -> callback.library(new Library(library, LibraryScope.COMPILE, true)));
assertThat(getEntryNames(dest)).containsSubsequence("org/springframework/boot/loader/",
"WEB-INF/classes/com/example/Application.class", "WEB-INF/lib/" + library.getName());
JarEntry unpackLibrary = getEntry(dest, "WEB-INF/lib/" + library.getName());
assertThat(unpackLibrary.getComment()).startsWith("UNPACK:");
}
@@ -636,15 +595,13 @@ public class RepackagerTests {
Layout layout = mock(Layout.class);
LibraryScope scope = mock(LibraryScope.class);
repackager.setLayout(layout);
repackager.repackage(
(callback) -> callback.library(new Library(libJarFile, scope)));
assertThat(getEntryNames(file)).containsExactly("META-INF/",
"META-INF/MANIFEST.MF", "a/", "a/b/", "a/b/C.class");
repackager.repackage((callback) -> callback.library(new Library(libJarFile, scope)));
assertThat(getEntryNames(file)).containsExactly("META-INF/", "META-INF/MANIFEST.MF", "a/", "a/b/",
"a/b/C.class");
}
@Test
public void jarThatUsesCustomCompressionConfigurationCanBeRepackaged()
throws IOException {
public void jarThatUsesCustomCompressionConfigurationCanBeRepackaged() throws IOException {
File source = this.temporaryFolder.newFile("source.jar");
ZipOutputStream output = new ZipOutputStream(new FileOutputStream(source)) {
{
@@ -666,8 +623,7 @@ public class RepackagerTests {
private File createLibrary() throws IOException {
TestJarFile library = new TestJarFile(this.temporaryFolder);
library.addClass("com/example/library/Library.class",
ClassWithoutMainMethod.class);
library.addClass("com/example/library/Library.class", ClassWithoutMainMethod.class);
return library.getFile();
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -55,12 +55,11 @@ public class TestJarFile {
addClass(filename, classToCopy, null);
}
public void addClass(String filename, Class<?> classToCopy, Long time)
throws IOException {
public void addClass(String filename, Class<?> classToCopy, Long time) throws IOException {
File file = getFilePath(filename);
file.getParentFile().mkdirs();
InputStream inputStream = getClass().getResourceAsStream(
"/" + classToCopy.getName().replace('.', '/') + ".class");
InputStream inputStream = getClass()
.getResourceAsStream("/" + classToCopy.getName().replace('.', '/') + ".class");
copyToFile(inputStream, file);
if (time != null) {
file.setLastModified(time);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -33,8 +33,7 @@ import static org.assertj.core.api.Assertions.assertThat;
public class ZipHeaderPeekInputStreamTests {
@Test
public void hasZipHeaderReturnsTrueWhenStreamStartsWithZipHeader()
throws IOException {
public void hasZipHeaderReturnsTrueWhenStreamStartsWithZipHeader() throws IOException {
try (ZipHeaderPeekInputStream in = new ZipHeaderPeekInputStream(
new ByteArrayInputStream(new byte[] { 0x50, 0x4b, 0x03, 0x04, 5, 6 }))) {
assertThat(in.hasZipHeader()).isTrue();
@@ -42,8 +41,7 @@ public class ZipHeaderPeekInputStreamTests {
}
@Test
public void hasZipHeaderReturnsFalseWhenStreamDoesNotStartWithZipHeader()
throws IOException {
public void hasZipHeaderReturnsFalseWhenStreamDoesNotStartWithZipHeader() throws IOException {
try (ZipHeaderPeekInputStream in = new ZipHeaderPeekInputStream(
new ByteArrayInputStream(new byte[] { 0, 1, 2, 3, 4, 5 }))) {
assertThat(in.hasZipHeader()).isFalse();
@@ -88,8 +86,7 @@ public class ZipHeaderPeekInputStreamTests {
}
@Test
public void readOfSomeOfTheHeaderThenMoreThanEntireStreamReadsToEndOfStream()
throws IOException {
public void readOfSomeOfTheHeaderThenMoreThanEntireStreamReadsToEndOfStream() throws IOException {
try (ZipHeaderPeekInputStream in = new ZipHeaderPeekInputStream(
new ByteArrayInputStream(new byte[] { 0, 1, 2, 3, 4, 5 }))) {
byte[] bytes = new byte[8];
@@ -101,10 +98,8 @@ public class ZipHeaderPeekInputStreamTests {
}
@Test
public void readMoreThanEntireStreamWhenStreamLengthIsLessThanZipHeaderLength()
throws IOException {
try (ZipHeaderPeekInputStream in = new ZipHeaderPeekInputStream(
new ByteArrayInputStream(new byte[] { 10 }))) {
public void readMoreThanEntireStreamWhenStreamLengthIsLessThanZipHeaderLength() throws IOException {
try (ZipHeaderPeekInputStream in = new ZipHeaderPeekInputStream(new ByteArrayInputStream(new byte[] { 10 }))) {
byte[] bytes = new byte[8];
assertThat(in.read(bytes)).isEqualTo(1);
assertThat(bytes).containsExactly(10, 0, 0, 0, 0, 0, 0, 0);
@@ -112,8 +107,7 @@ public class ZipHeaderPeekInputStreamTests {
}
@Test
public void readMoreThanEntireStreamWhenStreamLengthIsSameAsHeaderLength()
throws IOException {
public void readMoreThanEntireStreamWhenStreamLengthIsSameAsHeaderLength() throws IOException {
try (ZipHeaderPeekInputStream in = new ZipHeaderPeekInputStream(
new ByteArrayInputStream(new byte[] { 1, 2, 3, 4 }))) {
byte[] bytes = new byte[8];
@@ -124,8 +118,7 @@ public class ZipHeaderPeekInputStreamTests {
@Test
public void readMoreThanEntireStreamWhenStreamLengthIsZero() throws IOException {
try (ZipHeaderPeekInputStream in = new ZipHeaderPeekInputStream(
new ByteArrayInputStream(new byte[0]))) {
try (ZipHeaderPeekInputStream in = new ZipHeaderPeekInputStream(new ByteArrayInputStream(new byte[0]))) {
byte[] bytes = new byte[8];
assertThat(in.read(bytes)).isEqualTo(-1);
assertThat(bytes).containsExactly(0, 0, 0, 0, 0, 0, 0, 0);