I think this should be possible. I'm actually (slowly,
when I have the time) working on building in support
for this with jython. In Jython (as in Rhinoscript,
I believe) you can compile a python class to a 
java class, which can easily subclass an ant Task.
So I'm developing three ant tasks:

1)a task for running jython scripts (basically a more
jython-friendly version of Script task)
2)a task for compiling jython classes to java classes
3)a task for defining & compiling an ant task from a jython

So far only task 1) is done :) 

I'm planning on submitting these to the jython group
since (from listening to the jython-dev list) this is
not the sort of thing the ant developers want to 
encourage or maintain.

The third task is the interesting one. You should be
able to define a new task inline in your ant build
like this:

<jytaskdef name="cat">
    def setFile(self, String fileName):
        self.fileName = fileName

    def execute(self):
        print open(self.fileName).read()    

The above snippet would embed the code in a jython
class which extends org.apache.ant.main.Task, 
compile the jython class into a java class,
then define the task.

One of the (anticipated) beauties of this system
is that you could very rapidly create new tasks
by embedding them in your ant script. There would
be an easy path to convert tasks that
seem to be of more general usage into reusable 
tasks; maybe by adding a 'jar' attribute to
the jytaskdef.

I see no reason why you could not do the same 
thing for javascript, and I intend to once/if
I get a workable jython system.

Markus Kohler wrote:
> Hi,
> > -----Original Message-----
> > From: Erik Hatcher [mailto:[EMAIL PROTECTED]]
> > Sent: Wednesday, October 31, 2001 12:00 PM
> > To: Ant Users List; [EMAIL PROTECTED]
> > Subject: Re: script documentation
> >
> >
> > ----- Original Message -----
> > From: "Markus Kohler" <[EMAIL PROTECTED]>
> > > I wonder if it wouldn't be possible to support defining new
> > Tasks just
> > using
> > > Java script(or any other supported scripting language).
> > > I think that could be a very powerfull feature.
> >
> > You could define a <script> "task" within a standalone target (i.e. no
> > depends clause) and <antcall> to it - which would in effect
> > allow you to
> > have re-usable script code that could be used just like a Task.
> >
> > So the power is there!
> Yes. That's how I plan to doit now.
> >
> > Now just share anything slick you can do with it, as I've
> > only seen useful
> > one-liners in <script>.
> >
> Currently I'm calling  my own specific Java code for dumping information
> that is
> inside my jar file. It's not really usefull for general use.
> Anyway I think it would be even cooler, if I could just define some New
> Tasks using javascript, and with my limited knowledge about ANT's design, I
> cannot see why this would be
> difficult to support.
> Markus
> --
> To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to