You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Hunter Peress <hu...@gmail.com> on 2006/10/12 23:17:37 UTC

Did i reinvent the wheel with greaterthan?

Im using ant-contrib to implement a greater-than (for ints only)
functionality.
Did I miss something in the documentation? Or is this the best approach (i
realize I could have written a custom ant task)

Did i reinvent some wheel in ant?

  <target name="t">
    <taskdef resource="net/sf/antcontrib/antlib.xml">
     <classpath>
       <pathelement location="ant-contrib-0.6.jar"/>
     </classpath>
   </taskdef>

    <macrodef name="greaterthan">
       <attribute name="resultprop" default="NOT SET"/>
       <attribute name="arg1" default="NOT SET"/>
       <attribute name="arg2" default="NOT SET"/>
       <sequential>
         <math result="gt_tmp" datatype="int">
           <op op="max" >
             <num value="@{arg1}"/>
             <num value="@{arg2}"/>
           </op>
         </math>
         <echo>${gt_tmp}</echo>
         <if>
           <equals arg1="@{arg1}" arg2="${gt_tmp}" />
           <then>
             <property name="@{resultprop}" value="1" />
           </then>
           <else>
             <property name="@{resultprop}" value="0" />
           </else>
         </if>
       </sequential>
    </macrodef>

    <greaterthan arg1="100" arg2="20" resultprop="well" />
    <echo>${well}</echo>
  </target>

Re: Did i reinvent the wheel with greaterthan?

Posted by Dominique Devienne <dd...@gmail.com>.
On 10/12/06, Scot P. Floess <fl...@mindspring.com> wrote:
> Honestly, I've done something similar...  However, my approach was to
> subtract the two numbers and if examine the 1st character to determine
> <, > or =...  a "-" means less than, "0" means equal otherwise its
> greater than.
>
> I couldn't find exactly what I wanted either...that's why I "rolled my own"

FTR, this is precisely when one should be leaving the realm of pure
Ant, and write a little <script> using any one of the true scripting
languages one can leverage from within the build file. I find the
<ac:math> task a bit 'ugly' personally ;-) --DD

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: Did i reinvent the wheel with greaterthan?

Posted by "Scot P. Floess" <fl...@mindspring.com>.
Honestly, I've done something similar...  However, my approach was to 
subtract the two numbers and if examine the 1st character to determine 
<, > or =...  a "-" means less than, "0" means equal otherwise its 
greater than.

I couldn't find exactly what I wanted either...that's why I "rolled my own"



Hunter Peress wrote:
> Im using ant-contrib to implement a greater-than (for ints only)
> functionality.
> Did I miss something in the documentation? Or is this the best 
> approach (i
> realize I could have written a custom ant task)
>
> Did i reinvent some wheel in ant?
>
>  <target name="t">
>    <taskdef resource="net/sf/antcontrib/antlib.xml">
>     <classpath>
>       <pathelement location="ant-contrib-0.6.jar"/>
>     </classpath>
>   </taskdef>
>
>    <macrodef name="greaterthan">
>       <attribute name="resultprop" default="NOT SET"/>
>       <attribute name="arg1" default="NOT SET"/>
>       <attribute name="arg2" default="NOT SET"/>
>       <sequential>
>         <math result="gt_tmp" datatype="int">
>           <op op="max" >
>             <num value="@{arg1}"/>
>             <num value="@{arg2}"/>
>           </op>
>         </math>
>         <echo>${gt_tmp}</echo>
>         <if>
>           <equals arg1="@{arg1}" arg2="${gt_tmp}" />
>           <then>
>             <property name="@{resultprop}" value="1" />
>           </then>
>           <else>
>             <property name="@{resultprop}" value="0" />
>           </else>
>         </if>
>       </sequential>
>    </macrodef>
>
>    <greaterthan arg1="100" arg2="20" resultprop="well" />
>    <echo>${well}</echo>
>  </target>
>

-- 
Scot P. Floess
27 Lake Royale
Louisburg, NC  27549

252-478-8087 (Home)
919-754-4592 (Work)

Chief Architect JPlate  http://sourceforge.net/projects/jplate
Chief Architect JavaPIM http://sourceforge.net/projects/javapim


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org