Reputation: 3100
My teams ant task pulls in developer specific info from a build.properties
file by using the property file tag:
<property file="${user.home}/build.properties.txt" />
However, when this file is missing ant continues regardless. Later on in the build process it then tries to access properties that have not been defined and tries to log into the svn server as ${user.name}
and other similar errors. These errors were quite difficult to debug, as some of the ant tasks I used did not give useful error messages.
My primary question is: Is there a way to ask ant to fail-fast if it cannot find the properties file?
Upvotes: 4
Views: 4242
Reputation: 21
Use target "loadproperties" ant task instead of "property file ="…">, because the latter task doesn’t complain if a file is missing which is your case. The loadproperties task will always fail the build in such a situation where the properties are missing.
Upvotes: 2
Reputation: 10377
or even shorter with Ant Plugin Flaka =
<project xmlns:fl="antlib:it.haefelinger.flaka">
...
<fl:fail message="Houston we have a problem" test="!'${user.home}/build.properties.txt'.tofile.exists"/>
...
</project>
Upvotes: 0
Reputation: 45576
I suggest, instead of testing for existence of specific properties file, test for property definition. That way this property can be supplied in different ways ( for example as -Duser.name=myname
).
You can give suggested file name in the failure message.
E.g
<fail message="user.name property is not set.
It is usually defined in ${user.home}/build.properties.txt">
<condition>
<not><isset property="user.name"/></not>
</condition>
</fail>
Upvotes: 5
Reputation: 6229
You could add an explicit check first. Something like:
<fail message="Missing build.properties">
<condition>
<not>
<available file="${user.home}/build.properties.txt" />
</not>
</condition>
</fail>
would probably do the trick.
Upvotes: 8
Reputation: 18704
I think you can combine available and fail:
Sets the property if File is present
<available file="${user.home}/build.properties.txt" property="build.properties.present"/>
Fails if property is not set
<fail unless="build.properties.present"/>
Upvotes: 8