You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by peter reilly <pe...@corvil.com> on 2003/08/14 11:20:58 UTC

[new tasks] presetdef and macrodef

Hi,
I have written a couple of tasks to enable definition of new tasks
in ant.

<presetdef> (formally known as extendtype)
  this defines a new task or type based on a current ant task or type, with
  attributes or elements preset.

  example useage:
  <presetdef name="my.javac">
       <javac debug="${debug}" deprecation="${deprecation}"/>
  </presetdef>

  <my.javac> may now be used as a task in the same way as <javac>
  but the attribute debug and deprecation will be preset.


<macrodef>
  this defines a new task in the same way as <scriptdef> except it
  uses a <sequential> as a defintion of the task. The <macrodef>
  task has nested elements - param and element to allow the
  user to specify attributes and elements of the new task. These
  get substituted into the <sequential> when the new task is
  run.

 example: (from a current project)
     <macrodef name="call-cc">
        <param name="target"/>
        <param name="link"/>
        <param name="target.dir"/>
        <element name="cc-elements"/>
        <sequential>
            <mkdir dir="${obj.dir}/${target}"/>
            <mkdir dir="${target.dir}"/>
            <cc link="${link}" objdir="${obj.dir}/${target}"
                outfile="${target.dir}/${target}">
                <compiler refid="compiler.options"/>
                <cc-elements/>
            </cc>
        </sequential>
    </macrodef>

    <macrodef name="compile-exec">
        <param name="program"/>
        <element name="cc-files"/>
        <sequential>
            <call-cc target="${program}" link="executable"
                     target.dir="${build.bin.dir}">
                <cc-elements>
                    <includepath location="${gen.dir}"/>
                    <includepath location="test"/>
                    <cc-files/>
                    <linker refid="linker-libs"/>
                </cc-elements>
            </call-cc>
        </sequential>
    </macrodef>

     <compile-exec program="unittests">
            <cc-files>
                <fileset dir="test/unittest" includes = "**/*.cpp"/>
                <fileset dir="${gen.dir}" includes = "*.cpp"/>
            </cc-files>
      </compile-exec>

Will I place these tasks in ant or ant-contrib ?

Peter

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


Re: [new tasks] presetdef and macrodef

Posted by Stefan Bodewig <bo...@apache.org>.
On Thu, 14 Aug 2003, peter reilly <pe...@corvil.com> wrote:

> Will I place these tasks in ant or ant-contrib ?

Ant, they sound very useful.  <presetdef> is a wonderful way to plug
in user preferences.

Stefan

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


Re: [new tasks] presetdef and macrodef

Posted by Nicola Ken Barozzi <ni...@apache.org>.
The following tasks will be an excellent addition for the use Centipede 
does of Ant, so it's a big thumbs up!

Presetdef can be used to redefine the most used Ant tasks adding the 
defaults taken from the descriptor we use.

macrodef can make us finally create real macros that are not only 
targets, as instead has been done till now, so we can really make 
libraries of tasks defined through Ant buildfiles and not have them 
necessarily as targets.

:-D

peter reilly wrote, On 14/08/2003 11.20:
> Hi,
> I have written a couple of tasks to enable definition of new tasks
> in ant.
> 
> <presetdef> (formally known as extendtype)
>   this defines a new task or type based on a current ant task or type, with
>   attributes or elements preset.
> 
>   example useage:
>   <presetdef name="my.javac">
>        <javac debug="${debug}" deprecation="${deprecation}"/>
>   </presetdef>
> 
>   <my.javac> may now be used as a task in the same way as <javac>
>   but the attribute debug and deprecation will be preset.
> 
> 
> <macrodef>
>   this defines a new task in the same way as <scriptdef> except it
>   uses a <sequential> as a defintion of the task. The <macrodef>
>   task has nested elements - param and element to allow the
>   user to specify attributes and elements of the new task. These
>   get substituted into the <sequential> when the new task is
>   run.
> 
>  example: (from a current project)
>      <macrodef name="call-cc">
>         <param name="target"/>
>         <param name="link"/>
>         <param name="target.dir"/>
>         <element name="cc-elements"/>
>         <sequential>
>             <mkdir dir="${obj.dir}/${target}"/>
>             <mkdir dir="${target.dir}"/>
>             <cc link="${link}" objdir="${obj.dir}/${target}"
>                 outfile="${target.dir}/${target}">
>                 <compiler refid="compiler.options"/>
>                 <cc-elements/>
>             </cc>
>         </sequential>
>     </macrodef>
> 
>     <macrodef name="compile-exec">
>         <param name="program"/>
>         <element name="cc-files"/>
>         <sequential>
>             <call-cc target="${program}" link="executable"
>                      target.dir="${build.bin.dir}">
>                 <cc-elements>
>                     <includepath location="${gen.dir}"/>
>                     <includepath location="test"/>
>                     <cc-files/>
>                     <linker refid="linker-libs"/>
>                 </cc-elements>
>             </call-cc>
>         </sequential>
>     </macrodef>
> 
>      <compile-exec program="unittests">
>             <cc-files>
>                 <fileset dir="test/unittest" includes = "**/*.cpp"/>
>                 <fileset dir="${gen.dir}" includes = "*.cpp"/>
>             </cc-files>
>       </compile-exec>
> 
> Will I place these tasks in ant or ant-contrib ?
> 
> Peter

