Top Description Fields Constructors Methods
org.apache.tools.ant

public abstract Class Task

extends ProjectComponent
Class Inheritance
Known Direct Subclasses
org.apache.tools.ant.TaskAdapter, org.apache.tools.ant.UnknownElement, org.apache.tools.ant.dispatch.DispatchTask, org.apache.tools.ant.taskdefs.AbstractCvsTask, org.apache.tools.ant.taskdefs.AbstractJarSignerTask, org.apache.tools.ant.taskdefs.Ant, org.apache.tools.ant.taskdefs.Antlib, org.apache.tools.ant.taskdefs.AntlibDefinition, org.apache.tools.ant.taskdefs.AntStructure, org.apache.tools.ant.taskdefs.AugmentReference, org.apache.tools.ant.taskdefs.Available, org.apache.tools.ant.taskdefs.Basename, org.apache.tools.ant.taskdefs.BindTargets, org.apache.tools.ant.taskdefs.BuildNumber, org.apache.tools.ant.taskdefs.CallTarget, org.apache.tools.ant.taskdefs.CloseResources, org.apache.tools.ant.taskdefs.CommandLauncherTask, org.apache.tools.ant.taskdefs.Concat, org.apache.tools.ant.taskdefs.Copy, org.apache.tools.ant.taskdefs.Copyfile, org.apache.tools.ant.taskdefs.CopyPath, org.apache.tools.ant.taskdefs.CVSPass, org.apache.tools.ant.taskdefs.DefaultExcludes, org.apache.tools.ant.taskdefs.DiagnosticsTask, org.apache.tools.ant.taskdefs.Dirname, org.apache.tools.ant.taskdefs.Echo, org.apache.tools.ant.taskdefs.Exec, org.apache.tools.ant.taskdefs.ExecTask, org.apache.tools.ant.taskdefs.Exit, org.apache.tools.ant.taskdefs.Expand, org.apache.tools.ant.taskdefs.Filter, org.apache.tools.ant.taskdefs.Get, org.apache.tools.ant.taskdefs.HostInfo, org.apache.tools.ant.taskdefs.ImportTask, org.apache.tools.ant.taskdefs.Input, org.apache.tools.ant.taskdefs.Java, org.apache.tools.ant.taskdefs.Javadoc, org.apache.tools.ant.taskdefs.JDBCTask, org.apache.tools.ant.taskdefs.KeySubst, org.apache.tools.ant.taskdefs.Length, org.apache.tools.ant.taskdefs.LoadProperties, org.apache.tools.ant.taskdefs.Classloader, org.apache.tools.ant.taskdefs.Deltree, org.apache.tools.ant.taskdefs.GenerateKey, org.apache.tools.ant.taskdefs.LoadResource, org.apache.tools.ant.taskdefs.Parallel, org.apache.tools.ant.taskdefs.Local, org.apache.tools.ant.taskdefs.MacroInstance, org.apache.tools.ant.taskdefs.MakeUrl, org.apache.tools.ant.taskdefs.ManifestClassPath, org.apache.tools.ant.taskdefs.ManifestTask, org.apache.tools.ant.taskdefs.MatchingTask, org.apache.tools.ant.taskdefs.Mkdir, org.apache.tools.ant.taskdefs.Nice, org.apache.tools.ant.taskdefs.Pack, org.apache.tools.ant.taskdefs.Patch, org.apache.tools.ant.taskdefs.PathConvert, org.apache.tools.ant.taskdefs.ProjectHelperTask, org.apache.tools.ant.taskdefs.Property, org.apache.tools.ant.taskdefs.PropertyHelperTask, org.apache.tools.ant.taskdefs.Recorder, org.apache.tools.ant.taskdefs.Rename, org.apache.tools.ant.taskdefs.ResourceCount, org.apache.tools.ant.taskdefs.Retry, org.apache.tools.ant.taskdefs.Sequential, org.apache.tools.ant.taskdefs.SetPermissions, org.apache.tools.ant.taskdefs.Sleep, org.apache.tools.ant.taskdefs.SubAnt, org.apache.tools.ant.taskdefs.Sync, org.apache.tools.ant.taskdefs.TempFile, org.apache.tools.ant.taskdefs.Touch, org.apache.tools.ant.taskdefs.Truncate, org.apache.tools.ant.taskdefs.Tstamp, org.apache.tools.ant.taskdefs.Unpack, org.apache.tools.ant.taskdefs.UpToDate, org.apache.tools.ant.taskdefs.WhichResource, org.apache.tools.ant.taskdefs.XmlProperty, org.apache.tools.ant.taskdefs.condition.AntVersion, org.apache.tools.ant.taskdefs.email.EmailTask, org.apache.tools.ant.taskdefs.modules.Jmod, org.apache.tools.ant.taskdefs.modules.Link, org.apache.tools.ant.taskdefs.optional.EchoProperties, org.apache.tools.ant.taskdefs.optional.Javah, org.apache.tools.ant.taskdefs.optional.PropertyFile, org.apache.tools.ant.taskdefs.optional.ReplaceRegExp, org.apache.tools.ant.taskdefs.optional.Rpm, org.apache.tools.ant.taskdefs.optional.Script, org.apache.tools.ant.taskdefs.optional.XMLValidateTask, org.apache.tools.ant.taskdefs.optional.ccm.Continuus, org.apache.tools.ant.taskdefs.optional.clearcase.ClearCase, org.apache.tools.ant.taskdefs.optional.ejb.BorlandGenerateClient, org.apache.tools.ant.taskdefs.optional.ejb.IPlanetEjbcTask, org.apache.tools.ant.taskdefs.optional.extension.JarLibAvailableTask, org.apache.tools.ant.taskdefs.optional.extension.JarLibDisplayTask, org.apache.tools.ant.taskdefs.optional.extension.JarLibManifestTask, org.apache.tools.ant.taskdefs.optional.extension.JarLibResolveTask, org.apache.tools.ant.taskdefs.optional.j2ee.ServerDeploy, org.apache.tools.ant.taskdefs.optional.javacc.JavaCC, org.apache.tools.ant.taskdefs.optional.javacc.JJDoc, org.apache.tools.ant.taskdefs.optional.javacc.JJTree, org.apache.tools.ant.taskdefs.optional.net.SetProxy, org.apache.tools.ant.taskdefs.optional.pvcs.Pvcs, org.apache.tools.ant.taskdefs.optional.script.ScriptDefBase, org.apache.tools.ant.taskdefs.optional.sos.SOS, org.apache.tools.ant.taskdefs.optional.testing.Funtest, org.apache.tools.ant.taskdefs.optional.vss.MSVSS
Imports
java.io.IOException, java.util.Collections, org.apache.tools.ant.dispatch.DispatchUtils

