Set ant property by invoking a shell script?

我们两清 提交于 2019-12-08 17:37:39

问题


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!


回答1:


It seems that exec task has an outputproperty-property, like so:

<exec executable="bar" outputproperty="foo" />



回答2:


From the ANT exec task

  1. Set the output attribute : Name of a file to which to write the output.
  2. As Marble has suggested - set the outputproperty

When I tested they came out to be mutually exclusive. So set only 1 of them at a time.




回答3:


To expand on @Nim's answer, complex commands can be generated using arg tags:

<exec executable="/usr/bin/git" outputproperty="git.branch">
  <arg value="rev-parse"/>
  <arg value="--abbrev-ref"/>
  <arg value="HEAD"/>
</exec>

This can be referenced later like:

<attribute name="Git-Branch" value="${git.branch}"/>


来源:https://stackoverflow.com/questions/12364467/set-ant-property-by-invoking-a-shell-script

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!