You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ant.apache.org by ja...@apache.org on 2019/10/24 04:54:42 UTC
[ant] branch master updated: bz-63874 Fix regression introduced by
commit "Use commandline argument file for all options, but -J,
for case javac"
This is an automated email from the ASF dual-hosted git repository.
jaikiran pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ant.git
The following commit(s) were added to refs/heads/master by this push:
new 7b0e855 bz-63874 Fix regression introduced by commit "Use commandline argument file for all options, but -J, for case javac"
7b0e855 is described below
commit 7b0e8555a067d8288a4dcc653bf76f0102c349f8
Author: sergiys <se...@amazon.com>
AuthorDate: Wed Oct 23 13:24:19 2019 -0700
bz-63874 Fix regression introduced by commit "Use commandline argument file for all options, but -J, for case javac"
This closes #105 pull request at github/apache/ant repo
---
WHATSNEW | 4 +++
.../ant/taskdefs/compilers/JavacExternal.java | 35 ++++++++++--------
.../ant/taskdefs/compilers/JavacExternalTest.java | 42 ++++++++++++++++++++++
3 files changed, 66 insertions(+), 15 deletions(-)
diff --git a/WHATSNEW b/WHATSNEW
index 32424e4..ad4ac9e 100644
--- a/WHATSNEW
+++ b/WHATSNEW
@@ -10,6 +10,10 @@ Fixed bugs:
* sshexec failed to write output to a file if the file didn't exist
+ * Fixes a regression in javac task involving command line argument
+ files.
+ Bugzilla Report 63874
+
Other changes:
--------------
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 9569c7f..637e9bd 100644
--- a/src/main/org/apache/tools/ant/taskdefs/compilers/JavacExternal.java
+++ b/src/main/org/apache/tools/ant/taskdefs/compilers/JavacExternal.java
@@ -66,7 +66,7 @@ public class JavacExternal extends DefaultCompilerAdapter {
int firstFileName;
if (assumeJava1_2Plus()) {
- firstFileName = moveJOptionsToBeginning(commandLine);
+ firstFileName = moveArgFileEligibleOptionsToEnd(commandLine);
} else {
firstFileName = -1;
}
@@ -77,31 +77,36 @@ public class JavacExternal extends DefaultCompilerAdapter {
}
/**
- * Moves all -J arguments to the beginning
- * So that all command line arguments could be written to file, but -J
+ * Moves all -J and @argfiles arguments to the beginning
+ * So that all command line arguments could be written to file, but -J and @argfile
* As per javac documentation:
* you can specify one or more files that contain arguments to the javac command (except -J options)
* @param commandLine command line to process
- * @return int index of first non -J argument
+ * @return int index of first argument that could be put into argfile
*/
- private int moveJOptionsToBeginning(String[] commandLine) {
- int nonJArgumentIdx = 1; // 0 for javac executable
- while(nonJArgumentIdx < commandLine.length && commandLine[nonJArgumentIdx].startsWith("-J")) {
- nonJArgumentIdx++;
+ private int moveArgFileEligibleOptionsToEnd(String[] commandLine) {
+ int nonArgFileOptionIdx = 1; // 0 for javac executable
+ while(nonArgFileOptionIdx < commandLine.length &&
+ !isArgFileEligible(commandLine[nonArgFileOptionIdx])) {
+ nonArgFileOptionIdx++;
}
- for(int i = nonJArgumentIdx + 1; i < commandLine.length; i++) {
- if (commandLine[i].startsWith("-J")) {
- String jArgument = commandLine[i];
- for(int j = i - 1; j >= nonJArgumentIdx; j--) {
+ for(int i = nonArgFileOptionIdx + 1; i < commandLine.length; i++) {
+ if (!isArgFileEligible(commandLine[i])) {
+ String option = commandLine[i];
+ for(int j = i - 1; j >= nonArgFileOptionIdx; j--) {
commandLine[j + 1] = commandLine[j];
}
- commandLine[nonJArgumentIdx] = jArgument;
- nonJArgumentIdx++;
+ commandLine[nonArgFileOptionIdx] = option;
+ nonArgFileOptionIdx++;
}
}
- return nonJArgumentIdx;
+ return nonArgFileOptionIdx;
+ }
+
+ private static boolean isArgFileEligible(String option) {
+ return !(option.startsWith("-J") || option.startsWith("@"));
}
/**
diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/compilers/JavacExternalTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/compilers/JavacExternalTest.java
index 53aac63..a893fb4 100644
--- a/src/tests/junit/org/apache/tools/ant/taskdefs/compilers/JavacExternalTest.java
+++ b/src/tests/junit/org/apache/tools/ant/taskdefs/compilers/JavacExternalTest.java
@@ -28,6 +28,7 @@ import org.junit.Test;
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
+import java.util.stream.Stream;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
@@ -131,6 +132,47 @@ public class JavacExternalTest {
}
}
+ @Test
+ public void argFileOptionIsMovedToBeginning() throws Exception {
+ final File workDir = createWorkDir("testSMC");
+ try {
+ final File src = new File(workDir, "src");
+ src.mkdir();
+ createFile(src, "org/apache/ant/tests/J1.java");
+ createFile(src, "org/apache/ant/tests/J2.java");
+ final File modules = new File(workDir, "modules");
+ modules.mkdir();
+ final Project prj = new Project();
+ prj.setBaseDir(workDir);
+ final Javac javac = new Javac();
+ javac.setProject(prj);
+ final Commandline[] cmd = new Commandline[1];
+ final TestJavacExternal impl = new TestJavacExternal();
+ final Path srcPath = new Path(prj);
+ srcPath.setLocation(src);
+ javac.setSrcdir(srcPath);
+ javac.createModulepath().setLocation(modules);
+ javac.setSource("9");
+ javac.setTarget("9");
+ javac.setFork(true);
+ javac.setMemoryInitialSize("80m");
+ javac.setExecutable("javacExecutable");
+ javac.add(impl);
+ javac.createCompilerArg().setValue("-g");
+ javac.createCompilerArg().setValue("@/home/my-compiler.args");
+ javac.execute();
+ assertEquals("javacExecutable", impl.getArgs()[0]);
+ assertEquals("-J-Xms80m", impl.getArgs()[1]);
+ assertEquals("@/home/my-compiler.args", impl.getArgs()[2]);
+ assertTrue(Stream.of(impl.getArgs()).anyMatch(x -> x.equals("-g")));
+ assertTrue(impl.getArgs()[impl.getArgs().length - 2].endsWith("J1.java"));
+ assertTrue(impl.getArgs()[impl.getArgs().length - 1].endsWith("J2.java"));
+ assertEquals(3, impl.getFirstFileName());
+ } finally {
+ delete(workDir);
+ }
+ }
+
private File createWorkDir(String testName) {
final File tmp = new File(System.getProperty("java.io.tmpdir")); //NOI18N
final File destDir = new File(tmp, String.format("%s%s%d",