View | Details | Raw Unified | Return to bug 50781
Collapse All | Expand All

(-)src/main/org/apache/tools/ant/taskdefs/compilers/DefaultCompilerAdapter.java (-13 / +17 lines)
Lines 417-430 Link Here
417
    /**
417
    /**
418
     * Do the compile with the specified arguments.
418
     * Do the compile with the specified arguments.
419
     * @param args - arguments to pass to process on command line
419
     * @param args - arguments to pass to process on command line
420
     * @param firstFileName - index of the first source file in args,
420
     * @param separableArgIndex - index of the first source file in args,
421
     * if the index is negative, no temporary file will ever be
421
     * if the index is negative, no temporary file will ever be
422
     * created, but this may hit the command line length limit on your
422
     * created, but this may hit the command line length limit on your
423
     * system.
423
     * system.
424
     * @return the exit code of the compilation
424
     * @return the exit code of the compilation
425
     */
425
     */
426
    protected int executeExternalCompile(String[] args, int firstFileName) {
426
    protected int executeExternalCompile(String[] args, int separableArgIndex) {
427
        return executeExternalCompile(args, firstFileName, true);
427
        return executeExternalCompile(args, separableArgIndex, true);
428
    }
428
    }
429
429
430
    /**
430
    /**
Lines 434-443 Link Here
434
     * project's base directory.</p>
434
     * project's base directory.</p>
435
     *
435
     *
436
     * @param args - arguments to pass to process on command line
436
     * @param args - arguments to pass to process on command line
437
     * @param firstFileName - index of the first source file in args,
437
     * @param separableArgIndex - index of the first argument which could be
438
     * if the index is negative, no temporary file will ever be
438
     * placed in a separate file, if the total command line size exceeds some
439
     * created, but this may hit the command line length limit on your
439
     * platform-dependent threshold (typically 4Kb). This and subsequent
440
     * system.
440
     * arguments will be replaced with {@code @that-file-location}. May be
441
     * {@code -1} to suppress this feature entirely. Use {@code 0} to replace
442
     * all arguments, which is suitable for all modern compilers. Some very old
443
     * compilers require this to be the index of the first actual source file,
444
     * in case compiler options cannot be included.
441
     * @param quoteFiles - if set to true, filenames containing
445
     * @param quoteFiles - if set to true, filenames containing
442
     * spaces will be quoted when they appear in the external file.
446
     * spaces will be quoted when they appear in the external file.
443
     * This is necessary when running JDK 1.4's javac and probably
447
     * This is necessary when running JDK 1.4's javac and probably
Lines 446-452 Link Here
446
     *
450
     *
447
     * @since Ant 1.6
451
     * @since Ant 1.6
448
     */
452
     */
