From 87bf01f5de873b8eb5a25c2c62acbd7c9d1e92b1 Mon Sep 17 00:00:00 2001 From: Stefan Bodewig Date: Thu, 11 Apr 2002 15:59:37 +0000 Subject: [PATCH] added some options to the not-cloned Commandline potentially adding them several times of execute would be called more than once. Cosmetics. git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@272382 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/tools/ant/taskdefs/ExecTask.java | 8 +- .../ant/taskdefs/ExecuteStreamHandler.java | 3 +- .../tools/ant/taskdefs/ExecuteWatchdog.java | 1 + .../apache/tools/ant/taskdefs/Javadoc.java | 159 ++++++++++-------- .../tools/ant/taskdefs/LogOutputStream.java | 3 +- .../tools/ant/taskdefs/LogStreamHandler.java | 6 +- .../tools/ant/taskdefs/MatchingTask.java | 4 +- .../tools/ant/taskdefs/PumpStreamHandler.java | 6 +- 8 files changed, 113 insertions(+), 77 deletions(-) diff --git a/src/main/org/apache/tools/ant/taskdefs/ExecTask.java b/src/main/org/apache/tools/ant/taskdefs/ExecTask.java index 3603e8162..042c24e23 100644 --- a/src/main/org/apache/tools/ant/taskdefs/ExecTask.java +++ b/src/main/org/apache/tools/ant/taskdefs/ExecTask.java @@ -78,6 +78,8 @@ import java.io.FileNotFoundException; * @author Stefan Bodewig * @author Mariusz Nowostawski * + * @since Ant 1.2 + * * @ant.task category="control" */ public class ExecTask extends Task { @@ -259,10 +261,12 @@ public class ExecTask extends Task { throw new BuildException("no executable specified", location); } if (dir != null && !dir.exists()) { - throw new BuildException("The directory you specified does not exist"); + throw new BuildException("The directory you specified does not " + + "exist"); } if (dir != null && !dir.isDirectory()) { - throw new BuildException("The directory you specified is not a directory"); + throw new BuildException("The directory you specified is not a " + + "directory"); } } diff --git a/src/main/org/apache/tools/ant/taskdefs/ExecuteStreamHandler.java b/src/main/org/apache/tools/ant/taskdefs/ExecuteStreamHandler.java index ac9bfef5a..55af62322 100644 --- a/src/main/org/apache/tools/ant/taskdefs/ExecuteStreamHandler.java +++ b/src/main/org/apache/tools/ant/taskdefs/ExecuteStreamHandler.java @@ -1,7 +1,7 @@ /* * The Apache Software License, Version 1.1 * - * Copyright (c) 2000 The Apache Software Foundation. All rights + * Copyright (c) 2000,2002 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without @@ -63,6 +63,7 @@ import java.io.OutputStream; * subprocesses. * * @author thomas.haas@softwired-inc.com + * @since Ant 1.2 */ public interface ExecuteStreamHandler { diff --git a/src/main/org/apache/tools/ant/taskdefs/ExecuteWatchdog.java b/src/main/org/apache/tools/ant/taskdefs/ExecuteWatchdog.java index c49971464..ef8c5e9cd 100644 --- a/src/main/org/apache/tools/ant/taskdefs/ExecuteWatchdog.java +++ b/src/main/org/apache/tools/ant/taskdefs/ExecuteWatchdog.java @@ -75,6 +75,7 @@ import org.apache.tools.ant.util.Watchdog; * @author Stephane Bailliez * @see Execute * @see org.apache.tools.ant.util.Watchdog + * @since Ant 1.2 */ public class ExecuteWatchdog implements TimeoutObserver { diff --git a/src/main/org/apache/tools/ant/taskdefs/Javadoc.java b/src/main/org/apache/tools/ant/taskdefs/Javadoc.java index bb6d69352..fb273dea4 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Javadoc.java +++ b/src/main/org/apache/tools/ant/taskdefs/Javadoc.java @@ -102,6 +102,8 @@ import org.apache.tools.ant.util.JavaEnvUtils; * @author Ernst de Haan ernst@jollem.com * @author Stefan Bodewig * + * @since Ant 1.1 + * * @ant.task category="java" */ @@ -225,12 +227,12 @@ public class Javadoc extends Task { private Commandline cmd = new Commandline(); private static boolean javadoc1 = - (JavaEnvUtils.getJavaVersion() == Project.JAVA_1_1); + (JavaEnvUtils.getJavaVersion() == JavaEnvUtils.JAVA_1_1); private static boolean javadoc4 = - (JavaEnvUtils.getJavaVersion() != Project.JAVA_1_1 && - JavaEnvUtils.getJavaVersion() != Project.JAVA_1_2 && - JavaEnvUtils.getJavaVersion() != Project.JAVA_1_3); + (JavaEnvUtils.getJavaVersion() != JavaEnvUtils.JAVA_1_1 && + JavaEnvUtils.getJavaVersion() != JavaEnvUtils.JAVA_1_2 && + JavaEnvUtils.getJavaVersion() != JavaEnvUtils.JAVA_1_3); private void addArgIf(boolean b, String arg) { if (b) { @@ -244,9 +246,8 @@ public class Javadoc extends Task { cmd.createArgument().setValue(key); cmd.createArgument().setValue(value); } else { - project.log(this, - "Warning: Leaving out empty argument '" + key + "'", - Project.MSG_WARN); + log("Warning: Leaving out empty argument '" + key + "'", + Project.MSG_WARN); } } } @@ -569,8 +570,9 @@ public class Javadoc extends Task { if (!javadoc1) { LinkArgument le = createLink(); le.setOffline(true); - String linkOfflineError = "The linkoffline attribute must include a URL and " + - "a package-list file location separated by a space"; + String linkOfflineError = "The linkoffline attribute must include" + + " an URL and a package-list file location separated by a" + + " space"; if (src.trim().length() == 0) { throw new BuildException(linkOfflineError); } @@ -679,8 +681,8 @@ public class Javadoc extends Task { */ public TagArgument createTag() { if (!javadoc4) { - project.log ("-tag option not supported on JavaDoc < 1.4", - Project.MSG_VERBOSE); + log ("-tag option not supported on JavaDoc < 1.4", + Project.MSG_VERBOSE); } TagArgument ta = new TagArgument(); tags.addElement (ta); @@ -694,7 +696,8 @@ public class Javadoc extends Task { */ static final String[] SCOPE_ELEMENTS = { "overview", "packages", "types", "constructors", - "methods", "fields"}; + "methods", "fields" + }; /** * Class representing a -tag argument. @@ -749,9 +752,10 @@ public class Javadoc extends Task { * Must not be null, * should not be empty. * - * @exception BuildException if all is specified along with other elements, - * if any elements are repeated, if no elements are specified, - * or if any unrecognised elements are specified. + * @exception BuildException if all is specified along with + * other elements, if any elements are repeated, if no + * elements are specified, or if any unrecognised elements are + * specified. */ public void setScope (String verboseScope) throws BuildException { verboseScope=verboseScope.toLowerCase (Locale.US); @@ -780,12 +784,13 @@ public class Javadoc extends Task { break; } if (i==SCOPE_ELEMENTS.length) { - throw new BuildException ("Unrecognised scope element: "+next); + throw new BuildException ("Unrecognised scope element: " + + next); } else { if (elements[i]) { - getProject().log ("Repeated tag scope element: "+next, - Project.MSG_VERBOSE); + getProject().log ("Repeated tag scope element: " + + next, Project.MSG_VERBOSE); } elements[i]=true; gotNotAll=true; @@ -794,11 +799,12 @@ public class Javadoc extends Task { } if (gotNotAll && gotAll) { - throw new BuildException ("Mixture of \"all\" and other scope elements "+ - "in tag parameter."); + throw new BuildException ("Mixture of \"all\" and other scope " + + "elements in tag parameter."); } if (!gotNotAll && !gotAll) { - throw new BuildException ("No scope elements specified in tag parameter."); + throw new BuildException ("No scope elements specified in tag " + + "parameter."); } if (gotAll) { this.scope="a"; @@ -912,7 +918,7 @@ public class Javadoc extends Task { * the 1.4 version or a different doclet than the standard doclet * is used. * - * @since 1.86, Ant 1.5 + * @since Ant 1.5 */ public void setSource(String source) { this.source = source; @@ -930,27 +936,27 @@ public class Javadoc extends Task { log("Generating Javadoc", Project.MSG_INFO); + Commandline toExecute = (Commandline)cmd.clone(); + toExecute.setExecutable(JavaEnvUtils.getJdkExecutable("javadoc")); + +// ------------------------------------------------ general javadoc arguments if (doctitle != null) { - cmd.createArgument().setValue("-doctitle"); - cmd.createArgument().setValue(expand(doctitle.getText())); + toExecute.createArgument().setValue("-doctitle"); + toExecute.createArgument().setValue(expand(doctitle.getText())); } if (header != null) { - cmd.createArgument().setValue("-header"); - cmd.createArgument().setValue(expand(header.getText())); + toExecute.createArgument().setValue("-header"); + toExecute.createArgument().setValue(expand(header.getText())); } if (footer != null) { - cmd.createArgument().setValue("-footer"); - cmd.createArgument().setValue(expand(footer.getText())); + toExecute.createArgument().setValue("-footer"); + toExecute.createArgument().setValue(expand(footer.getText())); } if (bottom != null) { - cmd.createArgument().setValue("-bottom"); - cmd.createArgument().setValue(expand(bottom.getText())); + toExecute.createArgument().setValue("-bottom"); + toExecute.createArgument().setValue(expand(bottom.getText())); } - Commandline toExecute = (Commandline)cmd.clone(); - toExecute.setExecutable(JavaEnvUtils.getJdkExecutable("javadoc")); - -// ------------------------------------------------ general javadoc arguments if (classpath == null) { classpath = Path.systemClasspath; } else { @@ -964,8 +970,10 @@ public class Javadoc extends Task { toExecute.createArgument().setPath(sourcePath); } else { toExecute.createArgument().setValue("-classpath"); - toExecute.createArgument().setValue(sourcePath.toString() + - System.getProperty("path.separator") + classpath.toString()); + toExecute.createArgument() + .setValue(sourcePath.toString() + + System.getProperty("path.separator") + + classpath.toString()); } if (version && doclet == null) { @@ -982,15 +990,13 @@ public class Javadoc extends Task { } } - // --------------------------------- javadoc2 arguments for default doclet -// XXX: how do we handle a custom doclet? - if (!javadoc1) { if (doclet != null) { if (doclet.getName() == null) { - throw new BuildException("The doclet name must be specified.", location); + throw new BuildException("The doclet name must be " + + "specified.", location); } else { toExecute.createArgument().setValue("-doclet"); @@ -1003,15 +1009,18 @@ public class Javadoc extends Task { toExecute.createArgument().setPath(docletPath); } } - for (Enumeration e = doclet.getParams(); e.hasMoreElements();) { + for (Enumeration e = doclet.getParams(); + e.hasMoreElements();) { DocletParam param = (DocletParam)e.nextElement(); if (param.getName() == null) { - throw new BuildException("Doclet parameters must have a name"); + throw new BuildException("Doclet parameters must " + + "have a name"); } toExecute.createArgument().setValue(param.getName()); if (param.getValue() != null) { - toExecute.createArgument().setValue(param.getValue()); + toExecute.createArgument() + .setValue(param.getValue()); } } } @@ -1027,24 +1036,33 @@ public class Javadoc extends Task { LinkArgument la = (LinkArgument)e.nextElement(); if (la.getHref() == null) { - throw new BuildException("Links must provide the URL to the external class documentation."); + throw new BuildException("Links must provide the URL " + + "to the external class " + + "documentation."); } if (la.isLinkOffline()) { File packageListLocation = la.getPackagelistLoc(); if (packageListLocation == null) { - throw new BuildException("The package list location for link " + la.getHref() + - " must be provided because the link is offline"); + throw new BuildException("The package list " + + " location for link " + + la.getHref() + + " must be provided " + + "because the link is " + + "offline"); } - File packageList = new File(packageListLocation, "package-list"); + File packageList = + new File(packageListLocation, "package-list"); if (packageList.exists()) { toExecute.createArgument().setValue("-linkoffline"); toExecute.createArgument().setValue(la.getHref()); - toExecute.createArgument().setValue(packageListLocation.getAbsolutePath()); + toExecute.createArgument() + .setValue(packageListLocation + .getAbsolutePath()); } else { - log("Warning: No package list was found at " + packageListLocation, - Project.MSG_VERBOSE); + log("Warning: No package list was found at " + + packageListLocation, Project.MSG_VERBOSE); } } else { @@ -1087,7 +1105,9 @@ public class Javadoc extends Task { String title = ga.getTitle(); String packages = ga.getPackages(); if (title == null || packages == null) { - throw new BuildException("The title and packages must be specified for group elements."); + throw new BuildException("The title and packages must " + + "be specified for group " + + "elements."); } toExecute.createArgument().setValue("-group"); toExecute.createArgument().setValue(expand(title)); @@ -1104,15 +1124,16 @@ public class Javadoc extends Task { toExecute.createArgument().setValue ("-tag"); toExecute.createArgument().setValue (ta.getParameter()); } else { - ExtensionInfo tagletInfo - = (ExtensionInfo) element; + ExtensionInfo tagletInfo = (ExtensionInfo) element; toExecute.createArgument().setValue("-taglet"); - toExecute.createArgument().setValue(tagletInfo.getName()); + toExecute.createArgument().setValue(tagletInfo + .getName()); if (tagletInfo.getPath() != null) { - Path tagletPath - = tagletInfo.getPath().concatSystemClasspath("ignore"); + Path tagletPath = tagletInfo.getPath() + .concatSystemClasspath("ignore"); if (tagletPath.size() != 0) { - toExecute.createArgument().setValue("-tagletpath"); + toExecute.createArgument() + .setValue("-tagletpath"); toExecute.createArgument().setPath(tagletPath); } } @@ -1155,7 +1176,8 @@ public class Javadoc extends Task { } } if (packages.size() > 0) { - evaluatePackages(toExecute, sourcePath, packages, excludePackages); + evaluatePackages(toExecute, sourcePath, packages, + excludePackages); } } @@ -1169,10 +1191,13 @@ public class Javadoc extends Task { if (useExternalFile) { if (tmpList == null) { tmpList = fileUtils.createTempFile("javadoc", "", null); - toExecute.createArgument().setValue("@" + tmpList.getAbsolutePath()); + toExecute.createArgument() + .setValue("@" + tmpList.getAbsolutePath()); } - srcListWriter = new PrintWriter(new FileWriter(tmpList.getAbsolutePath(), - true)); + srcListWriter = new PrintWriter( + new FileWriter(tmpList + .getAbsolutePath(), + true)); } Enumeration enum = sourceFiles.elements(); @@ -1270,7 +1295,7 @@ public class Javadoc extends Task { String[] list = sourcePath.list(); if (list == null) { - list = new String[0]; + list = new String[0]; } FileSet fs = new FileSet(); @@ -1302,11 +1327,11 @@ public class Javadoc extends Task { try { if (useExternalFile) { tmpList = fileUtils.createTempFile("javadoc", "", null); - toExecute.createArgument().setValue("@" + tmpList.getAbsolutePath()); + toExecute.createArgument() + .setValue("@" + tmpList.getAbsolutePath()); packageListWriter = new PrintWriter(new FileWriter(tmpList)); } - for (int j=0; j 0) { - String pkgDir = packageDirs[i].replace('/','.').replace('\\','.'); + String pkgDir = + packageDirs[i].replace('/','.').replace('\\','.'); if (!addedPackages.contains(pkgDir)) { if (useExternalFile) { packageListWriter.println(pkgDir); @@ -1360,7 +1386,8 @@ public class Javadoc extends Task { // private String queuedLine = null; protected void processLine(String line, int messageLevel) { - if (messageLevel == Project.MSG_INFO && line.startsWith("Generating ")) { + if (messageLevel == Project.MSG_INFO + && line.startsWith("Generating ")) { if (queuedLine != null) { super.processLine(queuedLine, Project.MSG_VERBOSE); } diff --git a/src/main/org/apache/tools/ant/taskdefs/LogOutputStream.java b/src/main/org/apache/tools/ant/taskdefs/LogOutputStream.java index 471cbba7b..c4eeedb38 100644 --- a/src/main/org/apache/tools/ant/taskdefs/LogOutputStream.java +++ b/src/main/org/apache/tools/ant/taskdefs/LogOutputStream.java @@ -1,7 +1,7 @@ /* * The Apache Software License, Version 1.1 * - * Copyright (c) 2000-2001 The Apache Software Foundation. All rights + * Copyright (c) 2000-2002 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without @@ -70,6 +70,7 @@ import java.io.ByteArrayOutputStream; * of data written to the stream. * * @author thomas.haas@softwired-inc.com + * @since Ant 1.2 */ public class LogOutputStream extends OutputStream { diff --git a/src/main/org/apache/tools/ant/taskdefs/LogStreamHandler.java b/src/main/org/apache/tools/ant/taskdefs/LogStreamHandler.java index c13150911..a46dde898 100644 --- a/src/main/org/apache/tools/ant/taskdefs/LogStreamHandler.java +++ b/src/main/org/apache/tools/ant/taskdefs/LogStreamHandler.java @@ -1,7 +1,7 @@ /* * The Apache Software License, Version 1.1 * - * Copyright (c) 2000 The Apache Software Foundation. All rights + * Copyright (c) 2000,2002 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without @@ -55,17 +55,15 @@ package org.apache.tools.ant.taskdefs; import org.apache.tools.ant.BuildException; - import org.apache.tools.ant.Task; - - import java.io.IOException; /** * Logs standard output and error of a subprocess to the log system of ant. * * @author thomas.haas@softwired-inc.com + * @since Ant 1.2 */ public class LogStreamHandler extends PumpStreamHandler { diff --git a/src/main/org/apache/tools/ant/taskdefs/MatchingTask.java b/src/main/org/apache/tools/ant/taskdefs/MatchingTask.java index 5659befe4..8593af2aa 100644 --- a/src/main/org/apache/tools/ant/taskdefs/MatchingTask.java +++ b/src/main/org/apache/tools/ant/taskdefs/MatchingTask.java @@ -72,6 +72,7 @@ import java.util.StringTokenizer; * @author Sam Ruby rubys@us.ibm.com * @author Jon S. Stevens jon@clearink.com * @author Stefan Bodewig + * @since Ant 1.1 */ public abstract class MatchingTask extends Task { @@ -178,7 +179,8 @@ public abstract class MatchingTask extends Task { "Please use the excludes attribute.", Project.MSG_WARN); if (ignoreString != null && ignoreString.length() > 0) { - StringTokenizer tok = new StringTokenizer(ignoreString, ", ", false); + StringTokenizer tok = new StringTokenizer(ignoreString, ", ", + false); while (tok.hasMoreTokens()) { createExclude().setName("**/"+tok.nextToken().trim()+"/**"); } diff --git a/src/main/org/apache/tools/ant/taskdefs/PumpStreamHandler.java b/src/main/org/apache/tools/ant/taskdefs/PumpStreamHandler.java index 3d3d93f1f..585a1c871 100644 --- a/src/main/org/apache/tools/ant/taskdefs/PumpStreamHandler.java +++ b/src/main/org/apache/tools/ant/taskdefs/PumpStreamHandler.java @@ -1,7 +1,7 @@ /* * The Apache Software License, Version 1.1 * - * Copyright (c) 2000-2001 The Apache Software Foundation. All rights + * Copyright (c) 2000-2002 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without @@ -65,6 +65,7 @@ import java.io.OutputStream; * TODO: standard input of the subprocess is not implemented. * * @author thomas.haas@softwired-inc.com + * @since Ant 1.2 */ public class PumpStreamHandler implements ExecuteStreamHandler { @@ -139,7 +140,8 @@ public class PumpStreamHandler implements ExecuteStreamHandler { /** - * Creates a stream pumper to copy the given input stream to the given output stream. + * Creates a stream pumper to copy the given input stream to the + * given output stream. */ protected Thread createPump(InputStream is, OutputStream os) { final Thread result = new Thread(new StreamPumper(is, os));