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 7.3 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  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. <tr>
  44. <td valign="top">textname</td>
  45. <td valign="top">
  46. The textname attribute value becomes a macrodef
  47. attribute that
  48. gets set to the value of the text contents of the macro.
  49. <em>since ant 1.6.1</em>
  50. </td>
  51. <td valign="top" align="center">No</td>
  52. </tr>
  53. </table>
  54. <h3>Parameters specified as nested elements</h3>
  55. <h4>attribute</h4>
  56. <p>
  57. This is used to specify attributes of the new task. The values
  58. of the attributes get substituted into the templated task.
  59. The attributes will be required attributes unless a default
  60. value has been set.
  61. </p>
  62. <p>
  63. This attribute is placed in the body of the templated
  64. task using a notation similar to the ant property notation
  65. - @{attribute name}. (May be remembered as "put the substitution
  66. AT this location").
  67. The escape sequence @@{x} is used to allow @{x} to be
  68. placed in the text without substitution of x.
  69. This corresponds to the $${x} escape sequence for properties.
  70. </p>
  71. <p>
  72. The case of the attribute is ignored, so @{myAttribute} is treated the
  73. same as @{MyAttribute}.
  74. </p>
  75. <h3>Parameters</h3>
  76. <table border="1" cellpadding="2" cellspacing="0">
  77. <tr>
  78. <td valign="top"><b>Attribute</b></td>
  79. <td valign="top"><b>Description</b></td>
  80. <td align="center" valign="top"><b>Required</b></td>
  81. </tr>
  82. <tr>
  83. <td valign="top">name</td>
  84. <td valign="top">The name of the new attribute</td>
  85. <td valign="top" align="center">Yes</td>
  86. </tr>
  87. <tr>
  88. <td valign="top">default</td>
  89. <td valign="top">
  90. The default value of the attribute.
  91. </td>
  92. <td valign="top" align="center">No</td>
  93. </tr>
  94. <tr>
  95. <td valign="top">description</td>
  96. <td valign="top">
  97. This contains a description of the attribute.
  98. <em>since ant 1.6.1</em>
  99. </td>
  100. <td valign="top" align="center">No</td>
  101. </tr>
  102. </table>
  103. <h4>element</h4>
  104. <p>
  105. This is used to specify nested elements of the new task.
  106. The contents of the nested elements of the task instance
  107. are placed in the templated task at the tag name.
  108. </p>
  109. <p>
  110. The case of the element name is ignored.
  111. </p>
  112. <h3>Parameters</h3>
  113. <table border="1" cellpadding="2" cellspacing="0">
  114. <tr>
  115. <td valign="top"><b>Attribute</b></td>
  116. <td valign="top"><b>Description</b></td>
  117. <td align="center" valign="top"><b>Required</b></td>
  118. </tr>
  119. <tr>
  120. <td valign="top">name</td>
  121. <td valign="top">The name of the new attribute</td>
  122. <td valign="top" align="center">Yes</td>
  123. </tr>
  124. <tr>
  125. <td valign="top">optional</td>
  126. <td valign="top">
  127. If true this nested element is optional. Default is
  128. false - i.e the nested element is required in
  129. the new task.
  130. </td>
  131. <td valign="top" align="center">No</td>
  132. </tr>
  133. <tr>
  134. <td valign="top">description</td>
  135. <td valign="top">
  136. This contains a description
  137. informing the user what the contents of the element are expected to be.
  138. <em>since ant 1.6.1</em>
  139. </td>
  140. <td valign="top" align="center">No</td>
  141. </tr>
  142. </table>
  143. <h3>Examples</h3>
  144. <p>
  145. The following example defined a task called testing and
  146. runs it.
  147. </p>
  148. <blockquote>
  149. <pre class=code>
  150. &lt;macrodef name="testing"&gt;
  151. &lt;attribute name="v" default="NOT SET"/&gt;
  152. &lt;element name="some-tasks" optional="yes"/&gt;
  153. &lt;sequential&gt;
  154. &lt;echo&gt;v is @{v}&lt;/echo&gt;
  155. &lt;some-tasks/&gt;
  156. &lt;/sequential&gt;
  157. &lt;/macrodef&gt;
  158. &lt;testing v="This is v"&gt;
  159. &lt;some-tasks&gt;
  160. &lt;echo&gt;this is a test&lt;/echo&gt;
  161. &lt;/some-tasks&gt;
  162. &lt;/testing&gt;
  163. </pre>
  164. </blockquote>
  165. <p>
  166. The following fragment defines a task called &lt;call-cc&gt; which
  167. take the attributes "target", "link" and "target.dir" and the
  168. nested element "cc-elements". The body of the task
  169. uses the &lt;cc&gt; task from the
  170. <a href="http://ant-contrib.sourceforge.net/">ant-contrib</a> project.
  171. </p>
  172. <blockquote>
  173. <pre class="code">
  174. &lt;macrodef name="call-cc"&gt;
  175. &lt;attribute name="target"/&gt;
  176. &lt;attribute name="link"/&gt;
  177. &lt;attribute name="target.dir"/&gt;
  178. &lt;element name="cc-elements"/&gt;
  179. &lt;sequential&gt;
  180. &lt;mkdir dir="${obj.dir}/@{target}"/&gt;
  181. &lt;mkdir dir="@{target.dir}"/&gt;
  182. &lt;cc link="@{link}" objdir="${obj.dir}/@{target}"
  183. outfile="@{target.dir}/@{target}"&gt;
  184. &lt;compiler refid="compiler.options"/&gt;
  185. &lt;cc-elements/&gt;
  186. &lt;/cc&gt;
  187. &lt;/sequential&gt;
  188. &lt;/macrodef&gt;
  189. </pre>
  190. </blockquote>
  191. <p>
  192. This then can be used as follows:
  193. </p>
  194. <blockquote>
  195. <pre class="code">
  196. &lt;call-cc target="unittests" link="executable"
  197. target.dir="${build.bin.dir}"&gt;
  198. &lt;cc-elements&gt;
  199. &lt;includepath location="${gen.dir}"/&gt;
  200. &lt;includepath location="test"/&gt;
  201. &lt;fileset dir="test/unittest" includes = "**/*.cpp"/&gt;
  202. &lt;fileset dir="${gen.dir}" includes = "*.cpp"/&gt;
  203. &lt;linker refid="linker-libs"/&gt;
  204. &lt;/cc-elements&gt;
  205. &lt;/call-cc&gt;
  206. </pre>
  207. </blockquote>
  208. <p>
  209. The following shows the use of the <code>textname</code> attribute.
  210. </p>
  211. <blockquote>
  212. <pre class="code">
  213. &lt;macrodef name="echotest" textname="text"&gt;
  214. &lt;sequential&gt;
  215. &lt;echo&gt;@{text}&lt;/echo&gt;
  216. &lt;/sequential&gt;
  217. &lt;/macrodef&gt;
  218. &lt;echotest&gt;
  219. Hello world
  220. &lt;/echotest&gt;
  221. </pre>
  222. </blockquote>
  223. <hr>
  224. <p align="center">Copyright &copy; 2003-2004 Apache Software
  225. Foundation. All rights Reserved.</p>
  226. </body>
  227. </html>