vinayc      2003/08/28 11:41:18

  Added:       tools/src/java/org/apache/altrmi/tools/javacompiler
                        JavaCompiler.java SunJavaCompiler.java
  Log:
  Refactorize (includes modularize,mavenize & rest of the nice's)
  
  Revision  Changes    Path
  1.1                  
incubator-altrmi/tools/src/java/org/apache/altrmi/tools/javacompiler/JavaCompiler.java
  
  Index: JavaCompiler.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1997-2003 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 "Incubator", "AltRMI", 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 [EMAIL PROTECTED]
   *
   * 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.altrmi.tools.javacompiler;
  
  import java.io.ByteArrayOutputStream;
  import java.io.File;
  import java.io.IOException;
  import java.net.URL;
  
  /**
   * If you want to plugin your own Java compiler, you probably want to
   * write a class that implements this interface.
   *
   * @author Anil K. Vijendran
   * @author Sam Ruby
   * @author Costin Manolache
   */
  public abstract class JavaCompiler
  {
  
      static String CPSEP = System.getProperty( "path.separator" );
      protected String m_classpath;
      protected String m_compilerPath = "jikes";
      protected String m_outdir;
      protected ByteArrayOutputStream m_out;
      protected boolean m_classDebugInfo = false;
  
      protected JavaCompiler()
      {
          reset();
      }
  
      /**
       * Specify where the compiler can be found
       */
      public void setCompilerPath( String m_compilerPath )
      {
  
          if( m_compilerPath != null )
          {
              this.m_compilerPath = m_compilerPath;
          }
      }
  
      /**
       * Method addClassPath
       *
       *
       * @param path
       *
       */
      public void addClassPath( String path )
      {
  
          // XXX use StringBuffer
          m_classpath = m_classpath + CPSEP + path;
      }
  
      /**
       * Method addDefaultClassPath
       *
       *
       */
      public void addDefaultClassPath()
      {
          addClassPath( System.getProperty( "java.class.path" ) );
      }
  
      /**
       * Set the output directory
       */
      public void setOutputDir( String outdir )
      {
          this.m_outdir = outdir;
      }
  
      /**
       * Method getCompilerMessage
       *
       *
       * @return
       *
       */
      public String getCompilerMessage()
      {
          return m_out.toString();
      }
  
      /** Reset all compilation state, but keep the settings.
       *  The compiler can be used again.
       */
      public void reset()
      {
          m_out = new ByteArrayOutputStream( 256 );
      }
  
  
      /**
       * Execute the compiler
       * @param source - file name of the source to be compiled
       */
      public abstract boolean doCompile( String source );
  
      /**
       * Method getDefaultCompiler
       *
       *
       * @return
       *
       */
      public static JavaCompiler getDefaultCompiler()
      {
          return new SunJavaCompiler();
      }
  
      //-------------------- Class path utils --------------------
  
  }
  
  
  
  1.1                  
incubator-altrmi/tools/src/java/org/apache/altrmi/tools/javacompiler/SunJavaCompiler.java
  
  Index: SunJavaCompiler.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1997-2003 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 "Incubator", "AltRMI", 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 [EMAIL PROTECTED]
   *
   * 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.altrmi.tools.javacompiler;
  
  import sun.tools.javac.Main;
  
  /**
   * The default compiler. This is the javac present in JDK 1.1.x and
   * JDK 1.2.
   *
   * At some point we need to make sure there is a class like this for
   * JDK 1.3, and other javac-like animals that people want to use.
   *
   * @author Anil K. Vijendran
   */
  public class SunJavaCompiler extends JavaCompiler
  {
  
      /**
       * Method doCompile
       *
       *
       * @param source
       *
       * @return
       *
       */
      public boolean doCompile( String source )
      {
          Main compiler = new Main( m_out, "jsp->javac" );
          String[] args;
          args = new String[]{"-classpath", m_classpath, "-d", m_outdir, 
source};
          return compiler.compile( args );
      }
  }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to