Package org.apache.tools.ant
Class Task
- java.lang.Object
- 
- org.apache.tools.ant.ProjectComponent
- 
- org.apache.tools.ant.Task
 
 
- 
- All Implemented Interfaces:
- java.lang.Cloneable
 - Direct Known Subclasses:
- AbstractCvsTask,- AbstractJarSignerTask,- Ant,- Antlib,- AntlibDefinition,- ANTLR,- AntStructure,- AntVersion,- AugmentReference,- Available,- Basename,- BindTargets,- BorlandGenerateClient,- BuildNumber,- CallTarget,- Classloader,- ClearCase,- CloseResources,- CommandLauncherTask,- Concat,- Continuus,- Copy,- Copyfile,- CopyPath,- CVSPass,- DefaultExcludes,- Deltree,- DiagnosticsTask,- Dirname,- DispatchTask,- Echo,- EchoProperties,- EmailTask,- Exec,- ExecTask,- Exit,- Expand,- Filter,- FTP,- FTPTask,- Funtest,- GenerateKey,- Get,- HostInfo,- ImportTask,- Input,- IPlanetEjbcTask,- JarLibAvailableTask,- JarLibDisplayTask,- JarLibManifestTask,- JarLibResolveTask,- Java,- JavaCC,- Javadoc,- Javah,- JDBCTask,- JDependTask,- JJDoc,- JJTree,- Jmod,- JUnitLauncherTask,- JUnitTask,- KeySubst,- Length,- Link,- LoadProperties,- LoadResource,- Local,- MacroInstance,- MakeUrl,- ManifestClassPath,- ManifestTask,- MatchingTask,- Mkdir,- MSVSS,- Nice,- Pack,- Parallel,- Patch,- PathConvert,- ProjectHelperTask,- Property,- PropertyFile,- PropertyHelperTask,- Pvcs,- Recorder,- Rename,- ReplaceRegExp,- ResourceCount,- Retry,- RExecTask,- Rpm,- Script,- ScriptDefBase,- Sequential,- ServerDeploy,- SetPermissions,- SetProxy,- Sleep,- SOS,- SoundTask,- SplashTask,- SSHBase,- SubAnt,- Sync,- TaskAdapter,- TelnetTask,- TempFile,- Touch,- Truncate,- Tstamp,- UnknownElement,- Unpack,- UpToDate,- WhichResource,- XmlProperty,- XMLResultAggregator,- XMLValidateTask
 
 public abstract class Task extends ProjectComponent 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(java.lang.String)
 
- 
- 
Field SummaryFields Modifier and Type Field Description protected TargettargetDeprecated.since 1.6.x.protected java.lang.StringtaskNameDeprecated.since 1.6.x.protected java.lang.StringtaskTypeDeprecated.since 1.6.x.protected RuntimeConfigurablewrapperDeprecated.since 1.6.x.- 
Fields inherited from class org.apache.tools.ant.ProjectComponentdescription, location, project
 
- 
 - 
Constructor SummaryConstructors Constructor Description Task()
 - 
Method SummaryModifier and Type Method Description voidbindToOwner(Task owner)Bind a task to another; use this when configuring a newly created task to do work on behalf of another.voidexecute()Called by the project to let the task do its work.TargetgetOwningTarget()Returns the container target of this task.RuntimeConfigurablegetRuntimeConfigurableWrapper()Returns the wrapper used for runtime configuration.java.lang.StringgetTaskName()Returns the name to use in logging messages.java.lang.StringgetTaskType()Return the type of task.protected RuntimeConfigurablegetWrapper()Return the runtime configurable structure for this task.protected voidhandleErrorFlush(java.lang.String output)Handles an error line by logging it with the WARN priority.protected voidhandleErrorOutput(java.lang.String output)Handles an error output by logging it with the WARN priority.protected voidhandleFlush(java.lang.String output)Handles output by logging it with the INFO priority.protected inthandleInput(byte[] buffer, int offset, int length)Handle an input request by this task.protected voidhandleOutput(java.lang.String output)Handles output by logging it with the INFO priority.voidinit()Called by the project to let the task initialize properly.protected booleanisInvalid()Has this task been marked invalid?voidlog(java.lang.String msg)Logs a message with the default (INFO) priority.voidlog(java.lang.String msg, int msgLevel)Logs a message with the given priority.voidlog(java.lang.String msg, java.lang.Throwable t, int msgLevel)Logs a message with the given priority.voidlog(java.lang.Throwable t, int msgLevel)Logs a message with the given priority.voidmaybeConfigure()Configures this task - if it hasn't been done already.voidperform()Performs this task if it's still valid, or gets a replacement version and performs that otherwise.voidreconfigure()Force the task to be reconfigured from its RuntimeConfigurable.voidsetOwningTarget(Target target)Sets the target container of this task.voidsetRuntimeConfigurableWrapper(RuntimeConfigurable wrapper)Sets the wrapper to be used for runtime configuration.voidsetTaskName(java.lang.String name)Sets the name to use in logging messages.voidsetTaskType(java.lang.String type)Sets the name with which the task has been invoked.- 
Methods inherited from class org.apache.tools.ant.ProjectComponentclone, getDescription, getLocation, getProject, setDescription, setLocation, setProject
 
- 
 
- 
- 
- 
Field Detail- 
target@Deprecated protected Target target Deprecated.since 1.6.x. You should not be accessing this variable directly. Please use thegetOwningTarget()method.Target this task belongs to, if any.
 - 