Base class for all tasks. Use Project.createTask to create a new task instance rather than using this class directly for construction.
See Also
Project#createTask

Field Summary

Modifier and TypeField and Description
private boolean
invalid

Whether or not this task is invalid.

private UnknownElement
replacement

Replacement element used if this task is invalidated.

protected Target
target

Target this task belongs to, if any.

protected String
taskName

Name of this task to be used for logging purposes.

protected String
taskType

Type of this task.

protected RuntimeConfigurable
wrapper

Wrapper for this object, used to configure it at runtime.

Inherited from org.apache.tools.ant.ProjectComponent:
descriptionlocationproject

Constructor Summary

AccessConstructor and Description
public
Task()

Method Summary

Modifier and TypeMethod and Description
public final void
bindToOwner(Task
owning target
owner
)

Bind a task to another; use this when configuring a newly created task to do work on behalf of another.

public void
execute()

Called by the project to let the task do its work.

public Target

Returns:

The target containing this task, or null if this task is a top-level task.
getOwningTarget
()

Returns the container target of this task.

private UnknownElement

Returns:

the UnknownElement instance for the new definition of this task.
getReplacement
()

Creates an UnknownElement that can be used to replace this task.

public RuntimeConfigurable

Returns:

the wrapper used for runtime configuration. This method will generate a new wrapper (and cache it) if one isn't set already.
getRuntimeConfigurableWrapper
()

Returns the wrapper used for runtime configuration.

public String

Returns:

the name to use in logging messages.
getTaskName
()

Returns the name to use in logging messages.

public String

Returns:

the type of task.
getTaskType
()

Return the type of task.

protected RuntimeConfigurable

Returns:

the runtime structure for this task.
getWrapper
()

Return the runtime configurable structure for this task.

protected void
handleErrorFlush(String
The error output to log. Should not be null.
output
)

Handles an error line by logging it with the WARN priority.

protected void
handleErrorOutput(String
The error output to log. Should not be null.
output
)

Handles an error output by logging it with the WARN priority.

protected void
handleFlush(String
The output to log. Should not be null.
output
)

Handles output by logging it with the INFO priority.

protected int

Returns:

the number of bytes read.
handleInput
(byte[]
the buffer into which data is to be read.
buffer
,
int
the offset into the buffer at which data is stored.
offset
,
int
the amount of data to read.
length
)

