ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Richard Emberson <>
Subject three requests
Date Thu, 29 Nov 2001 17:46:49 GMT
Below are three changes I'd like to see in Ant (basically so that I can
integrate my application
as a task).  Thanks.
Richard Emberson

ONE - Fix org/apache/tools/ant/taskdefs/

The current implementation is incorrect because 1) it uses
java code that is not in the java public api; 2) its simply
wrong, if sun.misc.BASE64Encoder is not in the classpath, then
this code fails during class loading, not during execution.

    // check to see if sun's Base64 encoder is available.
    try {
        sun.misc.BASE64Encoder encoder = (sun.misc.BASE64Encoder)
        encoding = encoder.encode (up.getBytes());
    catch (Exception ex) { // sun's base64 encoder isn't available

    // check to see if sun's Base64 encoder is available.
    try {
        Class bcls = Class.forName("Ljava.lang.Byte.TYPE");
        Class cls = Class.forName("sun.misc.BASE64Encoder");
        java.lang.reflect.Method m = cls.getDeclaredMethod(
                    "encode", new Class[] { bcls });
        Object o = cls.newInstance();
        encoding = (String)m.invoke(o, new Object[] { up.getBytes() } );

    catch (Exception ex) { // sun's base64 encoder isn't available

TWO - Task wrapping application which uses xml to specify its behavior:

I have an application that uses xml to specify its behavior much
like Tomcat or Ant (element tag name to class mappings plus attributes).

 What I'd like to do is simply embed as child
elements of the wrapper task's element the application's xml.
The simplest way to do this is to allow such task to use its own
DocumentHandler (maybe the wrapper task can have a DocumentHandler
derived from the ProjectHelper.AbstractHandler if it were public) and
install it when the task's element tag is recognized, elementStart and
removed at endElement. Oh yea, the application has its own introspector.

In addition, the application's inner element tag names may or may not
collide with tag names already used by Ant (like 'target').

THREE - Dynamically set the tag-2-class in Introspector.

What the RuntimeConfigurable class allows is for the element tag
to class mapping to be created (Introspectors stored in the hashtable)
and then during the execution phase to set the attributes. Very
nice (since one certainly does not want to set attributes for
tasks that are not going to be executed). Here is the problem,
I've got a class that uses an implementation of OutputHandler
interface. There is a default implementation, StdOut which is used
if none other is specified as an attribute, for example,
        ... other stuff
uses the default OutputHandler, StdOut. On the other hand the following
uses the FileBackup OutputHandler:
    <myapp outputHandler="">
        ... other stuff
When the outputHandler attribute is set, an instance of the FileBackup
OutputHandler is created and installed. Now, StdOut has no attributes
FileBackup does have attributes, specifically which file suffix to use,
so I can do the following:
    <myapp outputHandler="">
        <outputHandler suffix="bak"/>
        ... other stuff
Which sets the suffix to 'bak'. Now the following, of course fails:
        <outputHandler suffix="bak"/>
        ... other stuff
Because the StdOut OutputHandler does not, via reflection, have the
attribute suffix (method setSuffix()). So what my application does
is to do reflection, the element tag to class mapping, and
attribute setting at the same time, as each element is encounted.
I realize that Ant can not do this, but Ant ought to provide
a mechanism so that a task can change an inner elements name to
class binding in the Introspector hashtable depending upon its
own attribute settings.

To unsubscribe, e-mail:   <>
For additional commands, e-mail: <>

View raw message