cvs commit: jakarta-tomcat-jasper/jasper34/generator/org/apache/jasper34/javacompiler JavaCompiler.java JikesJavaCompiler.java SunJavaCompiler.java

2001-06-16 Thread costin

costin  01/06/16 13:43:24

  Modified:jasper34/generator/org/apache/jasper34/javacompiler
JavaCompiler.java JikesJavaCompiler.java
SunJavaCompiler.java
  Log:
  More duplicated code is out.
  
  Prepare to add the jikes autodetection ( to be shared by all users of JavaCompiler ).
  The out is managed by JavaCompiler automatically.
  
  Prepare for recycling the object.
  
  Prepare to consolidate all the code related with compilation and simplify the 
interfaces.
  
  Revision  ChangesPath
  1.3   +63 -10
jakarta-tomcat-jasper/jasper34/generator/org/apache/jasper34/javacompiler/JavaCompiler.java
  
  Index: JavaCompiler.java
  ===
  RCS file: 
/home/cvs/jakarta-tomcat-jasper/jasper34/generator/org/apache/jasper34/javacompiler/JavaCompiler.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- JavaCompiler.java 2001/06/12 15:16:21 1.2
  +++ JavaCompiler.java 2001/06/16 20:43:24 1.3
  @@ -58,6 +58,7 @@
   package org.apache.jasper34.javacompiler;
   
   import java.io.*;
  +import java.net.*;
   
   // Temp ( ? )
   import org.apache.jasper34.core.*;
  @@ -75,9 +76,14 @@
   protected String classpath;
   protected String compilerPath = "jikes";
   protected String outdir;
  -protected OutputStream out;
  +protected ByteArrayOutputStream out;
   protected boolean classDebugInfo=false;
   
  +
  +protected JavaCompiler() {
  + reset();
  +}
  +
   /**
* Specify where the compiler can be found
*/ 
  @@ -107,13 +113,19 @@
 this.outdir = outdir;
   }
   
  -/**
  - * Set where you want the compiler output (messages) to go 
  - */ 
  -public void setMsgOutput(OutputStream out) {
  -  this.out = out;
  -}
  +// Removed - we manage ourself the buffer and return it as string.
  +// It can be added later if someone really need that.
  +// /**
  +//  * Set where you want the compiler output (messages) to go 
  +//  */ 
  +// public void setMsgOutput(OutputStream out) {
  +//   this.out = out;
  +// }
   
  +public String getCompilerMessage() {
  + return out.toString();
  +}
  +
   /**
* Set if you want debugging information in the class file 
*/ 
  @@ -121,12 +133,31 @@
this.classDebugInfo = classDebugInfo;
   }
   
  +public void recycle() {
  +
  +}
  +
  +/** Reset all compilation state, but keep the settings.
  + *  The compiler can be used again.
  + */
  +public void reset() {
  + out=new ByteArrayOutputStream( 256 );
  +}
  +
   //  Compile method 
  +
  +/** The main method - compile the source, using the previous settings.
  + */
  +public  boolean compile(String source) {
  + return doCompile(source);
  +}
  +
  +
   /**
* Execute the compiler
* @param source - file name of the source to be compiled
*/ 
  -public abstract boolean compile(String source);
  +public abstract boolean doCompile(String source);
   
   //  Utils 
   
  @@ -143,12 +174,12 @@
   {
Class c=getCompilerPluginClass( jspCompilerPluginS );
if( c==null ) return new SunJavaCompiler();
  - return createJavaCompiler( containerL, c );
  + return createJavaCompilerC( containerL, c );
   }

   /** tool for customizing javac.
*/
  -public static JavaCompiler createJavaCompiler(ContainerLiaison containerL,
  +private static JavaCompiler createJavaCompilerC(ContainerLiaison containerL,
  Class jspCompilerPlugin )
//  throws JasperException
   {
  @@ -175,5 +206,27 @@
return new SunJavaCompiler();
   }
   
  +
  +// Class path utils 
  +
  +/** Create a classpath string from a URL[] ( used in URLClassLoader )
  + */
  +public static String extractClassPath(URL urls[]){
  + String separator = System.getProperty("path.separator", ":");
  +String cpath="";
  +for(int i=0; i< urls.length; i++ ) {
  +URL cp = urls[i];
  + if( cp == null ) {
  + continue;
  + }
  +File f = new File( cp.getFile());
  +if (cpath.length()>0) cpath += separator;
  +cpath += f;
  +}
  +return cpath;
  +}
  +
  +
  +
   }
   
  
  
  
  1.3   +3 -2  
