luehe       2004/04/27 11:14:13

  Modified:    jasper2/src/share/org/apache/jasper/compiler Compiler.java
  Log:
  Fixed Bugzilla 28603 ("JspC Ant task does not detect errors on a
  second compile"):
  
  Remove empty .java file (that was generated by "new
  FileOutputStream()") if parser/validator/generator throws exception.
  
  Also removed tabs.
  
  Revision  Changes    Path
  1.81      +109 -86   
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.80
  retrieving revision 1.81
  diff -u -r1.80 -r1.81
  --- Compiler.java     20 Apr 2004 20:05:19 -0000      1.80
  +++ Compiler.java     27 Apr 2004 18:14:13 -0000      1.81
  @@ -146,105 +146,129 @@
        * @return a smap for the current JSP page, if one is generated,
        *         null otherwise
        */
  -    private String[] generateJava()
  -        throws Exception
  -    {
  -     String[] smapStr = null;
  +    private String[] generateJava() throws Exception {
  +        
  +        String[] smapStr = null;
   
           long t1=System.currentTimeMillis();
   
  -     // Setup page info area
  -     pageInfo = new PageInfo(new BeanRepository(ctxt.getClassLoader(),
  -                                                errDispatcher));
  -
  -     JspConfig jspConfig = options.getJspConfig();
  -     JspConfig.JspProperty jspProperty =
  -                     jspConfig.findJspProperty(ctxt.getJspFile());
  +        // Setup page info area
  +        pageInfo = new PageInfo(new BeanRepository(ctxt.getClassLoader(),
  +                                                   errDispatcher));
  +
  +        JspConfig jspConfig = options.getJspConfig();
  +        JspConfig.JspProperty jspProperty =
  +            jspConfig.findJspProperty(ctxt.getJspFile());
   
           /*
            * If the current uri is matched by a pattern specified in
            * a jsp-property-group in web.xml, initialize pageInfo with
            * those properties.
            */
  -        pageInfo.setELIgnored(JspUtil.booleanValue(jspProperty.isELIgnored()));
  -        
pageInfo.setScriptingInvalid(JspUtil.booleanValue(jspProperty.isScriptingInvalid()));
  +        pageInfo.setELIgnored(JspUtil.booleanValue(
  +                                            jspProperty.isELIgnored()));
  +        pageInfo.setScriptingInvalid(JspUtil.booleanValue(
  +                                            jspProperty.isScriptingInvalid()));
           if (jspProperty.getIncludePrelude() != null) {
               pageInfo.setIncludePrelude(jspProperty.getIncludePrelude());
           }
  -     if (jspProperty.getIncludeCoda() != null) {
  +        if (jspProperty.getIncludeCoda() != null) {
            pageInfo.setIncludeCoda(jspProperty.getIncludeCoda());
  -     }
  +        }
  +
           String javaFileName = ctxt.getServletJavaFileName();
  +        ServletWriter writer = null;
   
  -        // Setup the ServletWriter
  -        String javaEncoding = ctxt.getOptions().getJavaEncoding();
  -     OutputStreamWriter osw = null; 
  -     try {
  -         osw = new OutputStreamWriter(new FileOutputStream(javaFileName),
  -                                      javaEncoding);
  -     } catch (UnsupportedEncodingException ex) {
  -            errDispatcher.jspError("jsp.error.needAlternateJavaEncoding", 
javaEncoding);
  -     }
  -
  -     ServletWriter writer = new ServletWriter(new PrintWriter(osw));
  -        ctxt.setWriter(writer);
  -
  -        // Reset the temporary variable counter for the generator.
  -        JspUtil.resetTemporaryVariableName();
  -
  -     // Parse the file
  -     ParserController parserCtl = new ParserController(ctxt, this);
  -     pageNodes = parserCtl.parse(ctxt.getJspFile());
  -
  -     if (ctxt.isPrototypeMode()) {
  -         // generate prototype .java file for the tag file
  -         Generator.generate(writer, this, pageNodes);
  -            writer.close();
  -         return null;
  -     }
  +        try {
  +            // Setup the ServletWriter
  +            String javaEncoding = ctxt.getOptions().getJavaEncoding();
  +            OutputStreamWriter osw = null; 
  +
  +            try {
  +                osw = new OutputStreamWriter(
  +                            new FileOutputStream(javaFileName), javaEncoding);
  +            } catch (UnsupportedEncodingException ex) {
  +                errDispatcher.jspError("jsp.error.needAlternateJavaEncoding",
  +                                       javaEncoding);
  +            }
  +
  +            writer = new ServletWriter(new PrintWriter(osw));
  +            ctxt.setWriter(writer);
  +
  +            // Reset the temporary variable counter for the generator.
  +            JspUtil.resetTemporaryVariableName();
  +
  +         // Parse the file
  +         ParserController parserCtl = new ParserController(ctxt, this);
  +         pageNodes = parserCtl.parse(ctxt.getJspFile());
  +
  +         if (ctxt.isPrototypeMode()) {
  +                // generate prototype .java file for the tag file
  +                Generator.generate(writer, this, pageNodes);
  +                writer.close();
  +                writer = null;
  +                return null;
  +            }
  +
  +            // Validate and process attributes
  +            Validator.validate(this, pageNodes);
  +
  +            long t2=System.currentTimeMillis();
  +            // Dump out the page (for debugging)
  +            // Dumper.dump(pageNodes);
  +
  +            // Collect page info
  +            Collector.collect(this, pageNodes);
  +
  +            // Compile (if necessary) and load the tag files referenced in
  +            // this compilation unit.
  +            tfp = new TagFileProcessor();
  +            tfp.loadTagFiles(this, pageNodes);
   
  -     // Validate and process attributes
  -     Validator.validate(this, pageNodes);
  +            long t3=System.currentTimeMillis();
  +        
  +            // Determine which custom tag needs to declare which scripting vars
  +            ScriptingVariabler.set(pageNodes, errDispatcher);
   
  -        long t2=System.currentTimeMillis();
  -     // Dump out the page (for debugging)
  -     // Dumper.dump(pageNodes);
  +            // Optimizations by Tag Plugins
  +            TagPluginManager tagPluginManager = options.getTagPluginManager();
  +            tagPluginManager.apply(pageNodes, errDispatcher, pageInfo);
   
  -     // Collect page info
  -     Collector.collect(this, pageNodes);
  +            // Optimization: concatenate contiguous template texts.
  +            TextOptimizer.concatenate(this, pageNodes);
   
  -     // Compile (if necessary) and load the tag files referenced in
  -     // this compilation unit.
  -     tfp = new TagFileProcessor();
  -     tfp.loadTagFiles(this, pageNodes);
  +            // Generate static function mapper codes.
  +            ELFunctionMapper.map(this, pageNodes);
   
  -        long t3=System.currentTimeMillis();
  -        
  -     // Determine which custom tag needs to declare which scripting vars
  -     ScriptingVariabler.set(pageNodes, errDispatcher);
  +            // generate servlet .java file
  +            Generator.generate(writer, this, pageNodes);
  +            writer.close();
  +            writer = null;
   
  -     // Optimizations by Tag Plugins
  -     TagPluginManager tagPluginManager = options.getTagPluginManager();
  -     tagPluginManager.apply(pageNodes, errDispatcher, pageInfo);
  -
  -        // Optimization: concatenate contiguous template texts.
  -        TextOptimizer.concatenate(this, pageNodes);
  -
  -     // Generate static function mapper codes.
  -     ELFunctionMapper.map(this, pageNodes);
  -
  -     // generate servlet .java file
  -     Generator.generate(writer, this, pageNodes);
  -        writer.close();
  -        // The writer is only used during the compile, dereference
  -        // it in the JspCompilationContext when done to allow it
  -        // to be GC'd and save memory.
  -        ctxt.setWriter(null);
  -
  -        long t4=System.currentTimeMillis();
  -        if( t4-t1 > 500 ) {
  -            log.debug("Generated "+ javaFileName + " total=" +
  -                      (t4-t1) + " generate=" + ( t4-t3 ) + " validate=" + ( t2-t1 
));
  +            // The writer is only used during the compile, dereference
  +            // it in the JspCompilationContext when done to allow it
  +            // to be GC'd and save memory.
  +            ctxt.setWriter(null);
  +
  +            long t4=System.currentTimeMillis();
  +            if( t4-t1 > 500 ) {
  +                log.debug("Generated "+ javaFileName + " total=" +
  +                          (t4-t1) + " generate=" + ( t4-t3 ) + " validate=" +
  +                          ( t2-t1 ));
  +            }
  +
  +        } catch (Exception e) {
  +            // Remove the generated .java file
  +            new File(javaFileName).delete();            
  +            throw e;
  +        } finally {
  +            if (writer != null) {
  +                try {
  +                    writer.close();
  +                } catch (Exception e) {
  +                    // do nothing
  +                }
  +            }
           }
           
           // JSR45 Support
  @@ -252,15 +276,14 @@
               smapStr = SmapUtil.generateSmap(ctxt, pageNodes);
           }
   
  -     // If any proto type .java and .class files was generated,
  -     // the prototype .java may have been replaced by the current
  -     // compilation (if the tag file is self referencing), but the
  -     // .class file need to be removed, to make sure that javac would
  -     // generate .class again from the new .java file just generated.
  -
  -     tfp.removeProtoTypeFiles(ctxt.getClassFileName());
  +        // If any proto type .java and .class files was generated,
  +        // the prototype .java may have been replaced by the current
  +        // compilation (if the tag file is self referencing), but the
  +        // .class file need to be removed, to make sure that javac would
  +        // generate .class again from the new .java file just generated.
  +        tfp.removeProtoTypeFiles(ctxt.getClassFileName());
   
  -     return smapStr;
  +        return smapStr;
       }
   
       /** 
  
  
  

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

Reply via email to