Is it possible to check if a command exists as part of an ant task. For example, I want to ensure the "yasm" command is present as part of the ant task. Is this possible? If so, can you provide an example?
The following idiom can be used to find an executable somewhere in the environment's PATH.
<property environment="env" />
<available file="commandname"
filepath="${env.PATH}"
property="commandname.present"/>
The best way I can think of to do this is by using the available
task combined with an if
in a subsequent target. If you take a look at that task page you will see that you can check to see if something exists then set a property. For example:
<available file="/path/to/my/file" type="file" property="file.present"/>
Then in the target you would say something like <target name='foo' if='file.present'>
That doesn't check for executable permissions but it will get much closer. If a task exists to check for the executable permission specifically you would still probably combine it with the if
in the target.
It is better to use the ant copy task instead of trying to execute cp
yourself. This keeps its platform independent.
<copy todir"/some/target">
<fileset dir="/some/src"/>
</copy>
More usage on the Ant documentation for the copy task.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With