Extending the Task Class

Usually, you extend an Ant task class like org.apache.tools.ant.Task when you write custom tasks. Ant comes with a selection of task classes meant to be extended:

AbstractCvsTask

Abstract CVS task class

JDBCTask

Handles JDBC configuration needed by SQL type tasks

MatchingTask

Abstract task that should be extended by tasks required to include or exclude files based on pattern matching

Pack

Abstract base class for pack tasks

Task

Generic task and the one most commonly extended

Unpack

Abstract base class for unpacking tasks

The Task class (i.e., org.apache.tools.ant.Task) is used for most of this chapter, though some samples will use MatchingTask. The methods of the Task class appear in Table 12-2.

Table 12-2. The Task class's methods

Method

Does this

void execute( )

Specifies the task should execute.

java.lang.String getDescription( )

Returns the task's description.

Location getLocation( )

Returns the file and location at which the task is supported.

Target getOwningTarget( )

Returns the target that contains this task.

RuntimeConfigurable getRuntimeConfigurableWrapper( )

Returns the wrapper class instance the task uses for runtime configuration.

java.lang.String getTaskName( )

Returns the task name (used when when logging messages from the task).

java.lang.String getTaskType( )

Returns the type of task as a string.

protected RuntimeConfigurable getWrapper( )

Returns the runtime configurable structure for this task as a RuntimeConfigurable object.

protected void handleErrorFlush(java.lang.String ...

Get Ant: The Definitive Guide, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.