如何检查Ant任务的if条件中的两个属性?
通过指定如何检查Ant任务的if条件中的两个属性?,ant,Ant,通过指定if或除非子句,可以有条件地执行Ant目标。据我所知,这一条款只接受一个属性。我如何检查两个属性 这是一个例子: <project default="test"> <property name="a" value="true"/> <property name="b" value="true"/> <target name="test-a" if="a"> <echo>a</echo> <
if
或除非子句,可以有条件地执行Ant目标。据我所知,这一条款只接受一个属性。我如何检查两个属性
这是一个例子:
<project default="test">
<property name="a" value="true"/>
<property name="b" value="true"/>
<target name="test-a" if="a">
<echo>a</echo>
</target>
<target name="test-b" if="b">
<echo>b</echo>
</target>
<target name="test-ab" if="a,b">
<echo>a and b</echo>
</target>
<target name="test" depends="test-a,test-b,test-ab"/>
</project>
如何为这两个属性指定and表达式?很遗憾,没有
在if/除非子句中只能指定一个propertyname。如果你
如果要检查多个条件,可以使用从属目标进行检查
计算检查结果:
<target name="myTarget" depends="myTarget.check" if="myTarget.run">
<echo>Files foo.txt and bar.txt are present.</echo>
</target>
<target name="myTarget.check">
<condition property="myTarget.run">
<and>
<available file="foo.txt"/>
<available file="bar.txt"/>
</and>
</condition>
</target>
存在foo.txt和bar.txt文件。
不幸的是,没有
在if/除非子句中只能指定一个propertyname。如果你
如果要检查多个条件,可以使用从属目标进行检查
计算检查结果:
<target name="myTarget" depends="myTarget.check" if="myTarget.run">
<echo>Files foo.txt and bar.txt are present.</echo>
</target>
<target name="myTarget.check">
<condition property="myTarget.run">
<and>
<available file="foo.txt"/>
<available file="bar.txt"/>
</and>
</condition>
</target>
存在foo.txt和bar.txt文件。
这是我使用condition元素的示例:
<project default="test">
<property name="a" value="true"/>
<property name="b" value="true"/>
<target name="test-a" if="a">
<echo>a</echo>
</target>
<target name="test-b" if="b">
<echo>b</echo>
</target>
<condition property="a-and-b">
<and>
<equals arg1="${a}" arg2="true"/>
<equals arg1="${b}" arg2="true"/>
</and>
</condition>
<target name="test-ab" if="a-and-b">
<echo>a and b</echo>
</target>
<target name="test" depends="test-a,test-b,test-ab"/>
</project>
A.
B
a和b
这是我使用condition元素的示例:
<project default="test">
<property name="a" value="true"/>
<property name="b" value="true"/>
<target name="test-a" if="a">
<echo>a</echo>
</target>
<target name="test-b" if="b">
<echo>b</echo>
</target>
<condition property="a-and-b">
<and>
<equals arg1="${a}" arg2="true"/>
<equals arg1="${b}" arg2="true"/>
</and>
</condition>
<target name="test-ab" if="a-and-b">
<echo>a and b</echo>
</target>
<target name="test" depends="test-a,test-b,test-ab"/>
</project>
A.
B
a和b
这不会检查是否设置了两个属性a
和b
,而是检查文件foo.txt
和bar.txt
是否存在。这不是对问题中示例的替换。这不会检查是否设置了两个属性a
和b
,而是检查文件foo.txt
和bar.txt
是否存在。这不是问题中示例的替代品。