Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ant strings comparison

Tags:

ant

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

like image 631
Udi Avatar asked Jul 05 '26 08:07

Udi


1 Answers

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
like image 122
FailedDev Avatar answered Jul 07 '26 15:07

FailedDev



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!