|
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
-
- <!-- Content Stylesheet for Site -->
-
-
- <!-- start the processing -->
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>
-
- <meta name="author" value="Peter Donald">
- <meta name="email" value="peter@apache.org">
-
- <title>Apache Myrmidon - Writing a task</title>
- </head>
-
- <body bgcolor="#ffffff" text="#000000" link="#525D76">
- <table border="0" width="100%" cellspacing="0">
- <!-- TOP IMAGE -->
- <tr>
- <td> <td colspan="2">
- <a href="http://jakarta.apache.org"><img src="http://jakarta.apache.org/images/jakarta-logo.gif" align="left" border="0"/></a>
- </td>
- </td>
- <td valign="bottom"><div align="right"><b><font size="+3" color="#525D76">Apache Myrmidon</font></b></div></td>
- </tr>
- </table>
- <table border="0" width="100%" cellspacing="4">
- <tr><td colspan="2">
- <hr noshade="" size="1"/>
- </td></tr>
-
- <tr>
- <!-- LEFT SIDE NAVIGATION -->
- <td valign="top" nowrap="true">
- <p><strong>Myrmidon</strong></p>
- <ul>
- <li> <a href="./index.html">Introduction</a>
- </li>
- <li> <a href="./getinvolved.html">Get Involved</a>
- </li>
- <li> <a href="./user.html">Building Myrmidon</a>
- </li>
- <li> <a href="./todo.html">Todo List</a>
- </li>
- </ul>
- <p><strong>User Guide</strong></p>
- <ul>
- <li> <a href="./buildfile.html">Build file</a>
- </li>
- <li> <a href="./vfs.html">Virtual File System</a>
- </li>
- <li> <a href="./ant1compat.html">Ant1 Compatibility Layer</a>
- </li>
- <li> <a href="./differences.html">Differences to Ant1</a>
- </li>
- </ul>
- <p><strong>Extending Ant</strong></p>
- <ul>
- <li> <a href="./task.html">Task Writers HOWTO</a>
- </li>
- <li> <a href="./classloader.html">ClassLoader HOWTO</a>
- </li>
- <li> <a href="./librarys.html">Library HOWTO</a>
- </li>
- </ul>
- <p><strong>Container Design</strong></p>
- <ul>
- </ul>
- </td>
- <td align="left" valign="top">
- <table border="0" cellspacing="0" cellpadding="2" width="100%">
- <tr><td bgcolor="#525D76">
- <font color="#ffffff" face="arial,helvetica,sanserif">
- <a name="Writing a Task"><strong>Writing a Task</strong></a>
- </font>
- </td></tr>
- <tr><td>
- <blockquote>
- <p>In ant1 it was very easy to write your own task. In Ant2 we plan
- to make it even easier. To write a basic task simply follow the following
- formula.</p>
- <ol>
- <li>
- Create a Java class that extends
- <code>org.apache.myrmidon.api.AbstractTask</code>
- </li>
- <li>
- For each attribute, write a setter method. The setter method
- must be a public void method that takes a single argument. The name
- of the method must begin with "set", followed by the attribute name, with
- the first character of the name in uppercase, and the rest in lowercase.
- The type of the attribute can be:
- <ul>
- <li>String</li>
- <li>
- Any primitive type - they are converted for you from their
- String-representation in the buildfile
- </li>
- <li>
- File - the string representation will be interpreted relative to
- the project's basedir.
- </li>
- </ul>
- </li>
- <li>
- For each nested element create a public void method that takes a single
- argument. The name of the method must begin with "add", followed by the
- attribute name, with the first character of the name in uppercase, and
- the rest in lowercase. The type of the parameter is an object with a
- no-arguement constructor. It is configured in exactly the same was a
- task is configured (via setters and adders) and then added to the task.
- </li>
- <li>
- Write a public void method named "execute" with no arguments that
- throws a TaskException. This is the method called to do the
- actual work of the task.
- </li>
- </ol>
- <table border="0" cellspacing="0" cellpadding="2" width="100%">
- <tr><td bgcolor="#828DA6">
- <font color="#ffffff" face="arial,helvetica,sanserif">
- <a name="A Basic Example"><strong>A Basic Example</strong></a>
- </font>
- </td></tr>
- <tr><td>
- <blockquote>
- <p>So a basic task that has one attribute named "message" and just prints
- out this message is as simple as;</p>
- <div align="left">
- <table cellspacing="4" cellpadding="0" border="0">
- <tr>
- <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
- <td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
- <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
- </tr>
- <tr>
- <td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
- <td bgcolor="#ffffff"><pre>
- package org.realityforge.tasks;
-
- import org.apache.myrmidon.api.AbstractTask;
- import org.apache.myrmidon.api.TaskException;
-
- public class SystemOutPrinterTask
- extends Task
- {
- private String m_message;
-
- // The setter for the "message" attribute
- public void setMessage( final String message )
- {
- m_message = message;
- }
-
- // The method executing the task
- public void execute()
- throws TaskException
- {
- System.out.println( m_message );
- }
- }
- </pre></td>
- <td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
- </tr>
- <tr>
- <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
- <td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
- <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
- </tr>
- </table>
- </div>
- <p>To use this task you <em>could</em> create a library but instead we will
- just use <taskdef> to define the task. An example usage would be;</p>
- <div align="left">
- <table cellspacing="4" cellpadding="0" border="0">
- <tr>
- <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
- <td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
- <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
- </tr>
- <tr>
- <td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
- <td bgcolor="#ffffff"><pre>
-
-
- <?xml version="1.0"?>
-
- <project version="2.0">
-
- <target name="main">
- <taskdef name="printer"
- classname="org.realityforge.tasks.SystemOutPrinterTask"
- classpath="build/classes"/>
-
- <printer message="Hello World!"/>
- </target>
- </project>
-
-
- </pre></td>
- <td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
- </tr>
- <tr>
- <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
- <td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
- <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
- </tr>
- </table>
- </div>
- </blockquote>
- </td></tr>
- </table>
- </blockquote>
- </td></tr>
- </table>
- </td>
- </tr>
-
- <!-- FOOTER -->
- <tr><td colspan="2">
- <hr noshade="" size="1"/>
- </td></tr>
- <tr><td colspan="2">
- <div align="center"><font color="#525D76" size="-1"><em>
- Copyright © 2000-2002, Apache Software Foundation
- </em></font></div>
- </td></tr>
- </table>
- </body>
- </html>
- <!-- end the processing -->
-
-
-
|