Handle an input request by this task.

protected void
handleOutput(String
The output to log. Should not be null.
output
)

Handles output by logging it with the INFO priority.

public void
init()

Called by the project to let the task initialize properly.

protected final boolean

Returns:

true if this task is no longer valid. A new task should be configured in this case.
isInvalid
()

Has this task been marked invalid?

public void
log(String
The message to be logged. Should not be null.
msg
)

Overrides org.apache.tools.ant.ProjectComponent.log.

Logs a message with the default (INFO) priority.
public void
log(String
The message to be logged. Should not be null.
msg
,
int
The message priority at which this message is to be logged.
msgLevel
)

Overrides org.apache.tools.ant.ProjectComponent.log.

Logs a message with the given priority.
public void
log(Throwable
The exception to be logged. Should not be null.
t
,
int
The message priority at which this message is to be logged.
msgLevel
)

Logs a message with the given priority.

public void
log(String
The message to be logged. Should not be null.
msg
,
Throwable
The exception to be logged. May be null.
t
,
int
The message priority at which this message is to be logged.
msgLevel
)

Logs a message with the given priority.

pack-priv final void
markInvalid()

Marks this task as invalid.

public void
maybeConfigure()

Configures this task - if it hasn't been done already.

public final void
perform()

Performs this task if it's still valid, or gets a replacement version and performs that otherwise.

public void
reconfigure()

Force the task to be reconfigured from its RuntimeConfigurable.

private void
replaceChildren(RuntimeConfigurable wrapper, UnknownElement parentElement)

Recursively adds an UnknownElement instance for each child element of replacement.

public void
setOwningTarget(Target
Target in whose scope this task belongs. May be null, indicating a top-level task.
target
)

Sets the target container of this task.

public void
setRuntimeConfigurableWrapper(RuntimeConfigurable
The wrapper to be used for runtime configuration. May be null, in which case the next call to getRuntimeConfigurableWrapper will generate a new wrapper.
wrapper
)

Sets the wrapper to be used for runtime configuration.

public void
setTaskName(String
The name to use in logging messages. Should not be null.
name
)

Sets the name to use in logging messages.

public void
setTaskType(String
The name the task has been invoked as. Should not be null.
type
)

Sets the name with which the task has been invoked.

Inherited from org.apache.tools.ant.ProjectComponent:
clonegetDescriptiongetLocationgetProjectsetDescriptionsetLocationsetProject

Field Detail

invalidback to summary
private boolean invalid

Whether or not this task is invalid. A task becomes invalid if a conflicting class is specified as the implementation for its type.

replacementback to summary
private UnknownElement replacement

Replacement element used if this task is invalidated.

targetback to summary
protected Target target

Deprecated

since 1.6.x. You should not be accessing this variable directly. Please use the getOwningTarget() method.

Target this task belongs to, if any.

Annotations
@Deprecated
taskNameback to summary
protected String taskName

Deprecated

since 1.6.x. You should not be accessing this variable directly. Please use the getTaskName() method.

Name of this task to be used for logging purposes. This defaults to the same as the type, but may be overridden by the user. For instance, the name "java" isn't terribly descriptive for a task used within another task - the outer task code can probably provide a better one.

Annotations
@Deprecated
taskTypeback to summary
protected String taskType

Deprecated

since 1.6.x. You should not be accessing this variable directly. Please use the getTaskType() method.

Type of this task.

Annotations
@Deprecated
wrapperback to summary
protected RuntimeConfigurable wrapper

Deprecated

since 1.6.x. You should not be accessing this variable directly. Please use the getWrapper() method.

Wrapper for this object, used to configure it at runtime.

Annotations
@Deprecated

Constructor Detail

Taskback to summary
public Task()

Method Detail

bindToOwnerback to summary
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 Note

this method does not call Task#init(). If you are creating a task to delegate work to, call Task#init() to initialize it.

Parameters
owner:Task

owning target

Since
Ant1.7
executeback to summary
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.

Exceptions
BuildException:
if something goes wrong with the build.
getOwningTargetback to summary
public Target getOwningTarget()

Returns the container target of this task.

Returns:Target

The target containing this task, or null if this task is a top-level task.

getReplacementback to summary
private UnknownElement getReplacement()

Creates an UnknownElement that can be used to replace this task. Once this has been created once, it is cached and returned by future calls.

Returns:UnknownElement

the UnknownElement instance for the new definition of this task.

getRuntimeConfigurableWrapperback to summary
public RuntimeConfigurable getRuntimeConfigurableWrapper()

