You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Dieter König <Di...@data-experts.de> on 2008/11/12 14:24:57 UTC

param hierarchy inverse to property hierarchy

Hello list,

i have encountered a strange behaviour of ant scripts as property and 
param elements are using incompatible overwrite rules. Please let me 
explain in a small diagram.

- set some property
- use antcall with inheritall=true
- the called target tries to set the property again
==> first property is used

- use antcall with some param (e.g. <param name="foo" value="bar"/>)
- the called target uses antcall with param providing a new value (e.g. 
<param name="foo" value="bar2"/>)
==> called target uses second value (in the example foo would be "bar2")

This means that if in a script an <antcall> using <param> is used there is 
no chance to overwrite that setting/property when calling that script. Am 
i right? Or is there a way to set such a parameter?
Is this the desired behaviour of ant?

In my opinion the same overwrite-behaviour for <param> elements as for 
<property> elements would be better. The user of an ant script would then 
always be able to set all the parameters or propertys.

Best regards
Dieter König

AW: param hierarchy inverse to property hierarchy

Posted by Dieter König <Di...@data-experts.de>.
Hi Jürgen,

thanks for the explanation. I will ask the owner of ant1.xml. Your 
solution is great!

Regards
Dieter

AW: param hierarchy inverse to property hierarchy

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

Again: The behaviour of ANT is ok, because you need this very often!

If you have no access at all to ant1.xml and this script is holy, so that no one is allowed to change it and you need to call target t1, then there is no way to change foo for target t2.

But...
You import ant1.xml, therefore you have power over ant1.xml. 
E.g. you can change ant1.xml before you import it or:

What you could do is:
1.Instead of importing t1 you can use <ant> to call the target t2 directly.

Best solution is:
Talk to the owner of ant1.xml and ask him to change ant1.xml in the following way:

=== ant1.xml ===
<target name="t1">
        ... do something
<property name="paramproperty" value"bar"
<property name="foovalue" value"${paramproperty}"
        <antcall target="t2">
                <param name="foo" value="${paramproperty}" />
        </antcall>
        ... do something
</target>
<target name="t2">
        ... do something
</target>
=== ant1.xml ===

This will not change the behaviour of ant1.xml, except someone changes ${paramproperty}

And exactly this is, what you will do:
=== ant2.xml ===
<import file="ant1.xml" />
<target name="main">
        <antcall target="t1">
                <param name="paramproperty" value="myvalue" />
        </antcall>
</target>
=== ant2.xml ===

This will do the trick...

-- 
Jürgen Knuplesch 

-----Ursprüngliche Nachricht-----
Von: Dieter König [mailto:Dieter.Koenig@data-experts.de] 
Gesendet: Mittwoch, 12. November 2008 16:53
An: user@ant.apache.org
Betreff: Re: param hierarchy inverse to property hierarchy

Hi,

i expected that i will be missunderstood :(. So again:
=== ant1.xml ===
<target name="t1">
        ... do something
        <antcall target="t2">
                <param name="foo" value="bar" />
        </antcall>
        ... do something
</target>
<target name="t2">
        ... do something
</target>
=== ant1.xml ===

=== ant2.xml ===
<import file="ant1.xml" />
<target name="main">
        <antcall target="t1">
                <param name="foo" value="myvalue" />
        </antcall>
</target>
=== ant2.xml ===

Suppose i have no write access to ant1.xml but i have to use it. 
Furthermore i have to call the target "t1" (and not "t2" directly where passing the parameter would work) because all the other logic of "t1" 
should be used also. This way to pass "myvalue" as a value of "foo" doesnt work. And i didnt found a way else.
That's why in my opinion the behaviour of ant should be changed. Or do has somebody a solution for this problem?

Kind Regards
Dieter König

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


Re: param hierarchy inverse to property hierarchy

Posted by Dieter König <Di...@data-experts.de>.
Hi,

i expected that i will be missunderstood :(. So again:
=== ant1.xml ===
<target name="t1">
        ... do something
        <antcall target="t2">
                <param name="foo" value="bar" />
        </antcall>
        ... do something
</target>
<target name="t2">
        ... do something
</target>
=== ant1.xml ===

=== ant2.xml ===
<import file="ant1.xml" />
<target name="main">
        <antcall target="t1">
                <param name="foo" value="myvalue" />
        </antcall>
</target>
=== ant2.xml ===

Suppose i have no write access to ant1.xml but i have to use it. 
Furthermore i have to call the target "t1" (and not "t2" directly where 
passing the parameter would work) because all the other logic of "t1" 
should be used also. This way to pass "myvalue" as a value of "foo" doesnt 
work. And i didnt found a way else.
That's why in my opinion the behaviour of ant should be changed. Or do has 
somebody a solution for this problem?

Kind Regards
Dieter König

AW: param hierarchy inverse to property hierarchy

Posted by "Knuplesch, Juergen" <Ju...@icongmbh.de>.
In my opinion, ANT is doing exactly what ANT should do.

The param attribute is used to overwrite selected properties in the called target.
Param is not a datatype like properties. Param is just used to set properties for a called task.

So, when you use antcall with param, it should always set the property to the value you provide.
But only in the called task and not in the calling task.

So, when you give out foo in the second task, you receive bar, no matte when
Foo in the third task  is bar2, no matter when you ask.



-- 
Jürgen Knuplesch 
-----Ursprüngliche Nachricht-----
Von: Dieter König [mailto:Dieter.Koenig@data-experts.de] 
Gesendet: Mittwoch, 12. November 2008 14:25
An: user@ant.apache.org
Betreff: param hierarchy inverse to property hierarchy

Hello list,

i have encountered a strange behaviour of ant scripts as property and param elements are using incompatible overwrite rules. Please let me explain in a small diagram.

- set some property
- use antcall with inheritall=true
- the called target tries to set the property again ==> first property is used

- use antcall with some param (e.g. <param name="foo" value="bar"/>)
- the called target uses antcall with param providing a new value (e.g. 
<param name="foo" value="bar2"/>)
==> called target uses second value (in the example foo would be "bar2")

This means that if in a script an <antcall> using <param> is used there is no chance to overwrite that setting/property when calling that script. Am i right? Or is there a way to set such a parameter?
Is this the desired behaviour of ant?

In my opinion the same overwrite-behaviour for <param> elements as for <property> elements would be better. The user of an ant script would then always be able to set all the parameters or propertys.

Best regards
Dieter König

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