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

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