Executes a given command if the os platform is appropriate.
addConfiguredRedirector
public void addConfiguredRedirector(RedirectorElement redirectorElement)
Add a RedirectorElement
to this task.
redirectorElement
- RedirectorElement
.
addEnv
public void addEnv(Environment.Variable var)
Add an environment variable to the launched process.
var
- new environment variable.
checkConfiguration
protected void checkConfiguration()
throws BuildException
Has the user set all necessary attributes?
createArg
public Commandline.Argument createArg()
Adds a command-line argument.
- new command line argument created.
createHandler
protected ExecuteStreamHandler createHandler()
throws BuildException
Create the StreamHandler to use with our Execute instance.
- instance of ExecuteStreamHandler.
createWatchdog
protected ExecuteWatchdog createWatchdog()
throws BuildException
Create the Watchdog to kill a runaway process.
- instance of ExecuteWatchdog.
execute
public void execute()
throws BuildException
Do the work.
- execute in interface Task
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
getResolveExecutable
public boolean getResolveExecutable()
Indicates whether to attempt to resolve the executable to a
file.
- the resolveExecutable flag
isValidOs
protected boolean isValidOs()
Is this the OS the user wanted?
- boolean.
-
true
if the os and osfamily attributes are null.true
if 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
os
attribute must also evaluate true.
-
true
if os is set, and the system.property os.name
is found in the os attribute, false
otherwise.
logFlush
protected void logFlush()
Flush the output stream - if there is one.
maybeSetResultPropertyValue
protected void maybeSetResultPropertyValue(int result)
Helper method to set result property to the
passed in value if appropriate.
result
- value desired for the result property value.
prepareExec
protected Execute prepareExec()
throws BuildException
Create an Execute instance with the correct working directory set.
- an instance of the Execute class.
resolveExecutable
protected String resolveExecutable(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).
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.
- the executable as a full path if it can be determined.
runExec
protected void runExec(Execute exe)
throws BuildException
Run the command using the given Execute instance. This may be
overridden by subclasses.
exe
- instance of Execute to run.
BuildException
- if the new process could not be started
only if failIfExecFails is set to true (the default).
runExecute
protected final void runExecute(Execute exe)
throws IOException
A Utility method for this classes and subclasses to run an
Execute instance (an external command).
exe
- instance of the execute class.
setAppend
public void setAppend(boolean append)
Set whether output should be appended to or overwrite an existing file.
Defaults to false.
append
- if true append is desired.
setCommand
public void setCommand(Commandline cmdl)
Sets a command line.
setDir
public void setDir(File d)
Set the working directory of the process.
d
- the working directory of the process.
setError
public void setError(File error)
Set the File to which the error stream of the process should be redirected.
error
- a file to which stderr should be sent.
setErrorProperty
public void setErrorProperty(String errorProperty)
Sets the name of the property whose value should be set to the error of
the process.
errorProperty
- name of property.
setExecutable
public void setExecutable(String value)
Set the name of the executable program.
value
- the name of the executable program.
setFailIfExecutionFails
public void setFailIfExecutionFails(boolean flag)
Set whether to stop the build if program cannot be started.
Defaults to true.
flag
- stop the build if program cannot be started.
setFailonerror
public void setFailonerror(boolean fail)
Fail if the command exits with a non-zero return code.
fail
- if true fail the command on non-zero return code.
setInput
public void setInput(File input)
Set the input file to use for the task.
input
- name of a file from which to get input.
setInputString
public void setInputString(String inputString)
Set the string to use as input.
inputString
- the string which is used as the input source.
setLogError
public 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.
logError
- set to true to log error output in the normal ant log.
setNewenvironment
public void setNewenvironment(boolean newenv)
Do not propagate old environment when new environment variables are specified.
newenv
- if true, do not propagate old environment
when new environment variables are specified.
setOs
public void setOs(String os)
List of operating systems on which the command may be executed.
os
- list of operating systems on which the command may be executed.
setOsFamily
public void setOsFamily(String osFamily)
Restrict this execution to a single OS Family
osFamily
- the family to restrict to.
setOutput
public void setOutput(File out)
File the output of the process is redirected to. If error is not
redirected, it too will appear in the output.
out
- name of a file to which output should be sent.
setOutputproperty
public void setOutputproperty(String outputProp)
Sets the property name whose value should be set to the output of
the process.
outputProp
- name of property.
setResolveExecutable
public void setResolveExecutable(boolean resolveExecutable)
Set whether to attempt to resolve the executable to a file.
resolveExecutable
- if true, attempt to resolve the
path of the executable.
setResultProperty
public void setResultProperty(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.
resultProperty
- name of property.
setSearchPath
public void setSearchPath(boolean searchPath)
Set whether to search nested, then
system PATH environment variables for the executable.
searchPath
- if true, search PATHs.
setSpawn
public void setSpawn(boolean spawn)
Set whether or not you want the process to be spawned.
Default is false.
spawn
- if true you do not want Ant to wait for the end of the process.
setTimeout
public void setTimeout(Integer value)
Set the timeout in milliseconds after which the process will be killed.
value
- timeout in milliseconds.
setTimeout
public void setTimeout(Long value)
Set the timeout in milliseconds after which the process will be killed.
value
- timeout in milliseconds.
setVMLauncher
public void setVMLauncher(boolean vmLauncher)
Set whether to launch new process with VM, otherwise use the OS's shell.
Default value is true.
vmLauncher
- true if we want to launch new process with VM,
false if we want to use the OS's shell.
setupRedirector
protected void setupRedirector()
Set up properties on the redirector that we needed to store locally.