You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by "Julian M. Savage" <js...@fisci.com> on 2000/09/22 05:08:39 UTC

conditional loading of properties files

I'm wondering if there is any way to conditionally load a properties file.

I have two files, build.xml and test.properties in my example below, and as you can see, while defining the property deploy prevents the echo from being executed, it doesn't prevent the property file from being loaded, which is somewhat counter-intuitive. Is this expected/required behaviour?

Thanks,

Julian.

Example:

# build.xml
<project name="fisci" default= "prepare" basedir=".">
        <target name="init.user" unless="deploy">
                <echo message="init.user"/>
                <property file="${user.home}/test.properties"/>
        </target>

        <target name="init" depends="init.user">
                <echo message="init"/>
                <property name="test.port" value="4100"/>
        </target>

        <target name="prepare" depends="init">
                <echo message="prepare"/>
                <echo message="test.port=${test.port}"/>
                <tstamp/>
        </target>
</project>
EOT

# test.properties
test.port=1234

$ ant prepare
Buildfile: build.xml

init.user:
init.user

init:
init

prepare:
prepare
test.port=1234

BUILD SUCCESSFUL

Total time: 0 seconds
$ ant -Ddeploy=yes prepare
Buildfile: build.xml

init.user:

init:
init

prepare:
prepare
test.port=1234

BUILD SUCCESSFUL

Total time: 0 seconds


Re: conditional loading of properties files

Posted by Stefan Bodewig <bo...@bost.de>.
>>>>> "JMS" == Julian M Savage <js...@fisci.com> writes:

 JMS> Nico, Diane Holt pointed out to me via e-mail that my example
 JMS> works with more recent versions of ant than I have (-version
 JMS> wouldn't be useful because I recompiled this version today, but
 JMS> it represents the tree at an earlier stage).

It would because the Ant team thinks of everything - OK, remove this
shameless plug.

<property> does what you expect for Ant version 1.2alpha2 and above
8^).

alpha3 is runtime evaluation of <taskdef> BTW.

Stefan

Re: conditional loading of properties files

Posted by "Julian M. Savage" <js...@fisci.com>.
Nico,

Diane Holt pointed out to me via e-mail that my example works with more
recent versions of ant than I have (-version wouldn't be useful because I
recompiled this version today, but it represents the tree at an earlier
stage). I tested my example with that version and see that everything works
the way I would hope.

Unfortunately I can't just move over to the new version right now, but at
least I know it will work when I do.

Thanks,

Julian.
----- Original Message -----
From: "Nico Seessle" <ni...@seessle.de>
To: <an...@jakarta.apache.org>
Sent: Friday, September 22, 2000 4:46 PM
Subject: Re: conditional loading of properties files


> Hi Julian,
>
> Your example works for me as you would like it to work :-)
>
> Can you tell us what Version of Ant (ant -version) are you using? This
will
> not work with older versions (works since 14./15. Sep.)
>
> Try to run ant -verbose - it should tell you what is happening (and when).
>
> Nico
>
> ----- Original Message -----
> From: Julian M. Savage
> To: ant-dev@jakarta.apache.org
> Sent: Friday, September 22, 2000 5:08 AM
> Subject: conditional loading of properties files
>
>
> I'm wondering if there is any way to conditionally load a properties file.
>
> I have two files, build.xml and test.properties in my example below, and
as
> you can see, while defining the property deploy prevents the echo from
being
> executed, it doesn't prevent the property file from being loaded, which is
> somewhat counter-intuitive. Is this expected/required behaviour?
>
>
>


Re: conditional loading of properties files

Posted by Nico Seessle <ni...@seessle.de>.
Hi Julian,

Your example works for me as you would like it to work :-)

Can you tell us what Version of Ant (ant -version) are you using? This will
not work with older versions (works since 14./15. Sep.)

Try to run ant -verbose - it should tell you what is happening (and when).

Nico

----- Original Message -----
From: Julian M. Savage
To: ant-dev@jakarta.apache.org
Sent: Friday, September 22, 2000 5:08 AM
Subject: conditional loading of properties files


I'm wondering if there is any way to conditionally load a properties file.

I have two files, build.xml and test.properties in my example below, and as
you can see, while defining the property deploy prevents the echo from being
executed, it doesn't prevent the property file from being loaded, which is
somewhat counter-intuitive. Is this expected/required behaviour?