source: other-projects/trunk/realistic-books/packages/AntInstaller/web/manual1.7.0/manual/CoreTasks/macrodef.html@ 19253

Last change on this file since 19253 was 19253, checked in by davidb, 15 years ago

Establishing a source code repository for Veronica's Realistic Book's software

File size: 12.5 KB
Line 
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>&lt;sequential&gt;</code>
37 nested task as a template. Nested elements <code>&lt;attribute&gt;</code> and
38 <code>&lt;element&gt;</code> are used to specify attributes and elements of
39 the new task. These get substituted into the <code>&lt;sequential&gt;</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&lt;macrodef name="testing"&gt;
246 &lt;attribute name="v" default="NOT SET"/&gt;
247 &lt;element name="some-tasks" optional="yes"/&gt;
248 &lt;sequential&gt;
249 &lt;echo&gt;v is @{v}&lt;/echo&gt;
250 &lt;some-tasks/&gt;
251 &lt;/sequential&gt;
252&lt;/macrodef&gt;
253
254&lt;testing v="This is v"&gt;
255 &lt;some-tasks&gt;
256 &lt;echo&gt;this is a test&lt;/echo&gt;
257 &lt;/some-tasks&gt;
258&lt;/testing&gt;
259</pre>
260 </blockquote>
261 <p>
262 The following fragment defines a task called <code>&lt;call-cc&gt;</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>&lt;cc&gt;</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&lt;macrodef name="call-cc"&gt;
271 &lt;attribute name="target"/&gt;
272 &lt;attribute name="link"/&gt;
273 &lt;attribute name="target.dir"/&gt;
274 &lt;element name="cc-elements"/&gt;
275 &lt;sequential&gt;
276 &lt;mkdir dir="${obj.dir}/@{target}"/&gt;
277 &lt;mkdir dir="@{target.dir}"/&gt;
278 &lt;cc link="@{link}" objdir="${obj.dir}/@{target}"
279 outfile="@{target.dir}/@{target}"&gt;
280 &lt;compiler refid="compiler.options"/&gt;
281 &lt;cc-elements/&gt;
282 &lt;/cc&gt;
283 &lt;/sequential&gt;
284&lt;/macrodef&gt;
285</pre>
286 </blockquote>
287 <p>
288 This then can be used as follows:
289 </p>
290 <blockquote>
291<pre class="code">
292&lt;call-cc target="unittests" link="executable"
293 target.dir="${build.bin.dir}"&gt;
294 &lt;cc-elements&gt;
295 &lt;includepath location="${gen.dir}"/&gt;
296 &lt;includepath location="test"/&gt;
297 &lt;fileset dir="test/unittest" includes = "**/*.cpp"/&gt;
298 &lt;fileset dir="${gen.dir}" includes = "*.cpp"/&gt;
299 &lt;linker refid="linker-libs"/&gt;
300 &lt;/cc-elements&gt;
301&lt;/call-cc&gt;
302</pre>
303 </blockquote>
304 <p>
305 The following fragment shows &lt;call-cc&gt;, 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&lt;macrodef name="call-cc"&gt;
312 &lt;attribute name="target"/&gt;
313 &lt;attribute name="link" default="executable"/&gt;
314 &lt;attribute name="target.dir" default="${build.bin.dir}"/&gt;
315 &lt;element name="cc-elements" implicit="yes"/&gt;
316 &lt;sequential&gt;
317 &lt;mkdir dir="${obj.dir}/@{target}"/&gt;
318 &lt;mkdir dir="@{target.dir}"/&gt;
319 &lt;cc link="@{link}" objdir="${obj.dir}/@{target}"
320 outfile="@{target.dir}/@{target}"&gt;
321 &lt;compiler refid="compiler.options"/&gt;
322 &lt;cc-elements/&gt;
323 &lt;/cc&gt;
324 &lt;/sequential&gt;
325&lt;/macrodef&gt;
326</pre>
327 </blockquote>
328 <p>
329 This then can be used as follows, note that &lt;cc-elements&gt;
330 is not specified.
331 </p>
332 <blockquote>
333<pre class="code">
334&lt;call-cc target="unittests"/&gt;
335 &lt;includepath location="${gen.dir}"/&gt;
336 &lt;includepath location="test"/&gt;
337 &lt;fileset dir="test/unittest" includes = "**/*.cpp"/&gt;
338 &lt;fileset dir="${gen.dir}" includes = "*.cpp"/&gt;
339 &lt;linker refid="linker-libs"/&gt;
340&lt;/call-cc&gt;
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&lt;macrodef name="echotest"&gt;
349 &lt;text name="text"/&gt;
350 &lt;sequential&gt;
351 &lt;echo&gt;@{text}&lt;/echo&gt;
352 &lt;/sequential&gt;
353&lt;/macrodef&gt;
354&lt;echotest&gt;
355 Hello world
356&lt;/echotest&gt;
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&lt;macrodef name="test"&gt;
370 &lt;attribute name="one"/&gt; <b>*1</b>
371 &lt;attribute name="two" default="@{one}"/&gt; <b>*2</b>
372 &lt;sequential&gt;
373 &lt;echo&gt;one=@{one} two=@{two}&lt;/echo&gt;
374 &lt;/sequential&gt;
375&lt;/macrodef&gt;
376&lt;test one="test"/&gt;
377</pre>
378 </blockquote>
379
380
381</body>
382</html>
Note: See TracBrowser for help on using the repository browser.