Reputation: 631
Is there any way to set an ant property by capturing the output of a shellscript? (or another ant task)
Something like this:
<property name="foo">
<value>
<exec executable="bar" />
</value>
</property>
Thanks!
Upvotes: 6
Views: 3809
Reputation: 280
To expand on @Nim's answer:
The tag can appear as an immediate child of the . It doesn't have to be inside a . This gives it global scope, like a tag.
Also, if you need a complex command, you can use arg
tags.
For example, if you want to add the Git branch name to a jar manifest, you do something like this:
<project>
<property name="user" value="fred"/>
<!-- git.branch gets set globally -->
<exec executable="/usr/bin/git" outputproperty="git.branch">
<arg value="rev-parse"/>
<arg value="--abbrev-ref"/>
<arg value="HEAD"/>
</exec>
<target name="make-jar">
<jar jarfile="project.jar">
<manifest>
<attribute name="Built-By" value="${user}"/>
<attribute name="Git-Branch" value="${git.branch}"/>
</manifest>
<fileset dir="${classes.dir}" includes="**/*.class"/>
</jar>
</target>
</project>
Upvotes: 4
Reputation: 2481
From the ANT exec task
output
attribute : Name of a file to which to write the output. outputproperty
When I tested they came out to be mutually exclusive. So set only 1 of them at a time.
Upvotes: 8
Reputation: 631
It seems that exec task has an outputproperty-property, like so:
<exec executable="bar" outputproperty="foo" />
Upvotes: 9