Package org.apache.tools.ant.taskdefs
Class ExecTask
- java.lang.Object
- 
- org.apache.tools.ant.ProjectComponent
- 
- org.apache.tools.ant.Task
- 
- org.apache.tools.ant.taskdefs.ExecTask
 
 
 
- 
- 
Field SummaryFields Modifier and Type Field Description protected Commandlinecmdlprotected booleanfailOnErrorprotected booleannewEnvironmentprotected Redirectorredirectorprotected RedirectorElementredirectorElement- 
Fields inherited from class org.apache.tools.ant.ProjectComponentdescription, location, project
 
- 
 - 
Method SummaryModifier and Type Method Description voidaddConfiguredRedirector(RedirectorElement redirectorElement)Add aRedirectorElementto this task.voidaddEnv(Environment.Variable var)Add an environment variable to the launched process.protected voidcheckConfiguration()Has the user set all necessary attributes?Commandline.ArgumentcreateArg()Adds a command-line argument.protected ExecuteStreamHandlercreateHandler()Create the StreamHandler to use with our Execute instance.protected ExecuteWatchdogcreateWatchdog()Create the Watchdog to kill a runaway process.voidexecute()Do the work.java.lang.StringgetOs()List of operating systems on which the command may be executed.java.lang.StringgetOsFamily()Restrict this execution to a single OS FamilybooleangetResolveExecutable()Indicates whether to attempt to resolve the executable to a file.protected booleanisValidOs()Is this the OS the user wanted?protected voidlogFlush()Flush the output stream - if there is one.protected voidmaybeSetResultPropertyValue(int result)Helper method to set result property to the passed in value if appropriate.protected ExecuteprepareExec()Create an Execute instance with the correct working directory set.protected java.lang.StringresolveExecutable(java.lang.String exec, boolean mustSearchPath)The method attempts to figure out where the executable is so that we can feed the full path.protected voidrunExec(Execute exe)Run the command using the given Execute instance.protected voidrunExecute(Execute exe)A Utility method for this classes and subclasses to run an Execute instance (an external command).voidsetAppend(boolean append)Set whether output should be appended to or overwrite an existing file.voidsetCommand(Commandline cmdl)Sets a command line.voidsetDir(java.io.File d)Set the working directory of the process.voidsetError(java.io.File error)Set the File to which the error stream of the process should be redirected.voidsetErrorProperty(java.lang.String errorProperty)Sets the name of the property whose value should be set to the error of the process.voidsetExecutable(java.lang.String value)Set the name of the executable program.voidsetFailIfExecutionFails(boolean flag)Set whether to stop the build if program cannot be started.voidsetFailonerror(boolean fail)Fail if the command exits with a non-zero return code.voidsetInput(java.io.File input)Set the input file to use for the task.voidsetInputString(java.lang.String inputString)Set the string to use as input.voidsetLogError(boolean logError)Controls whether error output of exec is logged.voidsetNewenvironment(boolean newenv)Do not propagate old environment when new environment variables are specified.voidsetOs(java.lang.String os)List of operating systems on which the command may be executed.voidsetOsFamily(java.lang.String osFamily)Restrict this execution to a single OS FamilyvoidsetOutput(java.io.File out)File the output of the process is redirected to.voidsetOutputproperty(java.lang.String outputProp)Sets the property name whose value should be set to the output of the process.voidsetResolveExecutable(boolean resolveExecutable)Set whether to attempt to resolve the executable to a file.voidsetResultProperty(java.lang.String resultProperty)Sets the name of a property in which the return code of the command should be stored.voidsetSearchPath(boolean searchPath)Set whether to search nested, then system PATH environment variables for the executable.voidsetSpawn(boolean spawn)Set whether or not you want the process to be spawned.voidsetTimeout(java.lang.Integer value)Set the timeout in milliseconds after which the process will be killed.voidsetTimeout(java.lang.Long value)Set the timeout in milliseconds after which the process will be killed.protected voidsetupRedirector()Set up properties on the redirector that we needed to store locally.voidsetVMLauncher(boolean vmLauncher)Set whether to launch new process with VM, otherwise use the OS's shell.- 
Methods inherited from class org.apache.tools.ant.TaskbindToOwner, getOwningTarget, getRuntimeConfigurableWrapper, getTaskName, getTaskType, getWrapper, handleErrorFlush, handleErrorOutput, handleFlush, handleInput, handleOutput, init, isInvalid, log, log, log, log, maybeConfigure, perform, reconfigure, setOwningTarget, setRuntimeConfigurableWrapper, setTaskName, setTaskType
 - 
Methods inherited from class org.apache.tools.ant.ProjectComponentclone, getDescription, getLocation, getProject, setDescription, setLocation, setProject
 
