Package groovy.ant

# Class AntBuilder

java.lang.Object
groovy.lang.GroovyObjectSupport
groovy.util.BuilderSupport
groovy.ant.AntBuilder

All Implemented Interfaces:
  `GroovyObject`

public class AntBuilder extends BuilderSupport
Allows Ant tasks to be used with a Groovy builder-style markup. Requires that `ant.jar` is on your classpath which will happen automatically if you are using the Groovy distribution but will be up to you to organize if you are embedding Groovy. If you wish to use the optional tasks you will need to add one or more additional jars from the ant distribution to your classpath - see the library dependencies for more details.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `AntBuilder()`
  Creates an `AntBuilder` backed by a freshly initialized Ant project.
  `AntBuilder(org.apache.tools.ant.Project project)`
  Creates an `AntBuilder` backed by the supplied project.
  `AntBuilder(org.apache.tools.ant.Project project, org.apache.tools.ant.Target owningTarget)`
  Creates an `AntBuilder` backed by the supplied project and owning target.
  `AntBuilder(org.apache.tools.ant.Task parentTask)`
  Creates an `AntBuilder` that shares the context of the supplied parent task.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `protected static Attributes`
  `buildAttributes(Map attributes)`
  Builds an `Attributes` from a `Map`
  `protected Object`
  `createNode(Object tagName)`
  Creates a node with no attributes or body text.
  `protected Object`
  `createNode(Object name, Object value)`
  Creates a node and applies inline text to it.
  `protected Object`
  `createNode(Object name, Map attributes)`
  Creates a node from the supplied name and attributes.
  `protected Object`
  `createNode(Object name, Map attributes, Object value)`
  Creates a node, applies attributes, and then applies inline text to it.
  `protected static org.apache.tools.ant.Project`
  `createProject()`
  `protected Object`
  `doInvokeMethod(String methodName, Object name, Object args)`
  We don't want to return the node as created in `createNode(Object, Map, Object)` but the one made ready by `nodeCompleted(Object, Object)`
  `org.apache.tools.ant.Project`
  `getAntProject()`
  Returns the underlying Ant project instance.
  `org.apache.tools.ant.helper.AntXMLContext`
  `getAntXmlContext()`
  Gets the xml context of Ant used while creating tasks
  `org.apache.tools.ant.Project`
  `getProject()`
  # Gets the Ant project in which the tasks are executed
  `boolean`
  `isSaveStreams()`
  Whether stdin, stdout, stderr streams are saved.
  `protected void`
  `nodeCompleted(Object parent, Object node)`
  Determines, when the ANT Task that is represented by the "node" should perform.
  `protected void`
  `setParent(Object parent, Object child)`
  Ant child nodes are attached by Ant's own configuration machinery, so this hook is intentionally a no-op.
  `void`
  `setSaveStreams(boolean saveStreams)`
  Indicates that we save stdin, stdout, stderr and replace them while AntBuilder is executing tasks with streams that funnel the normal streams into Ant's logs.
  `protected void`
  `setText(Object task, String text)`
  Applies nested text content to the current Ant task.

  ### Methods inherited from class groovy.util.BuilderSupport

  `getCurrent, getName, invokeMethod, invokeMethod, postNodeCompletion, setClosureDelegate, setCurrent`

  ### Methods inherited from class groovy.lang.GroovyObjectSupport

  `getMetaClass, setMetaClass`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

  ### Methods inherited from interface groovy.lang.GroovyObject

  `getProperty, setProperty`

- ## Constructor Details

  - ### AntBuilder

    public AntBuilder()
    Creates an `AntBuilder` backed by a freshly initialized Ant project.

  - ### AntBuilder

    public AntBuilder(org.apache.tools.ant.Project project)
    Creates an `AntBuilder` backed by the supplied project.
    Parameters:
      `project` - the project used to create and execute Ant tasks

  - ### AntBuilder

    public AntBuilder(org.apache.tools.ant.Project project, org.apache.tools.ant.Target owningTarget)
    Creates an `AntBuilder` backed by the supplied project and owning target.
    Parameters:
      `project` - the project used to create and execute Ant tasks
      `owningTarget` - the target that should collect top-level tasks

  - ### AntBuilder

    public AntBuilder(org.apache.tools.ant.Task parentTask)
    Creates an `AntBuilder` that shares the context of the supplied parent task.
    Parameters:
      `parentTask` - the Ant task whose project and owning target should be reused

