Merge branch '1.1.x'
This commit is contained in:
commit
be2803a776
|
|
@ -107,6 +107,11 @@ public class Repackager {
|
||||||
if (libraries == null) {
|
if (libraries == null) {
|
||||||
throw new IllegalArgumentException("Libraries must not be null");
|
throw new IllegalArgumentException("Libraries must not be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (alreadyRepackaged()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
destination = destination.getAbsoluteFile();
|
destination = destination.getAbsoluteFile();
|
||||||
File workingSource = this.source;
|
File workingSource = this.source;
|
||||||
if (this.source.equals(destination)) {
|
if (this.source.equals(destination)) {
|
||||||
|
|
@ -132,6 +137,19 @@ public class Repackager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean alreadyRepackaged() throws IOException {
|
||||||
|
JarFile jarFile = new JarFile(this.source);
|
||||||
|
|
||||||
|
try {
|
||||||
|
Manifest manifest = jarFile.getManifest();
|
||||||
|
return manifest != null
|
||||||
|
&& manifest.getMainAttributes().getValue(BOOT_VERSION_ATTRIBUTE) != null;
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
jarFile.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void repackage(JarFile sourceJar, File destination, Libraries libraries)
|
private void repackage(JarFile sourceJar, File destination, Libraries libraries)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
final JarWriter writer = new JarWriter(destination);
|
final JarWriter writer = new JarWriter(destination);
|
||||||
|
|
@ -208,7 +226,7 @@ public class Repackager {
|
||||||
String launcherClassName = this.layout.getLauncherClassName();
|
String launcherClassName = this.layout.getLauncherClassName();
|
||||||
if (launcherClassName != null) {
|
if (launcherClassName != null) {
|
||||||
manifest.getMainAttributes()
|
manifest.getMainAttributes()
|
||||||
.putValue(MAIN_CLASS_ATTRIBUTE, launcherClassName);
|
.putValue(MAIN_CLASS_ATTRIBUTE, launcherClassName);
|
||||||
if (startClass == null) {
|
if (startClass == null) {
|
||||||
throw new IllegalStateException("Unable to find main class");
|
throw new IllegalStateException("Unable to find main class");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -134,6 +134,22 @@ public class RepackagerTests {
|
||||||
assertThat(hasLauncherClasses(file), equalTo(true));
|
assertThat(hasLauncherClasses(file), equalTo(true));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void jarIsOnlyRepackagedOnce() throws Exception {
|
||||||
|
this.testJarFile.addClass("a/b/C.class", ClassWithMainMethod.class);
|
||||||
|
File file = this.testJarFile.getFile();
|
||||||
|
Repackager repackager = new Repackager(file);
|
||||||
|
repackager.repackage(NO_LIBRARIES);
|
||||||
|
repackager.repackage(NO_LIBRARIES);
|
||||||
|
|
||||||
|
Manifest actualManifest = getManifest(file);
|
||||||
|
assertThat(actualManifest.getMainAttributes().getValue("Main-Class"),
|
||||||
|
equalTo("org.springframework.boot.loader.JarLauncher"));
|
||||||
|
assertThat(actualManifest.getMainAttributes().getValue("Start-Class"),
|
||||||
|
equalTo("a.b.C"));
|
||||||
|
assertThat(hasLauncherClasses(file), equalTo(true));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void multipleMainClassFound() throws Exception {
|
public void multipleMainClassFound() throws Exception {
|
||||||
this.testJarFile.addClass("a/b/C.class", ClassWithMainMethod.class);
|
this.testJarFile.addClass("a/b/C.class", ClassWithMainMethod.class);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue