glenn       2002/09/07 22:45:59

  Modified:    jasper2/src/share/org/apache/jasper Tag: tomcat_4_branch
                        EmbededServletOptions.java
               jasper2/src/share/org/apache/jasper/compiler Tag:
                        tomcat_4_branch Compiler.java
  Log:
  Update JSP compiles so that it works with both javac and jikes.
  
  The javaEncoding init parameter was only being used when generating
  the java source, and then only if UTF8 didn't work.  Changed so that
  if a javaEncoding is configured it gets used both for generating the
  java source and for compiling.  UTF8 is the default javaEncoding.
  
  Javac needed System.err captured but jikes needed the Ant DefaultLogger.
  Implement both so that error reporting works regardless of which compiler is used.
  
  In order to get jikes to work I had to do the following:
  
  Specify "jikes" using the init parameter "compiler" in conf/web.xml.
  On my Solaris system jikes would not work with UTF8 encoding so I
  set the "javaEncoding" init parameter to "ISO-8859-1".
  
  In order to get reporting of the line number in the JSP page
  where the error occurred to work I had to define
  -Dbuild.compiler.emacs=true when starting Tomcat.
  
  There is one more twist if you use the Java SecurityManager.
  Ant's jikes compiler option executes jikes by using exec("jikes").
  This forces the current PATH to be searched for jikes.
  In order for this to work with the Java SecurityManager the following
  permission has to be granted.
  
  permission java.io.FilePermission "<<ALL FILES>>", "execute";
  
  This is not a permission you would want to grant.  I had to modify
  the ant source so that I could specify the complete path to the
  jikes compiler using a property "jikes.compiler.path" so that
  only the following FilePermission was needed:
  
  permission java.io.FilePermission "/usr/local/bin/jikes", "execute";
  
  An enhancement request BUG 12038 has been filed for Ant requesting
  that the ability to specify a complete path be added.
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.8.2.1   +8 -5      
jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/EmbededServletOptions.java
  
  Index: EmbededServletOptions.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/EmbededServletOptions.java,v
  retrieving revision 1.8
  retrieving revision 1.8.2.1
  diff -u -r1.8 -r1.8.2.1
  --- EmbededServletOptions.java        26 Jun 2002 16:50:37 -0000      1.8
  +++ EmbededServletOptions.java        8 Sep 2002 05:45:59 -0000       1.8.2.1
  @@ -167,7 +167,7 @@
        * Java platform encoding to generate the JSP
        * page servlet.
        */
  -    private String javaEncoding;
  +    private String javaEncoding = "UTF8";
   
       public String getProperty(String name ) {
           return settings.getProperty( name );
  @@ -425,7 +425,10 @@
                                     
           this.compiler = config.getInitParameter("compiler");
   
  -        this.javaEncoding = config.getInitParameter("javaEncoding");
  +        String javaEncoding = config.getInitParameter("javaEncoding");
  +        if (javaEncoding != null) {
  +            this.javaEncoding = javaEncoding;
  +        }
   
        // Setup the global Tag Libraries location cache for this
        // web-application.
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.18.2.4  +38 -46    
jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/Compiler.java
  
  Index: Compiler.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/Compiler.java,v
  retrieving revision 1.18.2.3
  retrieving revision 1.18.2.4
  diff -u -r1.18.2.3 -r1.18.2.4
  --- Compiler.java     17 Aug 2002 00:14:23 -0000      1.18.2.3
  +++ Compiler.java     8 Sep 2002 05:45:59 -0000       1.18.2.4
  @@ -108,7 +108,6 @@
   
       }
   
  -
       // ----------------------------------------------------- Instance Variables
   
   
  @@ -117,12 +116,14 @@
       private ErrorDispatcher errDispatcher;
       private PageInfo pageInfo;
       private JspServletWrapper jsw;
  +    private JasperAntLogger logger;
   
       protected Project project=null;
   
       protected Options options;
   
       protected Node.Nodes pageNodes;
  +
       // ------------------------------------------------------------ Constructor
   
   
  @@ -144,39 +145,44 @@
           // Initializing project
           project = new Project();
           // XXX We should use a specialized logger to redirect to jasperlog
  -        //        DefaultLogger bl=new JasperAntLogger();
  -        DefaultLogger bl=new DefaultLogger();
  -        bl.setOutputPrintStream(System.err);
  -        bl.setErrorPrintStream(System.err);
  +        logger = new JasperAntLogger();
  +        logger.setOutputPrintStream(System.out);
  +        logger.setErrorPrintStream(System.err);
   
           if( Constants.jasperLog.getVerbosityLevel() >= Logger.DEBUG ) {
  -            bl.setMessageOutputLevel( Project.MSG_VERBOSE );
  +            logger.setMessageOutputLevel( Project.MSG_VERBOSE );
           } else {
  -            bl.setMessageOutputLevel( Project.MSG_INFO );
  +            logger.setMessageOutputLevel( Project.MSG_INFO );
           }
  -        project.addBuildListener( bl );
  +        project.addBuildListener( logger );
           
           if( options.getCompiler() != null ) {
               Constants.jasperLog.log("Compiler " + options.getCompiler(), 
Logger.ERROR );
               project.setProperty("build.compiler", options.getCompiler() );
           }
           project.init();
  -//         Vector v=project.getBuildListeners();
  -//         if( v.size() > 0 ) {
  -//             BuildListener bl=(BuildListener)v.elementAt(0);
  -//             System.out.println("XXX " + bl );
  -//             ((DefaultLogger)bl).setMessageOutputLevel(Project.MSG_VERBOSE);
  -//         }
           return project;
       }
   
  -    static class JasperAntLogger extends DefaultLogger {
  +    class JasperAntLogger extends DefaultLogger {
  +
  +        private StringBuffer reportBuf = new StringBuffer();
  +
           protected void printMessage(final String message,
                                       final PrintStream stream,
                                       final int priority) {
  -            Constants.jasperLog.log( message, Logger.INFORMATION );
           }
   
  +        protected void log(String message) {
  +            reportBuf.append(message);
  +            reportBuf.append(System.getProperty("line.separator"));
  +        }
  +
  +        protected String getReport() {
  +            String report = reportBuf.toString();
  +            reportBuf.setLength(0);
  +            return report;
  +        }
       }
   
       // --------------------------------------------------------- Public Methods
  @@ -194,31 +200,14 @@
           String javaFileName = ctxt.getServletJavaFileName();
   
           // Setup the ServletWriter
  -     // We try UTF8 by default. If it fails, we use the java encoding 
  -     // specified for JspServlet init parameter "javaEncoding".
  +        String javaEncoding = ctxt.getOptions().getJavaEncoding();
   
  -     String javaEncoding = "UTF8"; 
        OutputStreamWriter osw = null; 
        try {
            osw = new OutputStreamWriter(new FileOutputStream(javaFileName),
                                         javaEncoding);
        } catch (UnsupportedEncodingException ex) {
  -         // Try to get the java encoding from the "javaEncoding"
  -         // init parameter for JspServlet.
  -         javaEncoding = ctxt.getOptions().getJavaEncoding();
  -         if (javaEncoding != null) {
  -             try {
  -                 osw = new OutputStreamWriter
  -                        (new FileOutputStream(javaFileName),javaEncoding);
  -             } catch (UnsupportedEncodingException ex2) {
  -                 // no luck :-(
  -                 errDispatcher.jspError("jsp.error.invalid.javaEncoding",
  -                                        "UTF8", javaEncoding);
  -             }
  -         } else {
  -             errDispatcher.jspError("jsp.error.needAlternateJavaEncoding",
  -                                    "UTF8");
  -         }
  +         errDispatcher.jspError("jsp.error.needAlternateJavaEncoding", 
javaEncoding);
        }
   
        ServletWriter writer = new ServletWriter(new PrintWriter(osw));
  @@ -251,13 +240,13 @@
       public void generateClass()
           throws FileNotFoundException, JasperException, Exception
       {
  -     String javaEncoding = "UTF8"; 
  +        String javaEncoding = ctxt.getOptions().getJavaEncoding();
           String javaFileName = ctxt.getServletJavaFileName();
           String classpath = ctxt.getClassPath(); 
   
           String sep = System.getProperty("path.separator");
   
  -        String errorReport = null;
  +        StringBuffer errorReport = new StringBuffer();
           boolean success = true;
   
           // Start capturing the System.err output for this thread
  @@ -295,14 +284,18 @@
           try {
               javac.execute();
           } catch (BuildException e) {
  -            //   System.out.println("Javac execption ");
  -            //   e.printStackTrace(System.out);
               success = false;
           }
   
  +        errorReport.append(logger.getReport());
  +
           // Stop capturing the System.err output for this thread
  -        errorReport = SystemLogHandler.unsetThread();
  -        
  +        String errorCapture = SystemLogHandler.unsetThread();
  +        if (errorCapture != null) {
  +            errorReport.append(System.getProperty("line.separator"));
  +            errorReport.append(errorCapture);
  +        }
  +
           if (!ctxt.keepGenerated()) {
               File javaFile = new File(javaFileName);
               javaFile.delete();
  @@ -311,8 +304,7 @@
           if (!success) {
               Constants.jasperLog.log( "Error compiling file: " + javaFileName + " " 
+ errorReport,
                                        Logger.ERROR);
  -            if(errorReport!=null ) 
  -                errDispatcher.javacError(errorReport, javaFileName, pageNodes);
  +            errDispatcher.javacError(errorReport.toString(), javaFileName, 
pageNodes);
           }
       }
   
  
  
  

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

Reply via email to