ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jack Woehr <...@purematrix.com>
Subject Re: conditional logic and making it nicely extensible
Date Thu, 06 Sep 2001 13:46:22 GMT
Matt Denner wrote:

> Dear all,
>
> my first mail to this so if i'm out of order or in the wrong place then bash
> me know :)
>

Hi Matt ...

I posted to the list in a similar vein and was met with resounding silence :-)

My suggestion for AntCallIfElse along the lines of (the equally declarative) m4's
ifelse() macro is appended at the end of this message.

I have since realized that the way to accomplish what you and I both want
in the TRUE ANT THEOLOGY :-) is to

  1. Set a variable using Condition
       1. That variable should be the name of a target
  2. Use Antcall on the variable to hit the right target

Here's an example ... run it without setting any props, then run it with

     -Ddeterminant=yes

to get the conditional target hitting we want.

     <?xml version="1.0" encoding="UTF-8"?>
     <project default="myIfElse">
     <target name="myIfElse">
       <property name="callWhich" value="noItWarnt"/>
       <condition property="callWhich" value="yesItWas">
         <and>
           <equals arg1="${determinant}" arg2="yes"/>
         </and>
       </condition>
       <antcall target="${callWhich}"/>
     </target>

     <target name="yesItWas">
       <echo message="Yes!"/>
     </target>

     <target name="noItWarnt">
       <echo message="No :("/>
     </target>
     </project>

Here's the idea I had posted to the list earlier that was "met with silence".
-------------------------------------------------------

I'm looking at http://jakarta.apache.org/ant/ant2/requested-features.txt

      [DISC] procedural versus purely declarative
      -------------------------------------------

      * Simple flow control (if-then-else, for)

        [REJECTED - vetoes by Conor MacNeill, Glenn McAllister, Peter Donald
                    and Stefan Bodewig]

The reasons to keep Ant essentially declarative are obvious. With approval I note
that you also rejected a motion to make Ant 'purely declarative', a shibboleth
refuted already in logic programming.

There is precedent, however, for a "declarative kind of proceduralism" in other
declarative languages, for example, the m4 ifelse() macro.

It looks as if one could employ the style of coding worked out by Stefan Bodewig in
org/apache/tools/ant/taskdefs/condition to create a class CallTargetsIfElse based
on CallTarget. This would allow syntax like:

    <antcallifelse>
        <equal>
            <arg1="${some.prop}"/>
            <arg2="${some.prop}"/>
        </equal>
        <if target="true_target">
            <param="${a}"/>
            <param="${b}"/>
        </if>
        <else target="false_target">
                <param="${c}"/>
                <param="${b}"/>
        </else>
    </antcallifelse>

This seems a little clearer than what I do now (is this actually
correct?) :

    <target name="true_target" if="${a}">
        ...
    </target>

    <target name="false_target" unless="${a}">
        ...
    </target>

    <target name="switch">
            <antcall target="true_target"/>
            <antcall target="false_target"/>
    </target>

Would the coding of an AntCallIfElse task be, in the light of your
prior vote cited above, a welcome or unwelcome contribution?

--
Jack J. Woehr     # "I never worry that all hell will break loose.
Senior Consultant #  I worry that half hell will break loose, which
Purematrix, Inc.  #  is much harder to detect." - George Carlin



Mime
View raw message