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.5 KiB

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