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 如何检查属性或变量是否为空并设置值,然后测试该值_Ant - Fatal编程技术网

Ant 如何检查属性或变量是否为空并设置值,然后测试该值

Ant 如何检查属性或变量是否为空并设置值,然后测试该值,ant,Ant,我们正在使用Ant1.8。我不是一个Ant开发者,但有时我不得不假装 新属性${noReportDSUpgrade}应为“true”或“false” 默认情况下,它是空的(不存在?),这对于我们来说是“false” 如果此属性为空,则应将其设置为“false” 使用此参数的命令行应将其设置为true 1) 如果为空,如何将${noReportDSUpgrade}设置为false;如果提供,如何将${noReportDSUpgrade}设置为true 2) 对于目标,如何仅在false时执行 我已

我们正在使用Ant1.8。我不是一个Ant开发者,但有时我不得不假装

新属性${noReportDSUpgrade}应为“true”或“false”

默认情况下,它是空的(不存在?),这对于我们来说是“false”

如果此属性为空,则应将其设置为“false”

使用此参数的命令行应将其设置为true

1) 如果为空,如何将${noReportDSUpgrade}设置为false;如果提供,如何将${noReportDSUpgrade}设置为true

2) 对于目标,如何仅在false时执行

我已经尝试了我发现的几个建议,但都没能奏效

在脚本的开头:

<target name="init">
    <antcall target="setnoReportDSUpgradeProperty"/>

再往下看:

<target name="setnoReportDSUpgradeProperty">
    <condition>
        <or>
            <equals arg1="${noReportDSUpgrade}" arg2=""/>
            <not>
                <isset property="false"/>
            </not>
       </or>
    </condition>
    <echo message="noReportDSUpgrade set to ${noReportDSUpgrade}"/>         
</target>

以下是如何在Ant中设置默认属性值:

<property name="noReportDSUpgrade" value="false" />
但正如我上面所说,除非出于某种原因确实需要检查空白值,否则不要使用它。只需使用

对于有条件地运行目标,
块支持
if
,除非
属性控制整个对象是否运行。这可能有点让人困惑,因为这有两种模式

<target name="myTarget" if="myCondition">
    <echo message="Running myTarget" />
</target>
注意myCondition周围的
${}
。当您像这样展开属性时,Ant只会在属性值为“true”、“on”或“yes”时运行目标

最后,您通常不需要仅为设置条件而创建单独的目标。在相对简单的脚本中,您可以只使用隐式根目标(即,将根级别的任务置于所有其他目标之外)

简而言之,下面是编写脚本的最简单方法

<project name="myProject">
    <property name="noReportDSUpgrade" value="false" />

    <target name="myTarget" if="${noReportDSUpgrade}">
        <echo message="Running myTarget" />
    </target>
</project>
<target name="myTarget" if="${myCondition}">
    <echo message="Running myTarget" />
</target>
<project name="myProject">
    <property name="noReportDSUpgrade" value="false" />

    <target name="myTarget" if="${noReportDSUpgrade}">
        <echo message="Running myTarget" />
    </target>
</project>
<project name="myProject">
    <target name="init">
        <property name="noReportDSUpgrade" value="false" />
    </target>

    <target name="myTarget" if="${noReportDSUpgrade}" depends="init">
        <echo message="Running myTarget" />
    </target>
</project>