You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by Colm Smyth <la...@gmail.com> on 2008/05/12 00:51:25 UTC

Tiny patch to enable Recursion in Ant

Hi,

I wanted to be able to easily write recursive Ant build files, so I
developed a macro and a small patch to Ant. I'd like the advice of the
dev list as to if and how I should submit this patch for inclusion in
Ant.

The patch (roughly 30 extra lines of code across 6 files) adds two new
*dynamic* properties to Ant:
 1) ant.project.target - the default target of the current project
 2) ant.current.target - a comma-separated list of the actual targets
that were invoked on the current project

These properties are updated automatically, similar to ant.file or
ant.project.name.

The "recurse" macro uses the antcontrib:for task to iterate over
multiple targets (the antcontrib jar required the "for" task to be
added to its properties). The macro can accept an explicit list of
targets, but I also wanted to be able to recurse on the targets that
were actually invoked.

Here's how you would use it:

 <!-- define the "recurse" macro -->
 <typedef file="recurse.xml"/>

 <!-- "subdirs" is the ordered list of sub-folders that "recurse" uses -->
 <filelist dir="." id="subdirs" files="x1,x2"/>

 <!-- invokes the macro on the current target(s), which may be the
ones specified or the default target -->
 <recurse/>

Alternatively:
 <!-- invoke the macro on the specified targets -->
 <recurse targets="this,that,other"/>

My Ant experience is limited, so I may have overlooked an existing way
to achieve this, but reading and searching suggests that others are
still missing recursion in Ant. I look forward to your advice!

 All the best,
 Colm.

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


AW: Tiny patch to enable Recursion in Ant

Posted by Ja...@rzf.fin-nrw.de.
> I could imagine a task to set a property to the current target
> 
> <location target="targetproperty" buildfile="fileproperty" />
> 
> ...maybe even something for a complete stack trace/list of 
> imports that 
> is live


I found an old implementation of getting the information.
Enhancing with setting the property shouldnt be difficult ;-)

Jan


<project default="main">

    <scriptdef name="whereAmI" language="javascript"><![CDATA[
        selfAsTarget = self;
        currentTarget = selfAsTarget.getOwningTarget();
        currentLocation = selfAsTarget.getLocation();
        project.log(currentLocation + "Target '" + currentTarget + "'");
    ]]></scriptdef>

    <target name="one">
        <whereAmI/>
    </target>

    <target name="two">
        <whereAmI/>
    </target>

    <target name="main" depends="one,two">
        <whereAmI/>
    </target>

</project>

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


Re: Tiny patch to enable Recursion in Ant

Posted by Stefan Bodewig <bo...@apache.org>.
On Wed, 28 May 2008, Colm Smyth <la...@gmail.com> wrote:

> It's nice to see some feedback and new ideas; would anybody like to
> comment on what I actually did? ;)
> 
> See https://issues.apache.org/bugzilla/show_bug.cgi?id=44980 for the
> issue I raised almost immediately after posting a request for
> comments.

Thanks, I missed that, will look into it soon.

Stefan

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


Re: Tiny patch to enable Recursion in Ant

Posted by Colm Smyth <la...@gmail.com>.
It's nice to see some feedback and new ideas; would anybody like to
comment on what I actually did? ;)

See https://issues.apache.org/bugzilla/show_bug.cgi?id=44980 for the
issue I raised almost immediately after posting a request for
comments.

2008/5/28 Steve Loughran <st...@apache.org>:
> Stefan Bodewig wrote:
>>
>> sorry for the delay, a combination of a whole lot of work, a broken
>> iBook, very nice weather and severe back pain (not necessarily in that
>> order) have kept me offline.
>>
>> On Wed, 14 May 2008, Colm Smyth <la...@gmail.com> wrote:
>>
>>> Yes I used subant, but as I said, it can't recurse on the current
>>> target.
>>>
>>> Since recursion should be a core function of a hierarchical build
>>> system, I think this patch is worth adding to Ant.
>>
>> First of all your original mail didn't contain the patch itself.
>>
>> Second you said you used ant-contrib's for and I pointed out that
>> subant should be enough.  The only thing that's missing is a property
>> that knows the current target, isn't it?
>>
>> I know we have rejected the idea of such a property in the past, but
>> we may be at a different point today, so if you open an enhancement
>> request for such a property (or find the old one and reopen it), that
>> would e the right place to attach a patch to enable it.
>
> I could imagine a task to set a property to the current target
>
> <location target="targetproperty" buildfile="fileproperty" />
>
> ...maybe even something for a complete stack trace/list of imports that is
> live
>
> --
> Steve Loughran                  http://www.1060.org/blogxter/publish/5
> Author: Ant in Action           http://antbook.org/
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
> For additional commands, e-mail: dev-help@ant.apache.org
>
>

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


Re: Tiny patch to enable Recursion in Ant

Posted by Stefan Bodewig <bo...@apache.org>.
On Wed, 28 May 2008, Steve Loughran <st...@apache.org> wrote:

>Stefan Bodewig wrote:

>> Second you said you used ant-contrib's for and I pointed out that
>> subant should be enough.  The only thing that's missing is a property
>> that knows the current target, isn't it?
>>
>> I know we have rejected the idea of such a property in the past, but
>> we may be at a different point today,
>
> I could imagine a task to set a property to the current target
>
> <location target="targetproperty" buildfile="fileproperty" />
>
> ...maybe even something for a complete stack trace/list of imports
> that is live

Please note that this is not the what Colm is asking for.  With
"current target" I meant the target that has been specified on the
command line (or the default target of the build), not the target a
task lives in.

Stefan

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


Re: Tiny patch to enable Recursion in Ant

