2003-08-14 12:48:10 +00:00
|
|
|
<html>
|
2004-04-20 14:45:26 +00:00
|
|
|
|
2003-08-14 12:48:10 +00:00
|
|
|
<head>
|
|
|
|
<meta http-equiv="Content-Language" content="en-us"></meta>
|
|
|
|
<title>MacroDef Task</title>
|
2004-04-20 15:42:34 +00:00
|
|
|
<link rel="stylesheet" type="text/css" href="../stylesheets/antmanual.css">
|
2003-12-03 13:16:01 +00:00
|
|
|
<style type="text/css">
|
|
|
|
<!--
|
|
|
|
.code { background: #EFEFEF; margin-top: }
|
|
|
|
-->
|
|
|
|
</style>
|
2003-08-14 12:48:10 +00:00
|
|
|
</head>
|
2004-04-20 14:45:26 +00:00
|
|
|
|
2003-08-14 12:48:10 +00:00
|
|
|
<body>
|
2004-04-20 14:45:26 +00:00
|
|
|
|
2003-08-14 12:48:10 +00:00
|
|
|
<h2><a name="macrodef">MacroDef</a></h2>
|
|
|
|
<h3>Description</h3>
|
|
|
|
<p>
|
2004-04-20 14:45:26 +00:00
|
|
|
This defines a new task using a <sequential>
|
2003-08-15 09:33:45 +00:00
|
|
|
nested task as a template. Nested elements <attribute> and
|
2003-08-14 12:48:10 +00:00
|
|
|
<element> are used to specify attributes and elements of
|
|
|
|
the new task. These get substituted into the <sequential>
|
2003-10-31 09:51:24 +00:00
|
|
|
task when the new task is run.
|
2003-08-14 12:48:10 +00:00
|
|
|
</p>
|
2004-04-20 14:45:26 +00:00
|
|
|
<h3>Note</h3>
|
|
|
|
<p>
|
|
|
|
You can also use <i>prior defined</i> attributes for default-values in
|
|
|
|
other attributes. See the examples.
|
|
|
|
</p>
|
2003-08-14 12:48:10 +00:00
|
|
|
<p>
|
2003-10-14 09:59:19 +00:00
|
|
|
<em>since Ant 1.6</em>
|
2003-08-14 12:48:10 +00:00
|
|
|
</p>
|
|
|
|
<h3>Parameters</h3>
|
|
|
|
<table border="1" cellpadding="2" cellspacing="0">
|
|
|
|
<tr>
|
|
|
|
<td valign="top"><b>Attribute</b></td>
|
|
|
|
<td valign="top"><b>Description</b></td>
|
|
|
|
<td align="center" valign="top"><b>Required</b></td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td valign="top">name</td>
|
2003-08-15 09:33:45 +00:00
|
|
|
<td valign="top">The name of the new definition</td>
|
2003-08-14 12:48:10 +00:00
|
|
|
<td valign="top" align="center">Yes</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td valign="top">uri</td>
|
|
|
|
<td valign="top">
|
|
|
|
The uri that this definition should live in.
|
|
|
|
</td>
|
|
|
|
<td valign="top" align="center">No</td>
|
|
|
|
</tr>
|
|
|
|
</table>
|
|
|
|
<h3>Parameters specified as nested elements</h3>
|
2003-08-15 09:33:45 +00:00
|
|
|
<h4>attribute</h4>
|
2003-08-14 12:48:10 +00:00
|
|
|
<p>
|
|
|
|
This is used to specify attributes of the new task. The values
|
|
|
|
of the attributes get substituted into the templated task.
|
|
|
|
The attributes will be required attributes unless a default
|
|
|
|
value has been set.
|
|
|
|
</p>
|
|
|
|
<p>
|
|
|
|
This attribute is placed in the body of the templated
|
2003-12-03 13:16:01 +00:00
|
|
|
task using a notation similar to the ant property notation
|
|
|
|
- @{attribute name}. (May be remembered as "put the substitution
|
|
|
|
AT this location").
|
2004-02-25 11:33:34 +00:00
|
|
|
</p>
|
|
|
|
<p>
|
|
|
|
The escape sequence @@ is used to escape @. This allows @{x} to be
|
|
|
|
placed in the text without substitution of x by using @@{x}.
|
|
|
|
This corresponds to the $$ escape sequence for properties.
|
2003-12-22 09:46:23 +00:00
|
|
|
</p>
|
|
|
|
<p>
|
|
|
|
The case of the attribute is ignored, so @{myAttribute} is treated the
|
|
|
|
same as @{MyAttribute}.
|
2003-08-14 12:48:10 +00:00
|
|
|
</p>
|
|
|
|
<h3>Parameters</h3>
|
|
|
|
<table border="1" cellpadding="2" cellspacing="0">
|
|
|
|
<tr>
|
|
|
|
<td valign="top"><b>Attribute</b></td>
|
|
|
|
<td valign="top"><b>Description</b></td>
|
|
|
|
<td align="center" valign="top"><b>Required</b></td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td valign="top">name</td>
|
2003-08-15 09:33:45 +00:00
|
|
|
<td valign="top">The name of the new attribute</td>
|
2003-08-14 12:48:10 +00:00
|
|
|
<td valign="top" align="center">Yes</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td valign="top">default</td>
|
|
|
|
<td valign="top">
|
2003-08-15 09:33:45 +00:00
|
|
|
The default value of the attribute.
|
2003-08-14 12:48:10 +00:00
|
|
|
</td>
|
|
|
|
<td valign="top" align="center">No</td>
|
|
|
|
</tr>
|
2004-01-08 17:34:57 +00:00
|
|
|
<tr>
|
|
|
|
<td valign="top">description</td>
|
|
|
|
<td valign="top">
|
|
|
|
This contains a description of the attribute.
|
2004-01-22 16:33:16 +00:00
|
|
|
<em>since ant 1.6.1</em>
|
2004-01-08 17:34:57 +00:00
|
|
|
</td>
|
|
|
|
<td valign="top" align="center">No</td>
|
|
|
|
</tr>
|
2003-08-14 12:48:10 +00:00
|
|
|
</table>
|
|
|
|
<h4>element</h4>
|
|
|
|
<p>
|
|
|
|
This is used to specify nested elements of the new task.
|
|
|
|
The contents of the nested elements of the task instance
|
|
|
|
are placed in the templated task at the tag name.
|
|
|
|
</p>
|
2004-01-19 09:51:02 +00:00
|
|
|
<p>
|
|
|
|
The case of the element name is ignored.
|
|
|
|
</p>
|
2003-08-14 12:48:10 +00:00
|
|
|
<h3>Parameters</h3>
|
|
|
|
<table border="1" cellpadding="2" cellspacing="0">
|
|
|
|
<tr>
|
|
|
|
<td valign="top"><b>Attribute</b></td>
|
|
|
|
<td valign="top"><b>Description</b></td>
|
|
|
|
<td align="center" valign="top"><b>Required</b></td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td valign="top">name</td>
|
2004-05-26 12:25:20 +00:00
|
|
|
<td valign="top">The name of the element</td>
|
2003-08-14 12:48:10 +00:00
|
|
|
<td valign="top" align="center">Yes</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td valign="top">optional</td>
|
|
|
|
<td valign="top">
|
2003-08-15 09:33:45 +00:00
|
|
|
If true this nested element is optional. Default is
|
2003-08-14 12:48:10 +00:00
|
|
|
false - i.e the nested element is required in
|
|
|
|
the new task.
|
|
|
|
</td>
|
|
|
|
<td valign="top" align="center">No</td>
|
|
|
|
</tr>
|
2004-05-27 14:38:46 +00:00
|
|
|
<tr>
|
|
|
|
<td valign="top">implicit</td>
|
|
|
|
<td valign="top">
|
|
|
|
If true this nested element is implicit. This means that
|
|
|
|
any nested elements of the macrodef instance will be placed
|
|
|
|
in the element indicated by the name of this element.
|
|
|
|
There can only be one element if an element is implicit.
|
|
|
|
The default value is false. <em>since ant 1.6.2</em>
|
|
|
|
</td>
|
|
|
|
<td valign="top" align="center">No</td>
|
|
|
|
</tr>
|
2004-01-08 17:34:57 +00:00
|
|
|
<tr>
|
|
|
|
<td valign="top">description</td>
|
|
|
|
<td valign="top">
|
|
|
|
This contains a description
|
|
|
|
informing the user what the contents of the element are expected to be.
|
2004-01-22 16:33:16 +00:00
|
|
|
<em>since ant 1.6.1</em>
|
2004-01-08 17:34:57 +00:00
|
|
|
</td>
|
|
|
|
<td valign="top" align="center">No</td>
|
|
|
|
</tr>
|
2003-08-14 12:48:10 +00:00
|
|
|
</table>
|
2004-01-27 17:43:25 +00:00
|
|
|
<h4>text</h4>
|
|
|
|
<p>
|
|
|
|
This is used to specify the treatment of text contents of the macrodef.
|
|
|
|
If this element is not present, then any nested text in the macro
|
|
|
|
will be an error. If the text element is present, then the name
|
|
|
|
becomes an attribute that gets set to the nested text of the macro.
|
|
|
|
<em>Since ant 1.6.1.</em>
|
|
|
|
</p>
|
|
|
|
<p>
|
|
|
|
The case of the text name is ignored.
|
|
|
|
</p>
|
|
|
|
<h3>Parameters</h3>
|
|
|
|
<table border="1" cellpadding="2" cellspacing="0">
|
|
|
|
<tr>
|
|
|
|
<td valign="top"><b>Attribute</b></td>
|
|
|
|
<td valign="top"><b>Description</b></td>
|
|
|
|
<td align="center" valign="top"><b>Required</b></td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td valign="top">name</td>
|
|
|
|
<td valign="top">The name of the text attribute</td>
|
2004-04-20 15:42:34 +00:00
|
|
|
<td valign="top" align="center">Yes</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td valign="top">optional</td>
|
|
|
|
<td valign="top">
|
|
|
|
If true nested text in the macro is optional, default is "false".
|
|
|
|
</td>
|
|
|
|
<td valign="top" align="center">No</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td valign="top">trim</td>
|
|
|
|
<td valign="top">
|
|
|
|
If true, the nested text is trimmed of white space,
|
|
|
|
default is "false".
|
|
|
|
</td>
|
|
|
|
<td valign="top" align="center">No</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td valign="top">description</td>
|
|
|
|
<td valign="top">
|
|
|
|
This contains a description
|
|
|
|
informing the user what the nested text of the macro is expected
|
|
|
|
to be.
|
|
|
|
</td>
|
|
|
|
<td valign="top" align="center">No</td>
|
|
|
|
</tr>
|
|
|
|
</table>
|
2004-04-20 14:45:26 +00:00
|
|
|
|
2003-08-14 12:48:10 +00:00
|
|
|
<h3>Examples</h3>
|
|
|
|
<p>
|
|
|
|
The following example defined a task called testing and
|
|
|
|
runs it.
|
|
|
|
</p>
|
|
|
|
<blockquote>
|
2003-12-03 13:16:01 +00:00
|
|
|
<pre class=code>
|
2003-08-14 12:48:10 +00:00
|
|
|
<macrodef name="testing">
|
2003-08-15 09:33:45 +00:00
|
|
|
<attribute name="v" default="NOT SET"/>
|
2003-08-14 12:48:10 +00:00
|
|
|
<element name="some-tasks" optional="yes"/>
|
|
|
|
<sequential>
|
2003-12-03 13:16:01 +00:00
|
|
|
<echo>v is @{v}</echo>
|
2003-08-14 12:48:10 +00:00
|
|
|
<some-tasks/>
|
|
|
|
</sequential>
|
|
|
|
</macrodef>
|
|
|
|
|
|
|
|
<testing v="This is v">
|
|
|
|
<some-tasks>
|
|
|
|
<echo>this is a test</echo>
|
|
|
|
</some-tasks>
|
|
|
|
</testing>
|
2003-12-03 13:16:01 +00:00
|
|
|
</pre>
|
2003-08-14 12:48:10 +00:00
|
|
|
</blockquote>
|
|
|
|
<p>
|
|
|
|
The following fragment defines a task called <call-cc> which
|
|
|
|
take the attributes "target", "link" and "target.dir" and the
|
|
|
|
nested element "cc-elements". The body of the task
|
|
|
|
uses the <cc> task from the
|
|
|
|
<a href="http://ant-contrib.sourceforge.net/">ant-contrib</a> project.
|
|
|
|
</p>
|
|
|
|
<blockquote>
|
2003-12-03 13:16:01 +00:00
|
|
|
<pre class="code">
|
2003-08-14 12:48:10 +00:00
|
|
|
<macrodef name="call-cc">
|
2003-08-15 09:33:45 +00:00
|
|
|
<attribute name="target"/>
|
|
|
|
<attribute name="link"/>
|
|
|
|
<attribute name="target.dir"/>
|
2003-08-14 12:48:10 +00:00
|
|
|
<element name="cc-elements"/>
|
|
|
|
<sequential>
|
2003-12-03 13:16:01 +00:00
|
|
|
<mkdir dir="${obj.dir}/@{target}"/>
|
|
|
|
<mkdir dir="@{target.dir}"/>
|
|
|
|
<cc link="@{link}" objdir="${obj.dir}/@{target}"
|
|
|
|
outfile="@{target.dir}/@{target}">
|
2003-08-14 12:48:10 +00:00
|
|
|
<compiler refid="compiler.options"/>
|
|
|
|
<cc-elements/>
|
|
|
|
</cc>
|
|
|
|
</sequential>
|
|
|
|
</macrodef>
|
2003-12-03 13:16:01 +00:00
|
|
|
</pre>
|
2003-08-14 12:48:10 +00:00
|
|
|
</blockquote>
|
|
|
|
<p>
|
|
|
|
This then can be used as follows:
|
|
|
|
</p>
|
|
|
|
<blockquote>
|
2003-12-03 13:16:01 +00:00
|
|
|
<pre class="code">
|
2003-08-14 12:48:10 +00:00
|
|
|
<call-cc target="unittests" link="executable"
|
|
|
|
target.dir="${build.bin.dir}">
|
|
|
|
<cc-elements>
|
|
|
|
<includepath location="${gen.dir}"/>
|
|
|
|
<includepath location="test"/>
|
|
|
|
<fileset dir="test/unittest" includes = "**/*.cpp"/>
|
|
|
|
<fileset dir="${gen.dir}" includes = "*.cpp"/>
|
|
|
|
<linker refid="linker-libs"/>
|
|
|
|
</cc-elements>
|
|
|
|
</call-cc>
|
2004-05-27 14:38:46 +00:00
|
|
|
</pre>
|
|
|
|
</blockquote>
|
|
|
|
<p>
|
|
|
|
The following fragment shows <call-cc>, but this time
|
|
|
|
using an implicit element and with the link and target.dir arguments
|
|
|
|
having default values.
|
|
|
|
</p>
|
|
|
|
<blockquote>
|
|
|
|
<pre class="code">
|
|
|
|
<macrodef name="call-cc">
|
|
|
|
<attribute name="target"/>
|
|
|
|
<attribute name="link" default="executable"/>
|
|
|
|
<attribute name="target.dir" default="${build.bin.dir}"/>
|
|
|
|
<element name="cc-elements" implicit="yes"/>
|
|
|
|
<sequential>
|
|
|
|
<mkdir dir="${obj.dir}/@{target}"/>
|
|
|
|
<mkdir dir="@{target.dir}"/>
|
|
|
|
<cc link="@{link}" objdir="${obj.dir}/@{target}"
|
|
|
|
outfile="@{target.dir}/@{target}">
|
|
|
|
<compiler refid="compiler.options"/>
|
|
|
|
<cc-elements/>
|
|
|
|
</cc>
|
|
|
|
</sequential>
|
|
|
|
</macrodef>
|
|
|
|
</pre>
|
|
|
|
</blockquote>
|
|
|
|
<p>
|
|
|
|
This then can be used as follows, note that <cc-elements>
|
|
|
|
is not specified.
|
|
|
|
</p>
|
|
|
|
<blockquote>
|
|
|
|
<pre class="code">
|
|
|
|
<call-cc target="unittests"/>
|
|
|
|
<includepath location="${gen.dir}"/>
|
|
|
|
<includepath location="test"/>
|
|
|
|
<fileset dir="test/unittest" includes = "**/*.cpp"/>
|
|
|
|
<fileset dir="${gen.dir}" includes = "*.cpp"/>
|
|
|
|
<linker refid="linker-libs"/>
|
|
|
|
</call-cc>
|
2004-01-22 16:33:16 +00:00
|
|
|
</pre>
|
|
|
|
</blockquote>
|
|
|
|
<p>
|
2004-01-27 17:43:25 +00:00
|
|
|
The following shows the use of the <code>text</code> element.
|
2004-01-22 16:33:16 +00:00
|
|
|
</p>
|
|
|
|
<blockquote>
|
|
|
|
<pre class="code">
|
2004-01-27 17:43:25 +00:00
|
|
|
<macrodef name="echotest">
|
2004-05-07 18:00:43 +00:00
|
|
|
<text name="text"/>
|
2004-01-22 16:33:16 +00:00
|
|
|
<sequential>
|
|
|
|
<echo>@{text}</echo>
|
|
|
|
</sequential>
|
|
|
|
</macrodef>
|
|
|
|
<echotest>
|
|
|
|
Hello world
|
|
|
|
</echotest>
|
2004-04-20 14:45:26 +00:00
|
|
|
</pre>
|
|
|
|
</blockquote>
|
|
|
|
<p>
|
2004-04-20 15:26:39 +00:00
|
|
|
The following uses a prior defined attribute for setting the
|
2004-04-20 14:45:26 +00:00
|
|
|
default value of another. The output would be
|
|
|
|
<tt>one=test two=test</tt>. If you change the order of lines
|
|
|
|
*1 and *2 the output would be <tt>one=test two=@{one}</tt>,
|
|
|
|
because while processing the <i>two</i>-line the value for
|
|
|
|
<i>one</i> is not set.
|
|
|
|
</p>
|
|
|
|
<blockquote>
|
|
|
|
<pre class="code">
|
|
|
|
<macrodef name="test"/>
|
|
|
|
<attribute name="one"/> <b>*1</b>
|
|
|
|
<attribute name="two" default="@{one}"/> <b>*2</b>
|
|
|
|
<sequential>
|
|
|
|
<echo>one=@{one} two=@{two}</echo>
|
|
|
|
</sequential>
|
|
|
|
</macrodef/>
|
|
|
|
<test one="test"/>
|
2003-12-03 13:16:01 +00:00
|
|
|
</pre>
|
2003-08-14 12:48:10 +00:00
|
|
|
</blockquote>
|
|
|
|
<hr>
|
2004-04-20 15:42:34 +00:00
|
|
|
<p align="center">Copyright © 2003-2004 The Apache Software
|
2003-08-14 12:48:10 +00:00
|
|
|
Foundation. All rights Reserved.</p>
|
|
|
|
|
|
|
|
</body>
|
2004-05-07 18:00:43 +00:00
|
|
|
</html>
|