- ## Method Details

  - ### getProject

    public org.apache.tools.ant.Project getProject()
    # Gets the Ant project in which the tasks are executed
    Returns:
      the project

  - ### getAntXmlContext

    public org.apache.tools.ant.helper.AntXMLContext getAntXmlContext()
    Gets the xml context of Ant used while creating tasks
    Returns:
      the Ant xml context

  - ### isSaveStreams

    public boolean isSaveStreams()
    Whether stdin, stdout, stderr streams are saved.
    Returns:
      true if we are saving streams
    See Also:
      - `setSaveStreams(boolean)`

  - ### setSaveStreams

    public void setSaveStreams(boolean saveStreams)
    Indicates that we save stdin, stdout, stderr and replace them while AntBuilder is executing tasks with streams that funnel the normal streams into Ant's logs.
    Parameters:
      `saveStreams` - set to false to disable this behavior

  - ### createProject

    protected static org.apache.tools.ant.Project createProject()
    Returns:
      Factory method to create new Project instances

  - ### setParent

    protected void setParent(Object parent, Object child)
    Ant child nodes are attached by Ant's own configuration machinery, so this hook is intentionally a no-op.
    Specified by:
      `setParent` in class `BuilderSupport`
    Parameters:
      `parent` - the logical parent node
      `child` - the logical child node

  - ### doInvokeMethod

    protected Object doInvokeMethod(String methodName, Object name, Object args)
    We don't want to return the node as created in `createNode(Object, Map, Object)` but the one made ready by `nodeCompleted(Object, Object)`
    Overrides:
      `doInvokeMethod` in class `BuilderSupport`
    Parameters:
      `methodName` - the original method name
      `name` - the mapped node name
      `args` - the invocation arguments
    Returns:
      the created node, or a replacement from `BuilderSupport.postNodeCompletion(Object, Object)`
    See Also:
      - `BuilderSupport.doInvokeMethod(java.lang.String, java.lang.Object, java.lang.Object)`

  - ### nodeCompleted

    protected void nodeCompleted(Object parent, Object node)
    Determines, when the ANT Task that is represented by the "node" should perform. Node must be an ANT Task or no "perform" is called. If node is an ANT Task, it performs right after complete construction. If node is nested in a TaskContainer, calling "perform" is delegated to that TaskContainer.
    Overrides:
      `nodeCompleted` in class `BuilderSupport`
    Parameters:
      `parent` - note: null when node is root
      `node` - the node that now has all its children applied

  - ### createNode

    protected Object createNode(Object tagName)
    Creates a node with no attributes or body text.
    Specified by:
      `createNode` in class `BuilderSupport`
    Parameters:
      `tagName` - the requested node name
    Returns:
      the created Ant proxy

  - ### createNode

    protected Object createNode(Object name, Object value)
    Creates a node and applies inline text to it.
    Specified by:
      `createNode` in class `BuilderSupport`
    Parameters:
      `name` - the requested node name
      `value` - the inline text value
    Returns:
      the created Ant proxy

  - ### createNode

    protected Object createNode(Object name, Map attributes, Object value)
    Creates a node, applies attributes, and then applies inline text to it.
    Specified by:
      `createNode` in class `BuilderSupport`
    Parameters:
      `name` - the requested node name
      `attributes` - the node attributes
      `value` - the inline text value
    Returns:
      the created Ant proxy

  - ### buildAttributes

    protected static Attributes buildAttributes(Map attributes)
    Builds an `Attributes` from a `Map`
    Parameters:
      `attributes` - the attributes to wrap
    Returns:
      the wrapped attributes

  - ### createNode

    protected Object createNode(Object name, Map attributes)
    Creates a node from the supplied name and attributes.
    Specified by:
      `createNode` in class `BuilderSupport`
    Parameters:
      `name` - the requested node name
      `attributes` - the attributes to apply
    Returns:
      the created Ant proxy or target

  - ### setText

    protected void setText(Object task, String text)
    Applies nested text content to the current Ant task.
    Parameters:
      `task` - the current Ant task proxy
      `text` - the text content to apply

  - ### getAntProject

    public org.apache.tools.ant.Project getAntProject()
    Returns the underlying Ant project instance.
    Returns:
      the project backing this builder