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 Changes Path 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 +5 -54 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/jasper34/javacompiler/JikesJavaCompiler.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- JikesJavaCompiler.java 2001/05/28 03:01:20 1.1 +++ JikesJavaCompiler.java 2001/06/12 15:16:23 1.2 @@ -69,71 +69,22 @@ * @author Jeffrey Chiu * @author Hans Bergsten <[EMAIL PROTECTED]> */ -public class JikesJavaCompiler implements JavaCompiler { +public class JikesJavaCompiler extends JavaCompiler { static final int OUTPUT_BUFFER_SIZE = 1024; static final int BUFFER_SIZE = 512; static final String q = - "\\".equals(System.getProperty("file.separator")) ? "\"" : ""; - + "\\".equals(System.getProperty("file.separator")) ? "\"" : ""; + /* * Contains extra classpath for Jikes use from Microsoft systems: * Microsoft does not report it's internal classpath in * System.getProperty(java.class.path) which results in jikes to fail. * (Internal classpath with other JVMs contains for instance rt.jar). - */ - static StringBuffer MicrosoftClasspath = null; - - String encoding; - String classpath; - String compilerPath = "jikes"; - String outdir; - OutputStream out; - boolean classDebugInfo=false; - - /** - * Specify where the compiler can be found - */ - public void setCompilerPath(String compilerPath) { - this.compilerPath = compilerPath; - } - - /** - * Set the encoding (character set) of the source */ - public void setEncoding(String encoding) { - this.encoding = encoding; - } - + static StringBuffer MicrosoftClasspath = null; + /** - * Set the class path for the compiler - */ - public void setClasspath(String classpath) { - this.classpath = classpath; - } - - /** - * Set the output directory - */ - public void setOutputDir(String outdir) { - this.outdir = outdir; - } - - /** - * Set where you want the compiler output (messages) to go - */ - public void setMsgOutput(OutputStream out) { - this.out = out; - } - - /** - * Set if you want debugging information in the class file - */ - public void setClassDebugInfo(boolean classDebugInfo) { - this.classDebugInfo = classDebugInfo; - } - - /** * Execute the compiler * @param source - file name of the source to be compiled */ 1.2 +1 -58 jakarta-tomcat-jasper/jasper34/generator/org/apache/jasper34/javacompiler/SunJavaCompiler.java Index: SunJavaCompiler.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-jasper/jasper34/generator/org/apache/jasper34/javacompiler/SunJavaCompiler.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- SunJavaCompiler.java 2001/05/28 03:01:20 1.1 +++ SunJavaCompiler.java 2001/06/12 15:16:23 1.2 @@ -69,64 +69,7 @@ * * @author Anil K. Vijendran */ -public class SunJavaCompiler implements JavaCompiler { - - String encoding; - String classpath; // ignored - String compilerPath; - String outdir; - OutputStream out; - boolean classDebugInfo=false; - - /** - * Specify where the compiler can be found - */ - public void setCompilerPath(String compilerPath) { - // not used by the SunJavaCompiler - this.compilerPath = compilerPath; - } - - /** - * Set the encoding (character set) of the source - */ - public void setEncoding(String encoding) { - this.encoding = encoding; - } - - /** - * Set the class path for the compiler - */ - public void setClasspath(String classpath) { - this.classpath = classpath; - } - - /** - * Set the output directory - */ - public void setOutputDir(String outdir) { - this.outdir = outdir; - } - - /** - * Set where you want the compiler output (messages) to go - */ - public void setMsgOutput(OutputStream out) { - this.out = out; - } - - /** - * Set where you want the compiler output (messages) to go - */ - public void setOut(OutputStream out) { - this.out = out; - } - - /** - * Set if you want debugging information in the class file - */ - public void setClassDebugInfo(boolean classDebugInfo) { - this.classDebugInfo = classDebugInfo; - } +public class SunJavaCompiler extends JavaCompiler { public boolean compile(String source) { Main compiler = new Main(out, "jsp->javac");