Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/ant/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何检查Ant任务的if条件中的两个属性?_Ant - Fatal编程技术网

如何检查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
是否存在。这不是问题中示例的替代品。