Skip to content

Commit 3398a08

Browse files
Improve @arg-file processing in dev launcher
Stop processing argument when we reach application arguments
1 parent a0316f8 commit 3398a08

File tree

1 file changed

+60
-5
lines changed
  • espresso/src/com.oracle.truffle.espresso.launcher/src/com/oracle/truffle/espresso/launcher

1 file changed

+60
-5
lines changed

espresso/src/com.oracle.truffle.espresso.launcher/src/com/oracle/truffle/espresso/launcher/EspressoLauncher.java

Lines changed: 60 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -401,21 +401,76 @@ protected List<String> preprocessArguments(List<String> arguments, Map<String, S
401401
}
402402

403403
private List<String> expandAtFiles(List<String> arguments) {
404+
// Expand @arg-file arguments until we reach application arguments
404405
List<String> expanded = null;
405-
for (int i = 0; i < arguments.size(); i++) {
406+
int i = 0;
407+
for (; i < arguments.size(); i++) {
406408
String arg = arguments.get(i);
407-
if (arg.startsWith("@")) {
409+
if (arg.startsWith("@") && arg.length() > 1) {
408410
if (expanded == null) {
409411
expanded = new ArrayList<>(arguments.subList(0, i));
410412
}
411-
parseArgFile(arg.substring(1, arg.length()), expanded);
412-
} else if (expanded != null) {
413-
expanded.add(arg);
413+
String argArg = arg.substring(1);
414+
if (arg.charAt(1) == '@') {
415+
// escaped argument
416+
expanded.add(argArg);
417+
} else {
418+
// Note, at the moment we don't detect the end of VM arguments
419+
// inside the arg file itself
420+
parseArgFile(argArg, expanded);
421+
}
422+
} else {
423+
if (arg.startsWith("-")) {
424+
if (isWhiteSpaceOption(arg)) {
425+
// Skip the argument that follows this option
426+
if (expanded != null) {
427+
expanded.add(arg);
428+
}
429+
i++;
430+
arg = arguments.get(i);
431+
} else if ("--disable-@files".equals(arg) || arg.startsWith("--module=")) {
432+
break;
433+
}
434+
} else {
435+
// We have reached the main class or the jar
436+
break;
437+
}
438+
if (expanded != null) {
439+
expanded.add(arg);
440+
}
414441
}
415442
}
443+
if (expanded != null && i < arguments.size()) {
444+
expanded.addAll(arguments.subList(i, arguments.size()));
445+
}
416446
return expanded == null ? arguments : expanded;
417447
}
418448

449+
private static boolean isWhiteSpaceOption(String arg) {
450+
return switch (arg) {
451+
case "--module-path",
452+
"-p",
453+
"--upgrade-module-path",
454+
"--add-modules",
455+
"--enable-native-access",
456+
"--limit-modules",
457+
"--add-exports",
458+
"--add-opens",
459+
"--add-reads",
460+
"--patch-module",
461+
"--describe-module",
462+
"-d",
463+
"--source",
464+
"--module",
465+
"-m",
466+
"-classpath",
467+
"-cp",
468+
"--class-path" ->
469+
true;
470+
default -> false;
471+
};
472+
}
473+
419474
private void parseArgFile(String pathArg, List<String> expanded) {
420475
Path argFilePath = Paths.get(pathArg);
421476
try {

0 commit comments

Comments
 (0)