Merge branch '2.3.x'
Closes gh-23000
This commit is contained in:
@@ -27,6 +27,7 @@ import java.util.Map;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipInputStream;
|
||||
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StreamUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
@@ -66,6 +67,8 @@ class ExtractCommand extends Command {
|
||||
}
|
||||
try (ZipInputStream zip = new ZipInputStream(new FileInputStream(this.context.getJarFile()))) {
|
||||
ZipEntry entry = zip.getNextEntry();
|
||||
Assert.state(entry != null, "File '" + this.context.getJarFile().toString()
|
||||
+ "' is not compatible with layertools; ensure jar file is valid and launch script is not enabled");
|
||||
while (entry != null) {
|
||||
if (!entry.isDirectory()) {
|
||||
String layer = this.layers.getLayer(entry);
|
||||
|
||||
@@ -18,6 +18,7 @@ package org.springframework.boot.jarmode.layertools;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
@@ -33,6 +34,7 @@ import org.mockito.Mock;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
|
||||
/**
|
||||
@@ -99,6 +101,19 @@ class ExtractCommandTests {
|
||||
assertThat(new File(this.extract, "c/c/c.jar")).exists();
|
||||
}
|
||||
|
||||
@Test
|
||||
void runWithJarFileContainingNoEntriesFails() throws IOException {
|
||||
File file = new File(this.temp, "empty.jar");
|
||||
FileWriter writer = new FileWriter(file);
|
||||
writer.write("text");
|
||||
writer.flush();
|
||||
given(this.context.getJarFile()).willReturn(file);
|
||||
given(this.context.getWorkingDir()).willReturn(this.extract);
|
||||
assertThatIllegalStateException()
|
||||
.isThrownBy(() -> this.command.run(Collections.emptyMap(), Collections.emptyList()))
|
||||
.withMessageContaining("not compatible with layertools");
|
||||
}
|
||||
|
||||
private File createJarFile(String name) throws IOException {
|
||||
File file = new File(this.temp, name);
|
||||
try (ZipOutputStream out = new ZipOutputStream(new FileOutputStream(file))) {
|
||||
|
||||
Reference in New Issue
Block a user