2012-06-27 34 views
6

这是我正在尝试实现的:基于条件的antcall

如果设置了属性,则调用antcall目标。这是可行的吗?有人能告诉我如何?

<condition> 
    <isset property="some.property"> 
     <antcall target="do.something"> 
    </isset> 
</condition> 
+0

可能重复[如何检查一个条件在蚂蚁和取决于它的价值打印信息?](http://stackoverflow.com/questions/10680982/how-check-for-a-condition-in-ant并取决于它的价值打印消息) –

回答

6

像这样的东西应该工作:

<if> 
    <isset property="some.property"/> 
    <then> 
     <antcall target="do.something"> 
    </then> 
</if> 

如果当时条件要求ant-contrib,但这样做几乎任何事情在蚂蚁有用。

+0

太好了。适用于我。我很满意Ant Contrib。 – soothsayer

-1

考虑,你也可以为这些目的调用常规:

<use-groovy/> 
<groovy> 
    if (Boolean.valueOf(properties["some.property"])) { 
    ant.project.executeTarget("do.something") 
    } 
</groovy> 
6

我知道我真的晚了这一点,但这里是另一种方式来做到这一点,如果你使用的是蚂蚁的contrib的,如果没有按哪里不支持嵌套的antcall元素(我使用antcontrib 1.02b不支持)。

<target name="TaskUnderRightCondition" if="some.property"> 
    ... 
</target> 

可以进一步扩大这检查,看看是否some.property应设置之前这个目标是通过使用叫做取决于如果属性被评估之前监守所依赖的执行。因此,你可以有这样的:

<target name="TestSomeValue"> 
    <condition property="some.property"> 
    <equals arg1="${someval}" arg2="${someOtherVal}" /> 
    </condition> 
</target> 

<target name="TaskUnderRightCondition" if="some.property" depends="TestSomeValue"> 
    ... 
</target> 

在这种情况下TestSomeValue叫,如果someval == someOtherVal然后some.property设定最后,TaskUnderRightCondition将被执行。如果someval!= someOtherVal,那么TaskUnderRightCondition将被跳过。

您可以通过the documentation了解更多关于条件的信息。

+0

你能像''吗? – siledh

+0

@siledh我不知道。我不这么认为。 –