source: release-kits/lirk3/bin/ant-installer/web/manual1.6.2/manual/CoreTasks/macrodef.html@ 14982

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

initial import of LiRK3

File size: 11.1 KB
Line 
1<html>
2
3 <head>
4 <meta http-equiv="Content-Language" content="en-us"></meta>
5 <title>MacroDef Task</title>
6 <link rel="stylesheet" type="text/css" href="../stylesheets/antmanual.css">
7 <style type="text/css">
8 <!--
9 .code { background: #EFEFEF; margin-top: }
10 -->
11 </style>
12 </head>
13
14 <body>
15
16 <h2><a name="macrodef">MacroDef</a></h2>
17 <h3>Description</h3>
18 <p>
19 This defines a new task using a &lt;sequential&gt;
20 nested task as a template. Nested elements &lt;attribute&gt; and
21 &lt;element&gt; are used to specify attributes and elements of
22 the new task. These get substituted into the &lt;sequential&gt;
23 task when the new task is run.
24 </p>
25 <h3>Note</h3>
26 <p>
27 You can also use <i>prior defined</i> attributes for default-values in
28 other attributes. See the examples.
29 </p>
30 <p>
31 <em>since Ant 1.6</em>
32 </p>
33 <h3>Parameters</h3>
34 <table border="1" cellpadding="2" cellspacing="0">
35 <tr>
36 <td valign="top"><b>Attribute</b></td>
37 <td valign="top"><b>Description</b></td>
38 <td align="center" valign="top"><b>Required</b></td>
39 </tr>
40 <tr>
41 <td valign="top">name</td>
42 <td valign="top">The name of the new definition</td>
43 <td valign="top" align="center">Yes</td>
44 </tr>
45 <tr>
46 <td valign="top">uri</td>
47 <td valign="top">
48 The uri that this definition should live in.
49 </td>
50 <td valign="top" align="center">No</td>
51 </tr>
52 </table>
53 <h3>Parameters specified as nested elements</h3>
54 <h4>attribute</h4>
55 <p>
56 This is used to specify attributes of the new task. The values
57 of the attributes get substituted into the templated task.
58 The attributes will be required attributes unless a default
59 value has been set.
60 </p>
61 <p>
62 This attribute is placed in the body of the templated
63 task using a notation similar to the ant property notation
64 - @{attribute name}. (May be remembered as "put the substitution
65 AT this location").
66 </p>
67 <p>
68 The escape sequence @@ is used to escape @. This allows @{x} to be
69 placed in the text without substitution of x by using @@{x}.
70 This corresponds to the $$ escape sequence for properties.
71 </p>
72 <p>
73 The case of the attribute is ignored, so @{myAttribute} is treated the
74 same as @{MyAttribute}.
75 </p>
76 <h3>Parameters</h3>
77 <table border="1" cellpadding="2" cellspacing="0">
78 <tr>
79 <td valign="top"><b>Attribute</b></td>
80 <td valign="top"><b>Description</b></td>
81 <td align="center" valign="top"><b>Required</b></td>
82 </tr>
83 <tr>
84 <td valign="top">name</td>
85 <td valign="top">The name of the new attribute</td>
86 <td valign="top" align="center">Yes</td>
87 </tr>
88 <tr>
89 <td valign="top">default</td>
90 <td valign="top">
91 The default value of the attribute.
92 </td>
93 <td valign="top" align="center">No</td>
94 </tr>
95 <tr>
96 <td valign="top">description</td>
97 <td valign="top">
98 This contains a description of the attribute.
99 <em>since ant 1.6.1</em>
100 </td>
101 <td valign="top" align="center">No</td>
102 </tr>
103 </table>
104 <h4>element</h4>
105 <p>
106 This is used to specify nested elements of the new task.
107 The contents of the nested elements of the task instance
108 are placed in the templated task at the tag name.
109 </p>
110 <p>
111 The case of the element name is ignored.
112 </p>
113 <h3>Parameters</h3>
114 <table border="1" cellpadding="2" cellspacing="0">
115 <tr>
116 <td valign="top"><b>Attribute</b></td>
117 <td valign="top"><b>Description</b></td>
118 <td align="center" valign="top"><b>Required</b></td>
119 </tr>
120 <tr>
121 <td valign="top">name</td>
122 <td valign="top">The name of the element</td>
123 <td valign="top" align="center">Yes</td>
124 </tr>
125 <tr>
126 <td valign="top">optional</td>
127 <td valign="top">
128 If true this nested element is optional. Default is
129 false - i.e the nested element is required in
130 the new task.
131 </td>
132 <td valign="top" align="center">No</td>
133 </tr>
134 <tr>
135 <td valign="top">implicit</td>
136 <td valign="top">
137 If true this nested element is implicit. This means that
138 any nested elements of the macrodef instance will be placed
139 in the element indicated by the name of this element.
140 There can only be one element if an element is implicit.
141 The default value is false. <em>since ant 1.6.2</em>
142 </td>
143 <td valign="top" align="center">No</td>
144 </tr>
145 <tr>
146 <td valign="top">description</td>
147 <td valign="top">
148 This contains a description
149 informing the user what the contents of the element are expected to be.
150 <em>since ant 1.6.1</em>
151 </td>
152 <td valign="top" align="center">No</td>
153 </tr>
154 </table>
155 <h4>text</h4>
156 <p>
157 This is used to specify the treatment of text contents of the macrodef.
158 If this element is not present, then any nested text in the macro
159 will be an error. If the text element is present, then the name
160 becomes an attribute that gets set to the nested text of the macro.
161 <em>Since ant 1.6.1.</em>
162 </p>
163 <p>
164 The case of the text name is ignored.
165 </p>
166 <h3>Parameters</h3>
167 <table border="1" cellpadding="2" cellspacing="0">
168 <tr>
169 <td valign="top"><b>Attribute</b></td>
170 <td valign="top"><b>Description</b></td>
171 <td align="center" valign="top"><b>Required</b></td>
172 </tr>
173 <tr>
174 <td valign="top">name</td>
175 <td valign="top">The name of the text attribute</td>
176 <td valign="top" align="center">Yes</td>
177 </tr>
178 <tr>
179 <td valign="top">optional</td>
180 <td valign="top">
181 If true nested text in the macro is optional, default is "false".
182 </td>
183 <td valign="top" align="center">No</td>
184 </tr>
185 <tr>
186 <td valign="top">trim</td>
187 <td valign="top">
188 If true, the nested text is trimmed of white space,
189 default is "false".
190 </td>
191 <td valign="top" align="center">No</td>
192 </tr>
193 <tr>
194 <td valign="top">description</td>
195 <td valign="top">
196 This contains a description
197 informing the user what the nested text of the macro is expected
198 to be.
199 </td>
200 <td valign="top" align="center">No</td>
201 </tr>
202 </table>
203
204 <h3>Examples</h3>
205 <p>
206 The following example defined a task called testing and
207 runs it.
208 </p>
209 <blockquote>
210<pre class=code>
211&lt;macrodef name="testing"&gt;
212 &lt;attribute name="v" default="NOT SET"/&gt;
213 &lt;element name="some-tasks" optional="yes"/&gt;
214 &lt;sequential&gt;
215 &lt;echo&gt;v is @{v}&lt;/echo&gt;
216 &lt;some-tasks/&gt;
217 &lt;/sequential&gt;
218&lt;/macrodef&gt;
219
220&lt;testing v="This is v"&gt;
221 &lt;some-tasks&gt;
222 &lt;echo&gt;this is a test&lt;/echo&gt;
223 &lt;/some-tasks&gt;
224&lt;/testing&gt;
225</pre>
226 </blockquote>
227 <p>
228 The following fragment defines a task called &lt;call-cc&gt; which
229 take the attributes "target", "link" and "target.dir" and the
230 nested element "cc-elements". The body of the task
231 uses the &lt;cc&gt; task from the
232 <a href="http://ant-contrib.sourceforge.net/">ant-contrib</a> project.
233 </p>
234 <blockquote>
235<pre class="code">
236&lt;macrodef name="call-cc"&gt;
237 &lt;attribute name="target"/&gt;
238 &lt;attribute name="link"/&gt;
239 &lt;attribute name="target.dir"/&gt;
240 &lt;element name="cc-elements"/&gt;
241 &lt;sequential&gt;
242 &lt;mkdir dir="${obj.dir}/@{target}"/&gt;
243 &lt;mkdir dir="@{target.dir}"/&gt;
244 &lt;cc link="@{link}" objdir="${obj.dir}/@{target}"
245 outfile="@{target.dir}/@{target}"&gt;
246 &lt;compiler refid="compiler.options"/&gt;
247 &lt;cc-elements/&gt;
248 &lt;/cc&gt;
249 &lt;/sequential&gt;
250&lt;/macrodef&gt;
251</pre>
252 </blockquote>
253 <p>
254 This then can be used as follows:
255 </p>
256 <blockquote>
257<pre class="code">
258&lt;call-cc target="unittests" link="executable"
259 target.dir="${build.bin.dir}"&gt;
260 &lt;cc-elements&gt;
261 &lt;includepath location="${gen.dir}"/&gt;
262 &lt;includepath location="test"/&gt;
263 &lt;fileset dir="test/unittest" includes = "**/*.cpp"/&gt;
264 &lt;fileset dir="${gen.dir}" includes = "*.cpp"/&gt;
265 &lt;linker refid="linker-libs"/&gt;
266 &lt;/cc-elements&gt;
267&lt;/call-cc&gt;
268</pre>
269 </blockquote>
270 <p>
271 The following fragment shows &lt;call-cc&gt;, but this time
272 using an implicit element and with the link and target.dir arguments
273 having default values.
274 </p>
275 <blockquote>
276<pre class="code">
277&lt;macrodef name="call-cc"&gt;
278 &lt;attribute name="target"/&gt;
279 &lt;attribute name="link" default="executable"/&gt;
280 &lt;attribute name="target.dir" default="${build.bin.dir}"/&gt;
281 &lt;element name="cc-elements" implicit="yes"/&gt;
282 &lt;sequential&gt;
283 &lt;mkdir dir="${obj.dir}/@{target}"/&gt;
284 &lt;mkdir dir="@{target.dir}"/&gt;
285 &lt;cc link="@{link}" objdir="${obj.dir}/@{target}"
286 outfile="@{target.dir}/@{target}"&gt;
287 &lt;compiler refid="compiler.options"/&gt;
288 &lt;cc-elements/&gt;
289 &lt;/cc&gt;
290 &lt;/sequential&gt;
291&lt;/macrodef&gt;
292</pre>
293 </blockquote>
294 <p>
295 This then can be used as follows, note that &lt;cc-elements&gt;
296 is not specified.
297 </p>
298 <blockquote>
299<pre class="code">
300&lt;call-cc target="unittests"/&gt;
301 &lt;includepath location="${gen.dir}"/&gt;
302 &lt;includepath location="test"/&gt;
303 &lt;fileset dir="test/unittest" includes = "**/*.cpp"/&gt;
304 &lt;fileset dir="${gen.dir}" includes = "*.cpp"/&gt;
305 &lt;linker refid="linker-libs"/&gt;
306&lt;/call-cc&gt;
307</pre>
308 </blockquote>
309 <p>
310 The following shows the use of the <code>text</code> element.
311 </p>
312 <blockquote>
313<pre class="code">
314&lt;macrodef name="echotest"&gt;
315 &lt;text name="text"/&gt;
316 &lt;sequential&gt;
317 &lt;echo&gt;@{text}&lt;/echo&gt;
318 &lt;/sequential&gt;
319&lt;/macrodef&gt;
320&lt;echotest&gt;
321 Hello world
322&lt;/echotest&gt;
323</pre>
324 </blockquote>
325 <p>
326 The following uses a prior defined attribute for setting the
327 default value of another. The output would be
328 <tt>one=test two=test</tt>. If you change the order of lines
329 *1 and *2 the output would be <tt>one=test two=@{one}</tt>,
330 because while processing the <i>two</i>-line the value for
331 <i>one</i> is not set.
332 </p>
333 <blockquote>
334<pre class="code">
335&lt;macrodef name="test"/&gt;
336 &lt;attribute name="one"/&gt; <b>*1</b>
337 &lt;attribute name="two" default="@{one}"/&gt; <b>*2</b>
338 &lt;sequential&gt;
339 &lt;echo&gt;one=@{one} two=@{two}&lt;/echo&gt;
340 &lt;/sequential&gt;
341&lt;/macrodef/&gt;
342&lt;test one="test"/&gt;
343</pre>
344 </blockquote>
345<hr>
346<p align="center">Copyright &copy; 2003-2004 The Apache Software
347Foundation. All rights Reserved.</p>
348
349</body>
350</html>
Note: See TracBrowser for help on using the repository browser.