When I use the task, the property is only set to TRUE if the resource (say file) is available. If not, the property is undefined.
When I print the value of the property, it gives true if the resource was available, but otherwise just prints the property name.
Is there a way to set the property to some value if the resource is not available? I have tried setting the property explicitly before the available check, but then ant complains:
[available] DEPRECATED - used to override an existing property. [available] Build file should not reuse the same property name for different values.
The assignment of foosThere will only be successful if it has not already been set to true by your availability check.
The reason for this behaviour are the if/unless-attributes in targets. The target with such an attribute will be executed if/unless a property with the name is set. If it is set to false or set to true makes no difference. So you can use the available-task to set (or not) a property and based on this execute (or not) a task. Setting the property before the available-task is no solution, as properties in ant are immutable, they cannot be changed once set.
There are three possible solutions, to set a property to a value if unset before:
You can use a condition in combination with not:
http://ant.apache.org/manual/Tasks/condition.html