ApacheAnt小于

ApacheAnt小于,ant,Ant,究竟如何检查数字属性小于ApacheAnt中的数字属性 <property name="small" value="15"/> <property name="big" value="156"/> <fail message="small is less than big!"> <condition> <lessthan val1="${small}" val2="${big}"/> </condition>

究竟如何检查数字属性小于ApacheAnt中的数字属性

<property name="small" value="15"/>
<property name="big" value="156"/>
<fail message="small is less than big!">
  <condition>
    <lessthan val1="${small}" val2="${big}"/>
  </condition>
</fail>

据我所见(我是Ant新手),您只能执行

您可以使用
(请参阅)

仔细阅读文档,因为它需要在ant中安装额外的jar依赖项

情况可能如下(未测试):


var small=parseInt(project.getProperty(“small”);
var big=parseInt(project.getProperty(“big”);
自我设定值(小<大);

干杯,我们终于到了

<!-- Test the Ant Version -->
<property name="burning-boots-web-build.required-ant-version" value="1.8.2"/>
<script language="javascript">
    <![CDATA[
        var current     = project.getProperty("ant.version").match(/([0-9](\.)?)+/)[0].replace(/\./g,"");
        var required    = project.getProperty("burning-boots-web-build.required-ant-version").match(/([0-9](\.)?)+/)[0].replace(/\./g,"");
        project.setProperty('ant.valid-version', current < required ? "false" : "true");
    ]]>
</script>
<fail message="This build requires Ant version ${burning-boots-web-build.required-ant-version}.">
    <condition>
        <isfalse value="${ant.valid-version}"/>
    </condition>
</fail>

如果没有自定义任务或嵌入脚本,属性的“小于”比较是不可能的

但在大多数情况下,您可以通过将测试应用于值的源而不是属性来逃避。在构建系统中,这些“源”通常是文件。在文件上,您可以将
isfileselected
与。大多数选择器在属性时接受
,如
更少
更多
相等

isfileselected
条件的手册中给出了一个示例。

Ant插件提供了一个失败任务,用于计算EL表达式,例如:

<project name="demo" xmlns:fl="antlib:it.haefelinger.flaka">
 <property name="small" value="15"/>
 <property name="big" value="156"/>
 <fl:fail message="small is less than big!" test="small lt big"/>
</project>

有关更多详细信息,请参阅。以下是不带任何脚本的条件任务的用法:

<if>
    <isgreaterthan arg1="100" arg2="10"/>
    <then>
        <echo>Number 100 is greater than number 10</echo>
    </then>
</if>

数字100大于数字10
此外,arg1、arg2值可以是属性变量的值

注:
是Ant Contrib提供的附加条件:


事实上,@GnanaPrakash提供的答案是不完整的。 从文件中:

这些条件适合在元件中使用。不幸的是,它们不能在任务中使用,尽管任务的所有条件都可以与一起使用,并且可以在任何可以使用的地方使用

因此,
小于
或替代
大于
元素必须包装在
bool
元素中,如下所示:

<property name="small" value="15" />
<property name="big" value="156" />
<if>
    <bool>
        <islessthan arg1="${small}" arg2="${big}"/>
    </bool>
    <then>
        <echo message="small is less than big!" />
    </then>
    <else>
        <echo message="big is less than small!" />
    </else>
</if>

很遗憾,类似于这一点,您似乎需要嵌入一些脚本。谢谢您。遗憾的是,由于Stackoverflow搜索没有找到它,我在标题中放了小于,而不是大于:(.投票以重复方式关闭。我喜欢Ant Contrib中的
任务比
任务更好的外观(已经在使用它),我不知道如何使用它。你试过了吗?@MattClarkson你可能想在
任务中使用
吗?从@FailedDev提供的链接:“很遗憾,它们不能在任务中使用”。确实有效吗?从文档:“这些条件适合在元素中使用。不幸的是,它们无法在任务中使用…”当我尝试此操作时,生成失败:“如果不支持嵌套”比“元素”更大小注意:显然这不适用于antcontrib-1.0b3:
<if>
    <isgreaterthan arg1="100" arg2="10"/>
    <then>
        <echo>Number 100 is greater than number 10</echo>
    </then>
</if>
<property name="small" value="15" />
<property name="big" value="156" />
<if>
    <bool>
        <islessthan arg1="${small}" arg2="${big}"/>
    </bool>
    <then>
        <echo message="small is less than big!" />
    </then>
    <else>
        <echo message="big is less than small!" />
    </else>
</if>
if doesn't support the nested "islessthan" element.