ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Leo Sutic" <leo.su...@inspireinfrastructure.com>
Subject private to protected and extensibility of Ant
Date Sat, 14 Sep 2002 14:34:14 GMT
All,

I recently upgraded to Ant 1.5 and saw some of my code break.

No big deal that, but I'd like to 

 + offer some feedback on Ant

 + make one suggestion

Ant is good, otherwise I wouldn't use it. Now for the bad part.

 + Ant is difficult to extend.

   Take the Ant task for example. I have a subclass (now broken)
   that allows the addition of a subclass of Property to the
   Ant task. The Property subclass works just like its superclass,
   but it is lazily evaluated. I won't dwell on it, but basically
   I have a subclass of Ant, that would like to add a subclass of
   Property to the invoked project.

   In Ant 1.4, I could do this:

   public LazyProperty createLazyProperty() {
     if (p1 == null) {
            init();
        }

        LazyProperty p= (LazyProperty) p1.createTask ("lazyproperty");
        if (p == null) {
            p1.addTaskDefinition ("lazyproperty", LazyProperty.class);
            p= (LazyProperty)p1.createTask("lazyproperty");
        }
        p.setUserProperty (true);
        properties.addElement (p);
        return p;
      }
    }

    In Ant 1.5, init() and properties are private to Ant.

    A similar situation occurred when I wanted the SQLExec task to
    output data in XML format. I ended up simply copying the SQLExec
task
    (not subclassing) and added my functionality to the copy. Much
easier.

    So I would like to, well, *raise awareness*, that you shouldn't be 
    over-eager with the private and final keywords, because it severely
    cripples the extensibility of Ant itself.

Suggestion:

    In all simplicity. Add a 

       protected void addProperty(Property property) {
        if (newProject == null) {
            reinit();
        }
        properties.addElement(p);
       }

    method to the Ant task. I would like to have protected accessors
    for all fields, but for now, this is enough.

/LS


--
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