diff options
author | Stefan Bodewig <stefan.bodewig@innoq.com> | 2022-11-19 17:50:29 +0100 |
---|---|---|
committer | Stefan Bodewig <stefan.bodewig@innoq.com> | 2022-11-19 17:50:29 +0100 |
commit | 3e6d6acc38a47aa66e629e519f482ee975dd0480 (patch) | |
tree | 4408ce95e636cc281cec38adb3b365cbf4e3f5c2 /src/main/org/apache/tools/ant/taskdefs | |
parent | 0aca73974a1f03afc3f985a4beb94a5cd26e6bcf (diff) | |
download | ant-3e6d6acc38a47aa66e629e519f482ee975dd0480.tar.gz |
paths with wildcards do not work in javac's arg-file
https://bz.apache.org/bugzilla/show_bug.cgi?id=65621
Diffstat (limited to 'src/main/org/apache/tools/ant/taskdefs')
-rw-r--r-- | src/main/org/apache/tools/ant/taskdefs/compilers/JavacExternal.java | 61 |
1 files changed, 52 insertions, 9 deletions
diff --git a/src/main/org/apache/tools/ant/taskdefs/compilers/JavacExternal.java b/src/main/org/apache/tools/ant/taskdefs/compilers/JavacExternal.java index 8ce805900..d4487699c 100644 --- a/src/main/org/apache/tools/ant/taskdefs/compilers/JavacExternal.java +++ b/src/main/org/apache/tools/ant/taskdefs/compilers/JavacExternal.java @@ -20,6 +20,8 @@ package org.apache.tools.ant.taskdefs.compilers; import java.io.File; import java.io.IOException; +import java.util.Arrays; +import java.util.List; import org.apache.tools.ant.BuildException; import org.apache.tools.ant.Project; @@ -86,27 +88,68 @@ public class JavacExternal extends DefaultCompilerAdapter { */ private int moveArgFileEligibleOptionsToEnd(String[] commandLine) { int nonArgFileOptionIdx = 1; // 0 for javac executable - while(nonArgFileOptionIdx < commandLine.length && - !isArgFileEligible(commandLine[nonArgFileOptionIdx])) { - nonArgFileOptionIdx++; + while (nonArgFileOptionIdx < commandLine.length) { + int argsToMove = numberOfArgsNotEligibleForFile(commandLine, nonArgFileOptionIdx); + if (argsToMove > 0) { + nonArgFileOptionIdx += argsToMove; + } else { + break; + } } for(int i = nonArgFileOptionIdx + 1; i < commandLine.length; i++) { - if (!isArgFileEligible(commandLine[i])) { - String option = commandLine[i]; + int argsToMove = numberOfArgsNotEligibleForFile(commandLine, i); + if (argsToMove > 0) { + String[] options = Arrays.copyOfRange(commandLine, i, i + argsToMove); if (i - nonArgFileOptionIdx >= 0) { - System.arraycopy( commandLine, nonArgFileOptionIdx, commandLine, nonArgFileOptionIdx + 1, i - nonArgFileOptionIdx ); + System.arraycopy( commandLine, nonArgFileOptionIdx, commandLine, nonArgFileOptionIdx + argsToMove, i - nonArgFileOptionIdx ); } - commandLine[nonArgFileOptionIdx] = option; - nonArgFileOptionIdx++; + System.arraycopy(options, 0, commandLine, nonArgFileOptionIdx, argsToMove); + nonArgFileOptionIdx += argsToMove; + i += argsToMove - 1; } } return nonArgFileOptionIdx; } + private static int numberOfArgsNotEligibleForFile(String[] args, int currentIndex) { + String currentOption = args[currentIndex]; + if (!isArgFileEligible(currentOption)) { + return 1; + } + if (currentIndex + 1 < args.length && isArgFollowedByPath(currentOption) + && containsWildcards(args[currentIndex + 1])) { + return 2; + } + return 0; + } + + private static boolean containsWildcards(String path) { + return path.contains("*") || path.contains("?"); + } + private static boolean isArgFileEligible(String option) { - return !(option.startsWith("-J") || option.startsWith("@")); + return !(option.startsWith("-J") || option.startsWith("@") + || (option.startsWith("-Xbootclasspath/") && containsWildcards(option)) + ); + } + + private static List<String> ARGS_FOLLOWED_BY_PATH = Arrays.asList( + "-cp", "-classpath", "--class-path", + "-endorseddirs", + "-extdirs", + "--module-path", "-p", + "--module-source-path", + "--processor-module-path", + "--processor-path", "-processorpath", + "-sourcepath", "--source-path", + "-bootclasspath", "--boot-class-path", + "--upgrade-module-path" + ); + + private static boolean isArgFollowedByPath(String option) { + return ARGS_FOLLOWED_BY_PATH.contains(option); } /** |