0

I have problem testing file existence with ant. I want to check if files exist in target test, and if not, I want download files in target download. But the download target will be executed always (if files exist or not). Can anybody show what is wrong?

<!-- Test lib files if exist -->
<target name="test">
    <condition property="is.resource.exists" value="true" else="false">
        <and>
            <resourceexists>
                <file file="${lib}/jdom-2.0.5.jar" />
            </resourceexists>
            <resourceexists>
                <file file="${lib}/miglayout-4.0-swing.jar" />
            </resourceexists>
        </and>
    </condition>
</target>

<!-- Download lib files if not exist -->
<target name="download" if="is.resource.exists" depends="test">
    <exec dir="${lib}" executable="${lib}/get-libs.sh" />
</target>
Petr Přikryl
  • 1,641
  • 4
  • 22
  • 34

1 Answers1

1

A <target> with an if attribute will execute if the property in the if attribute exists. Similarly, a <target> with an unless attribute will execute if the property in the unless attribute doesn't exist. It doesn't matter what the value of the property is: true, false, kumquat, or whatever.

Replace the if="is.resource.exists" with unless="is.resource.exists" and you should be good.

Chad Nouis
  • 6,861
  • 1
  • 27
  • 28
  • Note that `else="false"` should be also removed from condition as it forces `is.resource.exists` property to be defined even if resource is not really present. `if` and `unless` check only existence of property, not it's value. – Vadzim Oct 07 '13 at 07:17