-- 
Nicola Ken Barozzi                   nicolaken@apache.org
             - verba volant, scripta manent -
    (discussions get forgotten, just code remains)
---------------------------------------------------------------------



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


Re: [new tasks] presetdef and macrodef

Posted by peter reilly <pe...@corvil.com>.
On Thursday 14 August 2003 12:28, Knut Wannheden wrote:
>
> A question: is <macrodef> a special task in the sense that it seems to be
> able to suppress Ant from resolving properties for it when the task is
> evaluated?  Is there a mechanism which allows this to be done in custom
> tasks as well?

The trick is that MacroDef uses TaskContainer in a nested element. This
is given UnknownElements before they are executed.  MacroInstance
then copies and walks the tree of unknownelements, modifing
attribute values and text values.

Peter


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


Re: [new tasks] presetdef and macrodef

Posted by Knut Wannheden <kn...@paranor.ch>.
This looks excellent!  It makes Ant a lot more flexible, but at the same
time also more compilcated to use.  Buildfiles with (possibly nested)
<macrodef/>s and <include/>s could be a lot harder to understand and
maintain.  But if used correctly, probably easier!

A question: is <macrodef> a special task in the sense that it seems to be
able to suppress Ant from resolving properties for it when the task is
evaluated?  Is there a mechanism which allows this to be done in custom
tasks as well?

--
knut

"peter reilly" <pe...@corvil.com> wrote in message
news:200308141051.11605.peter.reilly@corvil.com...
> On Thursday 14 August 2003 10:31, Conor MacNeill wrote:
> > Cool.
> >
> > I think these should go in Ant :-)
> Excellent.
> >
> > As you know I had thought about <macrodef> but I'm happy to
> > see you've done it. I think there is a slight property scoping issue
> > for the nested params. I had thought about a different syntax for
> > macro params (e.g. $[target]), perhaps hooked into a specific property
> > helper used for the macro scope.
>
> Initially I used $(target) but changed back to using
> ${target} as this is what people (including me) are used to.
> The substitution is done by the task itself and does not
> use the ant property infrastructure. The effect of this is to
> have a macro textual scope for the parameters (which look like
> properties).
>
> I had looked at having a task scope for properties, but this
> looked difficult to achieve.
>
> Peter




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


Re: [new tasks] presetdef and macrodef

Posted by peter reilly <pe...@corvil.com>.
On Thursday 14 August 2003 10:31, Conor MacNeill wrote:
> Cool.
>
> I think these should go in Ant :-)
Excellent.
>
> As you know I had thought about <macrodef> but I'm happy to
> see you've done it. I think there is a slight property scoping issue
> for the nested params. I had thought about a different syntax for
> macro params (e.g. $[target]), perhaps hooked into a specific property
> helper used for the macro scope.

Initially I used $(target) but changed back to using
${target} as this is what people (including me) are used to.
The substitution is done by the task itself and does not
use the ant property infrastructure. The effect of this is to
have a macro textual scope for the parameters (which look like
properties).

I had looked at having a task scope for properties, but this
looked difficult to achieve.

Peter


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


RE: [new tasks] presetdef and macrodef

Posted by Conor MacNeill <co...@cortexebusiness.com.au>.
Cool.

I think these should go in Ant :-)

As you know I had thought about <macrodef> but I'm happy to 
see you've done it. I think there is a slight property scoping issue
for the nested params. I had thought about a different syntax for 
macro params (e.g. $[target]), perhaps hooked into a specific property 
helper used for the macro scope.

Conor



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


RE : [new tasks] presetdef and macrodef

Posted by Emmanuel FELLER <Em...@maaf.fr>.

>-----Message d'origine-----
>De : peter reilly [mailto:peter.reilly@corvil.com] 
>Envoyé : jeudi 14 août 2003 11:21
>À : dev@ant.apache.org
>Objet : [new tasks] presetdef and macrodef
>
>
>Hi,
>I have written a couple of tasks to enable definition of new tasks
>in ant.
>
><presetdef> (formally known as extendtype)

[snip/]

><macrodef>
>  this defines a new task in the same way as <scriptdef> except it
>  uses a <sequential> as a defintion of the task. The <macrodef>
>  task has nested elements - param and element to allow the
>  user to specify attributes and elements of the new task. These
>  get substituted into the <sequential> when the new task is
>  run.
>

[snip/]

Hi,

I was looking to this kind of features when I started my build file
developement. I solved my need by doing dirty antcall.

I am very happy to see this in ant core now, and I will adapt my build
file as soon as possible ! :))
And it should solve some of my properties issues.

Thanks, it is a good job! (Like everybody's one) 

I am using Ant for two years and i never find real blocker issues, or
already closed in cvs. This kind of new features give me the desire for
taking an active part.

Thanks everybody!
Emmanuel 


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