You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Fred Hauschel <fr...@fiducia.de> on 2003/04/02 13:46:47 UTC

target - if

Hey all,
i want to check if a directory exists, before execute an task.
Here is my build.xml:

<project name="bv_ewu" basedir="." default="run">
    <target name="run">
        <antcall target="prepare"/>
        <antcall target="home_available"/>
        <antcall target="rename_home"/>
    </target>

    <!-- Check timestamp on files -->
    <target name="prepare">
        <tstamp/>
    </target>

    <target name="home_available">
        <available property="exists" file="C:\home" type="dir" />
        <echo message="###homeAvailable${exists} "/>
    </target>

    <target name="rename_home" if="exists">
        <echo message="###homeAvailable${exists} "/>
    </target>

</project>

And thats the output:

Buildfile: build.xml

run:

prepare:

home_available:
     [echo] ###homeAvailabletrue

rename_home:

BUILD SUCCESSFUL
Total time: 3 seconds

So the property "exists" semms only to exists inside the target, but not 
in other targets !
But if i declare the property like this:
<property name="exists" value=""/>
it always exists !!

How can i use the "if" ????

Thanks Fredy

Re: target - if

Posted by Stefan Bodewig <bo...@apache.org>.
On Wed, 2 Apr 2003, Fred Hauschel <fr...@fiducia.de> wrote:

> i want to check if a directory exists, before execute an task.

You are overusing antcall and should use depends instead.

After this general statement, properties set during <antcall> will not
be set after <antcall> returns, that's why rename_home will never get
executed.

What you really want is

<target name="run" depends="prepare,home_available,rename_home"/>

Or even more likely

<target name="run" depends="prepare,rename_home"/>

with

<target name="rename_home" if="exists" depends="home_available">
...

Stefan