taskName@Deprecated protected java.lang.String taskName Deprecated.since 1.6.x. You should not be accessing this variable directly. Please use thegetTaskName()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.
 - 
taskType@Deprecated protected java.lang.String taskType Deprecated.since 1.6.x. You should not be accessing this variable directly. Please use thegetTaskType()method.Type of this task.
 - 
wrapper@Deprecated protected RuntimeConfigurable wrapper Deprecated.since 1.6.x. You should not be accessing this variable directly. Please use thegetWrapper()method.Wrapper for this object, used to configure it at runtime.
 
- 
 - 
Method Detail- 
setOwningTargetpublic void setOwningTarget(Target target) Sets the target container of this task.- Parameters:
- target- Target in whose scope this task belongs. May be- null, indicating a top-level task.
 
 - 
getOwningTargetpublic Target getOwningTarget() Returns the container target of this task.- Returns:
- The target containing this task, or nullif this task is a top-level task.
 
 - 
setTaskNamepublic void setTaskName(java.lang.String name) Sets the name to use in logging messages.- Parameters:
- name- The name to use in logging messages. Should not be- null.
 
 - 
getTaskNamepublic java.lang.String getTaskName() Returns the name to use in logging messages.- Returns:
- the name to use in logging messages.
 
 - 
setTaskTypepublic void setTaskType(java.lang.String type) Sets the name with which the task has been invoked.- Parameters:
- type- The name the task has been invoked as. Should not be- null.
 
 - 
initpublic void init() throws BuildExceptionCalled by the project to let the task initialize properly. The default implementation is a no-op.- Throws:
- BuildException- if something goes wrong with the build
 
 - 
executepublic void execute() throws BuildExceptionCalled 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.- Throws:
- BuildException- if something goes wrong with the build.
 
 - 
getRuntimeConfigurableWrapperpublic RuntimeConfigurable getRuntimeConfigurableWrapper() Returns the wrapper used for runtime configuration.- Returns:
- the wrapper used for runtime configuration. This method will generate a new wrapper (and cache it) if one isn't set already.
 
 - 
setRuntimeConfigurableWrapperpublic 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- The wrapper to be used for runtime configuration. May be- null, in which case the next call to getRuntimeConfigurableWrapper will generate a new wrapper.
 
 - 
maybeConfigurepublic void maybeConfigure() throws BuildExceptionConfigures 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.- Throws:
- BuildException- if the task cannot be configured.
 
 - 
reconfigurepublic void reconfigure() Force the task to be reconfigured from its RuntimeConfigurable.
 - 
handleOutputprotected void handleOutput(java.lang.String output) Handles output by logging it with the INFO priority.- Parameters:
- output- The output to log. Should not be- null.
 
 - 
handleFlushprotected void handleFlush(java.lang.String output) Handles output by logging it with the INFO priority.- Parameters:
- output- The output to log. Should not be- null.
- Since:
- Ant 1.5.2
 
 - 
handleInputprotected int handleInput(byte[] buffer, int offset, int length) throws java.io.IOExceptionHandle an input request by this task.- Parameters:
- 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.
- Returns:
- the number of bytes read.
- Throws:
- java.io.IOException- if the data cannot be read.
- Since:
- Ant 1.6
 
 - 
handleErrorOutputprotected void handleErrorOutput(java.lang.String output) Handles an error output by logging it with the WARN priority.- Parameters:
- output- The error output to log. Should not be- null.
 
 - 
handleErrorFlushprotected void handleErrorFlush(java.lang.String output) Handles an error line by logging it with the WARN priority.- Parameters:
- output- The error output to log. Should not be- null.
- Since:
- Ant 1.5.2
 
 - 
logpublic void log(java.lang.String msg) Logs a message with the default (INFO) priority.- Overrides:
- login class- ProjectComponent
- Parameters:
- msg- The message to be logged. Should not be- null.
 
 - 
logpublic void log(java.lang.String msg, int msgLevel)Logs a message with the given priority. This delegates the actual logging to the project.- Overrides:
- login class- ProjectComponent
- Parameters:
- msg- The message to be logged. Should not be- null.
- msgLevel- The message priority at which this message is to be logged.
 
 - 
logpublic void log(java.lang.Throwable t, int msgLevel)Logs a message with the given priority. This delegates the actual logging to the project.- Parameters:
- t- The exception to be logged. Should not be- null.
- msgLevel- The message priority at which this message is to be logged.
- Since:
- 1.7
 
 - 
logpublic void log(java.lang.String msg, java.lang.Throwable t, int msgLevel)Logs a message with the given priority. This delegates the actual logging to the project.- Parameters:
- 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.
- Since:
- 1.7
 
 - 
performpublic 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.
 - 
isInvalidprotected final boolean isInvalid() Has this task been marked invalid?- Returns:
- true if this task is no longer valid. A new task should be configured in this case.
- Since:
- Ant 1.5
 
 - 
getTaskTypepublic java.lang.String getTaskType() Return the type of task.- Returns:
- the type of task.
 
 - 
getWrapperprotected RuntimeConfigurable getWrapper() Return the runtime configurable structure for this task.- Returns:
- the runtime structure for this task.
 
 - 
bindToOwnerpublic 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 callinit(). If you are creating a task to delegate work to, callinit()to initialize it.- Parameters:
- owner- owning target
- Since:
- Ant1.7
 
 
- 
 
-