Ant strings comparison

微笑、不失礼 提交于 2020-01-01 14:56:29

问题


I have a script in ant, and I need to compare 2 strings lexicographically. something like:

 "1.2.3".compareTo("1.2.4")

I can't find a way to do so... Any ideas? I'm using ant 1.8, and ant-contrib.

Thanks


回答1:


For this solution to work you will need to have your JAVA_HOME pointing to JRE 1.6 or later.

<project name="test" default="test">
<scriptdef name="compare" language="javascript">
     <attribute name="lhs" />
     <attribute name="rhs" />
     <attribute name="property" />
     <![CDATA[
       var lhs = attributes.get("lhs");
       var rhs = attributes.get("rhs");
       project.setProperty(attributes.get("property"), lhs > rhs);
     ]]>
</scriptdef>

<target name="test">
    <compare lhs="1.2.3" rhs="1.2.4" property="result"/>
    <echo message="Result is : ${result}"/>
</target>
</project>

Output :

test:
 [echo] Result is : false


来源:https://stackoverflow.com/questions/7412894/ant-strings-comparison

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!