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  Changes    Path
  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/jasper34/javacompiler/JikesJavaCompiler.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- JikesJavaCompiler.java    2001/06/12 15:16:23     1.2
  +++ JikesJavaCompiler.java    2001/06/16 20:43:24     1.3
  @@ -88,7 +88,7 @@
        * Execute the compiler
        * @param source - file name of the source to be compiled
        */ 
  -    public boolean compile(String source) {
  +    public boolean doCompile(String source) {
        Process p;
        int exitValue = -1;
   
  @@ -130,7 +130,8 @@
            };
        }
   
  -        ByteArrayOutputStream tmpErr = new 
ByteArrayOutputStream(OUTPUT_BUFFER_SIZE);
  +        ByteArrayOutputStream tmpErr =
  +         new ByteArrayOutputStream(OUTPUT_BUFFER_SIZE);
        try {
            p = Runtime.getRuntime().exec(compilerCmd);
            
  
  
  
  1.3       +1 -1      
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.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- SunJavaCompiler.java      2001/06/12 15:16:23     1.2
  +++ SunJavaCompiler.java      2001/06/16 20:43:24     1.3
  @@ -71,7 +71,7 @@
    */
   public class SunJavaCompiler extends JavaCompiler {
   
  -    public boolean compile(String source) {
  +    public boolean doCompile(String source) {
           Main compiler = new Main(out, "jsp->javac");
           String[] args;
   
  
  
  

Reply via email to