Skip to content

Commit 2f26088

Browse files
committed
Unpack CLI for its integration tests as dir is no longer assembled
Closes spring-projectsgh-9080
1 parent dc8a34f commit 2f26088

File tree

1 file changed

+33
-11
lines changed

1 file changed

+33
-11
lines changed

spring-boot-cli/src/it/java/org/springframework/boot/cli/infrastructure/CommandLineInvoker.java

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
import java.io.BufferedReader;
2020
import java.io.File;
2121
import java.io.FileFilter;
22+
import java.io.FileInputStream;
23+
import java.io.FileOutputStream;
2224
import java.io.IOException;
2325
import java.io.InputStream;
2426
import java.io.PrintWriter;
@@ -27,8 +29,11 @@
2729
import java.util.ArrayList;
2830
import java.util.Arrays;
2931
import java.util.List;
32+
import java.util.zip.ZipEntry;
33+
import java.util.zip.ZipInputStream;
3034

3135
import org.springframework.util.Assert;
36+
import org.springframework.util.StreamUtils;
3237

3338
/**
3439
* Utility to invoke the command line in the same way as a user would, i.e. via the shell
@@ -63,18 +68,35 @@ private Process runCliProcess(String... args) throws IOException {
6368
return processBuilder.start();
6469
}
6570

66-
private File findLaunchScript() {
67-
File dir = new File("target");
68-
dir = dir.listFiles(new FileFilter() {
69-
@Override
70-
public boolean accept(File pathname) {
71-
return pathname.isDirectory() && pathname.getName().contains("-bin");
71+
private File findLaunchScript() throws IOException {
72+
File unpacked = new File("target/unpacked-cli");
73+
if (!unpacked.isDirectory()) {
74+
File zip = new File("target").listFiles(new FileFilter() {
75+
76+
@Override
77+
public boolean accept(File pathname) {
78+
return pathname.getName().endsWith("-bin.zip");
79+
}
80+
81+
})[0];
82+
ZipInputStream input = new ZipInputStream(new FileInputStream(zip));
83+
ZipEntry entry;
84+
while ((entry = input.getNextEntry()) != null) {
85+
File file = new File(unpacked, entry.getName());
86+
if (entry.isDirectory()) {
87+
file.mkdirs();
88+
}
89+
else {
90+
file.getParentFile().mkdirs();
91+
StreamUtils.copy(input, new FileOutputStream(file));
92+
if (entry.getName().endsWith("/bin/spring")) {
93+
file.setExecutable(true);
94+
}
95+
}
7296
}
73-
})[0];
74-
dir = new File(dir,
75-
dir.getName().replace("-bin", "").replace("spring-boot-cli", "spring"));
76-
dir = new File(dir, "bin");
77-
File launchScript = new File(dir, isWindows() ? "spring.bat" : "spring");
97+
}
98+
File bin = new File(unpacked.listFiles()[0], "bin");
99+
File launchScript = new File(bin, isWindows() ? "spring.bat" : "spring");
78100
Assert.state(launchScript.exists() && launchScript.isFile(),
79101
"Could not find CLI launch script " + launchScript.getAbsolutePath());
80102
return launchScript;

0 commit comments

Comments
 (0)