Returns the wrapper used for runtime configuration.

Returns:RuntimeConfigurable

the wrapper used for runtime configuration. This method will generate a new wrapper (and cache it) if one isn't set already.

getTaskNameback to summary
public String getTaskName()

Returns the name to use in logging messages.

Returns:String

the name to use in logging messages.

getTaskTypeback to summary
public String getTaskType()

Return the type of task.

Returns:String

the type of task.

getWrapperback to summary
protected RuntimeConfigurable getWrapper()

Return the runtime configurable structure for this task.

Returns:RuntimeConfigurable

the runtime structure for this task.

handleErrorFlushback to summary
protected void handleErrorFlush(String output)

Handles an error line by logging it with the WARN priority.

Parameters
output:String

The error output to log. Should not be null.

Since
Ant 1.5.2
handleErrorOutputback to summary
protected void handleErrorOutput(String output)

Handles an error output by logging it with the WARN priority.

Parameters
output:String

The error output to log. Should not be null.

handleFlushback to summary
protected void handleFlush(String output)

Handles output by logging it with the INFO priority.

Parameters
output:String

The output to log. Should not be null.

Since
Ant 1.5.2
handleInputback to summary
protected int handleInput(byte[] buffer, int offset, int length) throws IOException

Handle an input request by this task.

Parameters
buffer:byte[]

the buffer into which data is to be read.

offset:int

the offset into the buffer at which data is stored.

length:int

the amount of data to read.

Returns:int

the number of bytes read.

Exceptions
IOException:
if the data cannot be read.
Since
Ant 1.6
handleOutputback to summary
protected void handleOutput(String output)

Handles output by logging it with the INFO priority.

Parameters
output:String

The output to log. Should not be null.

initback to summary
public void init() throws BuildException

Called by the project to let the task initialize properly. The default implementation is a no-op.

Exceptions
BuildException:
if something goes wrong with the build
isInvalidback to summary
protected final boolean isInvalid()

Has this task been marked invalid?

Returns:boolean

true if this task is no longer valid. A new task should be configured in this case.

Since
Ant 1.5
logback to summary
public void log(String msg)

Overrides org.apache.tools.ant.ProjectComponent.log.

Logs a message with the default (INFO) priority.

Parameters
msg:String

The message to be logged. Should not be null.

logback to summary
public void log(String msg, int msgLevel)

Overrides org.apache.tools.ant.ProjectComponent.log.

Logs a message with the given priority. This delegates the actual logging to the project.

Parameters
msg:String

The message to be logged. Should not be null.

msgLevel:int

The message priority at which this message is to be logged.

logback to summary
public void log(Throwable t, int msgLevel)

Logs a message with the given priority. This delegates the actual logging to the project.

Parameters
t:Throwable

The exception to be logged. Should not be null.

msgLevel:int

The message priority at which this message is to be logged.

Since
1.7
logback to summary
public void log(String msg, Throwable t, int msgLevel)

Logs a message with the given priority. This delegates the actual logging to the project.

Parameters
msg:String

The message to be logged. Should not be null.

t:Throwable

The exception to be logged. May be null.

msgLevel:int

The message priority at which this message is to be logged.

Since
1.7
markInvalidback to summary
pack-priv final void markInvalid()

Marks this task as invalid. Any further use of this task will go through a replacement with the updated definition.

maybeConfigureback to summary
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.

Exceptions
BuildException:
if the task cannot be configured.
performback to summary
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.

reconfigureback to summary
public void reconfigure()

Force the task to be reconfigured from its RuntimeConfigurable.

replaceChildrenback to summary
private void replaceChildren(RuntimeConfigurable wrapper, UnknownElement parentElement)

Recursively adds an UnknownElement instance for each child element of replacement.

Since
Ant 1.5.1
setOwningTargetback to summary
public void setOwningTarget(Target target)

Sets the target container of this task.

Parameters
target:Target

Target in whose scope this task belongs. May be null, indicating a top-level task.

setRuntimeConfigurableWrapperback to summary
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.

Parameters
wrapper:RuntimeConfigurable

The wrapper to be used for runtime configuration. May be null, in which case the next call to getRuntimeConfigurableWrapper will generate a new wrapper.

setTaskNameback to summary
public void setTaskName(String name)

Sets the name to use in logging messages.

Parameters
name:String

The name to use in logging messages. Should not be null.

setTaskTypeback to summary
public void setTaskType(String type)

Sets the name with which the task has been invoked.

Parameters
type:String

The name the task has been invoked as. Should not be null.