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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  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 - Writing a 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">Build file</a>
  43. </li>
  44. <li> <a href="./vfs.html">Virtual File System</a>
  45. </li>
  46. </ul>
  47. <p><strong>Extending Ant</strong></p>
  48. <ul>
  49. <li> <a href="./task.html">Task Writers HOWTO</a>
  50. </li>
  51. <li> <a href="./classloader.html">ClassLoader HOWTO</a>
  52. </li>
  53. <li> <a href="./librarys.html">Library HOWTO</a>
  54. </li>
  55. </ul>
  56. <p><strong>Container Design</strong></p>
  57. <ul>
  58. </ul>
  59. </td>
  60. <td align="left" valign="top">
  61. <table border="0" cellspacing="0" cellpadding="2" width="100%">
  62. <tr><td bgcolor="#525D76">
  63. <font color="#ffffff" face="arial,helvetica,sanserif">
  64. <a name="Writing a Task"><strong>Writing a Task</strong></a>
  65. </font>
  66. </td></tr>
  67. <tr><td>
  68. <blockquote>
  69. <p>In ant1 it was very easy to write your own task. In Ant2 we plan
  70. to make it even easier. To write a basic task simply follow the following
  71. formula.</p>
  72. <ol>
  73. <li>
  74. Create a Java class that extends
  75. <code>org.apache.myrmidon.api.AbstractTask</code>
  76. </li>
  77. <li>
  78. For each attribute, write a setter method. The setter method
  79. must be a public void method that takes a single argument. The name
  80. of the method must begin with "set", followed by the attribute name, with
  81. the first character of the name in uppercase, and the rest in lowercase.
  82. The type of the attribute can be:
  83. <ul>
  84. <li>String</li>
  85. <li>
  86. Any primitive type - they are converted for you from their
  87. String-representation in the buildfile
  88. </li>
  89. <li>
  90. File - the string representation will be interpreted relative to
  91. the project's basedir.
  92. </li>
  93. </ul>
  94. </li>
  95. <li>
  96. For each nested element create a public void method that takes a single
  97. argument. The name of the method must begin with "add", followed by the
  98. attribute name, with the first character of the name in uppercase, and
  99. the rest in lowercase. The type of the parameter is an object with a
  100. no-arguement constructor. It is configured in exactly the same was a
  101. task is configured (via setters and adders) and then added to the task.
  102. </li>
  103. <li>
  104. Write a public void method named "execute" with no arguments that
  105. throws a TaskException. This is the method called to do the
  106. actual work of the task.
  107. </li>
  108. </ol>
  109. <table border="0" cellspacing="0" cellpadding="2" width="100%">
  110. <tr><td bgcolor="#828DA6">
  111. <font color="#ffffff" face="arial,helvetica,sanserif">
  112. <a name="A Basic Example"><strong>A Basic Example</strong></a>
  113. </font>
  114. </td></tr>
  115. <tr><td>
  116. <blockquote>
  117. <p>So a basic task that has one attribute named "message" and just prints
  118. out this message is as simple as;</p>
  119. <div align="left">
  120. <table cellspacing="4" cellpadding="0" border="0">
  121. <tr>
  122. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  123. <td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  124. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  125. </tr>
  126. <tr>
  127. <td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  128. <td bgcolor="#ffffff"><pre>
  129. package org.realityforge.tasks;
  130. import org.apache.myrmidon.api.AbstractTask;
  131. import org.apache.myrmidon.api.TaskException;
  132. public class SystemOutPrinterTask
  133. extends Task
  134. {
  135. private String m_message;
  136. // The setter for the &quot;message&quot; attribute
  137. public void setMessage( final String message )
  138. {
  139. m_message = message;
  140. }
  141. // The method executing the task
  142. public void execute()
  143. throws TaskException
  144. {
  145. System.out.println( m_message );
  146. }
  147. }
  148. </pre></td>
  149. <td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  150. </tr>
  151. <tr>
  152. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  153. <td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  154. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  155. </tr>
  156. </table>
  157. </div>
  158. <p>To use this task you <em>could</em> create a library but instead we will
  159. just use &lt;taskdef&gt; to define the task. An example usage would be;</p>
  160. <div align="left">
  161. <table cellspacing="4" cellpadding="0" border="0">
  162. <tr>
  163. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  164. <td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  165. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  166. </tr>
  167. <tr>
  168. <td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  169. <td bgcolor="#ffffff"><pre>
  170. &lt;?xml version=&quot;1.0&quot;?&gt;
  171. &lt;project version=&quot;2.0&quot;&gt;
  172. &lt;target name=&quot;main&quot;&gt;
  173. &lt;taskdef name=&quot;printer&quot;
  174. classname=&quot;org.realityforge.tasks.SystemOutPrinterTask&quot;
  175. classpath=&quot;build/classes&quot;/&gt;
  176. &lt;printer message=&quot;Hello World!&quot;/&gt;
  177. &lt;/target&gt;
  178. &lt;/project&gt;
  179. </pre></td>
  180. <td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  181. </tr>
  182. <tr>
  183. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  184. <td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  185. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  186. </tr>
  187. </table>
  188. </div>
  189. </blockquote>
  190. </td></tr>
  191. </table>
  192. </blockquote>
  193. </td></tr>
  194. </table>
  195. </td>
  196. </tr>
  197. <!-- FOOTER -->
  198. <tr><td colspan="2">
  199. <hr noshade="" size="1"/>
  200. </td></tr>
  201. <tr><td colspan="2">
  202. <div align="center"><font color="#525D76" size="-1"><em>
  203. Copyright &#169; 2000-2002, Apache Software Foundation
  204. </em></font></div>
  205. </td></tr>
  206. </table>
  207. </body>
  208. </html>
  209. <!-- end the processing -->