Posted by Steve Loughran <st...@apache.org>.
Stefan Bodewig wrote:
> sorry for the delay, a combination of a whole lot of work, a broken
> iBook, very nice weather and severe back pain (not necessarily in that
> order) have kept me offline.
> 
> On Wed, 14 May 2008, Colm Smyth <la...@gmail.com> wrote:
> 
>> Yes I used subant, but as I said, it can't recurse on the current
>> target.
>>
>> Since recursion should be a core function of a hierarchical build
>> system, I think this patch is worth adding to Ant.
> 
> First of all your original mail didn't contain the patch itself.
> 
> Second you said you used ant-contrib's for and I pointed out that
> subant should be enough.  The only thing that's missing is a property
> that knows the current target, isn't it?
> 
> I know we have rejected the idea of such a property in the past, but
> we may be at a different point today, so if you open an enhancement
> request for such a property (or find the old one and reopen it), that
> would e the right place to attach a patch to enable it.

I could imagine a task to set a property to the current target

<location target="targetproperty" buildfile="fileproperty" />

...maybe even something for a complete stack trace/list of imports that 
is live

-- 
Steve Loughran                  http://www.1060.org/blogxter/publish/5
Author: Ant in Action           http://antbook.org/

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


Re: patches for DBpatch

Posted by Andrus Adamchik <an...@objectstyle.org>.
Thank you very much :-)

On May 29, 2008, at 6:54 PM, Stefan Bodewig wrote:

> On Wed, 28 May 2008, Andrus Adamchik <an...@objectstyle.org> wrote:
>
>> While we are at it, would it be possible to apply 2 patches per
>> tickets # 44969 and 45075?
>
> Done
>
> Stefan
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
> For additional commands, e-mail: dev-help@ant.apache.org
>
>


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


Re: patches for DBpatch

Posted by Stefan Bodewig <bo...@apache.org>.
On Wed, 28 May 2008, Andrus Adamchik <an...@objectstyle.org> wrote:

> While we are at it, would it be possible to apply 2 patches per
> tickets # 44969 and 45075?

Done

Stefan

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


patches for DBpatch [Was: Tiny patch to enable Recursion in Ant]

Posted by Andrus Adamchik <an...@objectstyle.org>.
Hi Stefan,

While we are at it, would it be possible to apply 2 patches per  
tickets # 44969 and 45075?

Thanks,
Andrus


On May 28, 2008, at 7:40 AM, Stefan Bodewig wrote:

> sorry for the delay, a combination of a whole lot of work, a broken
> iBook, very nice weather and severe back pain (not necessarily in that
> order) have kept me offline.
>
> On Wed, 14 May 2008, Colm Smyth <la...@gmail.com> wrote:
>
>> Yes I used subant, but as I said, it can't recurse on the current
>> target.
>>
>> Since recursion should be a core function of a hierarchical build
>> system, I think this patch is worth adding to Ant.
>
> First of all your original mail didn't contain the patch itself.
>
> Second you said you used ant-contrib's for and I pointed out that
> subant should be enough.  The only thing that's missing is a property
> that knows the current target, isn't it?
>
> I know we have rejected the idea of such a property in the past, but
> we may be at a different point today, so if you open an enhancement
> request for such a property (or find the old one and reopen it), that
> would e the right place to attach a patch to enable it.
>
> Stefan
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
> For additional commands, e-mail: dev-help@ant.apache.org
>
>


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


Re: Tiny patch to enable Recursion in Ant

Posted by Stefan Bodewig <bo...@apache.org>.
sorry for the delay, a combination of a whole lot of work, a broken
iBook, very nice weather and severe back pain (not necessarily in that
order) have kept me offline.

On Wed, 14 May 2008, Colm Smyth <la...@gmail.com> wrote:

> Yes I used subant, but as I said, it can't recurse on the current
> target.
> 
> Since recursion should be a core function of a hierarchical build
> system, I think this patch is worth adding to Ant.

First of all your original mail didn't contain the patch itself.

Second you said you used ant-contrib's for and I pointed out that
subant should be enough.  The only thing that's missing is a property
that knows the current target, isn't it?

I know we have rejected the idea of such a property in the past, but
we may be at a different point today, so if you open an enhancement
request for such a property (or find the old one and reopen it), that
would e the right place to attach a patch to enable it.

Stefan

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


Re: Tiny patch to enable Recursion in Ant

Posted by Colm Smyth <la...@gmail.com>.
Yes I used subant, but as I said, it can't recurse on the current target.

Since recursion should be a core function of a hierarchical build
system, I think this patch is worth adding to Ant.

2008/5/14 Stefan Bodewig <bo...@apache.org>:
> On Sun, 11 May 2008, Colm Smyth <la...@gmail.com> wrote:
>
>  > My Ant experience is limited, so I may have overlooked an existing
>  > way to achieve this, but reading and searching suggests that others
>  > are still missing recursion in Ant. I look forward to your advice!
>
>  Apart from the ability to recurse for the current target, <subant>
>  should be able to do what you need.  Your changes might be able to
>  enable the "recurse using the current target" use-case for subant as
>  well.
>
>  Stefan
>
>  ---------------------------------------------------------------------
>  To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
>  For additional commands, e-mail: dev-help@ant.apache.org
>
>

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


Re: Tiny patch to enable Recursion in Ant

Posted by Stefan Bodewig <bo...@apache.org>.
On Sun, 11 May 2008, Colm Smyth <la...@gmail.com> wrote:

> My Ant experience is limited, so I may have overlooked an existing
> way to achieve this, but reading and searching suggests that others
> are still missing recursion in Ant. I look forward to your advice!

Apart from the ability to recurse for the current target, <subant>
should be able to do what you need.  Your changes might be able to
enable the "recurse using the current target" use-case for subant as
well.

Stefan

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