Base class for all tasks.
Use Project.createTask to create a new task instance rather than
using this class directly for construction.
bindToOwner
public final void bindToOwner(Task owner)
Bind a task to another; use this when configuring a newly created
task to do work on behalf of another.
Project, OwningTarget, TaskName, Location and Description are all copied
Important: this method does not call
init()
.
If you are creating a task to delegate work to, call
init()
to initialize it.
execute
public void execute()
throws BuildException
Called by the project to let the task do its work. This method may be
called more than once, if the task is invoked more than once.
For example,
if target1 and target2 both depend on target3, then running
"ant target1 target2" will run all tasks in target3 twice.
getOwningTarget
public Target getOwningTarget()
Returns the container target of this task.
- The target containing this task, or
null
if
this task is a top-level task.
getRuntimeConfigurableWrapper
public RuntimeConfigurable getRuntimeConfigurableWrapper()
Returns the wrapper used for runtime configuration.
- the wrapper used for runtime configuration. This
method will generate a new wrapper (and cache it)
if one isn't set already.
getTaskName
public String getTaskName()
Returns the name to use in logging messages.
- the name to use in logging messages.
getTaskType
public String getTaskType()
Return the type of task.
getWrapper
protected RuntimeConfigurable getWrapper()
Return the runtime configurable structure for this task.
- the runtime structure for this task.
handleErrorFlush
protected void handleErrorFlush(String output)
Handles an error line by logging it with the WARN priority.
output
- The error output to log. Should not be null
.
handleErrorOutput
protected void handleErrorOutput(String output)
Handles an error output by logging it with the WARN priority.
output
- The error output to log. Should not be null
.
handleFlush
protected void handleFlush(String output)
Handles output by logging it with the INFO priority.
output
- The output to log. Should not be null
.
handleInput
protected int handleInput(byte[] buffer,
int offset,
int length)
throws IOException
Handle an input request by this task.
buffer
- the buffer into which data is to be read.offset
- the offset into the buffer at which data is stored.length
- the amount of data to read.
- the number of bytes read.
handleOutput
protected void handleOutput(String output)
Handles output by logging it with the INFO priority.
output
- The output to log. Should not be null
.
init
public void init()
throws BuildException
Called by the project to let the task initialize properly.
The default implementation is a no-op.
isInvalid
protected final boolean isInvalid()
Has this task been marked invalid?
- true if this task is no longer valid. A new task should be
configured in this case.
log
public void log(String msg)
Logs a message with the default (INFO) priority.
- log in interface ProjectComponent
msg
- The message to be logged. Should not be null
.
log
public void log(String msg,
Throwable t,
int msgLevel)
Logs a message with the given priority. This delegates
the actual logging to the project.
msg
- The message to be logged. Should not be null
.t
- The exception to be logged. May be null
.msgLevel
- The message priority at which this message is to
be logged.
log
public void log(String msg,
int msgLevel)
Logs a message with the given priority. This delegates
the actual logging to the project.
- log in interface ProjectComponent
msg
- The message to be logged. Should not be null
.msgLevel
- The message priority at which this message is to
be logged.
log
public void log(Throwable t,
int msgLevel)
Logs a message with the given priority. This delegates
the actual logging to the project.
t
- The exception to be logged. Should not be null
.msgLevel
- The message priority at which this message is to
be logged.
maybeConfigure
public void maybeConfigure()
throws BuildException
Configures this task - if it hasn't been done already.
If the task has been invalidated, it is replaced with an
UnknownElement task which uses the new definition in the project.
perform
public final void perform()
Performs this task if it's still valid, or gets a replacement
version and performs that otherwise.
Performing a task consists of firing a task started event,
configuring the task, executing it, and then firing task finished
event. If a runtime exception is thrown, the task finished event
is still fired, but with the exception as the cause.
reconfigure
public void reconfigure()
Force the task to be reconfigured from its RuntimeConfigurable.
setOwningTarget
public void setOwningTarget(Target target)
Sets the target container of this task.
target
- Target in whose scope this task belongs.
May be null
, indicating a top-level task.
setRuntimeConfigurableWrapper
public void setRuntimeConfigurableWrapper(RuntimeConfigurable wrapper)
Sets the wrapper to be used for runtime configuration.
This method should be used only by the ProjectHelper and Ant internals.
It is public to allow helper plugins to operate on tasks, normal tasks
should never use it.
wrapper
- The wrapper to be used for runtime configuration.
May be null
, in which case the next call
to getRuntimeConfigurableWrapper will generate a new
wrapper.
setTaskName
public void setTaskName(String name)
Sets the name to use in logging messages.
name
- The name to use in logging messages.
Should not be null
.
setTaskType
public void setTaskType(String type)
Sets the name with which the task has been invoked.
type
- The name the task has been invoked as.
Should not be null
.