ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From François Wolff <e...@noos.fr>
Subject Re: Proxy support in Ant
Date Fri, 03 May 2002 11:38:53 GMT
Stefan Bodewig wrote:

>On Thu, 02 May 2002, François Wolff <ejen@noos.fr> wrote:
>
>>I have written also a patch for the next 1.5 release of Ant (based
>>on the org.apache.tools.ant.Project class, revision 1.108).
>>
>
>This is the one I had a look at.  Ant 1.x is supposed to be JDK 1.1
>compatible (and even Ant2 will settle on 1.2, not 1.3).  Do you see
>any chance to rewrite your changes so that they use refelection and
>compile/run using JDK 1.1?
>
Thanks for your reply !

I have made a new patch for the Project class (still 1.108 CVS revision) 
that should be JDK 1.1 compatible (only tested with JDK 1.4 and Ant 
1.4.1 in the IntrospectionHelper class, because I don't have the entire 
CVS tree...).

The added code is:

    private static java.lang.reflect.Method isProxyClass;
    static {
        try {
            Class proxyClass = Class.forName("java.lang.reflect.Proxy");
            isProxyClass = proxyClass.getMethod("isProxyClass",
                                                new Class[]{ Class.class });
        } catch (Throwable t) {
            isProxyClass = null;
        }
    }

and, in getElementName(...) method,

        if (isProxyClass != null) {

            boolean isProxyInstance = false;

            try {
                Object o
                    = isProxyClass.invoke(null, new Object[]{ elementClass });
                isProxyInstance = ((Boolean)o).booleanValue();
            } catch (Throwable t) {
                isProxyInstance = false;
            }

            if (isProxyInstance) {
                Class[] interfaces = elementClass.getInterfaces();
                if (interfaces.length == 1)
                    return "Class " + interfaces[0].getName();
                else if (interfaces.length > 1) {
                    StringBuffer sb = new StringBuffer("Classes ");
                    for (int i = 0; i < interfaces.length; i++) {
                        if (i > 0)
                            sb.append(", ");
                        sb.append(interfaces[i].getName());
                    }
                    return sb.toString();
                }
            }
        }

See attachment.


>>I think it could be very interesting to add Proxy support in the
>>next release of Ant, because use of Proxys can be very useful when
>>adapting existing API to specific Ant constraints (create...,
>>set...).
>>
>
>Supporting it as an option is OK, but it cannot become part of Ant's
>core.
>
>Cheers
>
>        Stefan
>
Cheers,
F. Wolff.


Mime
View raw message