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 <code><sequential></code>
|
---|
20 | nested task as a template. Nested elements <code><attribute></code> and
|
---|
21 | <code><element></code> are used to specify attributes and elements of
|
---|
22 | the new task. These get substituted into the <code><sequential></code>
|
---|
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 | <macrodef name="testing">
|
---|
212 | <attribute name="v" default="NOT SET"/>
|
---|
213 | <element name="some-tasks" optional="yes"/>
|
---|
214 | <sequential>
|
---|
215 | <echo>v is @{v}</echo>
|
---|
216 | <some-tasks/>
|
---|
217 | </sequential>
|
---|
218 | </macrodef>
|
---|
219 |
|
---|
220 | <testing v="This is v">
|
---|
221 | <some-tasks>
|
---|
222 | <echo>this is a test</echo>
|
---|
223 | </some-tasks>
|
---|
224 | </testing>
|
---|
225 | </pre>
|
---|
226 | </blockquote>
|
---|
227 | <p>
|
---|
228 | The following fragment defines a task called <code><call-cc></code> 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 <code><cc></code> task from the
|
---|
232 | <a href="http://ant-contrib.sourceforge.net/">ant-contrib</a> project.
|
---|
233 | </p>
|
---|
234 | <blockquote>
|
---|
235 | <pre class="code">
|
---|
236 | <macrodef name="call-cc">
|
---|
237 | <attribute name="target"/>
|
---|
238 | <attribute name="link"/>
|
---|
239 | <attribute name="target.dir"/>
|
---|
240 | <element name="cc-elements"/>
|
---|
241 | <sequential>
|
---|
242 | <mkdir dir="${obj.dir}/@{target}"/>
|
---|
243 | <mkdir dir="@{target.dir}"/>
|
---|
244 | <cc link="@{link}" objdir="${obj.dir}/@{target}"
|
---|
245 | outfile="@{target.dir}/@{target}">
|
---|
246 | <compiler refid="compiler.options"/>
|
---|
247 | <cc-elements/>
|
---|
248 | </cc>
|
---|
249 | </sequential>
|
---|
250 | </macrodef>
|
---|
251 | </pre>
|
---|
252 | </blockquote>
|
---|
253 | <p>
|
---|
254 | This then can be used as follows:
|
---|
255 | </p>
|
---|
256 | <blockquote>
|
---|
257 | <pre class="code">
|
---|
258 | <call-cc target="unittests" link="executable"
|
---|
259 | target.dir="${build.bin.dir}">
|
---|
260 | <cc-elements>
|
---|
261 | <includepath location="${gen.dir}"/>
|
---|
262 | <includepath location="test"/>
|
---|
263 | <fileset dir="test/unittest" includes = "**/*.cpp"/>
|
---|
264 | <fileset dir="${gen.dir}" includes = "*.cpp"/>
|
---|
265 | <linker refid="linker-libs"/>
|
---|
266 | </cc-elements>
|
---|
267 | </call-cc>
|
---|
268 | </pre>
|
---|
269 | </blockquote>
|
---|
270 | <p>
|
---|
271 | The following fragment shows <call-cc>, 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 | <macrodef name="call-cc">
|
---|
278 | <attribute name="target"/>
|
---|
279 | <attribute name="link" default="executable"/>
|
---|
280 | <attribute name="target.dir" default="${build.bin.dir}"/>
|
---|
281 | <element name="cc-elements" implicit="yes"/>
|
---|
282 | <sequential>
|
---|
283 | <mkdir dir="${obj.dir}/@{target}"/>
|
---|
284 | <mkdir dir="@{target.dir}"/>
|
---|
285 | <cc link="@{link}" objdir="${obj.dir}/@{target}"
|
---|
286 | outfile="@{target.dir}/@{target}">
|
---|
287 | <compiler refid="compiler.options"/>
|
---|
288 | <cc-elements/>
|
---|
289 | </cc>
|
---|
290 | </sequential>
|
---|
291 | </macrodef>
|
---|
292 | </pre>
|
---|
293 | </blockquote>
|
---|
294 | <p>
|
---|
295 | This then can be used as follows, note that <cc-elements>
|
---|
296 | is not specified.
|
---|
297 | </p>
|
---|
298 | <blockquote>
|
---|
299 | <pre class="code">
|
---|
300 | <call-cc target="unittests"/>
|
---|
301 | <includepath location="${gen.dir}"/>
|
---|
302 | <includepath location="test"/>
|
---|
303 | <fileset dir="test/unittest" includes = "**/*.cpp"/>
|
---|
304 | <fileset dir="${gen.dir}" includes = "*.cpp"/>
|
---|
305 | <linker refid="linker-libs"/>
|
---|
306 | </call-cc>
|
---|
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 | <macrodef name="echotest">
|
---|
315 | <text name="text"/>
|
---|
316 | <sequential>
|
---|
317 | <echo>@{text}</echo>
|
---|
318 | </sequential>
|
---|
319 | </macrodef>
|
---|
320 | <echotest>
|
---|
321 | Hello world
|
---|
322 | </echotest>
|
---|
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 | <macrodef name="test">
|
---|
336 | <attribute name="one"/> <b>*1</b>
|
---|
337 | <attribute name="two" default="@{one}"/> <b>*2</b>
|
---|
338 | <sequential>
|
---|
339 | <echo>one=@{one} two=@{two}</echo>
|
---|
340 | </sequential>
|
---|
341 | </macrodef>
|
---|
342 | <test one="test"/>
|
---|
343 | </pre>
|
---|
344 | </blockquote>
|
---|
345 | <hr>
|
---|
346 | <p align="center">Copyright © 2003-2005 The Apache Software
|
---|
347 | Foundation. All rights Reserved.</p>
|
---|
348 |
|
---|
349 | </body>
|
---|
350 | </html>
|
---|