diff --git a/src/main/org/apache/tools/ant/taskdefs/ExecTask.java b/src/main/org/apache/tools/ant/taskdefs/ExecTask.java index f617bedb6..74a6008bc 100644 --- a/src/main/org/apache/tools/ant/taskdefs/ExecTask.java +++ b/src/main/org/apache/tools/ant/taskdefs/ExecTask.java @@ -73,19 +73,19 @@ public class ExecTask extends Task { private boolean vmLauncher = true; /** - * set whether or not you want the process to be spawned - * default is not spawned - * @param spawn if true you do not want ant to wait for the end of the process - * @since ant 1.6 + * Set whether or not you want the process to be spawned. + * Default is false. + * @param spawn if true you do not want Ant to wait for the end of the process. + * @since Ant 1.6 */ public void setSpawn(boolean spawn) { this.spawn = spawn; } /** - * Timeout in milliseconds after which the process will be killed. + * Set the timeout in milliseconds after which the process will be killed. * - * @param value timeout in milliseconds + * @param value timeout in milliseconds. * * @since Ant 1.5 */ @@ -95,22 +95,18 @@ public class ExecTask extends Task { } /** - * Timeout in milliseconds after which the process will be killed. + * Set the timeout in milliseconds after which the process will be killed. * - * @param value timeout in milliseconds + * @param value timeout in milliseconds. */ public void setTimeout(Integer value) { - if (value == null) { - timeout = null; - } else { - setTimeout(new Long(value.intValue())); - } - incompatibleWithSpawn = true; + setTimeout( + (Long) ((value == null) ? null : new Long(value.intValue()))); } /** * Set the name of the executable program. - * @param value the name of the executable program + * @param value the name of the executable program. */ public void setExecutable(String value) { this.executable = value; @@ -119,7 +115,7 @@ public class ExecTask extends Task { /** * Set the working directory of the process. - * @param d the working directory of the process + * @param d the working directory of the process. */ public void setDir(File d) { this.dir = d; @@ -127,15 +123,15 @@ public class ExecTask extends Task { /** * List of operating systems on which the command may be executed. - * @param os list of operating systems on which the command may be executed + * @param os list of operating systems on which the command may be executed. */ public void setOs(String os) { this.os = os; } /** - * Sets a command line - * @param cmdl command line + * Sets a command line. + * @param cmdl command line. * @ant.attribute ignore="true" */ public void setCommand(Commandline cmdl) { @@ -147,9 +143,9 @@ public class ExecTask extends Task { /** * File the output of the process is redirected to. If error is not - * redirected, it too will appear in the output + * redirected, it too will appear in the output. * - * @param out name of a file to which send output to + * @param out name of a file to which output should be sent. */ public void setOutput(File out) { this.output = out; @@ -157,9 +153,9 @@ public class ExecTask extends Task { } /** - * Set the input to use for the task + * Set the input file to use for the task. * - * @param input name of a file to get input from + * @param input name of a file from which to get input. */ public void setInput(File input) { if (inputString != null) { @@ -171,9 +167,9 @@ public class ExecTask extends Task { } /** - * Set the string to use as input + * Set the string to use as input. * - * @param inputString the string which is used as the input source + * @param inputString the string which is used as the input source. */ public void setInputString(String inputString) { if (input != null) { @@ -185,11 +181,10 @@ public class ExecTask extends Task { } /** - * Controls whether error output of exec is logged. This is only useful - * when output is being redirected and error output is desired in the - * Ant log + * Controls whether error output of exec is logged. This is only useful when + * output is being redirected and error output is desired in the Ant log. * - * @param logError set to true to log error output in the normal ant log + * @param logError set to true to log error output in the normal ant log. */ public void setLogError(boolean logError) { redirector.setLogError(logError); @@ -197,11 +192,11 @@ public class ExecTask extends Task { } /** - * File the error stream of the process is redirected to. + * Set the File to which the error stream of the process should be redirected. * - * @param error a file to which send stderr to + * @param error a file to which stderr should be sent. * - * @since ant 1.6 + * @since Ant 1.6 */ public void setError(File error) { this.error = error; @@ -212,7 +207,7 @@ public class ExecTask extends Task { * Sets the property name whose value should be set to the output of * the process. * - * @param outputProp name of property + * @param outputProp name of property. */ public void setOutputproperty(String outputProp) { redirector.setOutputProperty(outputProp); @@ -223,9 +218,9 @@ public class ExecTask extends Task { * Sets the name of the property whose value should be set to the error of * the process. * - * @param errorProperty name of property + * @param errorProperty name of property. * - * @since ant 1.6 + * @since Ant 1.6 */ public void setErrorProperty(String errorProperty) { redirector.setErrorProperty(errorProperty); @@ -253,21 +248,20 @@ public class ExecTask extends Task { } /** - * Sets a flag indicating whether to attempt to resolve the executable - * to a file + * Set whether to attempt to resolve the executable to a file. * * @param resolveExecutable if true, attempt to resolve the - * path of the executable + * path of the executable. */ public void setResolveExecutable(boolean resolveExecutable) { this.resolveExecutable = resolveExecutable; } /** - * Sets a flag indicating whether to search nested, then + * Set whether to search nested, then * system PATH environment variables for the executable. * - * @param searchPath if true, search PATHs + * @param searchPath if true, search PATHs. */ public void setSearchPath(boolean searchPath) { this.searchPath = searchPath; @@ -275,7 +269,7 @@ public class ExecTask extends Task { /** * Indicates whether to attempt to resolve the executable to a - * file + * file. * * @since Ant 1.6 */ @@ -286,7 +280,7 @@ public class ExecTask extends Task { /** * Add an environment variable to the launched process. * - * @param var new environment variable + * @param var new environment variable. */ public void addEnv(Environment.Variable var) { env.addVariable(var); @@ -295,7 +289,7 @@ public class ExecTask extends Task { /** * Adds a command-line argument. * - * @return new command line argument created + * @return new command line argument created. */ public Commandline.Argument createArg() { return cmdl.createArgument(); @@ -307,7 +301,7 @@ public class ExecTask extends Task { * * @since Ant 1.5 * - * @param resultProperty name of property + * @param resultProperty name of property. */ public void setResultProperty(String resultProperty) { this.resultProperty = resultProperty; @@ -315,10 +309,10 @@ public class ExecTask extends Task { } /** - * helper method to set result property to the - * passed in value if appropriate + * Helper method to set result property to the + * passed in value if appropriate. * - * @param result value desired for the result property value + * @param result value desired for the result property value. */ protected void maybeSetResultPropertyValue(int result) { if (resultProperty != null) { @@ -328,10 +322,10 @@ public class ExecTask extends Task { } /** - * Sets a flag to stop the build if program cannot be started. + * Set whether to stop the build if program cannot be started. * Defaults to true. * - * @param flag stop the build if program cannot be started + * @param flag stop the build if program cannot be started. * * @since Ant 1.5 */ @@ -341,10 +335,10 @@ public class ExecTask extends Task { } /** - * Sets whether output should be appended to or overwrite an existing file. + * Set whether output should be appended to or overwrite an existing file. * Defaults to false. * - * @param append if true append is desired + * @param append if true append is desired. * * @since 1.30, Ant 1.5 */ @@ -353,47 +347,43 @@ public class ExecTask extends Task { incompatibleWithSpawn = true; } - /** - * Add a RedirectorElement to this task. + * Add a RedirectorElement to this task. * - * @param redirectorElement RedirectorElement. + * @param redirectorElement RedirectorElement. * @since Ant 1.6.2 */ public void addConfiguredRedirector(RedirectorElement redirectorElement) { if (this.redirectorElement != null) { throw new BuildException("cannot have > 1 nested s"); - } else { - this.redirectorElement = redirectorElement; - incompatibleWithSpawn = true; } + this.redirectorElement = redirectorElement; + incompatibleWithSpawn = true; } /** * The method attempts to figure out where the executable is so that we can feed * the full path. We first try basedir, then the exec dir, and then - * fallback to the straight executable name (i.e. on ther path). + * fallback to the straight executable name (i.e. on the path). * - * @param exec the name of the executable - * @param searchPath if true, the excutable will be looked up in + * @param exec the name of the executable. + * @param mustSearchPath if true, the executable will be looked up in * the PATH environment and the absolute path is returned. * * @return the executable as a full path if it can be determined. * * @since Ant 1.6 */ - protected String resolveExecutable(String exec, boolean searchPath) { + protected String resolveExecutable(String exec, boolean mustSearchPath) { if (!resolveExecutable) { return exec; } - // try to find the executable File executableFile = getProject().resolveFile(exec); if (executableFile.exists()) { return executableFile.getAbsolutePath(); } - // now try to resolve against the dir if given if (dir != null) { executableFile = FILE_UTILS.resolveFile(dir, exec); @@ -401,46 +391,41 @@ public class ExecTask extends Task { return executableFile.getAbsolutePath(); } } - // couldn't find it - must be on path - if (searchPath) { + if (mustSearchPath) { Path p = null; String[] environment = env.getVariables(); if (environment != null) { for (int i = 0; i < environment.length; i++) { if (isPath(environment[i])) { - p = new Path(getProject(), - environment[i].substring(5)); + p = new Path(getProject(), environment[i].substring(5)); break; } } } - if (p == null) { - Vector envVars = Execute.getProcEnvironment(); - Enumeration e = envVars.elements(); - while (e.hasMoreElements()) { - String line = (String) e.nextElement(); - if (isPath(line)) { - p = new Path(getProject(), line.substring(5)); - break; + Vector envVars = Execute.getProcEnvironment(); + Enumeration e = envVars.elements(); + while (e.hasMoreElements()) { + String line = (String) e.nextElement(); + if (isPath(line)) { + p = new Path(getProject(), line.substring(5)); + break; + } } } - } - if (p != null) { String[] dirs = p.list(); for (int i = 0; i < dirs.length; i++) { - executableFile = FILE_UTILS.resolveFile(new File(dirs[i]), - exec); + executableFile + = FILE_UTILS.resolveFile(new File(dirs[i]), exec); if (executableFile.exists()) { return executableFile.getAbsolutePath(); } } } } - - // searchPath is false, or no PATH or not found - keep our + // mustSearchPath is false, or no PATH or not found - keep our // fingers crossed. return exec; } @@ -448,7 +433,7 @@ public class ExecTask extends Task { /** * Do the work. * - * @throws BuildException in a number of circumstances : + * @throws BuildException in a number of circumstances: *