diff --git a/spring-boot-project/spring-boot-tools/spring-boot-loader-tools/src/test/java/org/springframework/boot/loader/tools/TestJarFile.java b/spring-boot-project/spring-boot-tools/spring-boot-loader-tools/src/test/java/org/springframework/boot/loader/tools/TestJarFile.java index 0b4acbe9ab..cca814dedb 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-loader-tools/src/test/java/org/springframework/boot/loader/tools/TestJarFile.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-loader-tools/src/test/java/org/springframework/boot/loader/tools/TestJarFile.java @@ -22,10 +22,14 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.util.ArrayList; +import java.util.List; import java.util.jar.JarFile; import java.util.jar.Manifest; import org.junit.rules.TemporaryFolder; +import org.zeroturnaround.zip.FileSource; +import org.zeroturnaround.zip.ZipEntrySource; import org.zeroturnaround.zip.ZipUtil; /** @@ -40,6 +44,8 @@ public class TestJarFile { private final File jarSource; + private final List entries = new ArrayList<>(); + public TestJarFile(TemporaryFolder temporaryFolder) throws IOException { this.temporaryFolder = temporaryFolder; this.jarSource = temporaryFolder.newFolder(); @@ -59,6 +65,7 @@ public class TestJarFile { if (time != null) { file.setLastModified(time); } + this.entries.add(new FileSource(filename, file)); } public void addFile(String filename, File fileToCopy) throws IOException { @@ -67,6 +74,7 @@ public class TestJarFile { try (InputStream inputStream = new FileInputStream(fileToCopy)) { copyToFile(inputStream, file); } + this.entries.add(new FileSource(filename, file)); } public void addManifest(Manifest manifest) throws IOException { @@ -75,6 +83,7 @@ public class TestJarFile { try (OutputStream outputStream = new FileOutputStream(manifestFile)) { manifest.write(outputStream); } + this.entries.add(new FileSource("META-INF/MANIFEST.MF", manifestFile)); } private File getFilePath(String filename) { @@ -114,7 +123,7 @@ public class TestJarFile { public File getFile(String extension) throws IOException { File file = this.temporaryFolder.newFile(); file = new File(file.getParent(), file.getName() + "." + extension); - ZipUtil.pack(this.jarSource, file); + ZipUtil.pack(this.entries.toArray(new ZipEntrySource[this.entries.size()]), file); return file; }