From 7254e769ce095cc4272d5f936dd2740e09db8a9e Mon Sep 17 00:00:00 2001 From: Peter Reilly Date: Wed, 1 Nov 2006 23:19:33 +0000 Subject: [PATCH] bugzilla report 40852: useextenalfile of javadoc now applies to all command line args git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@470134 13f79535-47bb-0310-9956-ffa450edef68 --- CONTRIBUTORS | 1 + WHATSNEW | 3 + contributors.xml | 4 + docs/manual/CoreTasks/javadoc.html | 3 +- .../apache/tools/ant/taskdefs/Javadoc.java | 91 +++++++++++++++++++ 5 files changed, 101 insertions(+), 1 deletion(-) diff --git a/CONTRIBUTORS b/CONTRIBUTORS index 67a402b7f..79316535c 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -44,6 +44,7 @@ Curtis White Cyrille Morvan Dale Anson Dan Armbrust +Daniel Ribagnac Daniel Spilker Danno Ferrin Davanum Srinivas diff --git a/WHATSNEW b/WHATSNEW index 1ee9995b3..ea14d13f1 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -45,6 +45,9 @@ Other changes: * Diagnostics catches and logs security exceptions when accessing system properties. +* useexternalfile now applies to all command line arguments + of javadoc. Bugzilla report 40852. + Changes from Ant 1.7.0Beta2 to Ant 1.7.0Beta3 ============================================= diff --git a/contributors.xml b/contributors.xml index f5793f77a..d2a0a38b6 100644 --- a/contributors.xml +++ b/contributors.xml @@ -187,6 +187,10 @@ Dan Armbrust + + Daniel + Ribagnac + Daniel Spilker diff --git a/docs/manual/CoreTasks/javadoc.html b/docs/manual/CoreTasks/javadoc.html index 91c866a9b..f38d12e2d 100644 --- a/docs/manual/CoreTasks/javadoc.html +++ b/docs/manual/CoreTasks/javadoc.html @@ -413,7 +413,8 @@ to ensure that this command supports the attributes you wish to use.

in srcfiles or as nested source elements should be written to a temporary file to make the command line shorter. Also applies to the package names specified via the packagenames attribute or - nested package elements. + nested package elements.Since Ant 1.7.0, also applies + to all the other command line options. (yes | no). Default is no. all No diff --git a/src/main/org/apache/tools/ant/taskdefs/Javadoc.java b/src/main/org/apache/tools/ant/taskdefs/Javadoc.java index ea341eab7..87dd44f80 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Javadoc.java +++ b/src/main/org/apache/tools/ant/taskdefs/Javadoc.java @@ -1966,9 +1966,14 @@ public class Javadoc extends Task { Project.MSG_WARN); } } + // If using an external file, write the command line options to it + if (useExternalFile && javadoc4) { + writeExternalArgs(toExecute); + } File tmpList = null; PrintWriter srcListWriter = null; + try { /** @@ -2072,6 +2077,92 @@ public class Javadoc extends Task { } } + private void writeExternalArgs(Commandline toExecute) { + // If using an external file, write the command line options to it + File optionsTmpFile = null; + PrintWriter optionsListWriter = null; + try { + optionsTmpFile = FILE_UTILS.createTempFile( + "javadocOptions", "", null); + optionsTmpFile.deleteOnExit(); + String[] listOpt = toExecute.getArguments(); + toExecute.clearArgs(); + toExecute.createArgument().setValue( + "@" + optionsTmpFile.getAbsolutePath()); + optionsListWriter = new PrintWriter( + new FileWriter(optionsTmpFile.getAbsolutePath(), true)); + for (int i = 0; i < listOpt.length; i++) { + String string = listOpt[i]; + if (string.startsWith("-J-")) { + toExecute.createArgument().setValue(string); + } else { + if (string.startsWith("-")) { + optionsListWriter.print(string); + optionsListWriter.print(" "); + } else { + optionsListWriter.println(quoteString(string)); + } + } + } + optionsListWriter.close(); + } catch (IOException ex) { + if (optionsTmpFile != null) { + optionsTmpFile.delete(); + } + throw new BuildException( + "Error creating or writing temporary file for javadoc options", + ex, getLocation()); + } finally { + FILE_UTILS.close(optionsListWriter); + } + } + + /** + * Quote a string to place in a @ file. + * @param str the string to quote + * @return the quoted string, if there is no need to quote the string, + * return the original string. + */ + private String quoteString(String str) { + if (str.indexOf(' ') == -1 + && str.indexOf('\'') == -1 + && str.indexOf('"') == -1) { + return str; + } + if (str.indexOf('\'') == -1) { + return quoteString(str, '\''); + } else { + return quoteString(str, '"'); + } + } + + private String quoteString(String str, char delim) { + StringBuffer buf = new StringBuffer(str.length() * 2); + buf.append(delim); + if (str.indexOf('\\') != -1) { + str = replace(str, '\\', "\\\\"); + } + if (str.indexOf(delim) != -1) { + str = replace(str, delim, "\\" + delim); + } + buf.append(str); + buf.append(delim); + return buf.toString(); + } + + private String replace(String str, char fromChar, String toString) { + StringBuffer buf = new StringBuffer(str.length() * 2); + for (int i = 0; i < str.length(); ++i) { + char ch = str.charAt(i); + if (ch == fromChar) { + buf.append(toString); + } else { + buf.append(ch); + } + } + return buf.toString(); + } + /** * Add the files matched by the nested source files to the Vector * as SourceFile instances.