- 
 
- 
- 
- 
Field Detail- 
failOnErrorprotected boolean failOnError 
 - 
newEnvironmentprotected boolean newEnvironment 
 - 
cmdlprotected Commandline cmdl 
 - 
redirectorprotected Redirector redirector 
 - 
redirectorElementprotected RedirectorElement redirectorElement 
 
- 
 - 
Constructor Detail- 
ExecTaskpublic ExecTask() Create an instance. Needs to be configured by binding to a project.
 - 
ExecTaskpublic ExecTask(Task owner) create an instance that is helping another task. Project, OwningTarget, TaskName and description are all pulled out- Parameters:
- owner- task that we belong to
 
 
- 
 - 
Method Detail- 
setSpawnpublic void setSpawn(boolean spawn) Set whether or not you want the process to be spawned. Default is false.- Parameters:
- spawn- if true you do not want Ant to wait for the end of the process.
- Since:
- Ant 1.6
 
 - 
setTimeoutpublic void setTimeout(java.lang.Long value) Set the timeout in milliseconds after which the process will be killed.- Parameters:
- value- timeout in milliseconds.
- Since:
- Ant 1.5
 
 - 
setTimeoutpublic void setTimeout(java.lang.Integer value) Set the timeout in milliseconds after which the process will be killed.- Parameters:
- value- timeout in milliseconds.
 
 - 
setExecutablepublic void setExecutable(java.lang.String value) Set the name of the executable program.- Parameters:
- value- the name of the executable program.
 
 - 
setDirpublic void setDir(java.io.File d) Set the working directory of the process.- Parameters:
- d- the working directory of the process.
 
 - 
setOspublic void setOs(java.lang.String os) List of operating systems on which the command may be executed.- Parameters:
- os- list of operating systems on which the command may be executed.
 
 - 
getOspublic final java.lang.String getOs() List of operating systems on which the command may be executed.- Returns:
- String
- Since:
- Ant 1.8.0
 
 - 
setCommandpublic void setCommand(Commandline cmdl) Sets a command line.- Parameters:
- cmdl- command line.
 
 - 
setOutputpublic void setOutput(java.io.File out) File the output of the process is redirected to. If error is not redirected, it too will appear in the output.- Parameters:
- out- name of a file to which output should be sent.
 
 - 
setInputpublic void setInput(java.io.File input) Set the input file to use for the task.- Parameters:
- input- name of a file from which to get input.
 
 - 
setInputStringpublic void setInputString(java.lang.String inputString) Set the string to use as input.- Parameters:
- inputString- the string which is used as the input source.
 
 - 
setLogErrorpublic void setLogError(boolean logError) 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.- Parameters:
- logError- set to true to log error output in the normal ant log.
 
 - 
setErrorpublic void setError(java.io.File error) Set the File to which the error stream of the process should be redirected.- Parameters:
- error- a file to which stderr should be sent.
- Since:
- Ant 1.6
 
 - 
setOutputpropertypublic void setOutputproperty(java.lang.String outputProp) Sets the property name whose value should be set to the output of the process.- Parameters:
- outputProp- name of property.
 
 - 
setErrorPropertypublic void setErrorProperty(java.lang.String errorProperty) Sets the name of the property whose value should be set to the error of the process.- Parameters:
- errorProperty- name of property.
- Since:
- Ant 1.6
 
 - 
setFailonerrorpublic void setFailonerror(boolean fail) Fail if the command exits with a non-zero return code.- Parameters:
- fail- if true fail the command on non-zero return code.
 
 - 
setNewenvironmentpublic void setNewenvironment(boolean newenv) Do not propagate old environment when new environment variables are specified.- Parameters:
- newenv- if true, do not propagate old environment when new environment variables are specified.
 
 - 
setResolveExecutablepublic void setResolveExecutable(boolean resolveExecutable) Set whether to attempt to resolve the executable to a file.- Parameters:
- resolveExecutable- if true, attempt to resolve the path of the executable.
 
 - 
setSearchPathpublic void setSearchPath(boolean searchPath) Set whether to search nested, then system PATH environment variables for the executable.- Parameters:
- searchPath- if true, search PATHs.
 
 - 
getResolveExecutablepublic boolean getResolveExecutable() Indicates whether to attempt to resolve the executable to a file.- Returns:
- the resolveExecutable flag
- Since:
- Ant 1.6
 
 - 
addEnvpublic void addEnv(Environment.Variable var) Add an environment variable to the launched process.- Parameters:
- var- new environment variable.
 
 - 
createArgpublic Commandline.Argument createArg() Adds a command-line argument.- Returns:
- new command line argument created.
 
 - 
