costin      01/05/20 22:13:11

  Modified:    src/facade22/org/apache/tomcat/facade JspInterceptor.java
  Log:
  A small change in JspInterceptor, to reduce the configuration pains.
  
  We'll check if jikes is available and used it - many people find
  editing configuration files harder than having code guess for them :-)
  
  There are few other places in the code where we can try a bit harder to
  guess what the user wants.
  
  ( you can still explicitely set a javaCompiler ).
  
  Revision  Changes    Path
  1.23      +66 -28    
jakarta-tomcat/src/facade22/org/apache/tomcat/facade/JspInterceptor.java
  
  Index: JspInterceptor.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat/src/facade22/org/apache/tomcat/facade/JspInterceptor.java,v
  retrieving revision 1.22
  retrieving revision 1.23
  diff -u -r1.22 -r1.23
  --- JspInterceptor.java       2001/04/28 21:14:47     1.22
  +++ JspInterceptor.java       2001/05/21 05:13:10     1.23
  @@ -211,7 +211,9 @@
       public void setJavaCompiler( String type ) {
        if( "jikes".equals( type ) )
            type=JIKES;
  -
  +     if( "javac".equals( type ) )
  +         type="org.apache.jasper.compiler.SunJavaCompiler";
  +             
        args.put( "jspCompilerPlugin", type );
       }
   
  @@ -613,10 +615,9 @@
                                                                    jspFile,
                                                                    options,
                                                                    mangler);
  -             JavaCompiler javaC=createJavaCompiler( options );
  -
                jsp2java( mangler, ctxt );
  -             javac( javaC, ctxt, mangler );
  +
  +             javac( options, ctxt, mangler );
            
                if(debug>0)log.log( "Generated " +
                                    mangler.getClassFileName() );
  @@ -671,33 +672,77 @@
       String javaEncoding = "UTF8";           // perhaps debatable?
       static String sep = System.getProperty("path.separator");
   
  -    /** Compile a java to class. This should be moved to util, togheter
  -     with JavaCompiler - it's a general purpose code, no need to
  -     keep it part of jasper
  -    */
  -    void javac(JavaCompiler javac, JspCompilationContext ctxt,
  -            Mangler mangler)
  +    private void prepareCompiler( JavaCompiler javac,
  +                               Options options, 
  +                               JspCompilationContext ctxt )
        throws JasperException
       {
  +     String compilerPath = options.getJspCompilerPath();
  +        if (compilerPath != null)
  +            javac.setCompilerPath(compilerPath);
   
  -        javac.setEncoding(javaEncoding);
  +     javac.setClassDebugInfo(options.getClassDebugInfo());
  +
  +     javac.setEncoding(javaEncoding);
        String cp=System.getProperty("java.class.path")+ sep + 
            ctxt.getClassPath() + sep + ctxt.getOutputDir();
  -//        System.out.println("classpath:"+cp);
           javac.setClasspath( cp );
  -     if( debug>5) log.log( "ClassPath " + cp);
  -     
  -     ByteArrayOutputStream out = new ByteArrayOutputStream (256);
        javac.setOutputDir(ctxt.getOutputDir());
  -        javac.setMsgOutput(out);
   
  +     if( debug>5) log.log( "ClassPath " + cp);
  +    }
  +
  +    static boolean tryJikes=true;
  +    static Class jspCompilerPlugin = null;
  +    
  +    /** Compile a java to class. This should be moved to util, togheter
  +     with JavaCompiler - it's a general purpose code, no need to
  +     keep it part of jasper
  +    */
  +    void javac(Options options, JspCompilationContext ctxt,
  +            Mangler mangler)
  +     throws JasperException
  +    {
        String javaFileName = mangler.getJavaFileName();
        if( debug>0 ) log.log( "Compiling java file " + javaFileName);
  -     /**
  -         * Execute the compiler
  -         */
  -        boolean status = javac.compile(javaFileName);
   
  +     boolean status=true;
  +     if( jspCompilerPlugin == null ) {
  +         jspCompilerPlugin=options.getJspCompilerPlugin();
  +     }
  +     // If no explicit compiler, and we never tried before
  +     if( jspCompilerPlugin==null && tryJikes ) {
  +         ByteArrayOutputStream out = new ByteArrayOutputStream (256);
  +         try {
  +
  +             jspCompilerPlugin=Class.
  +                 forName("org.apache.jasper.compiler.JikesJavaCompiler");
  +             JavaCompiler javaC=createJavaCompiler( jspCompilerPlugin );
  +             
  +             prepareCompiler( javaC, options, ctxt );
  +             javaC.setMsgOutput(out);
  +             status = javaC.compile(javaFileName);
  +         } catch( Exception ex ) {   
  +             log.log("Guess java compiler: no jikes " + ex.toString());
  +             status=false;
  +         }
  +         if( status==false ) {
  +             log.log("Guess java compiler: no jikes ");
  +             log.log("Guess java compiler: OUT " + out.toString());
  +             jspCompilerPlugin=null;
  +             tryJikes=false;
  +         } else {
  +             log.log("Guess java compiler: using jikes ");
  +         }
  +     }
  +
  +     JavaCompiler javaC=createJavaCompiler( jspCompilerPlugin );
  +     prepareCompiler( javaC, options, ctxt );
  +     ByteArrayOutputStream out = new ByteArrayOutputStream (256);
  +     javaC.setMsgOutput(out);
  +     
  +     status = javaC.compile(javaFileName);
  +
           if (!ctxt.keepGenerated()) {
               File javaFile = new File(javaFileName);
               javaFile.delete();
  @@ -713,11 +758,9 @@
   
       /** tool for customizing javac.
        */
  -    public JavaCompiler createJavaCompiler(Options options)
  +    public JavaCompiler createJavaCompiler(Class jspCompilerPlugin )
        throws JasperException
       {
  -     String compilerPath = options.getJspCompilerPath();
  -     Class jspCompilerPlugin = options.getJspCompilerPlugin();
           JavaCompiler javac;
   
        if (jspCompilerPlugin != null) {
  @@ -732,11 +775,6 @@
        } else {
               javac = new SunJavaCompiler();
        }
  -
  -        if (compilerPath != null)
  -            javac.setCompilerPath(compilerPath);
  -
  -     javac.setClassDebugInfo(options.getClassDebugInfo());
   
        return javac;
       }
  
  
  

Reply via email to