source: release-kits/wirk3/ant-scripts/tasks/antelope/docs/manual/bk03ch24.html@ 15023

Last change on this file since 15023 was 15023, checked in by oranfry, 16 years ago

did the bulk of the work on wirk3

File size: 10.6 KB
Line 
1<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>Chapter 24. Repeat Task</title><meta name="generator" content="DocBook XSL Stylesheets V1.68.1"><link rel="start" href="index.html" title="Antelope Users Guide"><link rel="up" href="bk03.html" title="Additional Ant Tasks"><link rel="prev" href="bk03ch23.html" title="Chapter 23. Split Task"><link rel="next" href="bk03ch25.html" title="Chapter 25. Suite Task"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Chapter 24. Repeat Task</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="bk03ch23.html">Prev</a> </td><th width="60%" align="center">Additional Ant Tasks</th><td width="20%" align="right"> <a accesskey="n" href="bk03ch25.html">Next</a></td></tr></table><hr></div><div class="chapter" lang="en"><div class="titlepage"><div><div><h2 class="title"><a name="Repeat"></a>Chapter 24. Repeat Task</h2></div></div></div>
2<STYLE TYPE="text/css"> <!-- @import url(./style.css); --> </STYLE>
3 <p>
4The Repeat task performs the same subtasks over and over a certain number of times or until a condition is met. Since most tasks are configured when the build file is first loaded and never again, this task may not do what you want.
5</p><p>
6To use this task in your build files, include a task definition like this:
7</p><pre class="programlisting">
8
9 &lt;taskdef name="call" classname="ise.antelope.tasks.Repeat"/&gt;
10
11</pre><p>
12</p><p>
13</p><div class="table"><a name="id2525632"></a><p class="title"><b>Table 24.1. Repeat Task Attributes</b></p><table summary="Repeat Task Attributes" border="1"><colgroup><col><col><col><col></colgroup><thead><tr><th>Attribute</th><th>Description</th><th>Default</th><th>Required</th></tr></thead><tbody><tr><td>count</td><td>The number of times to repeat execution of the nested tasks.</td><td>1</td><td>No</td></tr><tr><td>interval</td><td>How long to wait between repetitions. If set to 0, only 1 repetition will be performed, this is to avoid a tight loop.</td><td>0</td><td>No</td></tr><tr><td>unit</td><td>The units for interval, allowed values are "milliseconds", "seconds", "minutes", "days", and "weeks"</td><td>seconds</td><td>No</td></tr><tr><td>property</td><td>The name of a property to set upon completion.</td><td>None</td><td>No</td></tr><tr><td>value</td><td>The value to set for the property to be set upon completion.</td><td>None</td><td>No</td></tr></tbody></table></div><p>
14</p><p>
15Here are a number of examples taken from the unit tests for this task:
16</p><pre class="programlisting">
17
18 &lt;target name="test1a"&gt;
19 &lt;!-- no count set, verify performs tasks once --&gt;
20 &lt;a:var name="count" value="0"/&gt;
21 &lt;a:repeat&gt;
22 &lt;a:math result="count" operand1="${count}" operand2="1" operation="+"/&gt;
23 &lt;/a:repeat&gt;
24 &lt;a:assert&gt;
25 &lt;bool&gt;
26 &lt;mathequals arg1="${count}" arg2="1"/&gt;
27 &lt;/bool&gt;
28 &lt;/a:assert&gt;
29 &lt;/target&gt;
30
31 &lt;target name="test1b"&gt;
32 &lt;!-- count &gt; 1, verify performs tasks correct number of times --&gt;
33 &lt;a:var name="count" value="0"/&gt;
34 &lt;a:repeat count="3" interval="1"&gt;
35 &lt;a:math result="count" operand1="${count}" operand2="1" operation="+"/&gt;
36 &lt;/a:repeat&gt;
37 &lt;a:assert message="Expected 3, got ${count}"&gt;
38 &lt;bool&gt;
39 &lt;mathequals arg1="${count}" arg2="3"/&gt;
40 &lt;/bool&gt;
41 &lt;/a:assert&gt;
42 &lt;/target&gt;
43
44 &lt;target name="test1c"&gt;
45 &lt;!-- count = -1, verify performs tasks indefinitely --&gt;
46 &lt;a:var name="count" value="0"/&gt;
47 &lt;a:limit maxwait="10"&gt;
48 &lt;a:repeat count="-1" interval="1"&gt;
49 &lt;a:math result="count" operand1="${count}" operand2="1" operation="+"/&gt;
50 &lt;/a:repeat&gt;
51 &lt;/a:limit&gt;
52 &lt;a:assert&gt;
53 &lt;bool&gt;
54 &lt;and&gt;
55 &lt;a:isgreaterthan arg1="${count}" arg2="8"/&gt;
56 &lt;a:islessthan arg1="${count}" arg2="12"/&gt;
57 &lt;/and&gt;
58 &lt;/bool&gt;
59 &lt;/a:assert&gt;
60 &lt;/target&gt;
61
62 &lt;target name="test2a"&gt;
63 &lt;!-- no interval set, verify performs tasks 10 seconds apart --&gt;
64 &lt;a:var name="count" value="0"/&gt;
65 &lt;a:stopwatch name="test2a_stopwatch" action="start"/&gt;
66 &lt;a:repeat count="2"&gt;
67 &lt;a:math result="count" operand1="${count}" operand2="1" operation="+"/&gt;
68 &lt;/a:repeat&gt;
69 &lt;a:stopwatch name="test2a_stopwatch" action="total"/&gt;
70 &lt;a:assert message="Got ${count}, expected 2"&gt;
71 &lt;bool&gt;
72 &lt;and&gt;
73 &lt;a:mathequals arg1="${count}" arg2="2"/&gt;
74 &lt;a:islessthan arg1="${test2a_stopwatch}" arg2="11"/&gt;
75 &lt;/and&gt;
76 &lt;/bool&gt;
77 &lt;/a:assert&gt;
78 &lt;/target&gt;
79
80
81 &lt;target name="test2b"&gt;
82 &lt;!-- interval set to other than 10 seconds, verify tasks performed correct
83 time apart. --&gt;
84 &lt;a:var name="count" value="0"/&gt;
85 &lt;a:stopwatch name="test2b_stopwatch" action="start"/&gt;
86 &lt;a:repeat count="2" interval="5"&gt;
87 &lt;a:math result="count" operand1="${count}" operand2="1" operation="+"/&gt;
88 &lt;/a:repeat&gt;
89 &lt;a:stopwatch name="test2b_stopwatch" action="total"/&gt;
90 &lt;a:assert&gt;
91 &lt;bool&gt;
92 &lt;and&gt;
93 &lt;a:mathequals arg1="${count}" arg2="2"/&gt;
94 &lt;a:islessthan arg1="${test2b_stopwatch}" arg2="6"/&gt;
95 &lt;/and&gt;
96 &lt;/bool&gt;
97 &lt;/a:assert&gt;
98 &lt;/target&gt;
99
100 &lt;target name="test2c"&gt;
101 &lt;!-- interval = 0, verify tasks performed just once --&gt;
102 &lt;a:var name="count" value="0"/&gt;
103 &lt;a:stopwatch name="test2c_stopwatch" action="start"/&gt;
104 &lt;a:repeat count="5" interval="0"&gt;
105 &lt;a:math result="count" operand1="${count}" operand2="1" operation="+" datatype="int"/&gt;
106 &lt;/a:repeat&gt;
107 &lt;a:stopwatch name="test2c_stopwatch" action="total"/&gt;
108 &lt;a:assert&gt;
109 &lt;bool&gt;
110 &lt;and&gt;
111 &lt;a:mathequals arg1="${count}" arg2="1"/&gt;
112 &lt;a:islessthan arg1="${test2c_stopwatch}" arg2="1"/&gt;
113 &lt;/and&gt;
114 &lt;/bool&gt;
115 &lt;/a:assert&gt;
116 &lt;/target&gt;
117
118 &lt;target name="test3a"&gt;
119 &lt;!-- failOnError not set, verify continues to execute tasks even if one fails --&gt;
120 &lt;a:var name="count" value="0"/&gt;
121 &lt;a:repeat count="3" interval="1"&gt;
122 &lt;a:math result="count" operand1="${count}" operand2="1" operation="+"/&gt;
123 &lt;fail/&gt;
124 &lt;/a:repeat&gt;
125 &lt;a:assert&gt;
126 &lt;bool&gt;
127 &lt;a:mathequals arg1="${count}" arg2="3"/&gt;
128 &lt;/bool&gt;
129 &lt;/a:assert&gt;
130 &lt;/target&gt;
131
132 &lt;target name="test3b"&gt;
133 &lt;!-- failOnError set to false, same as 3a --&gt;
134 &lt;a:var name="count" value="0"/&gt;
135 &lt;a:repeat count="3" interval="1" failonerror="no"&gt;
136 &lt;a:math result="count" operand1="${count}" operand2="1" operation="+"/&gt;
137 &lt;fail/&gt;
138 &lt;/a:repeat&gt;
139 &lt;a:assert&gt;
140 &lt;bool&gt;
141 &lt;a:mathequals arg1="${count}" arg2="3"/&gt;
142 &lt;/bool&gt;
143 &lt;/a:assert&gt;
144 &lt;/target&gt;
145
146 &lt;target name="test3c"&gt;
147 &lt;!-- failOnError set to true, verify build fails if subtask fails --&gt;
148 &lt;a:var name="count" value="0"/&gt;
149 &lt;a:try&gt;
150 &lt;a:repeat count="3" interval="1" failonerror="yes"&gt;
151 &lt;a:math result="count" operand1="${count}" operand2="1" operation="+"/&gt;
152 &lt;fail/&gt;
153 &lt;/a:repeat&gt;
154 &lt;/a:try&gt;
155 &lt;a:assert&gt;
156 &lt;bool&gt;
157 &lt;a:mathequals arg1="${count}" arg2="1"/&gt;
158 &lt;/bool&gt;
159 &lt;/a:assert&gt;
160 &lt;/target&gt;
161
162 &lt;target name="test4a"&gt;
163 &lt;!-- property name set, value not set, verify property is set to true when task
164 is complete --&gt;
165 &lt;a:var name="count" value="0"/&gt;
166 &lt;a:repeat count="1" interval="1" property="test4a_property"&gt;
167 &lt;a:math result="count" operand1="${count}" operand2="1" operation="+"/&gt;
168 &lt;fail/&gt;
169 &lt;/a:repeat&gt;
170 &lt;a:assert&gt;
171 &lt;bool&gt;
172 &lt;istrue value="${test4a_property}"/&gt;
173 &lt;/bool&gt;
174 &lt;/a:assert&gt;
175 &lt;/target&gt;
176
177 &lt;target name="test4b"&gt;
178 &lt;!-- property ame set, value set to a specific value, verify property is set to
179 specific value when task is complete --&gt;
180 &lt;a:var name="count" value="0"/&gt;
181 &lt;a:repeat count="1" interval="1" property="test4b_property" value="good"&gt;
182 &lt;a:math result="count" operand1="${count}" operand2="1" operation="+"/&gt;
183 &lt;fail/&gt;
184 &lt;/a:repeat&gt;
185 &lt;a:assert name="test4b_property" value="good"/&gt;
186 &lt;/target&gt;
187
188 &lt;target name="test5"&gt;
189 &lt;property name="call_count" value="0"/&gt;
190 &lt;a:limit seconds="5" failonerror="true"&gt;
191 &lt;a:repeat count="-1" interval="1"&gt;
192 &lt;a:until&gt;
193 &lt;a:contains property="log_contents" substring="All tests passed 4 times." /&gt;
194 &lt;/a:until&gt;
195
196 &lt;echo&gt;read log&lt;/echo&gt;
197 &lt;a:new&gt;
198 &lt;a:call target="readLog"/&gt;
199 &lt;/a:new&gt;
200 &lt;echo&gt;${call_count} - ${log_contents}&lt;/echo&gt;
201
202 &lt;/a:repeat&gt;
203 &lt;/a:limit&gt;
204 &lt;/target&gt;
205
206 &lt;target name="readLog"&gt;
207 &lt;a:unset name="log_contents"/&gt;
208 &lt;a:new&gt;
209 &lt;a:math result="call_count" operand1="${call_count}" operand2="1" operation="+" datatype="int"/&gt;
210 &lt;property name="log_contents" value="All tests passed ${call_count} times."/&gt;
211 &lt;/a:new&gt;
212 &lt;/target&gt;
213
214</pre><p>
215</p></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="bk03ch23.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="bk03.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="bk03ch25.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Chapter 23. Split Task </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> Chapter 25. Suite Task</td></tr></table></div></body></html>
Note: See TracBrowser for help on using the repository browser.