You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by David Weintraub <qa...@gmail.com> on 2007/08/31 19:14:02 UTC
Getting around Set Property Values
Okay,
I've got a quick question. Once a property is set, it can never be
overridden. (Actually, you can use the AntContrib task 'variable' to
do this, but...)
I am defining a Maco that looks like this:
<macrodef name="compile">
<attribute name="module"/>
<sequential>
<property name="destdir"
value="${workdir}/WEB-INF/classes/com/solbright/@{param1}/servlet"/>
<mkdir dir="${destdir}"/>
<javac srcdir="@{module}"
destdir="${destdir}"/>
</sequential>
<macrodef>
When I call the Macro the first time, the property "destdir" will be
set to the correct value, and everything will be fine.
However, on the second call, the property "destdir" won't be reset
since you cannot change the value of a property once it is set. The
files will be built in the wrong place.
How can I get around this issue? I could simply put my destination
directory in every place, but that means if I change something, I have
to hunt down all the places where it was set, and change it there. Is
there a way I can have the property be unset after the macro is
called?
--
David Weintraub
qazwart@gmail.com
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org
Re: Getting around Set Property Values
Posted by Peter Reilly <pe...@gmail.com>.
Currently you need to:
1 ) use <ac:var unset="yes" name="destdir"/>
2) use the invent new property based on macro instance trick:
<property name="@{module}-destdir"
value="${workdir}/WEB-INF/classes/com/solbright/@{param1}/servlet"/>
<mkdir dir="${@{module}-destdir}"/>
<javac srcdir="@{module}"
destdir="${@{module}-destdir}"/>
for ant 1.8.0, we are considering implementing a "local" property:
<local name="destdir"/> <!-- makes a local property called
"destdir" -->
<property name="destdir"
value="${workdir}/WEB-INF/classes/com/solbright/@{param1}/servlet"/>
<mkdir dir="$destdir}"/>
<javac srcdir="@{module}"
destdir="${destdir}"/>
Peter
On 8/31/07, David Weintraub <qa...@gmail.com> wrote:
> Okay,
>
> I've got a quick question. Once a property is set, it can never be
> overridden. (Actually, you can use the AntContrib task 'variable' to
> do this, but...)
>
> I am defining a Maco that looks like this:
>
> <macrodef name="compile">
> <attribute name="module"/>
> <sequential>
> <property name="destdir"
> value="${workdir}/WEB-INF/classes/com/solbright/@{param1}/servlet"/>
>
> <mkdir dir="${destdir}"/>
> <javac srcdir="@{module}"
> destdir="${destdir}"/>
> </sequential>
> <macrodef>
>
> When I call the Macro the first time, the property "destdir" will be
> set to the correct value, and everything will be fine.
>
> However, on the second call, the property "destdir" won't be reset
> since you cannot change the value of a property once it is set. The
> files will be built in the wrong place.
>
> How can I get around this issue? I could simply put my destination
> directory in every place, but that means if I change something, I have
> to hunt down all the places where it was set, and change it there. Is
> there a way I can have the property be unset after the macro is
> called?
>
> --
> David Weintraub
> qazwart@gmail.com
>
> ---------------------------------------------------------------------
> 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: Getting around Set Property Values
Posted by Guru Balse <gu...@oracle.com>.
You can also consider passing in the destdir as an optional parameter
(attribute) of the macro (with default value = ${@{module}-destdir})
David Weintraub wrote:
> Apparently, there are two methods:
>
> 1). Add the parameter name to my property name. Like this:
>
> <property name="@{module}-destdir" value="..."/>
>
> <javac srcdir="..."
> destdir=${@{module}-destdir}"/>
>
> 2). Use the Ant Contrib variables:
>
> <var name="v.destdir" value="..."/>
> <javac srcdir="..."
> destdir="${v.destdir}"/>
>
> 2a). Use the Ant Contrib var package, but to only reset the property:
>
> <var name="destdir" unset="true">
> <property name="destdir" value="..."/>
>
> <javac srcdir="..."
> destdir=${destdir}/>
>
> Although it would get me out of using the AntContrib library, I
> decided against prepending the module name parameter in front of my
> property name. I already have enough issues trying to track my curly
> braces, and I'm not too sure how easy it would be for someone to
> figure out what I am doing, so I decided to go ahead with method 2.
>
> 2a. was something I was thinking of, but if I am going to be using the
> <var> task, I might as well simply set the property using <var>. To
> show a difference between variables and regular properties, I'm
> prepending my variables with a "v." This way, I know that normal
> properties don't change, but that vars (which begin with a "v." may
> change in value.
>
> There were several things that made me decide to use the AntContrib
> task. Most people here are on very old versions of Ant (one guy has
> Ant 6.0 Alpha), so they'll have to reinstall Ant anyway. So, I created
> an install package of Ant 1.7 with the AntContrib tasks already built
> in. Since I was teetering on edge of using the AntContrib package (the
> <if> and <outofdate> tasks looked very helpful), this issue made me
> decide to go ahead and require it.
>
> Thanks for your help.
>
> ---------------------------------------------------------------------
> 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: Getting around Set Property Values
Posted by David Weintraub <qa...@gmail.com>.
Apparently, there are two methods:
1). Add the parameter name to my property name. Like this:
<property name="@{module}-destdir" value="..."/>
<javac srcdir="..."
destdir=${@{module}-destdir}"/>
2). Use the Ant Contrib variables:
<var name="v.destdir" value="..."/>
<javac srcdir="..."
destdir="${v.destdir}"/>
2a). Use the Ant Contrib var package, but to only reset the property:
<var name="destdir" unset="true">
<property name="destdir" value="..."/>
<javac srcdir="..."
destdir=${destdir}/>
Although it would get me out of using the AntContrib library, I
decided against prepending the module name parameter in front of my
property name. I already have enough issues trying to track my curly
braces, and I'm not too sure how easy it would be for someone to
figure out what I am doing, so I decided to go ahead with method 2.
2a. was something I was thinking of, but if I am going to be using the
<var> task, I might as well simply set the property using <var>. To
show a difference between variables and regular properties, I'm
prepending my variables with a "v." This way, I know that normal
properties don't change, but that vars (which begin with a "v." may
change in value.
There were several things that made me decide to use the AntContrib
task. Most people here are on very old versions of Ant (one guy has
Ant 6.0 Alpha), so they'll have to reinstall Ant anyway. So, I created
an install package of Ant 1.7 with the AntContrib tasks already built
in. Since I was teetering on edge of using the AntContrib package (the
<if> and <outofdate> tasks looked very helpful), this issue made me
decide to go ahead and require it.
Thanks for your help.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org
RE: Getting around Set Property Values
Posted by "Burgess, Benjamin" <BB...@tiaa-cref.org>.
You could use the parameter being passed in as part of the name of your
property. Something like:
<?xml version="1.0"?>
<project name="test" default="test" basedir=".">
<macrodef name="test">
<attribute name="module"/>
<sequential>
<property name="@{module}destdir"
value="${basedir}/@{module}"/>
<mkdir dir="${@{module}destdir}"/>
</sequential>
</macrodef>
<target name="test">
<test module="test1"/>
<test module="test2"/>
<test module="test3"/>
</target>
</project>
Ben Burgess
-----Original Message-----
From: David Weintraub [mailto:qazwart@gmail.com]
Sent: Friday, August 31, 2007 1:14 PM
To: Ant Users List
Subject: Getting around Set Property Values
Okay,
I've got a quick question. Once a property is set, it can never be
overridden. (Actually, you can use the AntContrib task 'variable' to
do this, but...)
I am defining a Maco that looks like this:
<macrodef name="compile">
<attribute name="module"/>
<sequential>
<property name="destdir"
value="${workdir}/WEB-INF/classes/com/solbright/@{param1}/servlet"/>
<mkdir dir="${destdir}"/>
<javac srcdir="@{module}"
destdir="${destdir}"/>
</sequential>
<macrodef>
When I call the Macro the first time, the property "destdir" will be
set to the correct value, and everything will be fine.
However, on the second call, the property "destdir" won't be reset
since you cannot change the value of a property once it is set. The
files will be built in the wrong place.
How can I get around this issue? I could simply put my destination
directory in every place, but that means if I change something, I have
to hunt down all the places where it was set, and change it there. Is
there a way I can have the property be unset after the macro is
called?
--
David Weintraub
qazwart@gmail.com
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org
********************************************************************************************
This message, including any attachments, contains confidential information intended
for a specific individual and purpose, and is protected by law. If you are not the intended
recipient, please contact the sender immediately by reply e-mail and destroy all copies.
You are hereby notified that any disclosure, copying, or distribution of this message, or
the taking of any action based on it, is strictly prohibited.
TIAA-CREF
********************************************************************************************
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org