Debian Codegraph @

docs/manual/tasks/for.html

raw symbols SCIP
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2 <html>
3 <head>
4 <title>Ant-contrib Tasks: For</title>
5 </head>
6
7 <body>
8 <h1>For</h1>
9
10 <p>The for task iterates over a list, a list of paths, or
11 any type that has a public iterator() method.
12 The list will be evaluated first.
13 Nested paths are evaluated in the order they
14 appear in the task.
15 Nested types will then be evalulated.
16 </p>
17 <p>
18 This task is the same as the &lt;foreach&gt; task, except that
19 <ul>
20 <li>it uses a nested sequential for each iteration; and
21 <li>it implements an additional &quot;keepgoing&quot; attribute.
22 </ul>
23 &lt;for&gt; makes use of ant's macrodef task, so the @{} notation
24 is used for parameter substition.
25 </p>
26 <p><em>
27 This task only works for ant version greater than or equal
28 to ant 1.6.0.
29 </em>
30 </p>
31
32 <h2>Parameters</h2>
33 <table border="1" cellpadding="2" cellspacing="0">
34 <tr>
35 <th>Attribute</th>
36 <th>Description</th>
37 <th>Required</th>
38 </tr>
39 <tr>
40 <td valign="top">list</td>
41 <td valign="top">The list of values to process, with the
42 delimiter character, indicated by the &quot;delimiter&quot;
43 attribute, separating each value.</td>
44 <td align="center" valign="top" rowspan="2">Yes, one of these need to
45 be set, unless a nested path
46 has been specified.</td>
47 </tr>
48 <tr>
49 <td valign="top">end</td>
50 <td valign="top">
51 Sets the ending index value. If this attribute is
52 set, the &lt;for&gt; task will loop from "start" (default 1)
53 to "end", using "step" (default 1) increments.
54 </td>
55 </tr>
56 <tr>
57 <td valign="top">param</td>
58 <td valign="top">Name of the parameter to pass the tokens or
59 files in as to the sequential.</td>
60 <td align="center" valign="top">Yes</td>
61 </tr>
62 <tr>
63 <td valign="top">delimiter</td>
64 <td valign="top">The delimiter characters that separates the
65 values in the &quot;list&quot; attribute. Each character in the
66 supplied string can act as a delimiter. This follows the semantics
67 of the StringTokenizer class.</td>
68 <td align="center" valign="top">No, defaults to &quot;,&quot;.</td>
69 </tr>
70 <tr>
71 <td valign="top">parallel</td>
72 <td valign="top">If <code>true</code>, all iterations of the nested
73 &lt;sequential&gt;
74 will execute in parallel. Defaults to <code>false</code>,
75 which forces sequential execution of the iterations. It is up to
76 the caller to ensure that parallel execution is safe.
77 <td align="center" valign="top">No</td>
78 </tr>
79 <tr>
80 <td valign="top">keepgoing</td>
81 <td valign="top">If <code>true</code>, all iterations of the called
82 &lt;sequential&gt; will be executed, even if a task in one or more of them fails.
83 Defaults
84 to <code>false</code>, which forces execution to stop as soon as a
85 task fails. At the end, if any iterator has failed, the &lt;for&gt;
86 task will fail, otherwise &lt;for&gt; will succeed.
87 <p>
88 Note that execution does not proceed keepgoing from one task
89 to the next within the &lt;sequential&gt, but rather from one iteration to the
90 next.
91 </p>
92 <p>It is up to the caller to ensure that keepgoing execution is safe.</p>
93 </td>
94 <td align="center" valign="top">No</td>
95 </tr>
96 <tr>
97 <td valign="top">threadCount</td>
98 <td valign="top">The maximum number of allowable threads when executing
99 in parallel.
100 <td align="center" valign="top">No. Defaults to 5.</td>
101 </tr>
102 <tr>
103 <td valign="top">trim</td>
104 <td valign="top">If <code>true</code>, any leading or trailing
105 whitespace will be removed from the list item before it is passed
106 to the sequential.
107 </td>
108 <td align="center" valign="top">No. Defaults to false.</td>
109 </tr>
110 <tr>
111 <td valign="top">begin</td>
112 <td valign="top">
113 Sets the starting index value. This in only used
114 if the "end" attribute is set.
115 </td>
116 <td align="center" valign="top">No. Defaults to "1".</td>
117 </tr>
118 <tr>
119 <td valign="top">step</td>
120 <td valign="top">
121 Sets the index increment step.
122 This in only used if the "end" attribute is set.
123 </td>
124 <td align="center" valign="top">No. Defaults to "1".</td>
125 </tr>
126 </table>
127
128 <h2>Parameters specified as nested elements</h2>
129
130 <a name="path"><h3>path</h3></a>
131
132 <p><a href="http://ant.apache.org/manual/using.html#path">Path</a>s
133 are used to select sets of files or directories to iterate over.</p>
134
135 <p>Using a path allows you to determine the order by which files
136 are considered by using
137 <a href="http://ant.apache.org/manual/CoreTypes/filelist.html">filelist</a>s
138 or explicit <code>pathelements</code>. You also can specify
139 whether you want to iterate over files or directories by chosing
140 either filesets or
141 <a href="http://ant.apache.org/manual/CoreTypes/dirset.html">dirset</a>s.</p>
142 <a name="fileset"><h3>fileset</h3></a>
143 <p><a href="http://ant.apache.org/manual/CoreTypes/fileset.html">FileSet</a>s
144 are used to select sets of files to iterate over.
145 </p>
146 <a name="fileset"><h3>dirset</h3></a>
147 <p><a href="http://ant.apache.org/manual/CoreTypes/dirset.html">DirSet</a>s
148 are used to select sets of directories to iterate over.
149 </p>
150
151 <a name="seqential"><h3>sequential</h3></a>
152 This is the list of tasks to be run for each iteration of
153 the list.
154 <h3>Example</h3>
155 <p>
156 To print out the first five letters of the latin alphabet:
157 </p>
158 <blockquote>
159 <pre>
160 &lt;echo message="The first five letters of the alphabet are:"/&gt;
161 &lt;for list="a,b,c,d,e" param="letter"&gt;
162 &lt;sequential&gt;
163 &lt;echo&gt;Letter @{letter}&lt;/echo&gt;
164 &lt;/sequential&gt;
165 &lt;/for&gt;
166 </pre>
167 </blockquote>
168 <p>
169 A more complicated example to to iterate over a set
170 of c++ source files and invoke the &lt;cc&gt; task on them:
171 </p>
172 <blockquote>
173 <pre>
174 &lt;for param="file"&gt;
175 &lt;path&gt;
176 &lt;fileset dir="${test.dir}/mains" includes="*.cpp"/&gt;
177 &lt;/path&gt;
178 &lt;sequential&gt;
179 &lt;propertyregex override="yes"
180 property="program" input="@{file}"
181 regexp=".*/([^\.]*)\.cpp" replace="\1"/&gt;
182 &lt;mkdir dir="${obj.dir}/${program}"/&gt;
183 &lt;mkdir dir="${build.bin.dir}"/&gt;
184 &lt;cc link="executable" objdir="${obj.dir}/${program}"
185 outfile="${build.bin.dir}/${program}"&gt;
186 &lt;compiler refid="compiler.options"/&gt;
187 &lt;fileset file="@{file}"/&gt;
188 &lt;linker refid="linker-libs"/&gt;
189 &lt;/cc&gt;
190 &lt;/sequential&gt;
191 &lt;/for&gt;
192 </pre>
193 </blockquote>
194 The preceding example will stop as soon as one of the &lt;cc&gt; tasks fails.
195 If you change the first line of the example to
196 <pre> &lt;for param="file" keepgoing="true"&gt;</pre>
197 All iterations will be executed, and then &lt;for&gt; will fail if any one
198 or more of the &lt;cc&gt; tasks failed.
199 <p>
200 The following example embeds an outofdate type and iterates over
201 the sources that are newer than their corresponding targets.
202 </p>
203
204 <pre>
205 &lt;ac:for param="xmlfile" xmlns:ac="antlib:net.sf.antcontrib"&gt;
206 &lt;ac:outofdate&gt;
207 &lt;ac:sourcefiles&gt;
208 &lt;ac:fileset dir="${basedir}/xdocs" includes="**/*.xml"/&gt;
209 &lt;/ac:sourcefiles&gt;
210 &lt;ac:mapper dir="${basedir}/xdocs"
211 type="glob" from="*.xml" to="${basedir}/docs/*.html"/&gt;
212 &lt;/ac:outofdate&gt;
213 &lt;ac:sequential&gt;
214 &lt;echo&gt;Need to generate a target html file from source file @{xmlfile}&lt;/echo&gt;
215 &lt;/ac:sequential&gt;
216 &lt;/ac:for&gt;
217 </pre>
218
219 <p>
220 The following example loops from one to ten.
221 </p>
222 <pre>
223 &lt;ac:for param="i" end="10"&gt;
224 &lt;sequential&gt;
225 &lt;echo&gt;i is @{i}&lt;/echo&gt;
226 &lt;/sequential&gt;
227 &lt;/ac:for&gt;
228 </pre>
229 <p>
230 The following example counts down from 10 to 0 in steps of -2.
231 </p>
232 <pre>
233 &lt;ac:for param="i" begin="10" step="-2" end="0"&gt;
234 &lt;sequential&gt;
235 &lt;echo&gt;i is @{i}&lt;/echo&gt;
236 &lt;/sequential&gt;
237 &lt;/ac:for&gt;
238 </pre>
239 <hr>
240 <p align="center">Copyright &copy; 2003-2006 Ant-Contrib Project. All
241 rights Reserved.</p>
242
243 </body>
244 </html>