From 6e7154321d3e95449b4a9ab838d0872384e641a0 Mon Sep 17 00:00:00 2001 From: Stefan Bodewig Date: Tue, 29 Apr 2003 13:16:22 +0000 Subject: [PATCH] From the JDK tool-docs for javac of JDK 1.4: > An argument file can include javac options and source filenames in > any combination. The arguments within a file can be space-separated > or newline-separated. that means, file names must be quoted if they contain spaces. No idea whether this is true for JDK 1.2 or 1.3 as well (1.1 doesn't support @argfile). PR: 10499 git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@274533 13f79535-47bb-0310-9956-ffa450edef68 --- WHATSNEW | 3 +++ .../compilers/DefaultCompilerAdapter.java | 25 ++++++++++++++++++- .../ant/taskdefs/compilers/JavacExternal.java | 7 ++++-- 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/WHATSNEW b/WHATSNEW index e7edcb135..1bbd39583 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -109,6 +109,9 @@ Fixed bugs: * didn't work for multi-byte encodings if byline was false. Bugzilla Report 19187. +* file names that include spaces need to be quoted inside the @argfile + argument using forked and JDK 1.4. Bugzilla Report 10499. + Other changes: -------------- * Six new Clearcase tasks added. diff --git a/src/main/org/apache/tools/ant/taskdefs/compilers/DefaultCompilerAdapter.java b/src/main/org/apache/tools/ant/taskdefs/compilers/DefaultCompilerAdapter.java index 8981b2024..fe5daec1d 100644 --- a/src/main/org/apache/tools/ant/taskdefs/compilers/DefaultCompilerAdapter.java +++ b/src/main/org/apache/tools/ant/taskdefs/compilers/DefaultCompilerAdapter.java @@ -398,6 +398,25 @@ public abstract class DefaultCompilerAdapter implements CompilerAdapter { * system. */ protected int executeExternalCompile(String[] args, int firstFileName) { + return executeExternalCompile(args, firstFileName, false); + } + + /** + * 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, + * 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 quoteFilenames - 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 + * others. + * + * @since Ant 1.6 + */ + protected int executeExternalCompile(String[] args, int firstFileName, + boolean quoteFiles) { String[] commandArray = null; File tmpFile = null; @@ -418,7 +437,11 @@ public abstract class DefaultCompilerAdapter implements CompilerAdapter { tmpFile = fileUtils.createTempFile("files", "", userDir); out = new PrintWriter(new FileWriter(tmpFile)); for (int i = firstFileName; i < args.length; i++) { - out.println(args[i]); + if (quoteFiles && args[i].indexOf(" ") > -1) { + out.println("\"" + args[i] + "\""); + } else { + out.println(args[i]); + } } out.flush(); commandArray = new String[firstFileName + 1]; 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 92c74413a..7e0cf39d1 100644 --- a/src/main/org/apache/tools/ant/taskdefs/compilers/JavacExternal.java +++ b/src/main/org/apache/tools/ant/taskdefs/compilers/JavacExternal.java @@ -1,7 +1,7 @@ /* * The Apache Software License, Version 1.1 * - * Copyright (c) 2001-2002 The Apache Software Foundation. All rights + * Copyright (c) 2001-2003 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without @@ -79,7 +79,10 @@ public class JavacExternal extends DefaultCompilerAdapter { logAndAddFilesToCompile(cmd); return - executeExternalCompile(cmd.getCommandline(), firstFileName) == 0; + executeExternalCompile(cmd.getCommandline(), firstFileName, + !assumeJava11() && !assumeJava12() + && !assumeJava13()) + == 0; } }