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>
|
---|
4 | The 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>
|
---|
6 | To use this task in your build files, include a task definition like this:
|
---|
7 | </p><pre class="programlisting">
|
---|
8 |
|
---|
9 | <taskdef name="call" classname="ise.antelope.tasks.Repeat"/>
|
---|
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>
|
---|
15 | Here are a number of examples taken from the unit tests for this task:
|
---|
16 | </p><pre class="programlisting">
|
---|
17 |
|
---|
18 | <target name="test1a">
|
---|
19 | <!-- no count set, verify performs tasks once -->
|
---|
20 | <a:var name="count" value="0"/>
|
---|
21 | <a:repeat>
|
---|
22 | <a:math result="count" operand1="${count}" operand2="1" operation="+"/>
|
---|
23 | </a:repeat>
|
---|
24 | <a:assert>
|
---|
25 | <bool>
|
---|
26 | <mathequals arg1="${count}" arg2="1"/>
|
---|
27 | </bool>
|
---|
28 | </a:assert>
|
---|
29 | </target>
|
---|
30 |
|
---|
31 | <target name="test1b">
|
---|
32 | <!-- count > 1, verify performs tasks correct number of times -->
|
---|
33 | <a:var name="count" value="0"/>
|
---|
34 | <a:repeat count="3" interval="1">
|
---|
35 | <a:math result="count" operand1="${count}" operand2="1" operation="+"/>
|
---|
36 | </a:repeat>
|
---|
37 | <a:assert message="Expected 3, got ${count}">
|
---|
38 | <bool>
|
---|
39 | <mathequals arg1="${count}" arg2="3"/>
|
---|
40 | </bool>
|
---|
41 | </a:assert>
|
---|
42 | </target>
|
---|
43 |
|
---|
44 | <target name="test1c">
|
---|
45 | <!-- count = -1, verify performs tasks indefinitely -->
|
---|
46 | <a:var name="count" value="0"/>
|
---|
47 | <a:limit maxwait="10">
|
---|
48 | <a:repeat count="-1" interval="1">
|
---|
49 | <a:math result="count" operand1="${count}" operand2="1" operation="+"/>
|
---|
50 | </a:repeat>
|
---|
51 | </a:limit>
|
---|
52 | <a:assert>
|
---|
53 | <bool>
|
---|
54 | <and>
|
---|
55 | <a:isgreaterthan arg1="${count}" arg2="8"/>
|
---|
56 | <a:islessthan arg1="${count}" arg2="12"/>
|
---|
57 | </and>
|
---|
58 | </bool>
|
---|
59 | </a:assert>
|
---|
60 | </target>
|
---|
61 |
|
---|
62 | <target name="test2a">
|
---|
63 | <!-- no interval set, verify performs tasks 10 seconds apart -->
|
---|
64 | <a:var name="count" value="0"/>
|
---|
65 | <a:stopwatch name="test2a_stopwatch" action="start"/>
|
---|
66 | <a:repeat count="2">
|
---|
67 | <a:math result="count" operand1="${count}" operand2="1" operation="+"/>
|
---|
68 | </a:repeat>
|
---|
69 | <a:stopwatch name="test2a_stopwatch" action="total"/>
|
---|
70 | <a:assert message="Got ${count}, expected 2">
|
---|
71 | <bool>
|
---|
72 | <and>
|
---|
73 | <a:mathequals arg1="${count}" arg2="2"/>
|
---|
74 | <a:islessthan arg1="${test2a_stopwatch}" arg2="11"/>
|
---|
75 | </and>
|
---|
76 | </bool>
|
---|
77 | </a:assert>
|
---|
78 | </target>
|
---|
79 |
|
---|
80 |
|
---|
81 | <target name="test2b">
|
---|
82 | <!-- interval set to other than 10 seconds, verify tasks performed correct
|
---|
83 | time apart. -->
|
---|
84 | <a:var name="count" value="0"/>
|
---|
85 | <a:stopwatch name="test2b_stopwatch" action="start"/>
|
---|
86 | <a:repeat count="2" interval="5">
|
---|
87 | <a:math result="count" operand1="${count}" operand2="1" operation="+"/>
|
---|
88 | </a:repeat>
|
---|
89 | <a:stopwatch name="test2b_stopwatch" action="total"/>
|
---|
90 | <a:assert>
|
---|
91 | <bool>
|
---|
92 | <and>
|
---|
93 | <a:mathequals arg1="${count}" arg2="2"/>
|
---|
94 | <a:islessthan arg1="${test2b_stopwatch}" arg2="6"/>
|
---|
95 | </and>
|
---|
96 | </bool>
|
---|
97 | </a:assert>
|
---|
98 | </target>
|
---|
99 |
|
---|
100 | <target name="test2c">
|
---|
101 | <!-- interval = 0, verify tasks performed just once -->
|
---|
102 | <a:var name="count" value="0"/>
|
---|
103 | <a:stopwatch name="test2c_stopwatch" action="start"/>
|
---|
104 | <a:repeat count="5" interval="0">
|
---|
105 | <a:math result="count" operand1="${count}" operand2="1" operation="+" datatype="int"/>
|
---|
106 | </a:repeat>
|
---|
107 | <a:stopwatch name="test2c_stopwatch" action="total"/>
|
---|
108 | <a:assert>
|
---|
109 | <bool>
|
---|
110 | <and>
|
---|
111 | <a:mathequals arg1="${count}" arg2="1"/>
|
---|
112 | <a:islessthan arg1="${test2c_stopwatch}" arg2="1"/>
|
---|
113 | </and>
|
---|
114 | </bool>
|
---|
115 | </a:assert>
|
---|
116 | </target>
|
---|
117 |
|
---|
118 | <target name="test3a">
|
---|
119 | <!-- failOnError not set, verify continues to execute tasks even if one fails -->
|
---|
120 | <a:var name="count" value="0"/>
|
---|
121 | <a:repeat count="3" interval="1">
|
---|
122 | <a:math result="count" operand1="${count}" operand2="1" operation="+"/>
|
---|
123 | <fail/>
|
---|
124 | </a:repeat>
|
---|
125 | <a:assert>
|
---|
126 | <bool>
|
---|
127 | <a:mathequals arg1="${count}" arg2="3"/>
|
---|
128 | </bool>
|
---|
129 | </a:assert>
|
---|
130 | </target>
|
---|
131 |
|
---|
132 | <target name="test3b">
|
---|
133 | <!-- failOnError set to false, same as 3a -->
|
---|
134 | <a:var name="count" value="0"/>
|
---|
135 | <a:repeat count="3" interval="1" failonerror="no">
|
---|
136 | <a:math result="count" operand1="${count}" operand2="1" operation="+"/>
|
---|
137 | <fail/>
|
---|
138 | </a:repeat>
|
---|
139 | <a:assert>
|
---|
140 | <bool>
|
---|
141 | <a:mathequals arg1="${count}" arg2="3"/>
|
---|
142 | </bool>
|
---|
143 | </a:assert>
|
---|
144 | </target>
|
---|
145 |
|
---|
146 | <target name="test3c">
|
---|
147 | <!-- failOnError set to true, verify build fails if subtask fails -->
|
---|
148 | <a:var name="count" value="0"/>
|
---|
149 | <a:try>
|
---|
150 | <a:repeat count="3" interval="1" failonerror="yes">
|
---|
151 | <a:math result="count" operand1="${count}" operand2="1" operation="+"/>
|
---|
152 | <fail/>
|
---|
153 | </a:repeat>
|
---|
154 | </a:try>
|
---|
155 | <a:assert>
|
---|
156 | <bool>
|
---|
157 | <a:mathequals arg1="${count}" arg2="1"/>
|
---|
158 | </bool>
|
---|
159 | </a:assert>
|
---|
160 | </target>
|
---|
161 |
|
---|
162 | <target name="test4a">
|
---|
163 | <!-- property name set, value not set, verify property is set to true when task
|
---|
164 | is complete -->
|
---|
165 | <a:var name="count" value="0"/>
|
---|
166 | <a:repeat count="1" interval="1" property="test4a_property">
|
---|
167 | <a:math result="count" operand1="${count}" operand2="1" operation="+"/>
|
---|
168 | <fail/>
|
---|
169 | </a:repeat>
|
---|
170 | <a:assert>
|
---|
171 | <bool>
|
---|
172 | <istrue value="${test4a_property}"/>
|
---|
173 | </bool>
|
---|
174 | </a:assert>
|
---|
175 | </target>
|
---|
176 |
|
---|
177 | <target name="test4b">
|
---|
178 | <!-- property ame set, value set to a specific value, verify property is set to
|
---|
179 | specific value when task is complete -->
|
---|
180 | <a:var name="count" value="0"/>
|
---|
181 | <a:repeat count="1" interval="1" property="test4b_property" value="good">
|
---|
182 | <a:math result="count" operand1="${count}" operand2="1" operation="+"/>
|
---|
183 | <fail/>
|
---|
184 | </a:repeat>
|
---|
185 | <a:assert name="test4b_property" value="good"/>
|
---|
186 | </target>
|
---|
187 |
|
---|
188 | <target name="test5">
|
---|
189 | <property name="call_count" value="0"/>
|
---|
190 | <a:limit seconds="5" failonerror="true">
|
---|
191 | <a:repeat count="-1" interval="1">
|
---|
192 | <a:until>
|
---|
193 | <a:contains property="log_contents" substring="All tests passed 4 times." />
|
---|
194 | </a:until>
|
---|
195 |
|
---|
196 | <echo>read log</echo>
|
---|
197 | <a:new>
|
---|
198 | <a:call target="readLog"/>
|
---|
199 | </a:new>
|
---|
200 | <echo>${call_count} - ${log_contents}</echo>
|
---|
201 |
|
---|
202 | </a:repeat>
|
---|
203 | </a:limit>
|
---|
204 | </target>
|
---|
205 |
|
---|
206 | <target name="readLog">
|
---|
207 | <a:unset name="log_contents"/>
|
---|
208 | <a:new>
|
---|
209 | <a:math result="call_count" operand1="${call_count}" operand2="1" operation="+" datatype="int"/>
|
---|
210 | <property name="log_contents" value="All tests passed ${call_count} times."/>
|
---|
211 | </a:new>
|
---|
212 | </target>
|
---|
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>
|
---|