Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if executable command exists using ant

Tags:

ant

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?

like image 818
William Seemann Avatar asked Dec 01 '22 19:12

William Seemann


2 Answers

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"/>
like image 170
Michael R Avatar answered Dec 04 '22 07:12

Michael R


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.


Original answer

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.

like image 20
cogsmos Avatar answered Dec 04 '22 09:12

cogsmos