ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mike Roberts <Mike.Robe...@digitalrum.com>
Subject RE: suggestions
Date Tue, 25 Sep 2001 17:33:31 GMT
Just come across this if-evaluation problem today. A complete hack I came up
with is:

    <target name="hack_preparer" if="myvar">
        <delete dir="touchdir"/>
        <mkdir dir="touchdir"/>
        <touch file="touchdir/${myvar}"/>

        <available file="touchdir/foo" property="my_var_is_foo"/>
        <available file="touchdir/bar" property="my_var_is_bar"/>
        <delete dir="touchdir"/>
    </target>
    
    <target name="do_if_foo" if="my_var_is_foo">
    </target>
    
    <target name="do_if_bar" if="my_var_is_bar">
    </target>
    
    <target name="mytarget" depends="hack_preparer">
        <antcall target="do_if_foo"/>
        <antcall target="do_if_bar"/>
    </target>

I know that the ant philosophy is that I should use a different property for
different scenarios. What I actually what conditional
evaluation for is that I want to check for special cases of a property, and
otherwise use the property value itself (so, a variant of the above hack)

eg:

- 'build trunk' will build from the single trunk location
- 'build 1.3' will build branch number 1.3
 
The only clean solution I can find, while keeping the user skill down, is to
do more stuff in my ant wrapper script. I don't like this
though since I'd rather keep all my ant wrapper scripts the same.

Mike

-----Original Message-----
From: Peter Donald [mailto:donaldp@apache.org]
Sent: 21 September 2001 08:21
To: ant-user@jakarta.apache.org
Subject: Re: suggestions


On Fri, 21 Sep 2001 15:34, Craig Longman wrote:
> On Thu, 2001-09-20 at 21:54, Peter Donald wrote:
> > > > --- Craig Longman <craigl@begeek.com> wrote:
> > > > >   <target name="target" if="some.property=hello"/>
> > > > >   <target name="target" if="some.property=goodbye"/>
> >
> > Because as soon as we did that there would almost imeadiately be someone
> > who wanted != and then probably < or > or ...
> >
> > Before too long you could have
> >
> > <target name="target" if="((x='y')&&(y>z+u))||(a~=b)"/>
>
> hehe.  yes, i guess you're absolutely right here.  in fact, i had even
> had a thought that if you could do an '=XXX', then why not use a regexp
> as the rhs and then you could do anything.  give 'em an inch... ;-)

;)

> > The if/else target attributes were originally added with much objection
> > from ant-dev and there are some (ie me) who would like to see them
> > removed altogether ;)
>
> interesting.  i am really not sure how i would do some of the things i
> need to do though.  at least, i think i need to do them.  anyway, i
> think if they're kept simple, they can be useful.

Basically an <if/> task so 

<target name="foo" if="X.set"/>

would become

<target name="foo">
 <if test="X.set">
  
 </if>
</target>

This would mean that the notion of <target/> go back to it's original notion

as a unit of work rather than what it is used for now (basiclly an if
block). 
It would also allow much more flexability inside targets.

> > <target name="bar" depends="foo" />
> > <target name="foo" depends="before"/>
>
> very clever.  the only problem is that this would mean i would be
> calling the 'bar' target, when what i really wanted to call was the
> 'foo' target.  but, this definitely acheives the desired effect, albeit
> being a /little/ convoluted.  and i'm sure playing with the names would
> still have the build code read sensibly.

The idea is to get away from thinking notions of order and towards thinking 
notions of dependencies. So what you sound like you want is something like

<target name="foo" depends="bar" />
<target name="bar" depends="old-foo" />
<target name="old-foo" depends="before"/>

So whatever you want to be executed last has to depend on what you want to 
execute first ;)

-- 
Cheers,

Pete

------------------------------------------------------
 Mark Twain: "In the real world, the right thing never
happens in the right place at the right time. It is 
the task of journalists and historians to rectify 
this error."
------------------------------------------------------

Mime
View raw message