Index: src/main/org/apache/tools/ant/taskdefs/compilers/DefaultCompilerAdapter.java =================================================================== --- src/main/org/apache/tools/ant/taskdefs/compilers/DefaultCompilerAdapter.java (revision 1341589) +++ src/main/org/apache/tools/ant/taskdefs/compilers/DefaultCompilerAdapter.java (working copy) @@ -417,14 +417,14 @@ /** * Do the compile with the specified arguments. * @param args - arguments to pass to process on command line - * @param firstFileName - index of the first source file in args, + * @param separableArgIndex - index of the first source file in args, * if the index is negative, no temporary file will ever be * created, but this may hit the command line length limit on your * system. * @return the exit code of the compilation */ - protected int executeExternalCompile(String[] args, int firstFileName) { - return executeExternalCompile(args, firstFileName, true); + protected int executeExternalCompile(String[] args, int separableArgIndex) { + return executeExternalCompile(args, separableArgIndex, true); } /** @@ -434,10 +434,14 @@ * project's base directory.

* * @param args - arguments to pass to process on command line - * @param firstFileName - index of the first source file in args, - * if the index is negative, no temporary file will ever be - * created, but this may hit the command line length limit on your - * system. + * @param separableArgIndex - index of the first argument which could be + * placed in a separate file, if the total command line size exceeds some + * platform-dependent threshold (typically 4Kb). This and subsequent + * arguments will be replaced with {@code @that-file-location}. May be + * {@code -1} to suppress this feature entirely. Use {@code 0} to replace + * all arguments, which is suitable for all modern compilers. Some very old + * compilers require this to be the index of the first actual source file, + * in case compiler options cannot be included. * @param quoteFiles - if set to true, filenames containing * spaces will be quoted when they appear in the external file. * This is necessary when running JDK 1.4's javac and probably @@ -446,7 +450,7 @@ * * @since Ant 1.6 */ - protected int executeExternalCompile(String[] args, int firstFileName, + protected int executeExternalCompile(String[] args, int separableArgIndex, boolean quoteFiles) { String[] commandArray = null; File tmpFile = null; @@ -460,13 +464,13 @@ * file if the total length of the command line exceeds this limit. */ if (Commandline.toString(args).length() > COMMAND_LINE_LIMIT - && firstFileName >= 0) { + && separableArgIndex >= 0) { BufferedWriter out = null; try { tmpFile = FILE_UTILS.createTempFile( "files", "", getJavac().getTempdir(), true, true); out = new BufferedWriter(new FileWriter(tmpFile)); - for (int i = firstFileName; i < args.length; i++) { + for (int i = separableArgIndex; i < args.length; i++) { if (quoteFiles && args[i].indexOf(" ") > -1) { args[i] = args[i].replace(File.separatorChar, '/'); out.write("\"" + args[i] + "\""); @@ -476,9 +480,9 @@ out.newLine(); } out.flush(); - commandArray = new String[firstFileName + 1]; - System.arraycopy(args, 0, commandArray, 0, firstFileName); - commandArray[firstFileName] = "@" + tmpFile; + commandArray = new String[separableArgIndex + 1]; + System.arraycopy(args, 0, commandArray, 0, separableArgIndex); + commandArray[separableArgIndex] = "@" + tmpFile; } catch (IOException e) { throw new BuildException("Error creating temporary file", e, location); Index: src/main/org/apache/tools/ant/taskdefs/compilers/AptExternalCompilerAdapter.java =================================================================== --- src/main/org/apache/tools/ant/taskdefs/compilers/AptExternalCompilerAdapter.java (revision 1341589) +++ src/main/org/apache/tools/ant/taskdefs/compilers/AptExternalCompilerAdapter.java (working copy) @@ -56,13 +56,13 @@ cmd.setExecutable(apt.getAptExecutable()); setupModernJavacCommandlineSwitches(cmd); AptCompilerAdapter.setAptCommandlineSwitches(apt, cmd); - int firstFileName = cmd.size(); + int separableArgIndex = Project.toBoolean(project.getProperty("pre-50781")) ? cmd.size() : 1; //add the files logAndAddFilesToCompile(cmd); //run return 0 == executeExternalCompile(cmd.getCommandline(), - firstFileName, + separableArgIndex, true); } Index: src/main/org/apache/tools/ant/taskdefs/compilers/JavacExternal.java =================================================================== --- src/main/org/apache/tools/ant/taskdefs/compilers/JavacExternal.java (revision 1341589) +++ src/main/org/apache/tools/ant/taskdefs/compilers/JavacExternal.java (working copy) @@ -50,16 +50,16 @@ } else { setupJavacCommandlineSwitches(cmd, true); } - int firstFileName = assumeJava11() ? -1 : cmd.size(); + int separableArgIndex = assumeJava11() ? -1 : Project.toBoolean(project.getProperty("pre-50781")) ? cmd.size() : 1; logAndAddFilesToCompile(cmd); //On VMS platform, we need to create a special java options file //containing the arguments and classpath for the javac command. //The special file is supported by the "-V" switch on the VMS JVM. if (Os.isFamily("openvms")) { - return execOnVMS(cmd, firstFileName); + return execOnVMS(cmd, separableArgIndex); } return - executeExternalCompile(cmd.getCommandline(), firstFileName, + executeExternalCompile(cmd.getCommandline(), separableArgIndex, true) == 0; } @@ -67,10 +67,10 @@ /** * helper method to execute our command on VMS. * @param cmd - * @param firstFileName + * @param separableArgIndex * @return */ - private boolean execOnVMS(Commandline cmd, int firstFileName) { + private boolean execOnVMS(Commandline cmd, int separableArgIndex) { File vmsFile = null; try { vmsFile = JavaEnvUtils.createVmsJavaOptionFile(cmd.getArguments()); @@ -78,7 +78,7 @@ "-V", vmsFile.getPath()}; return 0 == executeExternalCompile(commandLine, - firstFileName, + separableArgIndex, true); } catch (IOException e) { Index: WHATSNEW =================================================================== --- WHATSNEW (revision 1341589) +++ WHATSNEW (working copy) @@ -7,6 +7,12 @@ Fixed bugs: ----------- + * could create excessively long command lines when e.g. long classpaths + were given. Now fixed for contemporary compilers; if using very old compilers + which do not accept options in @argumentfiles, use -Dpre-50781=true or the + corresponding . + Bugzilla Report 50781. + * External XML catalog resolver failed to use project basedir when given an unmentioned relative path like the internal resolver does. Bugzilla Report 52754.