com.lutris.ant.taskdefs
Class ForEach

java.lang.Object
  |
  +--org.apache.tools.ant.ProjectComponent
        |
        +--org.apache.tools.ant.Task
              |
              +--com.lutris.ant.taskdefs.ForEach

public class ForEach
extends org.apache.tools.ant.Task

Simulate a looping control structure.
Iterate through a list of values specified directly, in a nested , or as lines of another file.
Typically made visible to an Ant build file with the following declaration:

 <taskdef name="foreach" classname="com.lutris.ant.taskdefs.ForEach"/>
Parameters

values - The list of values to process, with the separator character, indicated by the separator attribute, separating each value. Required = No
valuesfile - A file containing a list of values to process, one iteration per line. Required = No
target - The target to call for each token, passing the token as the parameter with the name indicated by the param attribute. Required = Yes
param - The name of the parameter to pass the tokens in as to the target. Required = No
separator - The string that separates the values in the values attribute. Required = No

<= Exactly one of the values attribute, valuesfile attribute, or nested element is permitted.

Syntax of the valuesfile
The valuesfile contains a series of values:
value1
value2
value3
or else a series of property=value definitions:
property="value1" property2="value2"
property="value3"
The set of all properties on a given line are set for one iteration, one invocation of the specified target.
If a value exists on a line in the valuesfile without a property name, it assigns the value to the property named by the param attribute, and if no param attribute exists, this is an error. It is also an error to list multiple unnamed values on a single line.
Comments are recognized in hash, slash-slash, and slash-star forms, for examples:
property="value" # comment
property="value" // comment
property="value" / comment /
XML-style comments are not permitted.
Newline or semicolon separates sets of properties, for example:

property="value1"; property="value2"
property="value3"
Example:
In file build.xml:
 <target name="describeOneFruit">
  <echo>${greeting}  Fruit is ${fruit}, fruit type is ${fruitType} </echo>
 </target>
 <target name="listFruits">
  <property name="fruitType" value="pome" />
  <property name="greeting" value="Hello!" />
  <foreach valuesfile="itemList.txt" param="fruit" target="describeOneFruit" />
 </target>
In file itemList.txt:
Apple
fruit="Apricot" fruitType="stone"
Orange
fruit="Peach" fruitType="stone" greeting="My favorite!"
Pear


Field Summary
protected  java.util.Vector filesets
           
protected  java.lang.String param
           
protected  java.lang.String separator
           
protected  java.lang.String target
           
protected  java.lang.String values
           
protected  java.io.File valuesFile
           
 
Fields inherited from class org.apache.tools.ant.Task
description, location, taskName, taskType, wrapper
 
Fields inherited from class org.apache.tools.ant.ProjectComponent
project
 
Constructor Summary
ForEach()
          Default Constructor.
 
Method Summary
 void addFileSet(org.apache.tools.ant.types.FileSet set)
          Adds a set of files (nested fileset attribute).
 void execute()
          Execute the logic for this task, once all attributes have been assembled.
 void setParam(java.lang.String param)
          The name of the parameter used as a scope-limited property, assigned the loop-variant values in the list.
 void setSeparator(java.lang.String separator)
          This attribute defines the character that separates tokens in the values string.
 void setTarget(java.lang.String target)
          This attribute names an Ant target in the current file to call for each iteration through the loop.
 void setValues(java.lang.String values)
          An attribute which is a list of values.
 void setValuesfile(java.lang.String fileName)
          The valuesfile attribute of the foreach task should be a string that is an absolute or relative path to a file, which contains loop-variant property values
 
Methods inherited from class org.apache.tools.ant.Task
getDescription, getLocation, getOwningTarget, getRuntimeConfigurableWrapper, getTaskName, handleErrorOutput, handleOutput, init, isInvalid, log, log, markInvalid, maybeConfigure, perform, setDescription, setLocation, setOwningTarget, setRuntimeConfigurableWrapper, setTaskName, setTaskType
 
Methods inherited from class org.apache.tools.ant.ProjectComponent
getProject, setProject
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

values

protected java.lang.String values

valuesFile

protected java.io.File valuesFile

param

protected java.lang.String param

separator

protected java.lang.String separator

target

protected java.lang.String target

filesets

protected java.util.Vector filesets
Constructor Detail

ForEach

public ForEach()
Default Constructor.
Method Detail

addFileSet

public void addFileSet(org.apache.tools.ant.types.FileSet set)
Adds a set of files (nested fileset attribute).
Parameters:
set -  

execute

public void execute()
             throws org.apache.tools.ant.BuildException
Execute the logic for this task, once all attributes have been assembled. Loops through values in the list, sets limited-scope properties, and executes the specified target.
Overrides:
execute in class org.apache.tools.ant.Task
Throws:
org.apache.tools.ant.BuildException -  

setParam

public void setParam(java.lang.String param)
The name of the parameter used as a scope-limited property, assigned the loop-variant values in the list.
Parameters:
param - - The name of the parameter to pass the tokens in as to the target

setSeparator

public void setSeparator(java.lang.String separator)
This attribute defines the character that separates tokens in the values string.
Parameters:
separator - - The string that separates the values in the values attribute

setTarget

public void setTarget(java.lang.String target)
This attribute names an Ant target in the current file to call for each iteration through the loop.
Parameters:
target -  

setValues

public void setValues(java.lang.String values)
An attribute which is a list of values.
Parameters:
values - - The list of values to process, with the separator character, indicated by the separator attribute, separating each value

setValuesfile

public void setValuesfile(java.lang.String fileName)
The valuesfile attribute of the foreach task should be a string that is an absolute or relative path to a file, which contains loop-variant property values
Parameters:
fileName - - A file containing a list of values to process, one iteration per line