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

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

问题描述

我有一个我应该修改的ant构建脚本。具体来说,我应该进行一个subversion checkout条件:当前只有trunk被检出,新版本应该在需要时检查给定的分支。

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>

属性分支将通过命令行,例如 -Dbranch = mybranch

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

如果属性分支为空,应检出主干,但如果属性有任何其他值,则应检出相应的分支,如 http:// t01 / svn / hlfg / HLFG / JAVA /分支/所述属性的值 - 的-。因此,根据属性,应修改 svn 调用的相应arg值。

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?

推荐答案

在使用Ant> = 1.9.3这是一个使用 Ant 1.9.1中引入的新if / unless功能的小菜单
(但是你应该至少使用Ant 1.9.3,因为Ant 1.9.1中存在错误,有关详细信息,请参阅此答案

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)

不要忘记激活该功能的名称空间,fe :

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>

在您的情况下如下:

<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天全站免登陆