Apply-macro Task Reference

From ControlTier

(Redirected from ApplyMacro Task Reference)
Jump to: navigation, search

Contents

Description

apply-macro iterates over the results of an input generator and calls the named macro with selected paramaters.

Input generators are specified as nested elements, you must specify exactly one. Input generators can be listed here: Category:ApplyMacro Ant Type.

Parameters

AttributeDescriptionRequired
macroThe defined macro to callNo if an inline sequential is used
threadcountMaximum number of threads to useNo. Defaults to 1

Parameters specified as nested elements

errorhandler

If ane error occurs during the course of the apply-macro execution, an errorhandler can be configured to handle the exception.

input generator

The apply-macro task also requires a input generator.

sequential

The apply-macro task also can accept a sequential element in lieu of an externally defined macro. This is the list of Ant tasks to be run for each iteration of apply-macro.

Examples

This example iterates against a nested propertiesquery and executes a defined macro with desired parameters and sort order:

<property name="var.download.dir" value="/var/tmp">
<property name="package.war.headlines-20060910.war.package-install-rank" 
    value="3"/>
<property name="package.jar.hncore-20060910.jar.package-install-rank" 
           value="2"/>
<property name="package.zip.jakarta-tomcat-4.1.31.zip.package-install-rank" 
           value="1"/>
 
<macrodef name="getPackage">
   <attribute name="pkgtype"/>
   <attribute name="filename"/>
   <sequential>
      <echo>downloading package file @{filename}</echo>
      <get src="http://repo:8080/webdav/pkgs/@{pkgtype}s/@{filename}"
               dest="${var.download.dir}/@{filename}"/>
   </sequential>
</macrodef>
 
 
<apply-macro macro="getPackage">
    <errorhandler>
      <fail/>
    </errorhandler>
    <propertiesquery id="packages-query"
                select="pkgtype,filename"
                from="package\.([^\.]*)\.(.*)\.package-install-rank">
         <sortby>
           <select name="pkgtype" by="name" order="ascending"/>
         </sortby>
     </propertiesquery>
</apply-macro>

You can specify the block of code to execute inline via a sequential element. Here's the above example with the body of the "getPackage" macrodef inside the sequential:

<apply-macro>
    <errorhandler>
      <fail/>
    </errorhandler>
    <propertiesquery id="packages-query"
                select="pkgtype,filename"
                from="package\.([^\.]*)\.(.*)\.package-install-rank">
         <sortby>
           <select name="pkgtype" by="name" order="ascending"/>
         </sortby>
    </propertiesquery>
    <sequential>
      <echo>downloading package file @{filename}</echo>
      <get src="http://repo:8080/webdav/pkgs/@{pkgtype}s/@{filename}"
               dest="${var.download.dir}/@{filename}"/>
   </sequential>
</apply-macro>

You can see that the same expansion tokens used in the getPackage macrodef (pkgtype and filename) can be referenced inside the sequential element. The values of those tokens get substituted during execution.

This example iterates against a queryresults and executes a defined macro with desired parameters and sort order:

 <macrodef name="processDeployment">
   <attribute name="dType"/>
   <attribute name="dName"/>
   <sequential>
      <echo>deployment type: @{dType}, deployment name: @{dName}/echo>
   </sequential>
</macrodef >
 
<propertiesquery-task id="deployments.query"
                         select="dType,dName"
                         from="deployment.([^\.]*).([^\.]*).startup-rank">
   <sortby>
      <select by="value" order="ascending"/>
   </sortby>
</propertiesquery-task>
 
 
<apply-macro macro="showDeploymentsByNode">
   <queryresults refid="deployments.query"/>
</apply-macro>
Personal tools
Namespaces
Variants
Actions
Navigation
Communication
Development
Toolbox
Print/export