axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject cvs commit: xml-axis/java/src/org/apache/axis/utils/compiler Javac.java
Date Wed, 05 Jun 2002 18:53:42 GMT
dims        2002/06/05 11:53:41

  Modified:    java/src/org/apache/axis/utils/compiler Javac.java
  Log:
  Use Reflection to avoid deprecation errors.
  
  NOTE:
  com.sun.tools.javac.Main does not have an entry point for passing an output stream to capture
the compile errors.
  So we use sun.tools.javac.Main entry-point in both environments. The modern flag is needed
to parse the output,
  
  Revision  Changes    Path
  1.8       +26 -5     xml-axis/java/src/org/apache/axis/utils/compiler/Javac.java
  
  Index: Javac.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/utils/compiler/Javac.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- Javac.java	15 Mar 2002 01:14:11 -0000	1.7
  +++ Javac.java	5 Jun 2002 18:53:41 -0000	1.8
  @@ -56,7 +56,6 @@
   package org.apache.axis.utils.compiler;
   
   import org.apache.axis.utils.JavaUtils;
  -
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
   
  @@ -65,6 +64,9 @@
   import java.io.ByteArrayOutputStream;
   import java.io.File;
   import java.io.IOException;
  +import java.io.OutputStream;
  +import java.lang.reflect.Constructor;
  +import java.lang.reflect.Method;
   import java.util.ArrayList;
   import java.util.List;
   import java.util.NoSuchElementException;
  @@ -75,7 +77,7 @@
    *
    * @author <a href="mailto:dims@yahoo.com">Davanum Srinivas</a>
    * @author <a href="mailto:stefano@apache.org">Stefano Mazzocchi</a>
  - * @version $Revision: 1.7 $ $Date: 2002/03/15 01:14:11 $
  + * @version $Revision: 1.8 $ $Date: 2002/06/05 18:53:41 $
    * @since 2.0
    */
   
  @@ -120,9 +122,28 @@
        */
       public boolean compile() throws IOException {
           ByteArrayOutputStream err = new ByteArrayOutputStream();
  -        sun.tools.javac.Main compiler = new sun.tools.javac.Main(err, "javac");
  -        boolean result =
  -                compiler.compile(toStringArray(fillArguments(new ArrayList())));
  +        boolean result = false;
  +
  +        try {
  +            // Create an instance of the compiler, redirecting output to err
  +            Class c = Class.forName("sun.tools.javac.Main");
  +            Constructor cons =
  +                c.getConstructor(new Class[] { OutputStream.class,
  +                                               String.class });
  +            Object compiler = cons.newInstance(new Object[] { err,
  +                                                              "javac" });
  +            // Call the compile() method
  +            Method compile = c.getMethod("compile",
  +                                         new Class [] { String[].class });
  +            Boolean ok =
  +                (Boolean) compile.invoke(compiler,
  +                                        new Object[] {toStringArray(fillArguments(new ArrayList()))});
  +            result = ok.booleanValue();
  +        } catch (Exception cnfe){
  +            log.error(JavaUtils.getMessage("noCompiler00"), cnfe);
  +            throw new RuntimeException(JavaUtils.getMessage("noCompiler00"));
  +        }
  +
           this.errors = new ByteArrayInputStream(err.toByteArray());
           return result;
       }
  
  
  

Mime
View raw message