ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Norris Boyd <nb...@atg.com>
Subject Conditionally setting properties
Date Fri, 06 Oct 2000 15:01:22 GMT
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