Return-Path: X-Original-To: apmail-sling-commits-archive@www.apache.org Delivered-To: apmail-sling-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 998BDC27D for ; Fri, 8 Jun 2012 07:42:20 +0000 (UTC) Received: (qmail 68045 invoked by uid 500); 8 Jun 2012 07:42:19 -0000 Delivered-To: apmail-sling-commits-archive@sling.apache.org Received: (qmail 67931 invoked by uid 500); 8 Jun 2012 07:42:17 -0000 Mailing-List: contact commits-help@sling.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@sling.apache.org Delivered-To: mailing list commits@sling.apache.org Received: (qmail 67854 invoked by uid 99); 8 Jun 2012 07:42:14 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 08 Jun 2012 07:42:14 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 08 Jun 2012 07:42:12 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 4D7CD2388978; Fri, 8 Jun 2012 07:41:52 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1347910 - in /sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp: ./ jasper/ jasper/compiler/ jasper/servlet/ Date: Fri, 08 Jun 2012 07:41:51 -0000 To: commits@sling.apache.org From: cziegeler@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20120608074152.4D7CD2388978@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: cziegeler Date: Fri Jun 8 07:41:51 2012 New Revision: 1347910 URL: http://svn.apache.org/viewvc?rev=1347910&view=rev Log: SLING-2505 : Try to load jsp class only if available for dependency check 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/IsolatedClassLoader.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/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=1347910&r1=1347909&r2=1347910&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 Fri Jun 8 07:41:51 2012 @@ -249,21 +249,13 @@ public class JspScriptEngineFactory rctxt.removeWrapper(wrapper.getJspUri()); this.renewJspRuntimeContext(); rctxt = this.getJspRuntimeContext(); - wrapper = null; } - synchronized (rctxt) { - wrapper = rctxt.getWrapper(scriptName); - if (wrapper != null) { - return wrapper; - } - - wrapper = new JspServletWrapper(servletConfig, options, + wrapper = new JspServletWrapper(servletConfig, options, scriptName, false, rctxt); - rctxt.addWrapper(scriptName, wrapper); + wrapper = rctxt.addWrapper(scriptName, wrapper); - return wrapper; - } + return wrapper; } private JspServletWrapper getJspWrapper(final SlingScriptHelper scriptHelper, final SlingBindings bindings) Modified: sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/jasper/IsolatedClassLoader.java URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/jasper/IsolatedClassLoader.java?rev=1347910&r1=1347909&r2=1347910&view=diff ============================================================================== --- sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/jasper/IsolatedClassLoader.java (original) +++ sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/jasper/IsolatedClassLoader.java Fri Jun 8 07:41:51 2012 @@ -33,9 +33,17 @@ public final class IsolatedClassLoader private final IOProvider ioProvider; - public IsolatedClassLoader(final IOProvider ioProvider) { + private final String className; + + private final InputStream classInputStream; + + public IsolatedClassLoader(final IOProvider ioProvider, + final String className, + final InputStream is) { super(ioProvider.getClassLoader()); this.ioProvider = ioProvider; + this.classInputStream = is; + this.className = className; } //---------- Class loader overwrites ------------------------------------- @@ -52,7 +60,8 @@ public final class IsolatedClassLoader * @return the resulting Class object * @exception ClassNotFoundException if the class could not be found */ - public final Class loadClass(String name, boolean resolve) throws ClassNotFoundException { + public final Class loadClass(final String name, final boolean resolve) + throws ClassNotFoundException { // First check if it's already loaded Class clazz = findLoadedClass(name); @@ -120,8 +129,18 @@ public final class IsolatedClassLoader final String path = ":/" + name.replace('.', '/') + ".class"; InputStream is = null; try { - is = this.ioProvider.getInputStream(path); - final Class c = defineClass(name, is); + final Class c; + if ( name.equals( this.className ) ) { + c = defineClass(name, this.classInputStream); + } else { + is = this.ioProvider.getInputStream(path); + if ( is == null ) { + c = null; + } else { + c = defineClass(name, is); + } + } + if (c == null) { throw new ClassNotFoundException(name); } @@ -130,6 +149,10 @@ public final class IsolatedClassLoader throw cnfe; } catch (final Throwable t) { throw new ClassNotFoundException(name, t); + } finally { + if ( is != null ) { + try { is.close(); } catch (final IOException ignore) {} + } } } 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=1347910&r1=1347909&r2=1347910&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 Jun 8 07:41:51 2012 @@ -503,7 +503,6 @@ public class JspCompilationContext { try { c.removeGeneratedFiles(); c.compile(); - this.getRuntimeContext().addJspDependencies(jsw); } catch (final JasperException ex) { return ex; } catch (final IOException ioe) { 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=1347910&r1=1347909&r2=1347910&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 Jun 8 07:41:51 2012 @@ -222,7 +222,7 @@ public final class JspRuntimeContext { /** * Maps JSP pages to their JspServletWrapper's */ - private final Map jsps = new ConcurrentHashMap(); + private final ConcurrentHashMap jsps = new ConcurrentHashMap(); /** * Maps dependencies to the using jsp. @@ -231,8 +231,7 @@ public final class JspRuntimeContext { // ------------------------------------------------------ Public Methods - public void addJspDependencies(final JspServletWrapper jsw) { - final List deps = jsw.getDependants(); + public void addJspDependencies(final JspServletWrapper jsw, List deps) { if ( deps != null ) { final String jspUri = jsw.getJspUri(); synchronized ( depToJsp ) { @@ -289,9 +288,13 @@ public final class JspRuntimeContext { * @param jspUri JSP URI * @param jsw Servlet wrapper for JSP */ - public void addWrapper(final String jspUri, final JspServletWrapper jsw) { - jsps.put(jspUri, jsw); - addJspDependencies(jsw); + public JspServletWrapper addWrapper(final String jspUri, final JspServletWrapper jsw) { + final JspServletWrapper previous = jsps.putIfAbsent(jspUri, jsw); + if ( previous == null ) { + addJspDependencies(jsw, jsw.getDependants()); + return jsw; + } + return previous; } /** 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=1347910&r1=1347909&r2=1347910&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 Fri Jun 8 07:41:51 2012 @@ -541,7 +541,7 @@ class TagFileProcessor { wrapper = new JspServletWrapper(ctxt.getServletContext(), ctxt .getOptions(), tagFilePath, tagInfo, ctxt .getRuntimeContext(), ctxt.getTagFileJarUrl(tagFilePath)); - rctxt.addWrapper(tagFilePath, wrapper); + wrapper = rctxt.addWrapper(tagFilePath, wrapper); // Use same classloader and classpath for compiling tag files //wrapper.getJspEngineContext().setClassLoader(ctxt.getClassLoader()); 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=1347910&r1=1347909&r2=1347910&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 Jun 8 07:41:51 2012 @@ -18,8 +18,9 @@ package org.apache.sling.scripting.jsp.jasper.servlet; import java.io.IOException; +import java.io.InputStream; import java.net.URL; -import java.net.URLConnection; +import java.util.Collections; import java.util.Iterator; import java.util.List; @@ -85,7 +86,6 @@ public class JspServletWrapper { private final Options options; private final boolean isTagFile; private volatile JasperException compileException; - private volatile long lastModificationTest = -1L; private volatile int tripCount; private volatile List dependents; @@ -139,6 +139,7 @@ public class JspServletWrapper { return false; } + @SuppressWarnings("unchecked") private Servlet loadServlet() throws ServletException, IOException { Servlet servlet = null; @@ -150,6 +151,11 @@ public class JspServletWrapper { annotationProcessor.processAnnotations(servlet); annotationProcessor.postConstruct(servlet); } + // update dependents + if (servlet != null && servlet instanceof JspSourceDependent) { + this.dependents = (List) ((JspSourceDependent) servlet).getDependants(); + this.ctxt.getRuntimeContext().addJspDependencies(this, this.dependents); + } } catch (IllegalAccessException e) { throw new JasperException(e); } catch (InstantiationException e) { @@ -167,21 +173,9 @@ public class JspServletWrapper { * Compile (if needed) and load a tag file */ public Class loadTagFile() throws JasperException { - if (this.lastModificationTest <= 0) { - synchronized (this) { - if (this.lastModificationTest <= 0 ) { - this.compileException = ctxt.compile(); - this.lastModificationTest = System.currentTimeMillis(); - if ( compileException != null ) { - throw compileException; - } - } else if ( compileException != null ) { - // Throw cached compilation exception - throw compileException; - } - } - } else { - if (compileException != null) { + synchronized (this) { + this.compileException = ctxt.compile(); + if ( compileException != null ) { throw compileException; } } @@ -211,14 +205,31 @@ public class JspServletWrapper { public List getDependants() { if ( this.dependents == null ) { try { - Object target; + 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(); - final ClassLoader cl = new IsolatedClassLoader(this.ctxt.getRuntimeContext().getIOProvider()); - target = cl.loadClass(name).newInstance(); + // 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 ) {} + } + } + } if (target != null && target instanceof JspSourceDependent) { this.dependents = (List) ((JspSourceDependent) target).getDependants(); @@ -226,6 +237,10 @@ public class JspServletWrapper { } catch (final Throwable ex) { // ignore } + // use empty list, until servlet is compiled and loaded + if ( this.dependents == null ) { + this.dependents = Collections.emptyList(); + } } return this.dependents; } @@ -279,20 +294,13 @@ public class JspServletWrapper { if ( include.startsWith("tld:") ) { continue; } - try { - final URL includeUrl = ctxt.getResource(include); - if (includeUrl == null) { - return true; - } - - URLConnection includeUconn = includeUrl.openConnection(); - long includeLastModified = includeUconn.getLastModified(); - includeUconn.getInputStream().close(); + final long includeLastModified = ctxt.getRuntimeContext().getIOProvider().lastModified(include); - if (includeLastModified > targetLastModified) { - return true; + if (includeLastModified > targetLastModified) { + if (log.isDebugEnabled()) { + log.debug("Compiler: outdated: " + targetFile + " because of dependency " + include + " : " + + targetLastModified + " - " + includeLastModified); } - } catch (Exception e) { return true; } }