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