Ant build.xml $$

时间:2014-03-13 18:16:26

标签: ant build

我有一个Ant build.xml,它执行如下检查,我只是想知道$$表示什么?

提前感谢您的帮助。

 <equals casesensitive="false" arg1="${subPlan}" arg2="$${subPlan}"/>

1 个答案:

答案 0 :(得分:3)

来自蚂蚁手册Properties and PropertyHelpers

..Ant will expand the text $$ to a single $ and suppress the normal property expansion mechanism..

它常常用于输出:

<property name="foo" value="bar"/>

<echo>$${foo} => ${foo}</echo>

输出:

[echo] ${foo} => bar

在您的情况下,它会检查项目中是否设置了名为subPlan的属性,因为$ {subPlan}如果不存在则不会被扩展,例如,f.e。 :

<project>
 <property name="subPlan" value="whatever"/>
 <echo>${subPlan}</echo>
</project>

输出:

[echo] whatever

而::

<project>
 <echo>${subPlan}</echo>
</project>

输出:

[echo] ${subPlan}

实际上可以将Property subPlan的propertyvalue设置为$ {subPlan}:

<property name="subPlan" value="$${subPlan}"/>

但这没有意义,因此您的代码段会进行组合检查=&gt;属性subPlan设置并具有有用的值?可以这样使用:

<fail message="Property not set or invalid value !">
 <condition>
  <equals casesensitive="false" arg1="${subPlan}" arg2="$${subPlan}"/>
 </condition>
</fail>

最后,检查属性是否设置的标准方法是使用isset condition,f.e。 :

<fail message="Property not set !">
 <condition>
  <not>
   <isset property="subPlan"/>
  </not>
 </condition>
</fail>
相关问题