ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From peter reilly <lucyk...@eircom.net>
Subject RE: DynamicTag
Date Mon, 14 Apr 2003 23:50:20 GMT
Hi, I am on holidays, but have followed
this thread.

I have been playing with DynamicTag and it is
quite neat, but there are some issues with it..
I have made some modifications (well rewrite...)

1) DynamicTag uses UnknownElement. This part of ant code is
   undergoing a number of changes at the moment, and currently
   DynamicTag does not work with cvs ant.

   I extracted the stuff that unknownelement does and placed
   them in a method, this is compatible with apr12 ant cvs and with
   ant 1.5.x (tested with 1.5.2).

2) I would like to have dynamic tag behavior on the the current
   task as well as nested elements.

3) I would like to use reflection in the same way as ant uses
   reflection for setters and creators.

4) I would like to support multiple dynamic types in the same class.

I initially considered using only datatypes, but on consideration
it does make sense to have tasks as well. The problems with this
are:
   a) tasks that do not extend ant.task get wrapped by ant.taskadapter
      which may not be what is expected
   b) tasks have a more complex life cycle that datatypes (init,
      perform, execute methods)

Attached are two files : DynamicElementHelper and DynamicElementTask.

Tasks and Datatypes/Sub-elements extend DynamicElementTask. 
The signature dynamicElement(Type) is used to indicate the type that
this method will handle.
DynamicElementTask implements DynamicConfigurator, and calls
DynamicElementHelper, which looks up the tag name in the
projects tasks and datatypes, if found that, the method
uses reflection to see if the calling object has a matching
dynamicElement method for the type.

DynamicElementHelper is written so that if this idea
is considered useful, it can be used by IntrospectionHelper,
It that case, there would be no need for DynamicElementTask.


To do the original example:
    <buildpath id="tahoebuildpath">
        <tahoeresolver destdir="${destdir}"
                  dependencies="${dependencies}" 
    </buildpath>

BuildPath.java extends DynamicElementTask and adds a dynamic element
handler:

  // Creates a nested resolver
  public void dynamicElement(BuildPathResolver resolver) {
     if (this.resolver != null)
         throw new BuildException("resolver already defined");
     this.resolver = resolver;
  }

And the xml filters:

<target name="test" depends="-init" >
   <xmlchain toDir="./build/chain" extension=".xxx">
     <fileset refid="workOnStuf" />
     <filter1 attr1="v1" attr2="v2">
       <mysubelement .../>
     </filter1>
     <xincludefilter .../>
     <xmlfilter refid="other-filter"/>
   </xmlchain>
</target>

and in xml chain:

public void dynamicElement(XmlFilter filter) {
    filters.addElement(filter)
}

One may also nest the custom filters in the same way as
dynamictag by writing a new class 

public class CustomFilters extends DynamicElementTask {
   private Vector filters = new Vector();
   public void dynamicElement(XmlFilter filter) {
      filters.addElement(filter);
   }
   public Vector getFilters() { return filters;}
}

and in XmlChain:
  public void addCustomFilters(CustomFilters customFilters) {
    this.customFilters = customFilters;
  }

Cheers,

Peter

Dominique Devienne wrote:
>>Two comments:

>>1) DynamicTag is fully Ant 1.5.x compatible. No need for 1.6. Just use
it
>>along side your own classes, and you're good to go.

>>2) DynamicTag *relies* on <taskdef> or <typedef> (you can declare your
>>custom extension either way), which takes care of all the
classloading,
>>already has all the special stuff like loaderref. Any enhancement to
these
>>tasks automatically benefit DynamicTag.



Mime
View raw message