You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

macrodef.html 5.7 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. <html>
  2. <head>
  3. <meta http-equiv="Content-Language" content="en-us"></meta>
  4. <title>MacroDef Task</title>
  5. <style type="text/css">
  6. <!--
  7. .code { background: #EFEFEF; margin-top: }
  8. -->
  9. </style>
  10. </head>
  11. <body>
  12. <h2><a name="macrodef">MacroDef</a></h2>
  13. <h3>Description</h3>
  14. <p>
  15. This defines a new task using a &lt;sequential&gt;
  16. nested task as a template. Nested elements &lt;attribute&gt; and
  17. &lt;element&gt; are used to specify attributes and elements of
  18. the new task. These get substituted into the &lt;sequential&gt;
  19. task when the new task is run.
  20. </p>
  21. <p>
  22. <em>since Ant 1.6</em>
  23. </p>
  24. <h3>Parameters</h3>
  25. <table border="1" cellpadding="2" cellspacing="0">
  26. <tr>
  27. <td valign="top"><b>Attribute</b></td>
  28. <td valign="top"><b>Description</b></td>
  29. <td align="center" valign="top"><b>Required</b></td>
  30. </tr>
  31. <tr>
  32. <td valign="top">name</td>
  33. <td valign="top">The name of the new definition</td>
  34. <td valign="top" align="center">Yes</td>
  35. </tr>
  36. <tr>
  37. <td valign="top">uri</td>
  38. <td valign="top">
  39. The uri that this definition should live in.
  40. </td>
  41. <td valign="top" align="center">No</td>
  42. </tr>
  43. </table>
  44. <h3>Parameters specified as nested elements</h3>
  45. <h4>attribute</h4>
  46. <p>
  47. This is used to specify attributes of the new task. The values
  48. of the attributes get substituted into the templated task.
  49. The attributes will be required attributes unless a default
  50. value has been set.
  51. </p>
  52. <p>
  53. This attribute is placed in the body of the templated
  54. task using a notation similar to the ant property notation
  55. - @{attribute name}. (May be remembered as "put the substitution
  56. AT this location").
  57. The escape sequence @@{x} is used to allow @{x} to be
  58. placed in the text without substitution of x.
  59. This corresponds to the $${x} escape sequence for properties
  60. </p>
  61. <h3>Parameters</h3>
  62. <table border="1" cellpadding="2" cellspacing="0">
  63. <tr>
  64. <td valign="top"><b>Attribute</b></td>
  65. <td valign="top"><b>Description</b></td>
  66. <td align="center" valign="top"><b>Required</b></td>
  67. </tr>
  68. <tr>
  69. <td valign="top">name</td>
  70. <td valign="top">The name of the new attribute</td>
  71. <td valign="top" align="center">Yes</td>
  72. </tr>
  73. <tr>
  74. <td valign="top">default</td>
  75. <td valign="top">
  76. The default value of the attribute.
  77. </td>
  78. <td valign="top" align="center">No</td>
  79. </tr>
  80. </table>
  81. <h4>element</h4>
  82. <p>
  83. This is used to specify nested elements of the new task.
  84. The contents of the nested elements of the task instance
  85. are placed in the templated task at the tag name.
  86. </p>
  87. <h3>Parameters</h3>
  88. <table border="1" cellpadding="2" cellspacing="0">
  89. <tr>
  90. <td valign="top"><b>Attribute</b></td>
  91. <td valign="top"><b>Description</b></td>
  92. <td align="center" valign="top"><b>Required</b></td>
  93. </tr>
  94. <tr>
  95. <td valign="top">name</td>
  96. <td valign="top">The name of the new attribute</td>
  97. <td valign="top" align="center">Yes</td>
  98. </tr>
  99. <tr>
  100. <td valign="top">optional</td>
  101. <td valign="top">
  102. If true this nested element is optional. Default is
  103. false - i.e the nested element is required in
  104. the new task.
  105. </td>
  106. <td valign="top" align="center">No</td>
  107. </tr>
  108. </table>
  109. <h3>Examples</h3>
  110. <p>
  111. The following example defined a task called testing and
  112. runs it.
  113. </p>
  114. <blockquote>
  115. <pre class=code>
  116. &lt;macrodef name="testing"&gt;
  117. &lt;attribute name="v" default="NOT SET"/&gt;
  118. &lt;element name="some-tasks" optional="yes"/&gt;
  119. &lt;sequential&gt;
  120. &lt;echo&gt;v is @{v}&lt;/echo&gt;
  121. &lt;some-tasks/&gt;
  122. &lt;/sequential&gt;
  123. &lt;/macrodef&gt;
  124. &lt;testing v="This is v"&gt;
  125. &lt;some-tasks&gt;
  126. &lt;echo&gt;this is a test&lt;/echo&gt;
  127. &lt;/some-tasks&gt;
  128. &lt;/testing&gt;
  129. </pre>
  130. </blockquote>
  131. <p>
  132. The following fragment defines a task called &lt;call-cc&gt; which
  133. take the attributes "target", "link" and "target.dir" and the
  134. nested element "cc-elements". The body of the task
  135. uses the &lt;cc&gt; task from the
  136. <a href="http://ant-contrib.sourceforge.net/">ant-contrib</a> project.
  137. </p>
  138. <blockquote>
  139. <pre class="code">
  140. &lt;macrodef name="call-cc"&gt;
  141. &lt;attribute name="target"/&gt;
  142. &lt;attribute name="link"/&gt;
  143. &lt;attribute name="target.dir"/&gt;
  144. &lt;element name="cc-elements"/&gt;
  145. &lt;sequential&gt;
  146. &lt;mkdir dir="${obj.dir}/@{target}"/&gt;
  147. &lt;mkdir dir="@{target.dir}"/&gt;
  148. &lt;cc link="@{link}" objdir="${obj.dir}/@{target}"
  149. outfile="@{target.dir}/@{target}"&gt;
  150. &lt;compiler refid="compiler.options"/&gt;
  151. &lt;cc-elements/&gt;
  152. &lt;/cc&gt;
  153. &lt;/sequential&gt;
  154. &lt;/macrodef&gt;
  155. </pre>
  156. </blockquote>
  157. <p>
  158. This then can be used as follows:
  159. </p>
  160. <blockquote>
  161. <pre class="code">
  162. &lt;call-cc target="unittests" link="executable"
  163. target.dir="${build.bin.dir}"&gt;
  164. &lt;cc-elements&gt;
  165. &lt;includepath location="${gen.dir}"/&gt;
  166. &lt;includepath location="test"/&gt;
  167. &lt;fileset dir="test/unittest" includes = "**/*.cpp"/&gt;
  168. &lt;fileset dir="${gen.dir}" includes = "*.cpp"/&gt;
  169. &lt;linker refid="linker-libs"/&gt;
  170. &lt;/cc-elements&gt;
  171. &lt;/call-cc&gt;
  172. </pre>
  173. </blockquote>
  174. <hr>
  175. <p align="center">Copyright &copy; 2003 Apache Software
  176. Foundation. All rights Reserved.</p>
  177. </body>
  178. </html>