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 kB

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