incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r1348403 - in /sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp: ./ jasper/ jasper/compiler/ jasper/servlet/
Date Sat, 09 Jun 2012 13:15:39 GMT
Author: cziegeler
Date: Sat Jun  9 13:15:38 2012
New Revision: 1348403

URL: http://svn.apache.org/viewvc?rev=1348403&view=rev
Log:
SLING-2505 : Don't load class for dependency check

Removed:
    sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/jasper/IsolatedClassLoader.java
Modified:
    sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/JspScriptEngineFactory.java
    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/TagFileProcessor.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/JspScriptEngineFactory.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/JspScriptEngineFactory.java?rev=1348403&r1=1348402&r2=1348403&view=diff
==============================================================================
--- sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/JspScriptEngineFactory.java
(original)
+++ sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/JspScriptEngineFactory.java
Sat Jun  9 13:15:38 2012
@@ -151,7 +151,7 @@ public class JspScriptEngineFactory
     /**
      * @see javax.script.ScriptEngineFactory#getParameter(String)
      */
-    public Object getParameter(String name) {
+    public Object getParameter(final String name) {
         if ("THREADING".equals(name)) {
             return "STATELESS";
         }
@@ -415,7 +415,7 @@ public class JspScriptEngineFactory
             super(JspScriptEngineFactory.this);
         }
 
-        public Object eval(Reader script, ScriptContext context)
+        public Object eval(final Reader script, final ScriptContext context)
                 throws ScriptException {
             Bindings props = context.getBindings(ScriptContext.ENGINE_SCOPE);
             SlingScriptHelper scriptHelper = (SlingScriptHelper) props.get(SLING);
@@ -469,7 +469,7 @@ public class JspScriptEngineFactory
         if (jrc != null) {
             try {
                 jrc.destroy();
-            } catch (NullPointerException npe) {
+            } catch (final NullPointerException npe) {
                 // SLING-530, might be thrown on system shutdown in a servlet
                 // container when using the Equinox servlet container bridge
                 logger.debug("deactivate: ServletContext might already be unavailable", npe);
@@ -526,6 +526,10 @@ public class JspScriptEngineFactory
         }
     }
 
+    /**
+     * Renew the jsp runtime context.
+     * A new context is created, the old context is destroyed in the background
+     */
     private void renewJspRuntimeContext() {
         final JspRuntimeContext jrc;
         synchronized ( this ) {

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=1348403&r1=1348402&r2=1348403&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
Sat Jun  9 13:15:38 2012
@@ -207,10 +207,6 @@ public class JspCompilationContext {
         return jspCompiler;
     }
 
-    public void reset() {
-        this.jspCompiler = null;
-    }
-
     /** ---------- Access resources in the webapp ---------- */
 
     /**

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=1348403&r1=1348402&r2=1348403&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
Sat Jun  9 13:15:38 2012
@@ -354,17 +354,7 @@ public abstract class Compiler {
      * Remove generated files
      */
     public void removeGeneratedFiles() {
-        try {
-            String classFileName = ctxt.getClassFileName();
-            if (classFileName != null) {
-                if (log.isDebugEnabled()) {
-                    log.debug("Deleting " + classFileName);
-                }
-                ctxt.delete(classFileName);
-            }
-        } catch (Exception e) {
-            // Remove as much as possible, ignore possible exceptions
-        }
+        this.removeGeneratedClassFiles();
         try {
             String javaFileName = ctxt.getServletJavaFileName();
             if (javaFileName != null) {

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=1348403&r1=1348402&r2=1348403&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
Sat Jun  9 13:15:38 2012
@@ -251,6 +251,10 @@ public final class JspRuntimeContext {
      * Handle jsp modifications
      */
     public boolean handleModification(final String scriptName) {
+        if ( log.isDebugEnabled() ) {
+            log.debug("Handling modification " + scriptName);
+        }
+
         JspServletWrapper wrapper = jsps.remove(scriptName);
 
         // first check if jsps contains this
@@ -274,8 +278,9 @@ public final class JspRuntimeContext {
      */
     private boolean invalidate(final JspServletWrapper wrapper) {
         if ( wrapper != null ) {
-            log.debug("Invalidating jsp " + wrapper.getJspUri());
-            this.ioProvider.delete(wrapper.getJspUri());
+            if ( log.isDebugEnabled() ) {
+                log.debug("Invalidating jsp " + wrapper.getJspUri());
+            }
             wrapper.destroy(true);
             return true;
         }

Modified: sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/jasper/compiler/TagFileProcessor.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/jasper/compiler/TagFileProcessor.java?rev=1348403&r1=1348402&r2=1348403&view=diff
==============================================================================
--- sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/jasper/compiler/TagFileProcessor.java
(original)
+++ sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/jasper/compiler/TagFileProcessor.java
Sat Jun  9 13:15:38 2012
@@ -533,68 +533,65 @@ class TagFileProcessor {
 
         JspCompilationContext ctxt = compiler.getCompilationContext();
         JspRuntimeContext rctxt = ctxt.getRuntimeContext();
-        JspServletWrapper wrapper = rctxt
-                .getWrapper(tagFilePath);
+        JspServletWrapper wrapper = rctxt.getWrapper(tagFilePath);
 
-        synchronized (rctxt) {
-            if (wrapper == null) {
-                wrapper = new JspServletWrapper(ctxt.getServletContext(), ctxt
-                        .getOptions(), tagFilePath, tagInfo, ctxt
-                        .getRuntimeContext(), ctxt.getTagFileJarUrl(tagFilePath));
-                wrapper = rctxt.addWrapper(tagFilePath, wrapper);
-
-                // Use same classloader and classpath for compiling tag files
-                //wrapper.getJspEngineContext().setClassLoader(ctxt.getClassLoader());
-                //wrapper.getJspEngineContext().setClassPath(ctxt.getClassPath());
-            } else {
-                // Make sure that JspCompilationContext gets the latest TagInfo
-                // for the tag file. TagInfo instance was created the last
-                // time the tag file was scanned for directives, and the tag
-                // file may have been modified since then.
-                wrapper.getJspEngineContext().setTagInfo(tagInfo);
-            }
+        if (wrapper == null) {
+            wrapper = new JspServletWrapper(ctxt.getServletContext(), ctxt
+                    .getOptions(), tagFilePath, tagInfo, ctxt
+                    .getRuntimeContext(), ctxt.getTagFileJarUrl(tagFilePath));
+            wrapper = rctxt.addWrapper(tagFilePath, wrapper);
+
+            // Use same classloader and classpath for compiling tag files
+            //wrapper.getJspEngineContext().setClassLoader(ctxt.getClassLoader());
+            //wrapper.getJspEngineContext().setClassPath(ctxt.getClassPath());
+        } else {
+            // Make sure that JspCompilationContext gets the latest TagInfo
+            // for the tag file. TagInfo instance was created the last
+            // time the tag file was scanned for directives, and the tag
+            // file may have been modified since then.
+            wrapper.getJspEngineContext().setTagInfo(tagInfo);
+        }
 
-            Class tagClazz;
-            int tripCount = wrapper.incTripCount();
-            try {
-                if (tripCount > 0) {
-                    // When tripCount is greater than zero, a circular
-                    // dependency exists. The circularily dependant tag
-                    // file is compiled in prototype mode, to avoid infinite
-                    // recursion.
-
-                    JspServletWrapper tempWrapper = new JspServletWrapper(ctxt
-                            .getServletContext(), ctxt.getOptions(),
-                            tagFilePath, tagInfo, ctxt.getRuntimeContext(),
-                            ctxt.getTagFileJarUrl(tagFilePath));
-                    tagClazz = tempWrapper.loadTagFilePrototype();
-                    tempVector.add(tempWrapper.getJspEngineContext()
-                            .getCompiler());
-                } else {
-                    tagClazz = wrapper.loadTagFile();
-                }
-            } finally {
-                wrapper.decTripCount();
+        Class tagClazz;
+        int tripCount = wrapper.incTripCount();
+        try {
+            if (tripCount > 0) {
+                // When tripCount is greater than zero, a circular
+                // dependency exists. The circularily dependant tag
+                // file is compiled in prototype mode, to avoid infinite
+                // recursion.
+
+                JspServletWrapper tempWrapper = new JspServletWrapper(ctxt
+                        .getServletContext(), ctxt.getOptions(),
+                        tagFilePath, tagInfo, ctxt.getRuntimeContext(),
+                        ctxt.getTagFileJarUrl(tagFilePath));
+                tagClazz = tempWrapper.loadTagFilePrototype();
+                tempVector.add(tempWrapper.getJspEngineContext()
+                        .getCompiler());
+            } else {
+                tagClazz = wrapper.loadTagFile();
             }
+        } finally {
+            wrapper.decTripCount();
+        }
 
-            // Add the dependants for this tag file to its parent's
-            // dependant list. The only reliable dependency information
-            // can only be obtained from the tag instance.
-            try {
-                Object tagIns = tagClazz.newInstance();
-                if (tagIns instanceof JspSourceDependent) {
-                    Iterator iter = ((List) ((JspSourceDependent) tagIns)
-                            .getDependants()).iterator();
-                    while (iter.hasNext()) {
-                        parentPageInfo.addDependant((String) iter.next());
-                    }
+        // Add the dependants for this tag file to its parent's
+        // dependant list. The only reliable dependency information
+        // can only be obtained from the tag instance.
+        try {
+            Object tagIns = tagClazz.newInstance();
+            if (tagIns instanceof JspSourceDependent) {
+                Iterator iter = ((List) ((JspSourceDependent) tagIns)
+                        .getDependants()).iterator();
+                while (iter.hasNext()) {
+                    parentPageInfo.addDependant((String) iter.next());
                 }
-            } catch (Exception e) {
-                // ignore errors
             }
-
-            return tagClazz;
+        } catch (Exception e) {
+            // ignore errors
         }
+
+        return tagClazz;
     }
 
     /*

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=1348403&r1=1348402&r2=1348403&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
Sat Jun  9 13:15:38 2012
@@ -19,7 +19,12 @@ package org.apache.sling.scripting.jsp.j
 
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.LineNumberReader;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
 import java.net.URL;
+import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Iterator;
 import java.util.List;
@@ -44,7 +49,6 @@ import org.apache.sling.api.scripting.Sc
 import org.apache.sling.api.scripting.SlingBindings;
 import org.apache.sling.commons.classloader.DynamicClassLoader;
 import org.apache.sling.scripting.jsp.SlingPageException;
-import org.apache.sling.scripting.jsp.jasper.IsolatedClassLoader;
 import org.apache.sling.scripting.jsp.jasper.JasperException;
 import org.apache.sling.scripting.jsp.jasper.JspCompilationContext;
 import org.apache.sling.scripting.jsp.jasper.Options;
@@ -78,13 +82,16 @@ public class JspServletWrapper {
     // Logger
     private final Log log = LogFactory.getLog(JspServletWrapper.class);
 
-    private Servlet theServlet;
-    private final String jspUri;
-    private final JspCompilationContext ctxt;
-    private long available = 0L;
     private final ServletConfig config;
     private final Options options;
     private final boolean isTagFile;
+    private final String jspUri;
+    private final JspCompilationContext ctxt;
+
+    private volatile Servlet theServlet;
+    private volatile Class<?> tagFileClass;
+
+    private volatile long available = 0L;
     private volatile JasperException compileException;
     private volatile int tripCount;
 
@@ -105,6 +112,9 @@ public class JspServletWrapper {
         this.ctxt = new JspCompilationContext(jspUri, isErrorPage, options,
 					 config.getServletContext(),
 					 this, rctxt);
+        if ( log.isDebugEnabled() ) {
+            log.debug("Creating new wrapper for servlet " + jspUri);
+        }
     }
 
     /**
@@ -124,6 +134,9 @@ public class JspServletWrapper {
         this.ctxt = new JspCompilationContext(jspUri, tagInfo, options,
 					 servletContext, this, rctxt,
 					 tagFileJarUrl);
+        if ( log.isDebugEnabled() ) {
+            log.debug("Creating new wrapper for tagfile " + jspUri);
+        }
     }
 
     public JspCompilationContext getJspEngineContext() {
@@ -145,6 +158,9 @@ public class JspServletWrapper {
         Servlet servlet = null;
 
         try {
+            if ( log.isDebugEnabled() ) {
+                log.debug("Loading servlet " + jspUri);
+            }
             servlet = (Servlet) ctxt.load().newInstance();
             AnnotationProcessor annotationProcessor = (AnnotationProcessor) config.getServletContext().getAttribute(AnnotationProcessor.class.getName());
             if (annotationProcessor != null) {
@@ -152,15 +168,22 @@ public class JspServletWrapper {
                annotationProcessor.postConstruct(servlet);
             }
             // update dependents
+            final List<String> oldDeps = this.dependents;
             if (servlet != null && servlet instanceof JspSourceDependent) {
                 this.dependents = (List<String>) ((JspSourceDependent) servlet).getDependants();
+                if ( this.dependents == null ) {
+                    this.dependents = Collections.EMPTY_LIST;
+                }
                 this.ctxt.getRuntimeContext().addJspDependencies(this, this.dependents);
             }
-        } catch (IllegalAccessException e) {
+            if ( !equals(oldDeps, this.dependents) ) {
+                this.persistDependencies();
+            }
+        } catch (final IllegalAccessException e) {
             throw new JasperException(e);
-        } catch (InstantiationException e) {
+        } catch (final InstantiationException e) {
             throw new JasperException(e);
-        } catch (Exception e) {
+        } catch (final Exception e) {
             throw new JasperException(e);
         }
 
@@ -170,17 +193,99 @@ public class JspServletWrapper {
     }
 
     /**
+     * Get the name of the dependencies file.
+     */
+    public String getDependencyFilePath() {
+        final String name;
+        if (isTagFile) {
+            name = this.ctxt.getTagInfo().getTagClassName();
+        } else {
+            name = this.ctxt.getServletPackageName() + "." + this.ctxt.getServletClassName();
+        }
+
+        final String path = ":/" + name.replace('.', '/') + ".deps";
+        return path;
+    }
+
+    /**
+     * Persist dependencies
+     */
+    private void persistDependencies() {
+        final String path = this.getDependencyFilePath();
+        if ( log.isDebugEnabled() ) {
+            log.debug("Writing dependencies for " + jspUri);
+        }
+        if ( this.dependents != null && this.dependents.size() > 0 ) {
+            OutputStream os = null;
+            try {
+                os = this.ctxt.getRuntimeContext().getIOProvider().getOutputStream(path);
+                final OutputStreamWriter writer = new OutputStreamWriter(os, "UTF-8");
+                for(final String dep : this.dependents) {
+                    writer.write(dep);
+                    writer.write("\n");
+                }
+                writer.flush();
+            } catch ( final IOException ioe) {
+                log.warn("Unable to write dependenies file " + path + " : " + ioe.getMessage(),
ioe);
+            } finally {
+                if ( os != null ) {
+                    try {
+                        os.close();
+                    } catch (final IOException ioe) {
+                        // ignore
+                    }
+                }
+            }
+        } else {
+            this.ctxt.getRuntimeContext().getIOProvider().delete(path);
+        }
+    }
+
+    /**
      * Compile (if needed) and load a tag file
      */
+    @SuppressWarnings("unchecked")
     public Class<?> loadTagFile() throws JasperException {
-        synchronized (this) {
-            this.compileException = ctxt.compile();
-            if ( compileException != null ) {
-                throw compileException;
-            }
+        if ( compileException != null ) {
+            throw compileException;
         }
 
-        return ctxt.load();
+        if ( this.tagFileClass == null ) {
+            synchronized (this) {
+                if ( this.tagFileClass == null ) {
+                    if ( log.isDebugEnabled() ) {
+                        log.debug("Compiling tagfile " + jspUri);
+                    }
+                    this.compileException = ctxt.compile();
+                    if ( compileException != null ) {
+                        throw compileException;
+                    }
+                    if ( log.isDebugEnabled() ) {
+                        log.debug("Loading tagfile " + jspUri);
+                    }
+                    this.tagFileClass = this.ctxt.load();
+                    try {
+                        final Object tag = this.tagFileClass.newInstance();
+                        // update dependents
+                        final List<String> oldDeps = this.dependents;
+                        if (tag != null && tag instanceof JspSourceDependent) {
+                            this.dependents = (List<String>) ((JspSourceDependent)
tag).getDependants();
+                            this.ctxt.getRuntimeContext().addJspDependencies(this, this.dependents);
+                            if ( this.dependents == null ) {
+                                this.dependents = Collections.EMPTY_LIST;
+                            }
+                        }
+                        if ( !equals(oldDeps, this.dependents) ) {
+                            this.persistDependencies();
+                        }
+                        this.persistDependencies();
+                    } catch (final Throwable t) {
+                        // ignore
+                    }
+                }
+            }
+        }
+        return this.tagFileClass;
     }
 
     /**
@@ -201,42 +306,33 @@ public class JspServletWrapper {
     /**
      * Get a list of files that the current page has source dependency on.
      */
-    @SuppressWarnings("unchecked")
     public List<String> getDependants() {
         if ( this.dependents == null ) {
+            // we load the deps file
+            final String path = this.getDependencyFilePath();
+            InputStream is = null;
             try {
-                Object target = null;
-                if (isTagFile) {
-                    target = ctxt.load().newInstance();
-                } else {
-                    // we load the servlet with a separate class loader
-                    final String name = this.ctxt.getServletPackageName() + "." + this.ctxt.getServletClassName();
-                    // first check if the class is available
-                    final String path = ":/" + name.replace('.', '/') + ".class";
-                    InputStream is = null;
-                    try {
-                        is = this.ctxt.getRuntimeContext().getIOProvider().getInputStream(path);
-                        if ( is != null ) {
-                            // class file is available, try to load it
-                            final ClassLoader cl = new IsolatedClassLoader(this.ctxt.getRuntimeContext().getIOProvider(),
-                                            name, is);
-                            target = cl.loadClass(name).newInstance();
-                        }
-                    } catch ( final IOException ignore ) {
-                        // excepted
-                    } finally {
-                        if ( is != null ) {
-                            try { is.close(); } catch ( final IOException ioe ) {}
-                        }
+                is = this.ctxt.getRuntimeContext().getIOProvider().getInputStream(path);
+                if ( is != null ) {
+                    if ( log.isDebugEnabled() ) {
+                        log.debug("Loading dependencies for " + jspUri);
+                    }
+                    this.dependents = new ArrayList<String>();
+                    final InputStreamReader reader = new InputStreamReader(is, "UTF-8");
+                    final LineNumberReader lnr = new LineNumberReader(reader);
+                    String line;
+                    while ( (line = lnr.readLine()) != null ) {
+                        this.dependents.add(line.trim());
                     }
-
                 }
-                if (target != null && target instanceof JspSourceDependent) {
-                    this.dependents = (List<String>) ((JspSourceDependent) target).getDependants();
+            } catch ( final IOException ignore ) {
+                // excepted
+            } finally {
+                if ( is != null ) {
+                    try { is.close(); } catch ( final IOException ioe ) {}
                 }
-            } catch (final Throwable ex) {
-                // ignore
             }
+
             // use empty list, until servlet is compiled and loaded
             if ( this.dependents == null ) {
                 this.dependents = Collections.emptyList();
@@ -320,7 +416,9 @@ public class JspServletWrapper {
     throws IOException, ServletException {
         if ( isOutDated() ) {
             // Compile...
-            log.debug("Compiling " + this.jspUri);
+            if ( log.isDebugEnabled() ) {
+                log.debug("Compiling servlet " + this.jspUri);
+            }
             this.compileException = ctxt.compile();
             if ( compileException != null ) {
                 throw compileException;
@@ -328,7 +426,6 @@ public class JspServletWrapper {
         }
 
         // (Re)load servlet class file
-        log.debug("Loading " + this.jspUri);
         this.theServlet = this.loadServlet();
     }
 
@@ -429,26 +526,59 @@ public class JspServletWrapper {
         }
     }
 
-    public void destroy(boolean deleteGeneratedFiles) {
-        if (theServlet != null) {
+    /**
+     * Destroy this wrapper
+     * @param deleteGeneratedFiles Should generated files be deleted as well?
+     */
+    public void destroy(final boolean deleteGeneratedFiles) {
+        if ( this.isTagFile ) {
+            if ( log.isDebugEnabled() ) {
+                log.debug("Destroying tagfile " + jspUri);
+            }
+            this.tagFileClass = null;
             if ( deleteGeneratedFiles ) {
-                final org.apache.sling.scripting.jsp.jasper.compiler.Compiler c = this.ctxt.getCompiler();
-                if ( c != null ) {
-                    c.removeGeneratedFiles();
+                if ( log.isDebugEnabled() ) {
+                    log.debug("Deleting generated files for tagfile " + jspUri);
                 }
+                this.ctxt.getRuntimeContext().getIOProvider().delete(this.getDependencyFilePath());
             }
-            theServlet.destroy();
-            AnnotationProcessor annotationProcessor = (AnnotationProcessor) config.getServletContext().getAttribute(AnnotationProcessor.class.getName());
-            if (annotationProcessor != null) {
-                try {
-                    annotationProcessor.preDestroy(theServlet);
-                } catch (Exception e) {
-                    // Log any exception, since it can't be passed along
-                    log.error(Localizer.getMessage("jsp.error.file.not.found",
-                           e.getMessage()), e);
+        } else {
+            if ( log.isDebugEnabled() ) {
+                log.debug("Destroying servlet " + jspUri);
+            }
+            if (theServlet != null) {
+                if ( deleteGeneratedFiles ) {
+                    if ( log.isDebugEnabled() ) {
+                        log.debug("Deleting generated files for servlet " + jspUri);
+                    }
+                    final String name;
+                    if (isTagFile) {
+                        name = this.ctxt.getTagInfo().getTagClassName();
+                    } else {
+                        name = this.ctxt.getServletPackageName() + "." + this.ctxt.getServletClassName();
+                    }
+
+                    final String path = ":/" + name.replace('.', '/') + ".class";
+                    this.ctxt.getRuntimeContext().getIOProvider().delete(path);
+                    this.ctxt.getRuntimeContext().getIOProvider().delete(this.getDependencyFilePath());
+                    final org.apache.sling.scripting.jsp.jasper.compiler.Compiler c = this.ctxt.getCompiler();
+                    if ( c != null ) {
+                        c.removeGeneratedFiles();
+                    }
                 }
+                theServlet.destroy();
+                AnnotationProcessor annotationProcessor = (AnnotationProcessor) config.getServletContext().getAttribute(AnnotationProcessor.class.getName());
+                if (annotationProcessor != null) {
+                    try {
+                        annotationProcessor.preDestroy(theServlet);
+                    } catch (Exception e) {
+                        // Log any exception, since it can't be passed along
+                        log.error(Localizer.getMessage("jsp.error.file.not.found",
+                               e.getMessage()), e);
+                    }
+                }
+                theServlet = null;
             }
-            theServlet = null;
         }
     }
 
@@ -545,7 +675,7 @@ public class JspServletWrapper {
             return new SlingException(Localizer.getMessage
                     ("jsp.exception", detail.getJspFileName(),
                             "" + jspLineNumber), realException);
-        } catch (Exception je) {
+        } catch (final Exception je) {
             // If anything goes wrong, just revert to the original behaviour
             if (realException instanceof ServletException) {
                 return (ServletException)realException;
@@ -554,4 +684,26 @@ public class JspServletWrapper {
         }
     }
 
+    /**
+     * Compare the dependencies.
+     */
+    private boolean equals(final List<String> oldDeps, final List<String> newDeps)
{
+        if ( oldDeps == null ) {
+            if ( newDeps == null || newDeps.size() == 0 ) {
+                return true;
+            }
+            return false;
+        }
+        if ( oldDeps.size() != newDeps.size() ) {
+            return false;
+        }
+        final Iterator<String> i1 = oldDeps.iterator();
+        final Iterator<String> i2 = newDeps.iterator();
+        while ( i1.hasNext() ) {
+            if ( !i1.next().equals(i2.next()) ) {
+                return false;
+            }
+        }
+        return true;
+    }
 }



Mime
View raw message