incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r922215 - in /sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/jasper: JspCompilationContext.java compiler/Compiler.java compiler/JspRuntimeContext.java compiler/ServletWriter.java servlet/JspServletWrapper.java
Date Fri, 12 Mar 2010 11:02:39 GMT
Author: cziegeler
Date: Fri Mar 12 11:02:38 2010
New Revision: 922215

URL: http://svn.apache.org/viewvc?rev=922215&view=rev
Log:
SLING-1038 : Recompile jsps on modifications and avoid periodic check - fix error handling
and sync problems.

Modified:
    sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/jasper/JspCompilationContext.java
    sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/jasper/compiler/Compiler.java
    sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/jasper/compiler/JspRuntimeContext.java
    sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/jasper/compiler/ServletWriter.java
    sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/jasper/servlet/JspServletWrapper.java

Modified: sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/jasper/JspCompilationContext.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/jasper/JspCompilationContext.java?rev=922215&r1=922214&r2=922215&view=diff
==============================================================================
--- sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/jasper/JspCompilationContext.java
(original)
+++ sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/jasper/JspCompilationContext.java
Fri Mar 12 11:02:38 2010
@@ -603,7 +603,7 @@ public class JspCompilationContext {
 
     // ==================== Compile and reload ====================
 
-    public void compile() throws JasperException, FileNotFoundException {
+    public void compile() throws JasperException, IOException, FileNotFoundException {
         createCompiler();
         if (isPackagedTagFile || jspCompiler.isOutDated()) {
             try {
@@ -617,6 +617,13 @@ public class JspCompilationContext {
                 // Cache compilation exception
                 jsw.setCompilationException(ex);
                 throw ex;
+            } catch (IOException ioe) {
+                JasperException je = new JasperException(
+                        Localizer.getMessage("jsp.error.unable.compile"),
+                        ioe);
+                // Cache compilation exception
+                jsw.setCompilationException(je);
+                throw ioe;
             } catch (Exception ex) {
                 JasperException je = new JasperException(
                             Localizer.getMessage("jsp.error.unable.compile"),

Modified: sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/jasper/compiler/Compiler.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/jasper/compiler/Compiler.java?rev=922215&r1=922214&r2=922215&view=diff
==============================================================================
--- sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/jasper/compiler/Compiler.java
(original)
+++ sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/jasper/compiler/Compiler.java
Fri Mar 12 11:02:38 2010
@@ -154,7 +154,7 @@ public abstract class Compiler {
                 errDispatcher.jspError("jsp.error.needAlternateJavaEncoding",
                         javaEncoding);
             } catch (IOException ioe) {
-                throw new FileNotFoundException(ioe.getMessage());
+                throw (IOException)new FileNotFoundException(ioe.getMessage()).initCause(ioe);
             }
 
             writer = new ServletWriter(new PrintWriter(osw));
@@ -209,8 +209,12 @@ public abstract class Compiler {
 
             // generate servlet .java file
             Generator.generate(writer, this, pageNodes);
-            writer.close();
+
+            // we have to use a temporary variable in order to not
+            // close the writer twice if close() throws an exception
+            final ServletWriter w = writer;
             writer = null;
+            w.close();
 
             // The writer is only used during the compile, dereference
             // it in the JspCompilationContext when done to allow it
@@ -359,10 +363,6 @@ public abstract class Compiler {
         }
         String jsp = ctxt.getJspFile();
 
-        if (jsw != null) {
-            jsw.setLastModificationTest(System.currentTimeMillis());
-        }
-
         long jspRealLastModified = 0;
         try {
             URL jspUrl = ctxt.getResource(jsp);

Modified: sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/jasper/compiler/JspRuntimeContext.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/jasper/compiler/JspRuntimeContext.java?rev=922215&r1=922214&r2=922215&view=diff
==============================================================================
--- sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/jasper/compiler/JspRuntimeContext.java
(original)
+++ sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/jasper/compiler/JspRuntimeContext.java
Fri Mar 12 11:02:38 2010
@@ -184,7 +184,7 @@ public final class JspRuntimeContext {
     }
 
     private void invalidate(final JspServletWrapper jsw) {
-        jsw.setLastModificationTest(0);
+        jsw.clearLastModificationTest();
     }
 
     public void handleModification(final String scriptName) {

Modified: sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/jasper/compiler/ServletWriter.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/jasper/compiler/ServletWriter.java?rev=922215&r1=922214&r2=922215&view=diff
==============================================================================
--- sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/jasper/compiler/ServletWriter.java
(original)
+++ sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/jasper/compiler/ServletWriter.java
Fri Mar 12 11:02:38 2010
@@ -5,9 +5,9 @@
  * The ASF licenses this file to You under the Apache License, Version 2.0
  * (the "License"); you may not use this file except in compliance with
  * the License.  You may obtain a copy of the License at
- * 
+ *
  *      http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -20,7 +20,7 @@ import java.io.IOException;
 import java.io.PrintWriter;
 
 /**
- * This is what is used to generate servlets. 
+ * This is what is used to generate servlets.
  *
  * @author Anil K. Vijendran
  * @author Kin-man Chung
@@ -35,7 +35,7 @@ public class ServletWriter {
 
     // The sink writer:
     PrintWriter writer;
-    
+
     // servlet line numbers start from 1
     private int javaLine = 1;
 
@@ -45,10 +45,13 @@ public class ServletWriter {
     }
 
     public void close() throws IOException {
-	writer.close();
+        final boolean hasErrors = this.writer.checkError();
+        writer.close();
+        if ( hasErrors ) {
+            throw new IOException("IOException during writing.");
+        }
     }
 
-    
     // -------------------- Access informations --------------------
 
     public int getJavaLine() {
@@ -72,15 +75,15 @@ public class ServletWriter {
 
     /**
      * Print a standard comment for echo outputed chunk.
-     * @param start The starting position of the JSP chunk being processed. 
-     * @param stop  The ending position of the JSP chunk being processed. 
+     * @param start The starting position of the JSP chunk being processed.
+     * @param stop  The ending position of the JSP chunk being processed.
      */
     public void printComment(Mark start, Mark stop, char[] chars) {
         if (start != null && stop != null) {
             println("// from="+start);
             println("//   to="+stop);
         }
-        
+
         if (chars != null)
             for(int i = 0; i < chars.length;) {
                 printin();

Modified: sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/jasper/servlet/JspServletWrapper.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/jasper/servlet/JspServletWrapper.java?rev=922215&r1=922214&r2=922215&view=diff
==============================================================================
--- sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/jasper/servlet/JspServletWrapper.java
(original)
+++ sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/jasper/servlet/JspServletWrapper.java
Fri Mar 12 11:02:38 2010
@@ -152,6 +152,8 @@ public class JspServletWrapper {
                         throw new JasperException(e);
                     } catch (InstantiationException e) {
                         throw new JasperException(e);
+                    } catch (IOException e) {
+                        throw e;
                     } catch (Exception e) {
                         throw new JasperException(e);
                     }
@@ -211,8 +213,9 @@ public class JspServletWrapper {
             }
             if (firstTime || this.lastModificationTest == 0) {
                 synchronized (this) {
-                    firstTime = false;
                     ctxt.compile();
+                    firstTime = false;
+                    this.lastModificationTest = System.currentTimeMillis();
                 }
             } else {
                 if (compileException != null) {
@@ -224,11 +227,11 @@ public class JspServletWrapper {
                 tagHandlerClass = ctxt.load();
                 reload = false;
             }
-        } catch (FileNotFoundException ex) {
+        } catch (IOException ex) {
             throw new JasperException(ex);
-	}
+	    }
 
-	return tagHandlerClass;
+	    return tagHandlerClass;
     }
 
     /**
@@ -315,16 +318,20 @@ public class JspServletWrapper {
              */
             if (firstTime || this.lastModificationTest == 0 ) {
                 synchronized (this) {
-                    firstTime = false;
+                    if (firstTime || this.lastModificationTest == 0 ) {
+                        // The following sets reload to true, if necessary
+                        ctxt.compile();
+                        this.lastModificationTest = System.currentTimeMillis();
+                        firstTime = false;
+                    } else if ( compileException != null ) {
+                        // Throw cached compilation exception
+                        throw compileException;
 
-                    // The following sets reload to true, if necessary
-                    ctxt.compile();
-                }
-            } else {
-                if (compileException != null) {
-                    // Throw cached compilation exception
-                    throw compileException;
+                    }
                 }
+            } else if (compileException != null) {
+                // Throw cached compilation exception
+                throw compileException;
             }
 
             /*
@@ -355,6 +362,7 @@ public class JspServletWrapper {
                        ex.getMessage()),
               ex);
             }
+            return;
         } catch (ServletException ex) {
             throw handleJspException(ex);
         } catch (IOException ex) {
@@ -398,6 +406,7 @@ public class JspServletWrapper {
             response.sendError
                 (HttpServletResponse.SC_SERVICE_UNAVAILABLE,
                  ex.getMessage());
+            return;
         } catch (ServletException ex) {
             throw handleJspException(ex);
         } catch (IOException ex) {
@@ -432,10 +441,10 @@ public class JspServletWrapper {
         return lastModificationTest;
     }
     /**
-     * @param lastModificationTest The lastModificationTest to set.
+     *Clea the lastModificationTest.
      */
-    public void setLastModificationTest(long lastModificationTest) {
-        this.lastModificationTest = lastModificationTest;
+    public void clearLastModificationTest() {
+        this.lastModificationTest = 0;
     }
 
     /**



Mime
View raw message