jakarta-tomcat-jasper/jasper34/generator/org/apache/jasper34/javacompiler/JikesJavaCompiler.java
  
  Index: JikesJavaCompiler.java
  ===
  RCS file: 
/home/cvs/jakarta-tomcat-jasper/jasper34/generator/org/apache/

cvs commit: jakarta-tomcat-jasper/jasper34/generator/org/apache/jasper34/javacompiler JavaCompiler.java JikesJavaCompiler.java SunJavaCompiler.java

2001-06-12 Thread costin

costin  01/06/12 08:16:30

  Modified:jasper34/generator/org/apache/jasper34/javacompiler
JavaCompiler.java JikesJavaCompiler.java
SunJavaCompiler.java
  Log:
  Turned the JavaCompiler interface into a class.
  
  Moved duplicated code into it, that will simplify the liaison.
  
  Still todo - move the compiler detection code from JspInterceptor ( detect
  if jikes is available, more self-configuration )
  
  Revision  ChangesPath
  1.2   +80 -9 
jakarta-tomcat-jasper/jasper34/generator/org/apache/jasper34/javacompiler/JavaCompiler.java
  
  Index: JavaCompiler.java
  ===
  RCS file: 
/home/cvs/jakarta-tomcat-jasper/jasper34/generator/org/apache/jasper34/javacompiler/JavaCompiler.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- JavaCompiler.java 2001/05/28 03:01:20 1.1
  +++ JavaCompiler.java 2001/06/12 15:16:21 1.2
  @@ -57,52 +57,123 @@
   
   package org.apache.jasper34.javacompiler;
   
  -import java.io.OutputStream;
  +import java.io.*;
   
  +// Temp ( ? )
  +import org.apache.jasper34.core.*;
  +
   /**
* 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 interface JavaCompiler {
  +public abstract class JavaCompiler {
  +protected String encoding;
  +protected String classpath;
  +protected String compilerPath = "jikes";
  +protected String outdir;
  +protected OutputStream out;
  +protected boolean classDebugInfo=false;
   
   /**
* Specify where the compiler can be found
*/ 
  -void setCompilerPath(String compilerPath);
  +public void setCompilerPath(String compilerPath) {
  + this.compilerPath = compilerPath;
  +}
  +
   
   /**
* Set the encoding (character set) of the source
*/ 
  -void setEncoding(String encoding);
  +public void setEncoding(String encoding) {
  +  this.encoding = encoding;
  +}
   
   /**
* Set the class path for the compiler
*/ 
  -void setClasspath(String classpath);
  +public void setClasspath(String classpath) {
  +  this.classpath = classpath;
  +}
   
   /**
* Set the output directory
*/ 
  -void setOutputDir(String outdir);
  +public void setOutputDir(String outdir) {
  +  this.outdir = outdir;
  +}
   
   /**
* Set where you want the compiler output (messages) to go 
*/ 
  -void setMsgOutput(OutputStream out);
  +public void setMsgOutput(OutputStream out) {
  +  this.out = out;
  +}
   
   /**
* Set if you want debugging information in the class file 
*/ 
  -void setClassDebugInfo(boolean classDebugInfo);
  +public void setClassDebugInfo(boolean classDebugInfo) {
  + this.classDebugInfo = classDebugInfo;
  +}
   
  +//  Compile method 
   /**
* Execute the compiler
* @param source - file name of the source to be compiled
*/ 
  -boolean compile(String source);
  +public abstract boolean compile(String source);
  +
  +//  Utils 
  +
  +public static Class getCompilerPluginClass( String s ) {
  + try {
  + Class c=Class.forName( s );
  + return c;
  + } catch( Exception ex ) {
  + return null;
  + }
  +}
  +public static JavaCompiler createJavaCompiler(ContainerLiaison containerL,
  +   String jspCompilerPluginS )
  +{
  + Class c=getCompilerPluginClass( jspCompilerPluginS );
  + if( c==null ) return new SunJavaCompiler();
  + return createJavaCompiler( containerL, c );
  +}
  + 
  +/** tool for customizing javac.
  + */
  +public static JavaCompiler createJavaCompiler(ContainerLiaison containerL,
  +   Class jspCompilerPlugin )
  + //  throws JasperException
  +{
  +JavaCompiler javac;
  +
  + if (jspCompilerPlugin != null) {
  +try {
  +javac = (JavaCompiler) jspCompilerPlugin.newInstance();
  +} catch (Exception ex) {
  + // containerL.message("jsp.warning.compiler.class.cantcreate",
  + //   new Object[] { jspCompilerPlugin, ex }, 
  + //Log.FATAL);
  +javac = new SunJavaCompiler();
  + }
  + } else {
  +javac = new SunJavaCompiler();
  + }
  +
  + return javac;
  +}
  +
  +
  +public static JavaCompiler getDefaultCompiler() {
  + return new SunJavaCompiler();
  +}
   
   }
   
  
  
  
  1.2 

