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
Direct Known Subclasses:
Artifact, Pom

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, wrapper

    Fields inherited from class org.apache.tools.ant.ProjectComponent

    description, location, project
  • Constructor Summary

    Constructors
    Constructor
    Description
    Default constructor for RefTask.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected void
    Verifies that attributes may still be set on this task.
    protected void
    Verifies that nested child elements may be added to this task.
    protected Object
    Resolves the reference set on this task and verifies it is of the same type as this class.
    protected Object
    getCheckedRef(Class<?> requiredClass, String dataTypeName, org.apache.tools.ant.Project project)
    Resolves and validates the reference set on this task.
    protected String
    Returns the Ant data type or task name associated with this task.
    boolean
    Checks whether this task is configured as a reference to another task.
    protected org.apache.tools.ant.BuildException
    Constructs a BuildException to indicate that nested elements are not allowed when refid is used.
    void
    setRefid(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.BuildException
    Constructs a BuildException to indicate that additional attributes are not allowed when refid is 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, setTaskType

    Methods inherited from class org.apache.tools.ant.ProjectComponent

    clone, getDescription, getLocation, getProject, setDescription, setLocation, setProject

    Methods inherited from class java.lang.Object

    equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • RefTask

      public RefTask()
      Default constructor for RefTask.
  • Method Details

    • isReference

      public boolean isReference()
      Checks whether this task is configured as a reference to another task.
      Returns:
      true if a refid was set, false otherwise
    • 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 - if refid is 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 - if refid is set
    • tooManyAttributes

      protected org.apache.tools.ant.BuildException tooManyAttributes()
      Constructs a BuildException to indicate that additional attributes are not allowed when refid is used.
      Returns:
      the build exception
    • noChildrenAllowed

      protected org.apache.tools.ant.BuildException noChildrenAllowed()
      Constructs a BuildException to indicate that nested elements are not allowed when refid is used.
      Returns:
      the build exception
    • getDataTypeName

      protected String 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

      protected Object 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 object
      dataTypeName - the Ant data type name used for error messages
      project - the current Ant project
      Returns:
      the referenced object
      Throws:
      org.apache.tools.ant.BuildException - if the reference is missing, the project is null, or the referenced object is of an incompatible type