|
19 | 19 | import java.io.BufferedReader;
|
20 | 20 | import java.io.File;
|
21 | 21 | import java.io.FileFilter;
|
| 22 | +import java.io.FileInputStream; |
| 23 | +import java.io.FileOutputStream; |
22 | 24 | import java.io.IOException;
|
23 | 25 | import java.io.InputStream;
|
24 | 26 | import java.io.PrintWriter;
|
|
27 | 29 | import java.util.ArrayList;
|
28 | 30 | import java.util.Arrays;
|
29 | 31 | import java.util.List;
|
| 32 | +import java.util.zip.ZipEntry; |
| 33 | +import java.util.zip.ZipInputStream; |
30 | 34 |
|
31 | 35 | import org.springframework.util.Assert;
|
| 36 | +import org.springframework.util.StreamUtils; |
32 | 37 |
|
33 | 38 | /**
|
34 | 39 | * 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 {
|
63 | 68 | return processBuilder.start();
|
64 | 69 | }
|
65 | 70 |
|
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 | + } |
72 | 96 | }
|
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"); |
78 | 100 | Assert.state(launchScript.exists() && launchScript.isFile(),
|
79 | 101 | "Could not find CLI launch script " + launchScript.getAbsolutePath());
|
80 | 102 | return launchScript;
|
|
0 commit comments