ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Aslak Helles√ły <aslak.helle...@netcom.no>
Subject Dynamic createBlaBla methods in Ant tasks using BCEL at runtime
Date Thu, 25 Apr 2002 23:27:32 GMT
Hi Erik, Ant, XDoclet. (I'm crossposting, and I'm not subscribed to ant-dev,
so if you want to reach me, please mail me personally or to xdoclet-devel).

This is a follow up to some mails Erik Hatcher and Ara Abrahamian (XDoclet
admin) posted to ant-dev some weeks ago.

I think I know how you (Ant) can incorporate the dynamic BCEL/createBlaBla
generation in tasks in the Ant core.
We're already doing this in XDoclet and are using it for dynamic modules
where we don't know at compile-time what
aub-elements a task will have.

You'll have to add

   private final Vector subTasks = new Vector(); // You're trying to avoid
the java.util.List aren't you ;-)

   protected void addSubTask(Object o) {
      _subTasks.add(o);
   }

   protected List/Vector getSubTasks() {
      return _subTasks;
   }

to org.apache.tools.ant.taskdefs.Task

If all ant modules have a deployment descriptor (which they do, don't they?)
have a section à la

   <subtask
      name="aslak"
      implementation-class="com.aslak.AslakServerSubTask"
      parent-task-class="org.apache.tools.ant.taskdefs.optional.ejb.EjbJar"
   />

for all classes intended to be used as subtasks you should have all the info
you need.
We use xdoclet to generate these deployment descriptors for our own plugins.
The BCEL-savvy class-loader will insert a method like this

   public com.aslak.AslakServerSubTask createAslak() {
      com.aslak.AslakServerSubTask = new com.aslak.AslakServerSubTask();
      addSubTask(subTask);
      return subTask;
   }

into org.apache.tools.ant.taskdefs.optional.ejb.EjbJar

P.S.
Currently we are in XDoclet generating slightly different and a bit more
fragile code:

   public com.aslak.AslakServerSubTask createAslak() {
      com.aslak.AslakServerSubTask = new com.aslak.AslakServerSubTask();
      _subTasks.add(subTask);
      return subTask;
   }

-so the BCEL juggling would be a bit modified from what you'll find inside
xdoclet.loader.BootstrapClassLoader,
but this is something you should definitely consider adding to the Ant core.
(IMHO).
D.S


Do you think this could work for you? Feel free to steal/improve the code
under xdoclet.loader

Thanks for a great product! (You probably don't hear that too often. People
must be taking you for granted now ;-)

Cheers,
Aslak


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


Mime
View raw message