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 6.4 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  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. <p>
  62. The case of the attribute is ignored, so @{myAttribute} is treated the
  63. same as @{MyAttribute}.
  64. </p>
  65. <h3>Parameters</h3>
  66. <table border="1" cellpadding="2" cellspacing="0">
  67. <tr>
  68. <td valign="top"><b>Attribute</b></td>
  69. <td valign="top"><b>Description</b></td>
  70. <td align="center" valign="top"><b>Required</b></td>
  71. </tr>
  72. <tr>
  73. <td valign="top">name</td>
  74. <td valign="top">The name of the new attribute</td>
  75. <td valign="top" align="center">Yes</td>
  76. </tr>
  77. <tr>
  78. <td valign="top">default</td>
  79. <td valign="top">
  80. The default value of the attribute.
  81. </td>
  82. <td valign="top" align="center">No</td>
  83. </tr>
  84. <tr>
  85. <td valign="top">description</td>
  86. <td valign="top">
  87. This contains a description of the attribute.
  88. </td>
  89. <td valign="top" align="center">No</td>
  90. </tr>
  91. </table>
  92. <h4>element</h4>
  93. <p>
  94. This is used to specify nested elements of the new task.
  95. The contents of the nested elements of the task instance
  96. are placed in the templated task at the tag name.
  97. </p>
  98. <p>
  99. The case of the element name is ignored.
  100. </p>
  101. <h3>Parameters</h3>
  102. <table border="1" cellpadding="2" cellspacing="0">
  103. <tr>
  104. <td valign="top"><b>Attribute</b></td>
  105. <td valign="top"><b>Description</b></td>
  106. <td align="center" valign="top"><b>Required</b></td>
  107. </tr>
  108. <tr>
  109. <td valign="top">name</td>
  110. <td valign="top">The name of the new attribute</td>
  111. <td valign="top" align="center">Yes</td>
  112. </tr>
  113. <tr>
  114. <td valign="top">optional</td>
  115. <td valign="top">
  116. If true this nested element is optional. Default is
  117. false - i.e the nested element is required in
  118. the new task.
  119. </td>
  120. <td valign="top" align="center">No</td>
  121. </tr>
  122. <tr>
  123. <td valign="top">description</td>
  124. <td valign="top">
  125. This contains a description
  126. informing the user what the contents of the element are expected to be.
  127. </td>
  128. <td valign="top" align="center">No</td>
  129. </tr>
  130. </table>
  131. <h3>Examples</h3>
  132. <p>
  133. The following example defined a task called testing and
  134. runs it.
  135. </p>
  136. <blockquote>
  137. <pre class=code>
  138. &lt;macrodef name="testing"&gt;
  139. &lt;attribute name="v" default="NOT SET"/&gt;
  140. &lt;element name="some-tasks" optional="yes"/&gt;
  141. &lt;sequential&gt;
  142. &lt;echo&gt;v is @{v}&lt;/echo&gt;
  143. &lt;some-tasks/&gt;
  144. &lt;/sequential&gt;
  145. &lt;/macrodef&gt;
  146. &lt;testing v="This is v"&gt;
  147. &lt;some-tasks&gt;
  148. &lt;echo&gt;this is a test&lt;/echo&gt;
  149. &lt;/some-tasks&gt;
  150. &lt;/testing&gt;
  151. </pre>
  152. </blockquote>
  153. <p>
  154. The following fragment defines a task called &lt;call-cc&gt; which
  155. take the attributes "target", "link" and "target.dir" and the
  156. nested element "cc-elements". The body of the task
  157. uses the &lt;cc&gt; task from the
  158. <a href="http://ant-contrib.sourceforge.net/">ant-contrib</a> project.
  159. </p>
  160. <blockquote>
  161. <pre class="code">
  162. &lt;macrodef name="call-cc"&gt;
  163. &lt;attribute name="target"/&gt;
  164. &lt;attribute name="link"/&gt;
  165. &lt;attribute name="target.dir"/&gt;
  166. &lt;element name="cc-elements"/&gt;
  167. &lt;sequential&gt;
  168. &lt;mkdir dir="${obj.dir}/@{target}"/&gt;
  169. &lt;mkdir dir="@{target.dir}"/&gt;
  170. &lt;cc link="@{link}" objdir="${obj.dir}/@{target}"
  171. outfile="@{target.dir}/@{target}"&gt;
  172. &lt;compiler refid="compiler.options"/&gt;
  173. &lt;cc-elements/&gt;
  174. &lt;/cc&gt;
  175. &lt;/sequential&gt;
  176. &lt;/macrodef&gt;
  177. </pre>
  178. </blockquote>
  179. <p>
  180. This then can be used as follows:
  181. </p>
  182. <blockquote>
  183. <pre class="code">
  184. &lt;call-cc target="unittests" link="executable"
  185. target.dir="${build.bin.dir}"&gt;
  186. &lt;cc-elements&gt;
  187. &lt;includepath location="${gen.dir}"/&gt;
  188. &lt;includepath location="test"/&gt;
  189. &lt;fileset dir="test/unittest" includes = "**/*.cpp"/&gt;
  190. &lt;fileset dir="${gen.dir}" includes = "*.cpp"/&gt;
  191. &lt;linker refid="linker-libs"/&gt;
  192. &lt;/cc-elements&gt;
  193. &lt;/call-cc&gt;
  194. </pre>
  195. </blockquote>
  196. <hr>
  197. <p align="center">Copyright &copy; 2003-2004 Apache Software
  198. Foundation. All rights Reserved.</p>
  199. </body>
  200. </html>