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 AbstractCompiler.java Compiler.java CompilerError.java CompilerFactory.java Javac.java Jikes.java
Date Mon, 10 Dec 2001 22:25:54 GMT
dims        01/12/10 14:25:54

  Modified:    java/src/org/apache/axis/handlers JWSProcessor.java
  Added:       java/src/org/apache/axis/utils/compiler
                        AbstractCompiler.java Compiler.java
                        CompilerError.java CompilerFactory.java Javac.java
                        Jikes.java
  Log:
  - First cut of a Compiler abstraction layer with code borrowed from Cocoon2.
  - "ant clean all" works out of the box.
  
  TODO:
  - Test in Servlet Environment.
  - Test the switching of compilers based on axis.Compiler system property.
  - Test Jikes Implementation layer
  - Test with Errors in JWS files.
  
  Revision  Changes    Path
  1.31      +33 -28    xml-axis/java/src/org/apache/axis/handlers/JWSProcessor.java
  
  Index: JWSProcessor.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/handlers/JWSProcessor.java,v
  retrieving revision 1.30
  retrieving revision 1.31
  diff -u -r1.30 -r1.31
  --- JWSProcessor.java	2001/12/03 22:49:23	1.30
  +++ JWSProcessor.java	2001/12/10 22:25:53	1.31
  @@ -63,20 +63,22 @@
   import org.apache.axis.utils.AxisClassLoader;
   import org.apache.axis.utils.JavaUtils;
   import org.apache.axis.utils.XMLUtils;
  +import org.apache.axis.utils.compiler.Compiler;
  +import org.apache.axis.utils.compiler.CompilerError;
  +import org.apache.axis.utils.compiler.CompilerFactory;
   import org.apache.log4j.Category;
   import org.w3c.dom.Document;
   import org.w3c.dom.Element;
  -import sun.tools.javac.Main;
   
   import java.io.File;
   import java.io.FileInputStream;
  -import java.io.FileOutputStream;
   import java.io.FileReader;
   import java.io.FileWriter;
   import java.io.IOException;
   import java.io.InputStream;
   import java.net.URL;
   import java.net.URLClassLoader;
  +import java.util.List;
   import java.util.StringTokenizer;
   import java.util.jar.Attributes;
   import java.util.jar.JarFile;
  @@ -96,7 +98,6 @@
    */
   public class JWSProcessor extends BasicHandler
   {
  -    static String errFile = "jws.err" ;
       static Category category =
               Category.getInstance(JWSProcessor.class.getName());
   
  @@ -169,8 +170,7 @@
                   category.debug("javac " + jFile );
                   // Process proc = rt.exec( "javac " + jFile );
                   // proc.waitFor();
  -                FileOutputStream  out      = new FileOutputStream( errFile );
  -                Main              compiler = new Main( out, "javac" );
  +                Compiler          compiler = CompilerFactory.getCompiler();
                   String            outdir   = null ;
                   String[]          args     = null ;
   
  @@ -178,13 +178,12 @@
                   if ( outdir == null ) outdir = f1.getParent();
                   if ( outdir == null ) outdir = "." ;
   
  -                args = new String[] { "-d", outdir,
  -                          "-classpath",
  -                          getDefaultClasspath(msgContext),
  -                          jFile };
  +                compiler.setClasspath(getDefaultClasspath(msgContext));
  +                compiler.setDestination(outdir);
  +                compiler.setFile(jFile);
   
  -                boolean           result   = compiler.compile( args );
  -
  +                boolean result   = compiler.compile();
  +                
                   /* Delete the temporary *.java file and check return code */
                   /**********************************************************/
                   (new File(jFile)).delete();
  @@ -199,22 +198,27 @@
                       Document doc = XMLUtils.newDocument();
   
                       Element         root = doc.createElementNS("", "Errors");
  -                    StringBuffer    sbuf = new StringBuffer();
  -                    FileReader      inp  = new FileReader( errFile );
  -
  -                    buf = new char[4096];
  -
  -                    while ( (rc = inp.read(buf, 0, 4096)) > 0 )
  -                        sbuf.append( buf, 0, rc );
  -                    inp.close();
  -                    root.appendChild( doc.createTextNode( sbuf.toString() ) );
  -                    (new File(errFile)).delete();
  +                    StringBuffer message = new StringBuffer("Error compiling ");
  +                    message.append(jFile);
  +                    message.append(":\n");
  +
  +                    List errors = compiler.getErrors();
  +                    int count = errors.size();
  +                    for (int i = 0; i < count; i++) {
  +                      CompilerError error = (CompilerError) errors.get(i);
  +                      if (i > 0) message.append("\n");
  +                      message.append("Line ");
  +                      message.append(error.getStartLine());
  +                      message.append(", column ");
  +                      message.append(error.getStartColumn());
  +                      message.append(": ");
  +                      message.append(error.getMessage());
  +                    }
  +                    root.appendChild( doc.createTextNode( message.toString() ) );
                       throw new AxisFault( "Server.compileError",
                            JavaUtils.getMessage("badCompile00", jFile),
                           null, new Element[] { root } );
                   }
  -                (new File(errFile)).delete();
  -
                   AxisClassLoader.removeClassLoader( clsName );
               }
               AxisClassLoader cl = msgContext.getClassLoader();
  @@ -276,10 +280,13 @@
   
                   for(int i=0; (urls != null) && i < urls.length; i++)
                   {
  -                    classpath.append(urls[i].getPath());
  +                    String path = urls[i].getPath();
  +                    //If it is a drive letter, adjust accordingly.
  +                    if(path.charAt(0)=='/'&&path.charAt(2)==':')
  +                        path = path.substring(1);
  +                    classpath.append(path);
                       classpath.append(File.pathSeparatorChar);
   
  -
                       // if its a jar extract Class-Path entries from manifest
                       File file = new File(urls[i].getFile());
                       if(file.isFile())
  @@ -361,10 +368,8 @@
               }
           }
   
  -
           // boot classpath isn't found in above search
  -        if(System.getProperty("sun.boot.class.path") != null)
  -        {
  +        if(System.getProperty("sun.boot.class.path") != null) {
               classpath.append(System.getProperty("sun.boot.class.path"));
           }
   
  
  
  
  1.1                  xml-axis/java/src/org/apache/axis/utils/compiler/AbstractCompiler.java
  
  Index: AbstractCompiler.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Axis" and "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  package org.apache.axis.utils.compiler;
  
  import java.io.BufferedReader;
  import java.io.IOException;
  import java.io.InputStream;
  import java.io.InputStreamReader;
  import java.util.List;
  
  /**
   * This class implements the functionality common to all Java compilers.
   * @author <a href="mailto:dims@yahoo.com">Davanum Srinivas</a>
   * @author <a href="mailto:stefano@apache.org">Stefano Mazzocchi</a>
   * @version $Revision: 1.1 $ $Date: 2001/12/10 22:25:53 $
   * @since 2.0
   */
  public abstract class AbstractCompiler implements Compiler {
  
    /**
     * The source program filename
     */
    protected String    file;
  
    /**
     * The name of the directory containing the source program file
     */
    protected String    srcDir;
  
    /**
     * The name of the directory to contain the resulting object program file
     */
    protected String    destDir;
  
    /**
     * The classpath to be used for compilation
     */
    protected String    classpath;
  
    /**
     * The encoding of the source program or <code>null</code> to use the
     * platform's default encoding
     */
    protected String    encoding = null;
  
    /**
     * The input stream to output compilation errors
     */
    protected InputStream errors;
  
    /**
     * Set the name of the file containing the source program
     *
     * @param file The name of the file containing the source program
     */
    public void setFile(String file) {
      this.file = file;
    }
  
    /**
     * Set the name of the directory containing the source program file
     *
     * @param srcDir The name of the directory containing the source program file
     */
    public void setSource(String srcDir) {
      this.srcDir = srcDir;
    }
  
    /**
     * Set the name of the directory to contain the resulting object program file
     *
     * @param destDir The name of the directory to contain the resulting object
     * program file
     */
    public void setDestination(String destDir) {
        this.destDir = destDir;
    }
  
    /**
     * Set the classpath to be used for this compilation
     *
     * @param classpath The classpath to be used for this compilation
     */
    public void setClasspath(String classpath) {
      this.classpath = classpath;
    }
  
    /**
     * Set the encoding of the input source file or <code>null</code> to use the
     * platform's default encoding
     *
     * @param encoding The encoding of the input source file or <code>null</code>
     * to use the platform's default encoding
     */
    public void setEncoding(String encoding) {
      this.encoding = encoding;
    }
  
    /**
     * Return the list of errors generated by this compilation
     *
     * @return The list of errors generated by this compilation
     * @exception IOException If an error occurs during message collection
     */
    public List getErrors() throws IOException {
      return parseStream(new BufferedReader(new InputStreamReader(errors)));
    }
  
    /**
     * Parse the compiler error stream to produce a list of
     * <code>CompilerError</code>s
     *
     * @param errors The error stream
     * @return The list of compiler error messages
     * @exception IOException If an error occurs during message collection
     */
    protected abstract List parseStream(BufferedReader errors)
        throws IOException;
  
    /**
     * Fill the arguments taken by the Java compiler
     *
     * @param argument The list of compilation arguments
     * @return The prepared list of compilation arguments
     */
    protected List fillArguments(List arguments) {
      // destination directory
      arguments.add("-d");
      arguments.add(destDir);
  
      // classpath
      arguments.add("-classpath");
      arguments.add(classpath);
  
      // sourcepath
      if(srcDir != null) {
          arguments.add("-sourcepath");
          arguments.add(srcDir);
      }
  
      // add optimization (for what is worth)
      arguments.add("-O");
  
      // add encoding if set
      if (encoding != null) {
        arguments.add("-encoding");
        arguments.add(encoding);
      }
  
      return arguments;
    }
  
    /**
     * Copy arguments to a string array
     *
     * @param arguments The compiler arguments
     * @return A string array containing compilation arguments
     */
    protected String[] toStringArray(List arguments) {
      int    i;
      String[] args = new String[arguments.size() + 1];
  
      for (i = 0; i < arguments.size(); i++) {
        args[i] = (String) arguments.get(i);
      }
  
      args[i] = file;
  
      return args;
    }
  }
  
  
  
  1.1                  xml-axis/java/src/org/apache/axis/utils/compiler/Compiler.java
  
  Index: Compiler.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Axis" and "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  package org.apache.axis.utils.compiler;
  
  import java.io.IOException;
  import java.util.List;
  
  /**
   * This interface defines a compiler's functionality for all
   * (Java-based) compiled languages
   * @author <a href="mailto:dims@yahoo.com">Davanum Srinivas</a>
   * @author <a href="mailto:stefano@apache.org">Stefano Mazzocchi</a>
   * @version $Revision: 1.1 $ $Date: 2001/12/10 22:25:53 $
   * @since 2.0
   */
  public interface Compiler {
    /**
     * Set the name of the file containing the source program
     *
     * @param file The name of the file containing the source program
     */
    void setFile(String file);
  
    /**
     * Set the name of the directory containing the source program file
     *
     * @param srcDir The name of the directory containing the source program file
     */
    void setSource(String srcDir);
  
    /**
     * Set the name of the directory to contain the resulting object program file
     *
     * @param destDir The name of the directory to contain the resulting object
     * program file
     */
    void setDestination(String destDir);
  
    /**
     * Set the classpath to be used for this compilation
     *
     * @param classpath The classpath to be used for this compilation
     */
    void setClasspath(String classpath);
  
    /**
     * Set the encoding of the input source file or <code>null</code> to use the
     * platform's default encoding
     *
     * @param encoding The encoding of the input source file or <code>null</code>
     * to use the platform's default encoding
     */
    void setEncoding(String encoding);
  
    /**
     * Compile a source file yielding a loadable program file.
     *
     * @param filename The object program base file name
     * @param baseDirectory The directory containing the object program file
     * @param encoding The encoding expected in the source file or
     * <code>null</code> if it is the platform's default encoding
     * @exception LanguageException If an error occurs during compilation
     */
    boolean compile() throws IOException;
  
    /**
     * Return the list of errors generated by this compilation
     *
     * @return The list of errors generated by this compilation
     * @exception IOException If an error occurs during message collection
     */
    List getErrors() throws IOException;
  }
  
  
  
  1.1                  xml-axis/java/src/org/apache/axis/utils/compiler/CompilerError.java
  
  Index: CompilerError.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Axis" and "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
   
  package org.apache.axis.utils.compiler;
  
  /**
   * This class encapsulates an error message produced by a programming language
   * processor (whether interpreted or compiled)
   * @author <a href="mailto:dims@yahoo.com">Davanum Srinivas</a>
   * @author <a href="mailto:stefano@apache.org">Stefano Mazzocchi</a>
   * @version $Revision: 1.1 $ $Date: 2001/12/10 22:25:53 $
   * @since 2.0
   */
  
  public class CompilerError {
    /**
     * Is this a severe error or a warning?
     */
    private boolean error;
    /**
     * The start line number of the offending program text
     */
    private int startline;
    /**
     * The start column number of the offending program text
     */
    private int startcolumn;
    /**
     * The end line number of the offending program text
     */
    private int endline;
    /**
     * The end column number of the offending program text
     */
    private int endcolumn;
    /**
     * The name of the file containing the offending program text
     */
    private String file;
    /**
     * The actual error text produced by the language processor
     */
    private String message;
      
    /**
     * The error message constructor.
     *
     * @param file The name of the file containing the offending program text
     * @param error The actual error text produced by the language processor
     * @param startline The start line number of the offending program text
     * @param startcolumn The start column number of the offending program text
     * @param endline The end line number of the offending program text
     * @param endcolumn The end column number of the offending program text
     * @param message The actual error text produced by the language processor
     */
    public CompilerError(
      String file,
      boolean error,
      int startline,
      int startcolumn,
      int endline,
      int endcolumn,
      String message
    ) 
    {
      this.file = file;
      this.error = error;
      this.startline = startline;
      this.startcolumn = startcolumn;
      this.endline = endline;
      this.endcolumn = endcolumn;
      this.message = message;
    }
  
    /**
     * The error message constructor.
     *
     * @param message The actual error text produced by the language processor
     */
    public CompilerError(String message) {
      this.message = message;
    }
    
    /**
     * Return the filename associated with this compiler error.
     *
     * @return The filename associated with this compiler error
     */
    public String getFile() {
      return file;
    }
  
    /**
     * Assert whether this is a severe error or a warning
     *
     * @return Whether the error is severe
     */
    public boolean isError() {
      return error;
    }
  
    /**
     * Return the starting line number of the program text originating this error
     *
     * @return The starting line number of the program text originating this error
     */
    public int getStartLine() {
      return startline;
    }
  
    /**
     * Return the starting column number of the program text originating this
     * error
     *
     * @return The starting column number of the program text originating this
     * error
     */
    public int getStartColumn() {
      return startcolumn;
    }
  
    /**
     * Return the ending line number of the program text originating this error
     *
     * @return The ending line number of the program text originating this error
     */
    public int getEndLine() {
      return endline;
    }
  
    /**
     * Return the ending column number of the program text originating this
     * error
     *
     * @return The ending column number of the program text originating this
     * error
     */
    public int getEndColumn() {
      return endcolumn;
    }
  
    /**
     * Return the message produced by the language processor
     *
     * @return The message produced by the language processor
     */
    public String getMessage() {
      return message;
    }
  }
  
  
  
  1.1                  xml-axis/java/src/org/apache/axis/utils/compiler/CompilerFactory.java
  
  Index: CompilerFactory.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Axis" and "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  package org.apache.axis.utils.compiler;
  
  /**
   * This class implements a factory to instantiate a Compiler.
   * @author <a href="mailto:dims@yahoo.com">Davanum Srinivas</a>
   * @author <a href="mailto:stefano@apache.org">Stefano Mazzocchi</a>
   * @version $Revision: 1.1 $ $Date: 2001/12/10 22:25:53 $
   * @since 2.0
   */
  public class CompilerFactory {
          public static Compiler getCompiler()
          {
              String compilerClassName = System.getProperty("axis.Compiler");
              if (compilerClassName != null) {
                  try {
                      Class compilerClass = Class.forName(compilerClassName);
                      if (Compiler.class.isAssignableFrom(compilerClass))
                          return (Compiler)compilerClass.newInstance();
                  } catch (Exception e) {
                      // If something goes wrong here, should we just fall
                      // through and use the default one?
                      e.printStackTrace(System.err);
                  }
              }
              Compiler compiler = new Javac();
              return compiler;
          }
  }
  
  
  
  1.1                  xml-axis/java/src/org/apache/axis/utils/compiler/Javac.java
  
  Index: Javac.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Axis" and "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  package org.apache.axis.utils.compiler;
  
  import org.apache.axis.utils.AxisClassLoader;
  import org.apache.log4j.Category;
  
  import java.io.BufferedReader;
  import java.io.ByteArrayInputStream;
  import java.io.ByteArrayOutputStream;
  import java.io.File;
  import java.io.IOException;
  import java.util.ArrayList;
  import java.util.List;
  import java.util.NoSuchElementException;
  import java.util.StringTokenizer;
  
  /**
   * This class wraps the Sun's Javac Compiler.
   *
   * @author <a href="mailto:dims@yahoo.com">Davanum Srinivas</a>
   * @author <a href="mailto:stefano@apache.org">Stefano Mazzocchi</a>
   * @version $Revision: 1.1 $ $Date: 2001/12/10 22:25:53 $
   * @since 2.0
   */
  
  public class Javac extends AbstractCompiler {
  
      static Category category =
              Category.getInstance(Javac.class.getName());
      
    public final static String CLASSIC_CLASS = "sun.tools.javac.Main";
    public final static String MODERN_CLASS = "com.sun.tools.javac.Main";
  
    private boolean modern = false;
  
    public Javac() {
  
      // Use reflection to be able to build on all JDKs
      AxisClassLoader   cl     = AxisClassLoader.getClassLoader();
      try {
          cl.loadClass(MODERN_CLASS);
          modern = true;
      } catch (ClassNotFoundException e) {
          category.debug("Javac connector could not find modern compiler -- falling back to classic.");
          try {
              cl.loadClass(CLASSIC_CLASS);
              modern = false;
          } catch (Exception ex) {
              category.error("No compiler found in your classpath. Make sure you added 'tools.jar'", ex);
              throw new RuntimeException("No compiler found in your classpath. Make sure you added 'tools.jar'");
          }
      }
    }
  
    /**
     * Compile a source file yielding a loadable class file.
     *
     * @param filename The object program base file name
     * @param baseDirectory The directory containing the object program file
     * @param encoding The encoding expected in the source file or
     * <code>null</code> if it is the platform's default encoding
     * @exception LanguageException If an error occurs during compilation
     */
    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())));
      this.errors = new ByteArrayInputStream(err.toByteArray());
      return result;
    }
  
    /**
     * Parse the compiler error stream to produce a list of
     * <code>CompilerError</code>s
     *
     * @param errors The error stream
     * @return The list of compiler error messages
     * @exception IOException If an error occurs during message collection
     */
    protected List parseStream(BufferedReader input) throws IOException {
      if (modern) {
          return parseModernStream(input);
      } else {
          return parseClassicStream(input);
      }
    }
  
    /**
     * Parse the compiler error stream to produce a list of
     * <code>CompilerError</code>s
     *
     * @param errors The error stream
     * @return The list of compiler error messages
     * @exception IOException If an error occurs during message collection
     */
    protected List parseModernStream(BufferedReader input) throws IOException {
      List errors = new ArrayList();
      String line = null;
      StringBuffer buffer = null;
  
      while (true) {
        // cleanup the buffer
        buffer = new StringBuffer(); // this is quicker than clearing it
  
        // most errors terminate with the '^' char
        do {
          if ((line = input.readLine()) == null)
          {
              if (buffer.length() > 0) {
                  // There's an error which doesn't end with a '^'
                  errors.add(new CompilerError("\n" + buffer.toString()));
              }
              return errors;
          }
          buffer.append(line);
          buffer.append('\n');
        } while (!line.endsWith("^"));
  
        // add the error bean
        errors.add(parseModernError(buffer.toString()));
      }
    }
  
    /**
     * Parse an individual compiler error message with modern style.
     *
     * @param error The error text
     * @return A messaged <code>CompilerError</code>
     */
    private CompilerError parseModernError(String error) {
      StringTokenizer tokens = new StringTokenizer(error, ":");
      try {
        String file = tokens.nextToken();
        if (file.length() == 1) file = new StringBuffer(file).append(":").append(tokens.nextToken()).toString();
        int line = Integer.parseInt(tokens.nextToken());
  
        String message = tokens.nextToken("\n").substring(1);
        String context = tokens.nextToken("\n");
        String pointer = tokens.nextToken("\n");
        int startcolumn = pointer.indexOf("^");
        int endcolumn = context.indexOf(" ", startcolumn);
        if (endcolumn == -1) endcolumn = context.length();
        return new CompilerError(file, false, line, startcolumn, line, endcolumn, message);
      } catch(NoSuchElementException nse) {
        return new CompilerError("no more tokens - could not parse error message: " + error);
      } catch(Exception nse) {
        return new CompilerError("could not parse error message: " + error);
      }
    }
  
    /**
     * Parse the compiler error stream to produce a list of
     * <code>CompilerError</code>s
     *
     * @param errors The error stream
     * @return The list of compiler error messages
     * @exception IOException If an error occurs during message collection
     */
    protected List parseClassicStream(BufferedReader input) throws IOException {
  
      List errors = null;
      String line = null;
      StringBuffer buffer = null;
  
      while (true) {
        // cleanup the buffer
        buffer = new StringBuffer(); // this is faster than clearing it
  
        // each error has 3 lines
        for (int i = 0; i < 3 ; i++) {
          if ((line = input.readLine()) == null) return errors;
          buffer.append(line);
          buffer.append('\n');
        }
  
        // if error is found create the vector
        if (errors == null) errors = new ArrayList();
  
        // add the error bean
        errors.add(parseClassicError(buffer.toString()));
      }
    }
  
    /**
     * Parse an individual compiler error message with classic style.
     *
     * @param error The error text
     * @return A messaged <code>CompilerError</code>
     */
    private CompilerError parseClassicError(String error) {
  
      StringTokenizer tokens = new StringTokenizer(error, ":");
      try {
        String file = tokens.nextToken();
        if (file.length() == 1) file = new StringBuffer(file).append(":").append(tokens.nextToken()).toString();
        int line = Integer.parseInt(tokens.nextToken());
  
        String last = tokens.nextToken();
        // In case the message contains ':', it should be reassembled
        while (tokens.hasMoreElements()) {
          last += tokens.nextToken();
        }
        tokens = new StringTokenizer(last.trim(), "\n");
        String message = tokens.nextToken();
        String context = tokens.nextToken();
        String pointer = tokens.nextToken();
        int startcolumn = pointer.indexOf("^");
        int endcolumn = context.indexOf(" ", startcolumn);
        if (endcolumn == -1) endcolumn = context.length();
  
        return new CompilerError(srcDir + File.separator + file, true, line, startcolumn, line, endcolumn, message);
      } catch(NoSuchElementException nse) {
        return new CompilerError("no more tokens - could not parse error message: " + error);
      } catch(Exception nse) {
        return new CompilerError("could not parse error message: " + error);
      }
    }
  
    public String toString() {
      return "Sun Javac Compiler";
    }
  }
  
  
  
  1.1                  xml-axis/java/src/org/apache/axis/utils/compiler/Jikes.java
  
  Index: Jikes.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Axis" and "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  package org.apache.axis.utils.compiler;
  
  import org.apache.log4j.Category;
  
  import java.io.BufferedInputStream;
  import java.io.BufferedReader;
  import java.io.ByteArrayInputStream;
  import java.io.ByteArrayOutputStream;
  import java.io.IOException;
  import java.io.OutputStream;
  import java.util.ArrayList;
  import java.util.List;
  import java.util.StringTokenizer;
  
  /**
   * This class wraps IBM's <i>Jikes</i> Java compiler
   * NOTE: inspired by the Apache Jasper implementation.
   * @author <a href="mailto:dims@yahoo.com">Davanum Srinivas</a>
   * @author <a href="mailto:stefano@apache.org">Stefano Mazzocchi</a>
   * @version $Revision: 1.1 $ $Date: 2001/12/10 22:25:53 $
   * @since 2.0
   */
  
  public class Jikes extends AbstractCompiler {
  
      static Category category =
              Category.getInstance(Jikes.class.getName());
      
      static final int OUTPUT_BUFFER_SIZE = 1024;
      static final int BUFFER_SIZE = 512;
  
      private class StreamPumper extends Thread {
  
          private BufferedInputStream stream;
          private boolean endOfStream = false;
          private boolean stopSignal  = false;
          private int SLEEP_TIME = 5;
          private OutputStream out;
  
          public StreamPumper(BufferedInputStream is, OutputStream out) {
              this.stream = is;
              this.out = out;
          }
  
          public void pumpStream() throws IOException {
              byte[] buf = new byte[BUFFER_SIZE];
              if (!endOfStream) {
                  int bytesRead = stream.read(buf, 0, BUFFER_SIZE);
  
                  if (bytesRead > 0) {
                      out.write(buf, 0, bytesRead);
                  } else if (bytesRead == -1) {
                      endOfStream = true;
                  }
              }
          }
  
          public void run() {
              try {
                  while (!endOfStream) {
                      pumpStream();
                      sleep(SLEEP_TIME);
                  }
              } catch (Exception e) {
                 // getLogger().warn("Jikes.run()", e);
              }
          }
      }
  
      /**
       * Copy arguments to a string array
       *
       * @param arguments The compiler arguments
       * @return A string array containing compilation arguments
       */
      protected String[] toStringArray(List arguments) {
        int i;
  
        for (i = 0; i < arguments.size(); i++) {
          String arg = (String) arguments.get(i);
          if (arg.equals("-sourcepath")) {
            // Remove -sourcepath option. Jikes does not understand that.
            arguments.remove(i);
            arguments.remove(i);
            break;
          }
        }
  
        String[] args = new String[arguments.size() + 1];
        for (i = 0; i < arguments.size(); i++) {
          args[i] = (String) arguments.get(i);
        }
  
        args[i] = file;
  
        return args;
      }
  
      /**
       * Execute the compiler
       */
      public boolean compile() throws IOException {
  
          List args = new ArrayList();
          // command line name
          args.add("jikes");
          // indicate Emacs output mode must be used
          args.add("+E");
          // avoid warnings
          // Option nowarn with one hyphen only
          args.add("-nowarn");
  
          int exitValue;
          ByteArrayOutputStream tmpErr = new ByteArrayOutputStream(OUTPUT_BUFFER_SIZE);
  
          try {
              Process p = Runtime.getRuntime().exec(toStringArray(fillArguments(args)));
  
              BufferedInputStream compilerErr = new BufferedInputStream(p.getErrorStream());
  
              StreamPumper errPumper = new StreamPumper(compilerErr, tmpErr);
  
              errPumper.start();
  
              p.waitFor();
              exitValue = p.exitValue();
  
              // Wait until the complete error stream has been read
              errPumper.join();
              compilerErr.close();
  
              p.destroy();
  
              tmpErr.close();
              this.errors = new ByteArrayInputStream(tmpErr.toByteArray());
  
          } catch (InterruptedException somethingHappened) {
              category.debug("Jikes.compile():SomethingHappened", somethingHappened);
              return false;
          }
  
          // Jikes returns 0 even when there are some types of errors.
          // Check if any error output as well
          // Return should be OK when both exitValue and
          // tmpErr.size() are 0 ?!
          return ((exitValue == 0) && (tmpErr.size() == 0));
      }
  
      /**
       * Parse the compiler error stream to produce a list of
       * <code>CompilerError</code>s
       *
       * @param errors The error stream
       * @return The list of compiler error messages
       * @exception IOException If an error occurs during message collection
       */
      protected List parseStream(BufferedReader input) throws IOException {
          List errors = null;
          String line = null;
          StringBuffer buffer = null;
  
          while (true) {
              // cleanup the buffer
              buffer = new StringBuffer(); // this is faster than clearing it
  
              // first line is not space-starting
              if (line == null) line = input.readLine();
              if (line == null) return errors;
              buffer.append(line);
  
              // all other space-starting lines are one error
              while (true) {
                  line = input.readLine();
                  // EOF
                  if (line == null)
                      break;
                  // Continuation of previous error starts with ' '
                  if (line.length() > 0 && line.charAt(0) != ' ')
                      break;
                  buffer.append('\n');
                  buffer.append(line);
              }
  
              // if error is found create the vector
              if (errors == null) errors = new ArrayList();
  
              // add the error bean
              errors.add(parseError(buffer.toString()));
          }
      }
  
      /**
       * Parse an individual compiler error message
       *
       * @param error The error text
       * @return A mssaged <code>CompilerError</code>
       */
      private CompilerError parseError(String error) {
          StringTokenizer tokens = new StringTokenizer(error, ":");
          String file = tokens.nextToken();
          if (file.length() == 1) file = new StringBuffer(file).append(":").append(tokens.nextToken()).toString();
          StringBuffer message = new StringBuffer();
          String type = "";
          int startline = 0;
          int startcolumn = 0;
          int endline = 0;
          int endcolumn = 0;
  
          try {
              startline = Integer.parseInt(tokens.nextToken());
              startcolumn = Integer.parseInt(tokens.nextToken());
              endline = Integer.parseInt(tokens.nextToken());
              endcolumn = Integer.parseInt(tokens.nextToken());
          } catch (Exception e) {
              // FIXME: VG: This is not needed anymore?
              message.append("Please ensure that you have your JDK's rt.jar listed in your classpath. Jikes needs it to operate.");
              type="error";
              category.error(message.toString(), e);
          }
  
          if ("".equals(message)) {
              type = tokens.nextToken().trim().toLowerCase();
              message.append(tokens.nextToken("\n").substring(1).trim());
  
              while (tokens.hasMoreTokens())
                  message.append("\n").append(tokens.nextToken());
          }
  
          return new CompilerError(file, type.equals("error"), startline, startcolumn, endline, endcolumn, message.toString());
      }
  
      public String toString() {
          return "IBM Jikes Compiler";
      }
  }
  
  
  

Mime
View raw message