You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by "Knuplesch, Juergen" <Ju...@icongmbh.de> on 2010/02/11 18:10:55 UTC

Setter in my own Anttask

Hello,

I analyse a DOPE_task written for our project.
In one of the setters an application is started.
I have other setters that must start before this setter, because they have some attributes für the application.
In what sequence the setters are executed?

I guess in the sewuence I wrote them into ma call inside my Antfile.

(I dont think this was a good idea to strat an application in a setter that needs more than one attribute.
If possible I will change this...)

Greetings Juergen


-- 
Jürgen Knuplesch

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: Setter in my own Anttask

Posted by Stefan Bodewig <bo...@apache.org>.
On 2010-02-12, Knuplesch, Juergen <Ju...@icongmbh.de> wrote:

> Hello,

> I read about the init() methos in Stefans link about the life cycle of an ANT task:
> 6.init() is called at run time.

> I did not find documentation for this.
> Is init() a static method or wht else?

No.  init() is a method in the Task class and Ant checks at runtime
whether the task (which doesn't have to extend Task) has such a method
and calls it.

Stefan

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


AW: Setter in my own Anttask

Posted by "Knuplesch, Juergen" <Ju...@icongmbh.de>.
Hello,

I read about the init() methos in Stefans link about the life cycle of an ANT task:
6.init() is called at run time. 

I did not find documentation for this.
Is init() a static method or wht else?

Greetings Juergen

-- 
Jürgen Knuplesch                    www.icongmbh.de
icon Systemhaus GmbH                Tel. +49 711 806098-275
Sophienstraße 40                    
D-70178 Stuttgart                   Fax. +49 711 806098-299

Geschäftsführer: Uwe Seltmann
HRB Stuttgart 17655
USt-IdNr.: DE 811944121 
-----Ursprüngliche Nachricht-----
Von: Knuplesch, Juergen [mailto:Juergen.Knuplesch@icongmbh.de] 
Gesendet: Freitag, 12. Februar 2010 16:00
An: Ant Users List
Betreff: AW: Setter in my own Anttask

Hello,

Thanks for the link, but either I did not understand the docu correct or sth. wrong:

6.init() is called at run time. 
7.All child elements of the XML element corresponding to this task are created via this task's createXXX() methods or instantiated and added to this task via its addXXX() methods, at run time. 
8.All attributes of this task get set via their corresponding setXXX methods, at runtime. 

Does this mean that the addConfigured methods should be called before the setters?

I experience that the setters are called before the add methods!!

So what is now the truth?

Greetings Juergen

-- 
Jürgen Knuplesch                    
-----Ursprüngliche Nachricht-----
Von: Stefan Bodewig [mailto:bodewig@apache.org]
Gesendet: Freitag, 12. Februar 2010 15:43
An: user@ant.apache.org
Betreff: Re: Setter in my own Anttask

On 2010-02-12, Knuplesch, Juergen <Ju...@icongmbh.de> wrote:

> So I now start the application in every method that "runs" a nested 
> element. E.g. addConfigured... and some others.

> Is this a good way to do it?

Hard to tell.  Maybe it would be better to collect the nested elements and just do something once execute has been called.

> Is it right that nested elements are added after the setters have been 
> executed?

It depends on whether you use createX(), addX() or addConfiguredX().
See "The Life-cycle of a Task" in
<http://ant.apache.org/manual/develop.html#writingowntask>

Stefan

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org For additional commands, e-mail: user-help@ant.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org For additional commands, e-mail: user-help@ant.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: Setter in my own Anttask

Posted by Stefan Bodewig <bo...@apache.org>.
On 2010-02-12, Knuplesch, Juergen <Ju...@icongmbh.de> wrote:

> Thanks for the link, but either I did not understand the docu correct
> or sth. wrong:

indeed there is something wrong, a step is missing.

> 6.init() is called at run time.
> 7.All child elements of the XML element corresponding to this task are
> created via this task's createXXX() methods or instantiated and added
> to this task via its addXXX() methods, at run time.
> 8.All attributes of this task get set via their corresponding setXXX
> methods, at runtime.

> Does this mean that the addConfigured methods should be called before
> the setters?

No.  addConfiguredXXX is called between steps 10 and 11.

This is hinted at in
<http://ant.apache.org/manual/develop.html#nested-elements>

Stefan

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


AW: Setter in my own Anttask

Posted by "Knuplesch, Juergen" <Ju...@icongmbh.de>.
Hello,

Thanks for the link, but either I did not understand the docu correct or sth. wrong:

6.init() is called at run time. 
7.All child elements of the XML element corresponding to this task are created via this task's createXXX() methods or instantiated and added to this task via its addXXX() methods, at run time. 
8.All attributes of this task get set via their corresponding setXXX methods, at runtime. 

Does this mean that the addConfigured methods should be called before the setters?

I experience that the setters are called before the add methods!!

So what is now the truth?

Greetings Juergen

-- 
Jürgen Knuplesch                    
-----Ursprüngliche Nachricht-----
Von: Stefan Bodewig [mailto:bodewig@apache.org] 
Gesendet: Freitag, 12. Februar 2010 15:43
An: user@ant.apache.org
Betreff: Re: Setter in my own Anttask

On 2010-02-12, Knuplesch, Juergen <Ju...@icongmbh.de> wrote:

> So I now start the application in every method that "runs" a nested 
> element. E.g. addConfigured... and some others.

> Is this a good way to do it?

Hard to tell.  Maybe it would be better to collect the nested elements and just do something once execute has been called.

> Is it right that nested elements are added after the setters have been 
> executed?

It depends on whether you use createX(), addX() or addConfiguredX().
See "The Life-cycle of a Task" in
<http://ant.apache.org/manual/develop.html#writingowntask>

Stefan

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org For additional commands, e-mail: user-help@ant.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: Setter in my own Anttask

Posted by Stefan Bodewig <bo...@apache.org>.
On 2010-02-12, Knuplesch, Juergen <Ju...@icongmbh.de> wrote:

> So I now start the application in every method that "runs" a nested
> element. E.g. addConfigured... and some others.

> Is this a good way to do it?

Hard to tell.  Maybe it would be better to collect the nested elements
and just do something once execute has been called.

> Is it right that nested elements are added after the setters have been
> executed?

It depends on whether you use createX(), addX() or addConfiguredX().
See "The Life-cycle of a Task" in
<http://ant.apache.org/manual/develop.html#writingowntask>

Stefan

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


AW: Setter in my own Anttask

Posted by "Knuplesch, Juergen" <Ju...@icongmbh.de>.
Hello,

Thanks for the answers!

I now understood more about the task I investigate:

There are nested elements, that require that the application is started.

The challenge is: Start the application
1.after the setters executed
2.before the nested elements are added.

So the programmer started the application in a setter, to be sure that it is started before the nested element is executed.
But I dont like that, because I added a second attribute that defines how the application is started!

So I now start the application in every method that "runs" a nested element. E.g. addConfigured... and some others.

Is this a good way to do it?
Is it right that nested elements are added after the setters have been executed?

It seems to work...

Greetings Juergen
 

-- 
Jürgen Knuplesch                    
-----Ursprüngliche Nachricht-----
Von: Stefan Bodewig [mailto:bodewig@apache.org] 
Gesendet: Freitag, 12. Februar 2010 10:23
An: user@ant.apache.org
Betreff: Re: Setter in my own Anttask

On 2010-02-11, Knuplesch, Juergen <Ju...@icongmbh.de> wrote:

> In what sequence the setters are executed?

> I guess in the sewuence I wrote them into ma call inside my Antfile.

There is no defined order and in fact I'd be surprised if it was the same accross all possible combinations of Java VMs and XML parsers.

XML Parsers are allowed attributes in any order (in XML attribute order is insignificant) so even if the setters were invoked in the same order they have been handed down by the XML parser - which they not necessarily are - the final order would still depend on the XML parser.

Stefan

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org For additional commands, e-mail: user-help@ant.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: Setter in my own Anttask

Posted by Stefan Bodewig <bo...@apache.org>.
On 2010-02-11, Knuplesch, Juergen <Ju...@icongmbh.de> wrote:

> In what sequence the setters are executed?

> I guess in the sewuence I wrote them into ma call inside my Antfile.

There is no defined order and in fact I'd be surprised if it was the
same accross all possible combinations of Java VMs and XML parsers.

XML Parsers are allowed attributes in any order (in XML attribute order
is insignificant) so even if the setters were invoked in the same order
they have been handed down by the XML parser - which they not
necessarily are - the final order would still depend on the XML parser.

Stefan

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


AW: Setter in my own Anttask

Posted by Ja...@rzf.fin-nrw.de.
>I analyse a DOPE_task written for our project.
>In one of the setters an application is started.
>I have other setters that must start before this setter, 
>because they have some attributes für the application.
>In what sequence the setters are executed?

IMHO not a good idea ... 
What if the application is required for two attributes? Do you start them twice? 



>I guess in the sewuence I wrote them into ma call inside my Antfile.

Not sure if there is a guaranteed sequence ... order from the buildfile sounds reasonable as this should be the order a parser works. But in Ant there is a step between strict xml parsing and the real objects: UnknownObject and its transformation into real objects. 


>(I dont think this was a good idea to strat an application in 
>a setter that needs more than one attribute.
>If possible I will change this...)


In my own tasks I have three phases:
1. build the datastructure (attributes, nested elements, text)
2. check precondition (could use oata.TaskConfigurationChecker)
3. execution

I would try to start the application in step#3

Jan


    public void execute() throws BuildException {
        checkConfiguration();
        doExecute();
    }

    protected void checkConfiguration() throws BuildException {
        TaskConfigurationChecker checker = new TaskConfigurationChecker(this);
        checker.assertConfig(
            srcdir != null,
            "Attribute 'srcdir' must be set.
        );
        checker.assertConfig(
            srcdir.exists(),
            "Srcdir (" + srcdir + ") must exist."
        );
        if (someComplexCondition()) {
            fail("Complex condition failed.");
        }
        checker.checkErrors();
    }

    protected void doExecute() throws BuildException {
        try {
            if (attributeA != null || attributeB != null) {
                startApplication();
            }
        } catch (Exception e) {
            throw new BuildException(e, getLocation());
        }
    }

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org