setResultPropertypublic void setResultProperty(java.lang.String resultProperty) Sets the name of a property in which the return code of the command should be stored. Only of interest if failonerror=false.- Parameters:
- resultProperty- name of property.
- Since:
- Ant 1.5
 
 - 
maybeSetResultPropertyValueprotected void maybeSetResultPropertyValue(int result) Helper method to set result property to the passed in value if appropriate.- Parameters:
- result- value desired for the result property value.
 
 - 
setFailIfExecutionFailspublic void setFailIfExecutionFails(boolean flag) Set whether to stop the build if program cannot be started. Defaults to true.- Parameters:
- flag- stop the build if program cannot be started.
- Since:
- Ant 1.5
 
 - 
setAppendpublic void setAppend(boolean append) Set whether output should be appended to or overwrite an existing file. Defaults to false.- Parameters:
- append- if true append is desired.
- Since:
- 1.30, Ant 1.5
 
 - 
addConfiguredRedirectorpublic void addConfiguredRedirector(RedirectorElement redirectorElement) Add aRedirectorElementto this task.- Parameters:
- redirectorElement-- RedirectorElement.
- Since:
- Ant 1.6.2
 
 - 
setOsFamilypublic void setOsFamily(java.lang.String osFamily) Restrict this execution to a single OS Family- Parameters:
- osFamily- the family to restrict to.
 
 - 
getOsFamilypublic final java.lang.String getOsFamily() Restrict this execution to a single OS Family- Returns:
- the family to restrict to.
- Since:
- Ant 1.8.0
 
 - 
resolveExecutableprotected java.lang.String resolveExecutable(java.lang.String exec, boolean mustSearchPath)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 the path).- Parameters:
- exec- the name of the executable.
- mustSearchPath- if true, the executable will be looked up in the PATH environment and the absolute path is returned.
- Returns:
- the executable as a full path if it can be determined.
- Since:
- Ant 1.6
 
 - 
executepublic void execute() throws BuildExceptionDo the work.- Overrides:
- executein class- Task
- Throws:
- BuildException- in a number of circumstances:- if failIfExecFails is set to true and the process cannot be started
- the java13command launcher can send build exceptions
- this list is not exhaustive or limitative
 
 
 - 
checkConfigurationprotected void checkConfiguration() throws BuildExceptionHas the user set all necessary attributes?- Throws:
- BuildException- if there are missing required parameters.
 
 - 
setupRedirectorprotected void setupRedirector() Set up properties on the redirector that we needed to store locally.
 - 
isValidOsprotected boolean isValidOs() Is this the OS the user wanted?- Returns:
- boolean.
 
- trueif the os and osfamily attributes are null.
- trueif osfamily is set, and the os family and must match that of the current OS, according to the logic of- Os.isOs(String, String, String, String), and the result of the- osattribute must also evaluate true.
- 
 trueif os is set, and the system.property os.name is found in the os attribute,
- falseotherwise.
 
 
 - 
setVMLauncherpublic void setVMLauncher(boolean vmLauncher) Set whether to launch new process with VM, otherwise use the OS's shell. Default value is true.- Parameters:
- vmLauncher- true if we want to launch new process with VM, false if we want to use the OS's shell.
 
 - 
prepareExecprotected Execute prepareExec() throws BuildException Create an Execute instance with the correct working directory set.- Returns:
- an instance of the Execute class.
- Throws:
- BuildException- under unknown circumstances.
 
 - 
runExecuteprotected final void runExecute(Execute exe) throws java.io.IOException A Utility method for this classes and subclasses to run an Execute instance (an external command).- Parameters:
- exe- instance of the execute class.
- Throws:
- java.io.IOException- in case of problem to attach to the stdin/stdout/stderr streams of the process.
 
 - 
runExecprotected void runExec(Execute exe) throws BuildException Run the command using the given Execute instance. This may be overridden by subclasses.- Parameters:
- exe- instance of Execute to run.
- Throws:
- BuildException- if the new process could not be started only if failIfExecFails is set to true (the default).
 
 - 
createHandlerprotected ExecuteStreamHandler createHandler() throws BuildException Create the StreamHandler to use with our Execute instance.- Returns:
- instance of ExecuteStreamHandler.
- Throws:
- BuildException- under unknown circumstances.
 
 - 
createWatchdogprotected ExecuteWatchdog createWatchdog() throws BuildException Create the Watchdog to kill a runaway process.- Returns:
- instance of ExecuteWatchdog.
- Throws:
- BuildException- under unknown circumstances.
 
 - 
logFlushprotected void logFlush() Flush the output stream - if there is one.
 
- 
 
-