The for task iterates over a list, a list of paths, or both. If both, list and paths, are specified, the list will be evaluated first. Nested paths are evaluated in the order they appear in the task.
This task is the same as the <foreach> task, except that it uses a nested sequential for each iteration. It makes use of ant's macrodef task, so the @{} notation is used for parameter substition.
This task only works for ant version greater than or equal to ant 1.6beta3.
Attribute | Description | Required |
---|---|---|
list | The list of values to process, with the delimiter character, indicated by the "delimiter" attribute, separating each value. | Yes, unless a nested path has been specified. |
param | Name of the parameter to pass the tokens or files in as to the sequential. | Yes |
delimiter | The delimiter string that separates the values in the "list" attribute. | No, defaults to ",". |
trim | If true , any leading or trailing
whitespace will be removed from the list item before it is passed
to the sequential.
|
No. Defaults to false. |
Paths are used to select sets of files or directories to iterate over.
Using a path allows you to determine the order by which files
are considered by using
filelists
or explicit pathelements
. You also can specify
whether you want to iterate over files or directories by chosing
either filesets or
dirsets.
To print out the first five letters of the latin alphabet:
<echo message="The first five letters of the alphabet are:"/> <for list="a,b,c,d,e" param="letter"> <sequential> <echo>Letter @{letter}</echo> </sequential> </for>
A more complicated example to to iterate over a set of c++ source files and invoke the cc task on them:
<for param="file"> <path> <fileset dir="${test.dir}/mains" includes="*.cpp"/> </path> <sequential> <propertyregex override="yes" property="program" input="@{file}" regexp=".*/([^\.]*)\.cpp" replace="\1"/> <mkdir dir="${obj.dir}/${program}"/> <mkdir dir="${build.bin.dir}"/> <cc link="executable" objdir="${obj.dir}/${program}" outfile="${build.bin.dir}/${program}"> <compiler refid="compiler.options"/> <fileset file="@{file}"/> <linker refid="linker-libs"/> </cc> </sequential> </for>
Copyright © 2003 Ant-Contrib Project. All rights Reserved.