You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by Alexey Solofnenko <A....@mdl.com> on 2003/06/06 17:33:52 UTC

RE: Embedded dynamic ANT tasks.

Hello Dawid,

  I was thinking about something like that. There is DynamicConfigurator to
support dynamic properties, but there is no way to create dynamic tasks.
Maybe we should ask ANT developers to support task factories in addition to
class names. It would be a simple patch. For example in
ComponentHelper.createNewTask() we can add something like:

if (o instanceof TaskFactory) {
  o=((TaskFactory)o).createNewTask(taskType);
}

// continue
if (o instanceof Task) {
....


- Alexey.

--
{ http://trelony.cjb.net/ } Alexey N. Solofnenko
Pleasant Hill, CA (GMT-8 usually)


-----Original Message-----
From: Dawid Weiss [mailto:Dawid.Weiss@cs.put.poznan.pl] 
Sent: Friday, June 06, 2003 7:53 AM
To: user@ant.apache.org
Subject: Embedded dynamic ANT tasks.


Dear ANT community,

I thought one day: maybe it would be fun if I could define ANT tasks INSIDE
the  ANT  script that is being executed? So it could look like this:

> <!-- Define an embedded task and use it immediately -->
> <target name="example" depends="prepare">
> 
>     <!-- define the task -->
>     <embeddedtaskdef name="counterTask"><![CDATA[
>         String message;
>         int    min;
>         int    max;
>         
>         void setMin(int min) {
>             // note how 'global' is used instead of 'this'
>             // global scope refers to the task instance anyway.
>             global.min = min;
>         }
> 
>         void setMax(int max) {
>             global.max = max;
>         }
> 
>         void setMessage(String message) {
>             global.message = message;
>         }
> 
>         void execute() {
>             if (message != null)
>                 System.out.print(message);
>             for (int i=min;i<max;i++) {
>                 System.out.print(i);
>                 if (i+1 != max) System.out.print(",");
>             }
>         }
>     ]]></embeddedtaskdef>
>     
>     <!-- use the defined task right away! -->
>     <counterTask min="0" max="10" message="The numbers from 0 to 10 are: "
/>
>     <counterTask min="5" max="20" message="And the numbers from 5 to 20
are: " />
> </target>


I've played with BSH and BCEL and the solution can be found at:

http://www.cs.put.poznan.pl/dweiss/index.php/projects/bsh-binding/index.xml?
lang=en

I  personally find it quite a useful task, even though it started purely as
a toy and a mind-exerciser :)

Regards,
Dawid

_______________________
Dawid Weiss, http://www.cs.put.poznan.pl/dweiss
Laboratory of Intelligent Decision Support Systems, Poznan UT, Poland


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

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


Re[2]: Embedded dynamic ANT tasks.

Posted by Dawid Weiss <Da...@cs.put.poznan.pl>.
It    could   certainly be done in other ways than what I have implemented;
so you are probably right - you could modify ANT towards this direction.

On the other hand... the ANT task/ extension I created really does work, so
maybe    modifying    ANT    is    no    longer  needed  and  it  can  stay
within the borders of task-is-a-class technique.

Anyway,  playing with BeanShell and BCEL was good fun :) It was a little bit
like  the times when I used to write a dynamic assembly code (the code that
actually produced code to be executed).

Again,  if  you want to try out the BeanShell wrapper feel free to download
it from here -

http://www.cs.put.poznan.pl/dweiss/index.php/projects/bsh-binding/index.xml


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


Re[2]: Embedded dynamic ANT tasks.

Posted by Dawid Weiss <Da...@cs.put.poznan.pl>.
It    could   certainly be done in other ways than what I have implemented;
so you are probably right - you could modify ANT towards this direction.

On the other hand... the ANT task/ extension I created really does work, so
maybe    modifying    ANT    is    no    longer  needed  and  it  can  stay
within the borders of task-is-a-class technique.

Anyway,  playing with BeanShell and BCEL was good fun :) It was a little bit
like  the times when I used to write a dynamic assembly code (the code that
actually produced code to be executed).

Again,  if  you want to try out the BeanShell wrapper feel free to download
it from here -

http://www.cs.put.poznan.pl/dweiss/index.php/projects/bsh-binding/index.xml


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