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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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;param&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. </table>
  39. <h3>Parameters specified as nested elements</h3>
  40. <h4>param</h4>
  41. <p>
  42. This is used to specify attributes of the new task. The values
  43. of the attributes get substituted into the templated task.
  44. The attributes will be required attributes unless a default
  45. value has been set.
  46. </p>
  47. <p>
  48. This attribute is placed in the body of the templated
  49. task using the ant property notation - ${attribute name}.
  50. Note that is not an actual ant property.
  51. </p>
  52. <h3>Parameters</h3>
  53. <table border="1" cellpadding="2" cellspacing="0">
  54. <tr>
  55. <td valign="top"><b>Attribute</b></td>
  56. <td valign="top"><b>Description</b></td>
  57. <td align="center" valign="top"><b>Required</b></td>
  58. </tr>
  59. <tr>
  60. <td valign="top">name</td>
  61. <td valign="top">the name of the new attribute</td>
  62. <td valign="top" align="center">Yes</td>
  63. </tr>
  64. <tr>
  65. <td valign="top">default</td>
  66. <td valign="top">
  67. the default value of the attribute.
  68. </td>
  69. <td valign="top" align="center">No</td>
  70. </tr>
  71. </table>
  72. <h4>element</h4>
  73. <p>
  74. This is used to specify nested elements of the new task.
  75. The contents of the nested elements of the task instance
  76. are placed in the templated task at the tag name.
  77. </p>
  78. <h3>Parameters</h3>
  79. <table border="1" cellpadding="2" cellspacing="0">
  80. <tr>
  81. <td valign="top"><b>Attribute</b></td>
  82. <td valign="top"><b>Description</b></td>
  83. <td align="center" valign="top"><b>Required</b></td>
  84. </tr>
  85. <tr>
  86. <td valign="top">name</td>
  87. <td valign="top">the name of the new attribute</td>
  88. <td valign="top" align="center">Yes</td>
  89. </tr>
  90. <tr>
  91. <td valign="top">optional</td>
  92. <td valign="top">
  93. if true this nested element is optional. Default is
  94. false - i.e the nested element is required in
  95. the new task.
  96. </td>
  97. <td valign="top" align="center">No</td>
  98. </tr>
  99. </table>
  100. <h3>Examples</h3>
  101. <p>
  102. The following example defined a task called testing and
  103. runs it.
  104. </p>
  105. <blockquote>
  106. <pre>
  107. &lt;macrodef name="testing"&gt;
  108. &lt;param name="v" default="NOT SET"/&gt;
  109. &lt;element name="some-tasks" optional="yes"/&gt;
  110. &lt;sequential&gt;
  111. &lt;echo&gt;v is ${v}&lt;/echo&gt;
  112. &lt;some-tasks/&gt;
  113. &lt;/sequential&gt;
  114. &lt;/macrodef&gt;
  115. &lt;testing v="This is v"&gt;
  116. &lt;some-tasks&gt;
  117. &lt;echo&gt;this is a test&lt;/echo&gt;
  118. &lt;/some-tasks&gt;
  119. &lt;/testing&gt;
  120. </pre>
  121. </blockquote>
  122. <p>
  123. The following fragment defines a task called &lt;call-cc&gt; which
  124. take the attributes "target", "link" and "target.dir" and the
  125. nested element "cc-elements". The body of the task
  126. uses the &lt;cc&gt; task from the
  127. <a href="http://ant-contrib.sourceforge.net/">ant-contrib</a> project.
  128. </p>
  129. <blockquote>
  130. <pre>
  131. &lt;macrodef name="call-cc"&gt;
  132. &lt;param name="target"/&gt;
  133. &lt;param name="link"/&gt;
  134. &lt;param name="target.dir"/&gt;
  135. &lt;element name="cc-elements"/&gt;
  136. &lt;sequential&gt;
  137. &lt;mkdir dir="${obj.dir}/${target}"/&gt;
  138. &lt;mkdir dir="${target.dir}"/&gt;
  139. &lt;cc link="${link}" objdir="${obj.dir}/${target}"
  140. outfile="${target.dir}/${target}"&gt;
  141. &lt;compiler refid="compiler.options"/&gt;
  142. &lt;cc-elements/&gt;
  143. &lt;/cc&gt;
  144. &lt;/sequential&gt;
  145. &lt;/macrodef&gt;
  146. </pre>
  147. </blockquote>
  148. <p>
  149. This then can be used as follows:
  150. </p>
  151. <blockquote>
  152. <pre>
  153. &lt;call-cc target="unittests" link="executable"
  154. target.dir="${build.bin.dir}"&gt;
  155. &lt;cc-elements&gt;
  156. &lt;includepath location="${gen.dir}"/&gt;
  157. &lt;includepath location="test"/&gt;
  158. &lt;fileset dir="test/unittest" includes = "**/*.cpp"/&gt;
  159. &lt;fileset dir="${gen.dir}" includes = "*.cpp"/&gt;
  160. &lt;linker refid="linker-libs"/&gt;
  161. &lt;/cc-elements&gt;
  162. &lt;/call-cc&gt;
  163. </pre>
  164. </blockquote>
  165. <hr>
  166. <p align="center">Copyright &copy; 2003 Apache Software
  167. Foundation. All rights Reserved.</p>
  168. </body>
  169. </html>