ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jose Alberto Fernandez <JFernan...@viquity.com>
Subject RE: Javaworld Article about Ant
Date Tue, 24 Oct 2000 19:11:05 GMT
> From: Sam Ruby/Raleigh/IBM [mailto:rubys@us.ibm.com]
> 
> Jose Alberto Fernandez wrote:
> >
> > BTW, can someone tell me how to do introspection
> > on a piece of BSF script?  I would like to find
> > out what functions are defined on a script.
> > And its parameter type information.
> 
> Not possible.  To BSF, it is simply a string.  In fact, many scripting
> languages don't even have the concept of staticly defined functions or
> parameter type information.
> 

But in BSF there is a call(...) API to call a function defined in a script.
So it seems that there should be a way to identify the functions that are
there.

What I would like to be able to do is the following:

1) Being able to define a task as a script:

  <scriptdef name="mytask" language="javascript" >
    function setArg1(...){...}
    function setArg2(...){...}
    function createArg3(){...}
    function init(){...}
    function execute(){...}
  </scriptdef>

2) Such task will do as Nico suggested, define the task using
a predefined java class that will know how to find and execute the script.
This is the part I have a little fuzzy, where to store the script
associated with the task, since in the current ANT the task table only
stores
instances of classes. I need to store actual script instances.

3) Use the task as any normal task:
  
  <target .... >
    <mytask arg1="a" arg2="b" >
     <arg3 ... />
    </mytask>
  </target>

4) And of course, being able to define such task in the proposed tasklib.xml
model that we have been talking for 2.0.

In other words, a user should see no difference between Java based tasks and
script based tasks from the point of view of usability. I should be able to
define 
something using scripts in a tasklib, and then in the future reimplement it
in
Java without a need to change the build.xml file.

The best would be to be able to say:

<taskdef name="mytask" ....>
  <script ....>
  </script>
</taskdef>

But given that taskdef is core and script is optional, I do not know how we
could
settle this, unless we modify <taskdef> to provide a more open architecture.
For example, do not assume tasks are only classes, but use a factory pattern
to access them.

<taskdef name="copy" >
  <factory classname="org.apache.ant.DefaultTaskFactory">
    org.apache.ant.taskdefs.Copy
  </factory>
</taskdef>

The above would be equivalent for the current shorthand definition:

<taskdef name="copy" classname="org.apache.ant.taskdefs.Copy" />

But with this syntax the proposed script could be defined as:

<taskdef name="mytask" >
  <factory classname="org.apache.ant.taskdefs.optional.ScriptFactory">
    function setArg1(...){...}
    function setArg2(...){...}
    function createArg3(){...}
    function init(){...}
    function execute(){...}
  </factory>
</taskdef>

Which means that it is upto the Factory to interpret the String as
appropriate.

Does this makes sense?

Jose Alberto

Mime
View raw message