ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jack Woehr <>
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


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">
           <equals arg1="${determinant}" arg2="yes"/>
       <antcall target="${callWhich}"/>

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

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

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

I'm looking at

      [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:

        <if target="true_target">
        <else target="false_target">

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

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

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

    <target name="switch">
            <antcall target="true_target"/>
            <antcall target="false_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

View raw message