ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From KC Baltz <KBa...@responsenetworks.com>
Subject RE: Conditionally setting properties
Date Fri, 06 Oct 2000 15:06:53 GMT
If you are using Ant 1.1 (the latest release) then you are seeing correct
behavior.  In 1.1, properties are indeed set at parse time and in the order
they appear in the build file.  Once set, they are immutable.

Ant 1.2, which is coming soon, will have mutable, set-at-runtime,
properties.  

You can check your version with ant -version 

K.C.

> -----Original Message-----
> From: Norris Boyd [mailto:nboyd@atg.com]
> Sent: Friday, October 06, 2000 11:01 AM
> To: ant-user@jakarta.apache.org
> Subject: Conditionally setting properties
> 
> 
> I tried to conditionally set properties in my buildfile and it doesn't
> seem to work.
> 
> Here's a sample buildfile that demonstrates the problem:
> 
> <?xml version="1.0" encoding="utf-8"?>
> 
> <project name="test" default="print" basedir=".">
> 
>   <target name="init">
>     <available file="foo" property="foo-available"/>
>   </target>
> 
>   <target name="has-foo" if="foo-available" depends="init">
>     <echo message="setting yes"/>
>     <property name="foo-present" value="yes"/>
>   </target>
> 
>   <target name="no-foo" unless="foo-available" depends="init">
>     <echo message="setting no"/>
>     <property name="foo-present" value="no"/>
>   </target>
> 
>   <target name="print" depends="has-foo,no-foo">
>     <echo message="foo-present = ${foo-present}"/>
>   </target>
> 
> </project>
> 
> Now if a file "foo" is present in the directory when I build I get the
> following ant output:
> 
> Buildfile: build.xml
> 
> init:
> 
> has-foo:
> setting yes
> 
> no-foo:
> 
> print:
> foo-present = yes
> 
> BUILD SUCCESSFUL
> 
> Total time: 0 seconds
> 
> But if I remove foo I get the following output:
> 
> Buildfile: build.xml
> 
> init:
> 
> has-foo:
> 
> no-foo:
> setting no
> 
> print:
> foo-present = yes
> 
> BUILD SUCCESSFUL
> 
> Total time: 0 seconds
> 
> Am I misunderstanding how it should work? It appears that 
> properties are
> set at parse time rather than build time because if I swap 
> the order of
> the "has-foo" and "no-foo" targets, I always get "foo-present = no"
> whether or not foo is present.
> 
> Thanks,
> Norris
> 

Mime
View raw message