Class RefTask
java.lang.Object
org.apache.tools.ant.ProjectComponent
org.apache.tools.ant.Task
org.apache.maven.resolver.internal.ant.tasks.RefTask
- All Implemented Interfaces:
Cloneable
public abstract class RefTask
extends org.apache.tools.ant.Task
An abstract base class for Ant tasks that support referencing another task instance via
refid.
This allows build scripts to reuse task definitions by referencing a previously defined instance.
Subclasses that extend RefTask gain support for reference checking, attribute and child validation,
and safe type casting of the referenced object.
Tasks inheriting from RefTask should use checkAttributesAllowed() and checkChildrenAllowed()
to enforce correct usage when a reference is set.
-
Field Summary
Fields inherited from class org.apache.tools.ant.Task
target, taskName, taskType, wrapperFields inherited from class org.apache.tools.ant.ProjectComponent
description, location, project -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidVerifies that attributes may still be set on this task.protected voidVerifies that nested child elements may be added to this task.protected ObjectResolves the reference set on this task and verifies it is of the same type as this class.protected ObjectgetCheckedRef(Class<?> requiredClass, String dataTypeName, org.apache.tools.ant.Project project) Resolves and validates the reference set on this task.protected StringReturns the Ant data type or task name associated with this task.booleanChecks whether this task is configured as a reference to another task.protected org.apache.tools.ant.BuildExceptionConstructs aBuildExceptionto indicate that nested elements are not allowed whenrefidis used.voidsetRefid(org.apache.tools.ant.types.Reference ref) Sets a reference to another task instance defined elsewhere in the build file.protected org.apache.tools.ant.BuildExceptionConstructs aBuildExceptionto indicate that additional attributes are not allowed whenrefidis used.Methods inherited from class org.apache.tools.ant.Task
bindToOwner, execute, getOwningTarget, getRuntimeConfigurableWrapper, getTaskName, getTaskType, getWrapper, handleErrorFlush, handleErrorOutput, handleFlush, handleInput, handleOutput, init, isInvalid, log, log, log, log, maybeConfigure, perform, reconfigure, setOwningTarget, setRuntimeConfigurableWrapper, setTaskName, setTaskTypeMethods inherited from class org.apache.tools.ant.ProjectComponent
clone, getDescription, getLocation, getProject, setDescription, setLocation, setProject
-
Constructor Details
-
RefTask
public RefTask()Default constructor forRefTask.
-
-
Method Details
-
isReference
public boolean isReference()Checks whether this task is configured as a reference to another task.- Returns:
trueif arefidwas set,falseotherwise
-
setRefid
public void setRefid(org.apache.tools.ant.types.Reference ref) Sets a reference to another task instance defined elsewhere in the build file.Once set, no other attributes or nested elements should be specified on this task.
- Parameters:
ref- the reference to another task
-
checkAttributesAllowed
protected void checkAttributesAllowed()Verifies that attributes may still be set on this task.If this task is configured as a reference, this method throws an exception.
- Throws:
org.apache.tools.ant.BuildException- ifrefidis set
-
checkChildrenAllowed
protected void checkChildrenAllowed()Verifies that nested child elements may be added to this task.If this task is configured as a reference, this method throws an exception.
- Throws:
org.apache.tools.ant.BuildException- ifrefidis set
-
tooManyAttributes
protected org.apache.tools.ant.BuildException tooManyAttributes()Constructs aBuildExceptionto indicate that additional attributes are not allowed whenrefidis used.- Returns:
- the build exception
-
noChildrenAllowed
protected org.apache.tools.ant.BuildException noChildrenAllowed()Constructs aBuildExceptionto indicate that nested elements are not allowed whenrefidis used.- Returns:
- the build exception
-
getDataTypeName
Returns the Ant data type or task name associated with this task. This is primarily used for error reporting and validation messages.- Returns:
- the element name of this task
-
getCheckedRef
Resolves the reference set on this task and verifies it is of the same type as this class.- Returns:
- the referenced object
- Throws:
org.apache.tools.ant.BuildException- if the reference is not set or is of an unexpected type
-
getCheckedRef
protected Object getCheckedRef(Class<?> requiredClass, String dataTypeName, org.apache.tools.ant.Project project) Resolves and validates the reference set on this task. Ensures the referenced object is assignable to the specified class.- Parameters:
requiredClass- the expected class of the referenced objectdataTypeName- the Ant data type name used for error messagesproject- the current Ant project- Returns:
- the referenced object
- Throws:
org.apache.tools.ant.BuildException- if the reference is missing, the project isnull, or the referenced object is of an incompatible type
-