diff --git a/spring-boot-tools/spring-boot-antlib/src/main/resources/org/springframework/boot/ant/antlib.xml b/spring-boot-tools/spring-boot-antlib/src/main/resources/org/springframework/boot/ant/antlib.xml index 010d04b2df1..787a2d68bab 100644 --- a/spring-boot-tools/spring-boot-antlib/src/main/resources/org/springframework/boot/ant/antlib.xml +++ b/spring-boot-tools/spring-boot-antlib/src/main/resources/org/springframework/boot/ant/antlib.xml @@ -74,6 +74,8 @@ + + diff --git a/spring-boot-tools/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/Repackager.java b/spring-boot-tools/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/Repackager.java index c9c59376ad4..5059e5f805f 100644 --- a/spring-boot-tools/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/Repackager.java +++ b/spring-boot-tools/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/Repackager.java @@ -45,6 +45,10 @@ public class Repackager { private static final String BOOT_VERSION_ATTRIBUTE = "Spring-Boot-Version"; + private static final String BOOT_LIB_ATTRIBUTE = "Spring-Boot-Lib"; + + private static final String BOOT_CLASSES_ATTRIBUTE = "Spring-Boot-Classes"; + private static final byte[] ZIP_FILE_HEADER = new byte[] { 'P', 'K', 3, 4 }; private String mainClass; @@ -282,6 +286,12 @@ public class Repackager { } String bootVersion = getClass().getPackage().getImplementationVersion(); manifest.getMainAttributes().putValue(BOOT_VERSION_ATTRIBUTE, bootVersion); + manifest.getMainAttributes().putValue(BOOT_CLASSES_ATTRIBUTE, + (this.layout instanceof RepackagingLayout) + ? ((RepackagingLayout) this.layout).getRepackagedClassesLocation() + : this.layout.getClassesLocation()); + manifest.getMainAttributes().putValue(BOOT_LIB_ATTRIBUTE, + this.layout.getLibraryDestination("", LibraryScope.COMPILE)); return manifest; } diff --git a/spring-boot-tools/spring-boot-loader-tools/src/test/java/org/springframework/boot/loader/tools/RepackagerTests.java b/spring-boot-tools/spring-boot-loader-tools/src/test/java/org/springframework/boot/loader/tools/RepackagerTests.java index 83f92b98bc0..edc4656fbfc 100644 --- a/spring-boot-tools/spring-boot-loader-tools/src/test/java/org/springframework/boot/loader/tools/RepackagerTests.java +++ b/spring-boot-tools/spring-boot-loader-tools/src/test/java/org/springframework/boot/loader/tools/RepackagerTests.java @@ -370,6 +370,33 @@ public class RepackagerTests { .containsKey(new Attributes.Name("Spring-Boot-Version")); } + @Test + public void executableJarLayoutAttributes() 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); + 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/"); + } + + @Test + public void executableWarLayoutAttributes() throws Exception { + 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/"); + } + @Test public void nullCustomLayout() throws Exception { this.testJarFile.addClass("a/b/C.class", ClassWithoutMainMethod.class); diff --git a/spring-boot-tools/spring-boot-loader-tools/src/test/java/org/springframework/boot/loader/tools/TestJarFile.java b/spring-boot-tools/spring-boot-loader-tools/src/test/java/org/springframework/boot/loader/tools/TestJarFile.java index 00cdf103290..ee94dc29102 100644 --- a/spring-boot-tools/spring-boot-loader-tools/src/test/java/org/springframework/boot/loader/tools/TestJarFile.java +++ b/spring-boot-tools/spring-boot-loader-tools/src/test/java/org/springframework/boot/loader/tools/TestJarFile.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2015 the original author or authors. + * Copyright 2012-2016 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. @@ -31,6 +31,7 @@ import org.zeroturnaround.zip.ZipUtil; /** * @author Phillip Webb + * @author Andy Wilkinson */ public class TestJarFile { @@ -121,8 +122,12 @@ public class TestJarFile { } public File getFile() throws IOException { + return getFile("jar"); + } + + public File getFile(String extension) throws IOException { File file = this.temporaryFolder.newFile(); - file = new File(file.getParent(), file.getName() + ".jar"); + file = new File(file.getParent(), file.getName() + "." + extension); ZipUtil.pack(this.jarSource, file); return file; }