如何有条件地设置exec任务的arg值? [英] How to conditionally set arg value of exec task?

查看:30
本文介绍了如何有条件地设置exec任务的arg值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 ant 构建脚本,我应该修改它.具体来说,我应该有条件地进行 subversion checkout:目前只有主干被检出,如果需要,新版本应该检出给定的分支.

属性 branch 将通过命令行设置,例如 -Dbranch=mybranch.

如果属性 branch 为空,则应检出主干,但如果该属性有任何其他值,则应检出相应的分支,例如 http://t01/svn/hlfg/HLFG/java/branch/the-value-of-the-property.因此,应根据属性修改 svn 调用的相应 arg 值.

是否可以使用基本的 Ant 来解决这个问题,或者我是否需要使用内联脚本?

解决方案

当使用 Ant >= 1.9.3 时,Ant 1.9.1 引入的新 if/unless 功能(但您至少应该使用 Ant 1.9.3,因为 Ant 1.9.1 中存在错误,查看此答案了解详情)>

不要忘记激活该功能的命名空间,例如:

在你的情况下是这样的:

I've got an ant build script which I should modify. Specifically I should make a subversion checkout conditional: currently only the trunk gets checked out, the new version should checkout a given branch if needed.

<target name="do-svn-checkout" depends="init"
    <property name="branch" value=""/>
  <exec executable="svn">
    <arg value="checkout"/>
    <arg value="-r"/>
    <arg value="HEAD"/>
    <arg value="http://t01/java/trunk"/>
    <arg value="zzz"/>
    <arg value="--password"/>
    <arg value="xxx"/>
    <arg value="--username"/>
    <arg value="yyy"/>
  </exec>
</target>

The property branch will be set via the command line like for instance -Dbranch=mybranch.

If the property branch is empty, the trunk should be checked out, but if the property has any other value, the respective branch should be checked out, like http://t01/svn/hlfg/HLFG/java/branch/the-value-of-the-property. So depending on the property the respective arg-value of the svn call should be modified.

Is it possible to solve this with basic Ant or would I need to use an inline script?

解决方案

When using Ant >= 1.9.3 it's a piece of cake with the new if/unless feature introduced with Ant 1.9.1 (but you should at least use Ant 1.9.3 because of bugs in Ant 1.9.1, see this answer for details)

Don't forget the namespaces to activate that feature, f.e. :

<project
  xmlns:if="ant:if"
  xmlns:unless="ant:unless"
>

 <property name="foobar" value=" "/>

 <echo if:blank="${foobar}">foobar blank !</echo>
 <echo unless:blank="${foobar}">foobar not blank !</echo>

</project>

in your case something like :

<target name="do-svn-checkout" depends="init"
 <property name="branch" value=""/>
 <exec executable="svn">
   <arg value="checkout"/>
   <arg value="-r"/>
   <arg value="HEAD"/>
   <arg value="http://t01/java/trunk" if:blank="${branch}">
   <arg value=".." unless:blank="${branch}">
   <arg value="zzz"/>
   <arg value="--password"/>
   <arg value="xxx"/>
   <arg value="--username"/>
   <arg value="yyy"/>
 </exec>
</target>

这篇关于如何有条件地设置exec任务的arg值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