449
    protected int executeExternalCompile(String[] args, int firstFileName,
453
    protected int executeExternalCompile(String[] args, int separableArgIndex,
450
                                         boolean quoteFiles) {
454
                                         boolean quoteFiles) {
451
        String[] commandArray = null;
455
        String[] commandArray = null;
452
        File tmpFile = null;
456
        File tmpFile = null;
Lines 460-472 Link Here
460
             * file if the total length of the command line exceeds this limit.
464
             * file if the total length of the command line exceeds this limit.
461
             */
465
             */
462
            if (Commandline.toString(args).length() > COMMAND_LINE_LIMIT
466
            if (Commandline.toString(args).length() > COMMAND_LINE_LIMIT
463
                && firstFileName >= 0) {
467
                && separableArgIndex >= 0) {
464
                BufferedWriter out = null;
468
                BufferedWriter out = null;
465
                try {
469
                try {
466
                    tmpFile = FILE_UTILS.createTempFile(
470
                    tmpFile = FILE_UTILS.createTempFile(
467
                        "files", "", getJavac().getTempdir(), true, true);
471
                        "files", "", getJavac().getTempdir(), true, true);
468
                    out = new BufferedWriter(new FileWriter(tmpFile));
472
                    out = new BufferedWriter(new FileWriter(tmpFile));
469
                    for (int i = firstFileName; i < args.length; i++) {
473
                    for (int i = separableArgIndex; i < args.length; i++) {
470
                        if (quoteFiles && args[i].indexOf(" ") > -1) {
474
                        if (quoteFiles && args[i].indexOf(" ") > -1) {
471
                            args[i] = args[i].replace(File.separatorChar, '/');
475
                            args[i] = args[i].replace(File.separatorChar, '/');
472
                            out.write("\"" + args[i] + "\"");
476
                            out.write("\"" + args[i] + "\"");
Lines 476-484 Link Here
476
                        out.newLine();
480
                        out.newLine();
477
                    }
481
                    }
478
                    out.flush();
482
                    out.flush();
479
                    commandArray = new String[firstFileName + 1];
483
                    commandArray = new String[separableArgIndex + 1];
480
                    System.arraycopy(args, 0, commandArray, 0, firstFileName);
484
                    System.arraycopy(args, 0, commandArray, 0, separableArgIndex);
481
                    commandArray[firstFileName] = "@" + tmpFile;
485
                    commandArray[separableArgIndex] = "@" + tmpFile;
482
                } catch (IOException e) {
486
                } catch (IOException e) {
483
                    throw new BuildException("Error creating temporary file",
487
                    throw new BuildException("Error creating temporary file",
484
                                             e, location);
488
                                             e, location);
(-)src/main/org/apache/tools/ant/taskdefs/compilers/AptExternalCompilerAdapter.java (-2 / +2 lines)
Lines 56-68 Link Here
56
        cmd.setExecutable(apt.getAptExecutable());
56
        cmd.setExecutable(apt.getAptExecutable());
57
        setupModernJavacCommandlineSwitches(cmd);
57
        setupModernJavacCommandlineSwitches(cmd);
58
        AptCompilerAdapter.setAptCommandlineSwitches(apt, cmd);
58
        AptCompilerAdapter.setAptCommandlineSwitches(apt, cmd);
59
        int firstFileName = cmd.size();
59
        int separableArgIndex = Project.toBoolean(project.getProperty("pre-50781")) ? cmd.size() : 0;
60
        //add the files
60
        //add the files
61
        logAndAddFilesToCompile(cmd);
61
        logAndAddFilesToCompile(cmd);
62
62
63
        //run
63
        //run
64
        return 0 == executeExternalCompile(cmd.getCommandline(),
64
        return 0 == executeExternalCompile(cmd.getCommandline(),
65
                firstFileName,
65
                separableArgIndex,
66
                true);
66
                true);
67
67
68
    }
68
    }
(-)src/main/org/apache/tools/ant/taskdefs/compilers/JavacExternal.java (-6 / +6 lines)
Lines 50-65 Link Here
50
        } else {
50
        } else {
51
            setupJavacCommandlineSwitches(cmd, true);
51
            setupJavacCommandlineSwitches(cmd, true);
52
        }
52
        }
53
        int firstFileName = assumeJava11() ? -1 : cmd.size();
53
        int separableArgIndex = assumeJava11() ? -1 : Project.toBoolean(project.getProperty("pre-50781")) ? cmd.size() : 0;
54
        logAndAddFilesToCompile(cmd);
54
        logAndAddFilesToCompile(cmd);
55
        //On VMS platform, we need to create a special java options file
55
        //On VMS platform, we need to create a special java options file
56
        //containing the arguments and classpath for the javac command.
56
        //containing the arguments and classpath for the javac command.
57
        //The special file is supported by the "-V" switch on the VMS JVM.
57
        //The special file is supported by the "-V" switch on the VMS JVM.
58
        if (Os.isFamily("openvms")) {
58
        if (Os.isFamily("openvms")) {
59
            return execOnVMS(cmd, firstFileName);
59
            return execOnVMS(cmd, separableArgIndex);
60
        }
60
        }
61
        return
61
        return
62
                executeExternalCompile(cmd.getCommandline(), firstFileName,
62
                executeExternalCompile(cmd.getCommandline(), separableArgIndex,
63
                        true)
63
                        true)
64
                == 0;
64
                == 0;
65
    }
65
    }
Lines 67-76 Link Here
67
    /**
67
    /**
68
     * helper method to execute our command on VMS.
68
     * helper method to execute our command on VMS.
69
     * @param cmd
69
     * @param cmd
70
     * @param firstFileName
70
     * @param separableArgIndex
71
     * @return
71
     * @return
72
     */
72
     */
73
    private boolean execOnVMS(Commandline cmd, int firstFileName) {
73
    private boolean execOnVMS(Commandline cmd, int separableArgIndex) {
74
        File vmsFile = null;
74
        File vmsFile = null;
75
        try {
75
        try {
76
            vmsFile = JavaEnvUtils.createVmsJavaOptionFile(cmd.getArguments());
76
            vmsFile = JavaEnvUtils.createVmsJavaOptionFile(cmd.getArguments());
Lines 78-84 Link Here
78
                                    "-V",
78
                                    "-V",
79
                                    vmsFile.getPath()};
79
                                    vmsFile.getPath()};
80
            return 0 == executeExternalCompile(commandLine,
80
            return 0 == executeExternalCompile(commandLine,
81
                            firstFileName,
81
                            separableArgIndex,
82
                            true);
82
                            true);
83
83
84
        } catch (IOException e) {
84
        } catch (IOException e) {
(-)WHATSNEW (+6 lines)
Lines 7-12 Link Here
7
Fixed bugs:
7
Fixed bugs:
8
-----------
8
-----------
9
9
10
 * <javac> could create excessively long command lines when e.g. long classpaths
11
   were given. Now fixed for contemporary compilers; if using very old compilers
12
   which do not accept options in @argumentfiles, use -Dpre-50781=true or the
13
   corresponding <property>.
14
   Bugzilla Report 50781.
15
10
 * External XML catalog resolver failed to use project basedir when given an
16
 * External XML catalog resolver failed to use project basedir when given an
11
   unmentioned relative path like the internal resolver does.
17
   unmentioned relative path like the internal resolver does.
12
   Bugzilla Report 52754.
18
   Bugzilla Report 52754.

Return to bug 50781