|
50 | 50 | import java.util.Map; |
51 | 51 | import java.util.Optional; |
52 | 52 | import java.util.Properties; |
| 53 | +import java.util.StringJoiner; |
53 | 54 | import java.util.function.BiConsumer; |
54 | 55 | import java.util.function.BiFunction; |
55 | 56 | import java.util.function.Consumer; |
@@ -1301,7 +1302,22 @@ protected static List<String> createImageBuilderArgs(ArrayList<String> imageArgs |
1301 | 1302 | protected static String createVMInvocationArgumentFile(List<String> arguments) { |
1302 | 1303 | try { |
1303 | 1304 | Path argsFile = Files.createTempFile("vminvocation", ".args"); |
1304 | | - String joinedOptions = String.join("\n", arguments); |
| 1305 | + StringJoiner joiner = new StringJoiner("\n"); |
| 1306 | + for (String arg : arguments) { |
| 1307 | + // Options in @argfile need to be properly quoted as |
| 1308 | + // this relies on the JDK's @argfile parsing when the |
| 1309 | + // native image generator is being launched. |
| 1310 | + String quoted = SubstrateUtil.quoteShellArg(arg); |
| 1311 | + // @argfile rules for Windows quirk: backslashes don't need to be |
| 1312 | + // escaped if the option they are used in isn't quoted. If it is |
| 1313 | + // though, then they need to be escaped. This might mean that |
| 1314 | + // user-supplied arguments containing '\' will be double escaped. |
| 1315 | + if (quoted.startsWith("'")) { |
| 1316 | + quoted = quoted.replace("\\", "\\\\"); |
| 1317 | + } |
| 1318 | + joiner.add(quoted); |
| 1319 | + } |
| 1320 | + String joinedOptions = joiner.toString(); |
1305 | 1321 | Files.write(argsFile, joinedOptions.getBytes()); |
1306 | 1322 | argsFile.toFile().deleteOnExit(); |
1307 | 1323 | return "@" + argsFile; |
|
0 commit comments