cvs commit: jakarta-tomcat-jasper/jasper34/generator/org/apache/jasper34/javacompiler JavaCompiler.java JikesJavaCompiler.java SunJavaCompiler.java

2001-05-27 Thread costin

costin  01/05/27 20:01:20

  Added:   jasper34/generator/org/apache/jasper34/javacompiler
JavaCompiler.java JikesJavaCompiler.java
SunJavaCompiler.java
  Log:
  The javac part.
  
  Revision  ChangesPath
  1.1  
jakarta-tomcat-jasper/jasper34/generator/org/apache/jasper34/javacompiler/JavaCompiler.java
  
  Index: JavaCompiler.java
  ===
  /*
   * 
   * 
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999 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 acknowlegement:  
   *   "This product includes software developed by the 
   *Apache Software Foundation (http://www.apache.org/)."
   *Alternately, this acknowlegement may appear in the software itself,
   *if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Tomcat", 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 names without prior written
   *permission of the Apache Group.
   *
   * 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
   * .
   *
   */ 
  
  package org.apache.jasper34.javacompiler;
  
  import java.io.OutputStream;
  
  /**
   * 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
   */
  public interface JavaCompiler {
  
  /**
   * Specify where the compiler can be found
   */ 
  void setCompilerPath(String compilerPath);
  
  /**
   * Set the encoding (character set) of the source
   */ 
  void setEncoding(String encoding);
  
  /**
   * Set the class path for the compiler
   */ 
  void setClasspath(String classpath);
  
  /**
   * Set the output directory
   */ 
  void setOutputDir(String outdir);
  
  /**
   * Set where you want the compiler output (messages) to go 
   */ 
  void setMsgOutput(OutputStream out);
  
  /**
   * Set if you want debugging information in the class file 
   */ 
  void setClassDebugInfo(boolean classDebugInfo);
  
  /**
   * Execute the compiler
   * @param source - file name of the source to be compiled
   */ 
  boolean compile(String source);
  
  }
  
  
  
  
  1.1  
jakarta-tomcat-jasper/jasper34/generator/org/apache/jasper34/javacompiler/JikesJavaCompiler.java
  
  Index: JikesJavaCompiler.java
  ===
  /*
   * 
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modif