ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From umag...@apache.org
Subject cvs commit: jakarta-ant/proposal/sandbox/filterreaders/src/main/org/apache/tools/ant/filters ClassConstants.java
Date Tue, 05 Mar 2002 20:40:37 GMT
umagesh     02/03/05 12:40:36

  Modified:    proposal/sandbox/filterreaders/src/main/org/apache/tools/ant/filters
                        ClassConstants.java
  Log:
  Eliminate compile time dependency of ClassConstants with JavaClasshelper that uses bcel.
 Compilation of JavaClassHelper will be performed only if bcel is present at the time of compile.
  
  Revision  Changes    Path
  1.5       +37 -5     jakarta-ant/proposal/sandbox/filterreaders/src/main/org/apache/tools/ant/filters/ClassConstants.java
  
  Index: ClassConstants.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/sandbox/filterreaders/src/main/org/apache/tools/ant/filters/ClassConstants.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- ClassConstants.java	4 Mar 2002 00:33:11 -0000	1.4
  +++ ClassConstants.java	5 Mar 2002 20:40:36 -0000	1.5
  @@ -56,9 +56,10 @@
   import java.io.ByteArrayInputStream;
   import java.io.IOException;
   import java.io.Reader;
  +import java.lang.reflect.InvocationTargetException;
  +import java.lang.reflect.Method;
   
   import org.apache.tools.ant.Project;
  -import org.apache.tools.ant.filters.util.JavaClassHelper;
   
   /**
    * Assemble the constants declared in a Java class in
  @@ -92,6 +93,10 @@
       /** Data that must be read from, if not null. */
       private String queuedData = null;
   
  +    /** Helper Class to be invoked via reflection. */
  +    private String JAVA_CLASS_HELPER =
  +        "org.apache.tools.ant.filters.util.JavaClassHelper";
  +
       /**
        * This constructor is a dummy constructor and is
        * not meant to be used by any class other than Ant's
  @@ -134,10 +139,37 @@
                   ch = -1;
               } else {
                   final byte[] bytes = clazz.getBytes();
  -                final StringBuffer sb = JavaClassHelper.getConstants(bytes);
  -                if (sb.length() > 0) {
  -                    queuedData = sb.toString();
  -                    return read();
  +                try {
  +                    final Class javaClassHelper =
  +                        Class.forName(JAVA_CLASS_HELPER);
  +                    if (javaClassHelper != null) {
  +                        final Class params[] = {
  +                            byte[].class
  +                        };
  +                        final Method getConstants =
  +                            javaClassHelper.getMethod("getConstants", params);
  +                        final Object[] args = {
  +                            bytes
  +                        };
  +                        // getConstants is a staic method, no need to
  +                        // pass in the object
  +                        final StringBuffer sb = (StringBuffer)
  +                                getConstants.invoke(null, args);
  +                        if (sb.length() > 0) {
  +                            queuedData = sb.toString();
  +                            return read();
  +                        }
  +                    }
  +                } catch (ClassNotFoundException cnfe) {
  +                    throw new IOException(cnfe.getMessage());
  +                } catch (NoSuchMethodException nsme) {
  +                    throw new IOException(nsme.getMessage());
  +                } catch (IllegalAccessException iae) {
  +                    throw new IOException(iae.getMessage());
  +                } catch (IllegalArgumentException iarge) {
  +                    throw new IOException(iarge.getMessage());
  +                } catch (InvocationTargetException ite) {
  +                    throw new IOException(ite.getMessage());
                   }
               }
           }
  
  
  

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