ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Stefan Bodewig <bode...@apache.org>
Subject Re: how do I call a task from within a listener.
Date Wed, 22 Nov 2000 09:00:37 GMT
Take whatever I say about <mail> with a grain of salt as I've neither
read the source code for the mail task nor its documentation.

Jay Glanville <dickon@nortelnetworks.com> wrote:

> If I want to call a task from within a listener, how do I do it?

Take a look at the description of the life cycle of tasks under
Writing your own task in the Ant documentation. Here you can see what
actually happens with a Task (and what a given task might rely upon).

(1) Use Project.createTask(taskName) to create your task. You can get
an instance of Project from the BuildEvent you've received.

This will set the project for the task as well, there is no reasonable
location attached to your task, so don't set it. Same for target.

(2) Call Task.init() on your instance (might do nothing at all).

(3) If you need to create nested child elements of you task, do so
now.

(4) Set the attributes of your task instance. 

(5) Add any text via Task.addText() if needed.

(6) Set the attributes of the nested child elements (if any) after
that, starting with the first child you've created.

(7) Add any text to the nested children via addText() if
needed. Again using the order you've defined them.

(8) Call Task.execute

(9) Catch any exceptions and do something reasonable with
them. Throwing a BuildException is no good choice as the invocation of
the BuildListener might not be enclosed in a try block.

> PS: the documentation for the <mail> task is very minimal.  What are
> the requirements for this task?  Do I need to have the JavaMail
> package in my classpath?  Do I need a UNIX-like "mail" command in my
> path?

<mail> doesn't use JavaMail at all, it uses a "simple" layer on top of
SMTP written by Jason Hunter. You can find it in
org.apache.tools.mail. So <mail> is a stand alone task that doesn't
rely on any code/utility that doesn't ship with Ant.

Stefan

Mime
View raw message