You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Matt Koss <m....@open.ac.uk> on 2002/06/25 11:44:01 UTC

Task.init() called twice ?

I am trying to understand the execution loop of the task.

I have written a custom task and I have put the initialisation code inside of 
the init() method.
I thought that init() method is called only once ( for taskdef ) and that 
execute() method is then called for each occurence of the custom task.

However, init() method is called for each occurence of my task.
Is this the correct behaviour ?

cheers

Matt


-- 
Matt Koss
Knowledge Media Institute
Open University
e-mail: m.koss@open.ac.uk



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Task.init() called twice ?

Posted by Conor MacNeill <co...@cortexebusiness.com.au>.
Matt Koss wrote:
> Thank you for your answer.
> I have seen the life-cycle, but I wasn't sure what does the "parser-time" mean 
> exactly and how many instances get created.
> 

At a high level, Ant processes a build in two stages. "Parse-Time" is 
when the XML is parsed and the tasks needed are created. "Run-Time" is 
when all the tasks get executed. A lot more things happen under the 
covers to complicate this picture but from the task point of view this 
is a reasonable picture.

Each occurence of your task in the XML, i.e. every <task>, will create a 
separate instance of you task class if it is executed.

Conor



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Task.init() called twice ?

Posted by Matt Koss <m....@open.ac.uk>.
On Tuesday 25 June 2002 3:45 pm, Conor MacNeill wrote:
> Matt Koss wrote:
> > I am trying to understand the execution loop of the task.
> >
> > I have written a custom task and I have put the initialisation code
> > inside of the init() method.
> > I thought that init() method is called only once ( for taskdef ) and that
> > execute() method is then called for each occurence of the custom task.
> >
> > However, init() method is called for each occurence of my task.
> > Is this the correct behaviour ?
>
> This is correct. Taskdef does not create an instance of your task. It
> creates a mapping from a taskname to a Java class. There will be a new
> instance of your custom task for each instance in the XML.
>
> Check out the following link for the lifecyle of a task and when init() is
> called relative to execute().
>
> http://jakarta.apache.org/ant/manual/develop.html#writingowntask
>
> Conor

Thank you for your answer.
I have seen the life-cycle, but I wasn't sure what does the "parser-time" mean 
exactly and how many instances get created.

Cheers

Matt


-- 
Matt Koss
Knowledge Media Institute
Open University
e-mail: m.koss@open.ac.uk

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Task.init() called twice ?

Posted by Conor MacNeill <co...@cortexebusiness.com.au>.
Matt Koss wrote:
> I am trying to understand the execution loop of the task.
> 
> I have written a custom task and I have put the initialisation code inside of 
> the init() method.
> I thought that init() method is called only once ( for taskdef ) and that 
> execute() method is then called for each occurence of the custom task.
> 
> However, init() method is called for each occurence of my task.
> Is this the correct behaviour ?
> 

This is correct. Taskdef does not create an instance of your task. It 
creates a mapping from a taskname to a Java class. There will be a new 
instance of your custom task for each instance in the XML.

Check out the following link for the lifecyle of a task and when init() is 
called relative to execute().

http://jakarta.apache.org/ant/manual/develop.html#writingowntask

Conor



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Task.init() called twice ?

Posted by Matt Koss <m....@open.ac.uk>.
On Tuesday 25 June 2002 10:41 am, Matt Koss wrote:
> I am trying to understand the execution loop of the task.
>
> I have written a custom task and I have put the initialisation code inside
> of the init() method.
> I thought that init() method is called only once ( for taskdef ) and that
> execute() method is then called for each occurence of the custom task.
>
> However, init() method is called for each occurence of my task.
> Is this the correct behaviour ?
>
> cheers
>
> Matt

I am sorry, I didn't realize that this is a list for the people who actually 
work on ant, and not for the people who write custom tasks.
I have cross-posted this message to the ant-user instead.

Cheers

Matt


-- 
Matt Koss
Knowledge Media Institute
Open University
e-mail: m.koss@open.ac.uk

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>