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

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