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.

task.html 9.0 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <!-- Content Stylesheet for Site -->
  3. <!-- start the processing -->
  4. <html>
  5. <head>
  6. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>
  7. <meta name="author" value="Peter Donald">
  8. <meta name="email" value="peter@apache.org">
  9. <title>Apache Myrmidon - My First Task</title>
  10. </head>
  11. <body bgcolor="#ffffff" text="#000000" link="#525D76">
  12. <table border="0" width="100%" cellspacing="0">
  13. <!-- TOP IMAGE -->
  14. <tr>
  15. <td> <td colspan="2">
  16. <a href="http://jakarta.apache.org"><img src="http://jakarta.apache.org/images/jakarta-logo.gif" align="left" border="0"/></a>
  17. </td>
  18. </td>
  19. <td valign="bottom"><div align="right"><b><font size="+3" color="#525D76">Apache Myrmidon</font></b></div></td>
  20. </tr>
  21. </table>
  22. <table border="0" width="100%" cellspacing="4">
  23. <tr><td colspan="2">
  24. <hr noshade="" size="1"/>
  25. </td></tr>
  26. <tr>
  27. <!-- LEFT SIDE NAVIGATION -->
  28. <td valign="top" nowrap="true">
  29. <p><strong>Myrmidon</strong></p>
  30. <ul>
  31. <li> <a href="./index.html">Introduction</a>
  32. </li>
  33. <li> <a href="./getinvolved.html">Get Involved</a>
  34. </li>
  35. <li> <a href="./user.html">Building Myrmidon</a>
  36. </li>
  37. <li> <a href="./todo.html">Todo List</a>
  38. </li>
  39. </ul>
  40. <p><strong>User Guide</strong></p>
  41. <ul>
  42. <li> <a href="./buildfile.html">Project File</a>
  43. </li>
  44. <li> <a href="./vfs.html">Virtual File System</a>
  45. </li>
  46. <li> <a href="./ant1compat.html">Ant 1 Compatibility Layer</a>
  47. </li>
  48. <li> <a href="./differences.html">Differences to Ant 1</a>
  49. </li>
  50. <li> <a href="./task.html">My First Task</a>
  51. </li>
  52. </ul>
  53. <p><strong>Extending Ant</strong></p>
  54. <ul>
  55. <li> <a href="./configuring.html">Configuration HOWTO</a>
  56. </li>
  57. <li> <a href="./converter.html">Converter HOWTO</a>
  58. </li>
  59. <li> <a href="./type.html">Type HOWTO</a>
  60. </li>
  61. <li> <a href="./classloader.html">ClassLoader HOWTO</a>
  62. </li>
  63. <li> <a href="./librarys.html">Library HOWTO</a>
  64. </li>
  65. </ul>
  66. <p><strong>Container Design</strong></p>
  67. <ul>
  68. </ul>
  69. </td>
  70. <td align="left" valign="top">
  71. <table border="0" cellspacing="0" cellpadding="2" width="100%">
  72. <tr><td bgcolor="#525D76">
  73. <font color="#ffffff" face="arial,helvetica,sanserif">
  74. <a name="My First Task"><strong>My First Task</strong></a>
  75. </font>
  76. </td></tr>
  77. <tr><td>
  78. <blockquote>
  79. <p>In Ant 1 it was very easy to write your own task. In Ant 2 we plan
  80. to make it even easier. To write a basic task simply follow the following
  81. formula.</p>
  82. <ol>
  83. <li>
  84. Create a Java class that extends
  85. <code>org.apache.myrmidon.api.AbstractTask</code>
  86. </li>
  87. <li>
  88. For each attribute, write a setter method. The setter method
  89. must be a public void method that takes a single argument. The name
  90. of the method must begin with "set", followed by the attribute name, with
  91. the first character of the name in uppercase, and the rest in lowercase.
  92. The type of the attribute can be:
  93. <ul>
  94. <li>String</li>
  95. <li>
  96. Any primitive type - they are converted for you from their
  97. String-representation in the buildfile
  98. </li>
  99. <li>
  100. File - the string representation will be interpreted relative to
  101. the project's basedir.
  102. </li>
  103. </ul>
  104. </li>
  105. <li>
  106. For each nested element create a public void method that takes a single
  107. argument. The name of the method must begin with "add", followed by the
  108. attribute name, with the first character of the name in uppercase, and
  109. the rest in lowercase. The type of the parameter is an object with a
  110. no-arguement constructor. It is configured in exactly the same was a
  111. task is configured (via setters and adders) and then added to the task.
  112. </li>
  113. <li>
  114. Write a public void method named "execute" with no arguments that
  115. throws a TaskException. This is the method called to do the
  116. actual work of the task.
  117. </li>
  118. </ol>
  119. <table border="0" cellspacing="0" cellpadding="2" width="100%">
  120. <tr><td bgcolor="#828DA6">
  121. <font color="#ffffff" face="arial,helvetica,sanserif">
  122. <a name="A Basic Example"><strong>A Basic Example</strong></a>
  123. </font>
  124. </td></tr>
  125. <tr><td>
  126. <blockquote>
  127. <p>So a basic task that has one attribute named "message" and just prints
  128. out this message is as simple as;</p>
  129. <div align="left">
  130. <table cellspacing="4" cellpadding="0" border="0">
  131. <tr>
  132. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  133. <td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  134. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  135. </tr>
  136. <tr>
  137. <td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  138. <td bgcolor="#ffffff"><pre>
  139. package org.realityforge.tasks;
  140. import org.apache.myrmidon.api.AbstractTask;
  141. import org.apache.myrmidon.api.TaskException;
  142. public class SystemOutPrinterTask
  143. extends Task
  144. {
  145. private String m_message;
  146. // The setter for the &quot;message&quot; attribute
  147. public void setMessage( final String message )
  148. {
  149. m_message = message;
  150. }
  151. // The method executing the task
  152. public void execute()
  153. throws TaskException
  154. {
  155. System.out.println( m_message );
  156. }
  157. }
  158. </pre></td>
  159. <td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  160. </tr>
  161. <tr>
  162. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  163. <td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  164. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  165. </tr>
  166. </table>
  167. </div>
  168. <p>To use this task you <em>could</em> create a library but instead we will
  169. just use &lt;taskdef&gt; to define the task. An example usage would be;</p>
  170. <div align="left">
  171. <table cellspacing="4" cellpadding="0" border="0">
  172. <tr>
  173. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  174. <td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  175. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  176. </tr>
  177. <tr>
  178. <td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  179. <td bgcolor="#ffffff"><pre>
  180. &lt;?xml version=&quot;1.0&quot;?&gt;
  181. &lt;project version=&quot;2.0&quot;&gt;
  182. &lt;target name=&quot;main&quot;&gt;
  183. &lt;taskdef name=&quot;printer&quot;
  184. classname=&quot;org.realityforge.tasks.SystemOutPrinterTask&quot;
  185. classpath=&quot;build/classes&quot;/&gt;
  186. &lt;printer message=&quot;Hello World!&quot;/&gt;
  187. &lt;/target&gt;
  188. &lt;/project&gt;
  189. </pre></td>
  190. <td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  191. </tr>
  192. <tr>
  193. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  194. <td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  195. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  196. </tr>
  197. </table>
  198. </div>
  199. </blockquote>
  200. </td></tr>
  201. </table>
  202. </blockquote>
  203. </td></tr>
  204. </table>
  205. </td>
  206. </tr>
  207. <!-- FOOTER -->
  208. <tr><td colspan="2">
  209. <hr noshade="" size="1"/>
  210. </td></tr>
  211. <tr><td colspan="2">
  212. <div align="center"><font color="#525D76" size="-1"><em>
  213. Copyright &#169; 2000-2002, Apache Software Foundation
  214. </em></font></div>
  215. </td></tr>
  216. </table>
  217. </body>
  218. </html>
  219. <!-- end the processing -->