You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by jb...@apache.org on 2013/08/12 03:21:39 UTC

svn commit: r1513025 - in /tomcat/trunk: java/org/apache/jasper/JspC.java java/org/apache/jasper/servlet/JspCServletContext.java test/org/apache/jasper/servlet/TestJspCServletContext.java

Author: jboynes
Date: Mon Aug 12 01:21:38 2013
New Revision: 1513025

URL: http://svn.apache.org/r1513025
Log:
Have JspC initialize its ClassLoader before the ServletContext.
This avoids the need to re-initialize the ClassLoader for every JSP being pre-compiled.
It also allows the ServletContext to be used before starting a compilation run, e.g. to scan for TLDs

Modified:
    tomcat/trunk/java/org/apache/jasper/JspC.java
    tomcat/trunk/java/org/apache/jasper/servlet/JspCServletContext.java
    tomcat/trunk/test/org/apache/jasper/servlet/TestJspCServletContext.java

Modified: tomcat/trunk/java/org/apache/jasper/JspC.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/jasper/JspC.java?rev=1513025&r1=1513024&r2=1513025&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/jasper/JspC.java (original)
+++ tomcat/trunk/java/org/apache/jasper/JspC.java Mon Aug 12 01:21:38 2013
@@ -151,7 +151,7 @@ public class JspC extends Task implement
     }
 
     protected String classPath = null;
-    protected URLClassLoader loader = null;
+    protected ClassLoader loader = null;
     protected boolean trimSpaces = false;
     protected boolean genStringAsCharArray = false;
     protected boolean xpoweredBy;
@@ -1154,9 +1154,6 @@ public class JspC extends Task implement
             }
 
             originalClassLoader = Thread.currentThread().getContextClassLoader();
-            if( loader==null ) {
-                initClassLoader( clctxt );
-            }
             Thread.currentThread().setContextClassLoader(loader);
 
             clctxt.setClassLoader(loader);
@@ -1288,8 +1285,11 @@ public class JspC extends Task implement
                     Localizer.getMessage("jsp.error.jspc.uriroot_not_dir"));
             }
 
+            if (loader == null) {
+                loader = initClassLoader();
+            }
             if (context == null) {
-                initServletContext();
+                initServletContext(loader);
             }
 
             // No explicit pages, we'll process all .jsp in the webapp
@@ -1412,12 +1412,13 @@ public class JspC extends Task implement
         }
     }
 
-    protected void initServletContext() throws IOException, JasperException {
+    protected void initServletContext(ClassLoader classLoader)
+            throws IOException, JasperException {
         // TODO: should we use the Ant Project's log?
         PrintWriter log = new PrintWriter(System.out);
         URL resourceBase = new File(uriRoot).getCanonicalFile().toURI().toURL();
 
-        context = new JspCServletContext(log, resourceBase);
+        context = new JspCServletContext(log, resourceBase, classLoader);
         tldLocationsCache = TldLocationsCache.getInstance(context);
         rctxt = new JspRuntimeContext(context, this);
         jspConfig = new JspConfig(context);
@@ -1428,11 +1429,9 @@ public class JspC extends Task implement
      * Initializes the classloader as/if needed for the given
      * compilation context.
      *
-     * @param clctxt The compilation context
      * @throws IOException If an error occurs
      */
-    protected void initClassLoader(JspCompilationContext clctxt)
-        throws IOException {
+    protected ClassLoader initClassLoader() throws IOException {
 
         classPath = getClassPath();
 
@@ -1502,14 +1501,10 @@ public class JspC extends Task implement
             }
         }
 
-        // What is this ??
-        urls.add(new File(
-                clctxt.getRealPath("/")).getCanonicalFile().toURI().toURL());
-
         URL urlsA[]=new URL[urls.size()];
         urls.toArray(urlsA);
         loader = new URLClassLoader(urlsA, this.getClass().getClassLoader());
-        context.setClassLoader(loader);
+        return loader;
     }
 
     /**

Modified: tomcat/trunk/java/org/apache/jasper/servlet/JspCServletContext.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/jasper/servlet/JspCServletContext.java?rev=1513025&r1=1513024&r2=1513025&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/jasper/servlet/JspCServletContext.java (original)
+++ tomcat/trunk/java/org/apache/jasper/servlet/JspCServletContext.java Mon Aug 12 01:21:38 2013
@@ -98,7 +98,7 @@ public class JspCServletContext implemen
     /**
      * Web application class loader.
      */
-    private ClassLoader loader;
+    private final ClassLoader loader;
 
 
     // ----------------------------------------------------------- Constructors
@@ -110,12 +110,13 @@ public class JspCServletContext implemen
      * @param aResourceBaseURL Resource base URL
      * @throws JasperException
      */
-    public JspCServletContext(PrintWriter aLogWriter, URL aResourceBaseURL)
-            throws JasperException {
+    public JspCServletContext(PrintWriter aLogWriter, URL aResourceBaseURL, ClassLoader classLoader)
+        throws JasperException {
 
         myAttributes = new HashMap<>();
         myLogWriter = aLogWriter;
         myResourceBaseURL = aResourceBaseURL;
+        this.loader = classLoader;
 
         this.webXml = buildMergedWebXml();
         jspConfigDescriptor = webXml.getJspConfigDescriptor();
@@ -643,11 +644,6 @@ public class JspCServletContext implemen
     }
 
 
-    public void setClassLoader(ClassLoader loader) {
-        this.loader = loader;
-    }
-
-
     @Override
     public int getEffectiveMajorVersion() {
         return webXml.getMajorVersion();

Modified: tomcat/trunk/test/org/apache/jasper/servlet/TestJspCServletContext.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/jasper/servlet/TestJspCServletContext.java?rev=1513025&r1=1513024&r2=1513025&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/jasper/servlet/TestJspCServletContext.java (original)
+++ tomcat/trunk/test/org/apache/jasper/servlet/TestJspCServletContext.java Mon Aug 12 01:21:38 2013
@@ -32,7 +32,7 @@ public class TestJspCServletContext {
     public void testWebapp() throws Exception {
         File appDir = new File("test/webapp");
         JspCServletContext context =
-                new JspCServletContext(null, appDir.toURI().toURL());
+                new JspCServletContext(null, appDir.toURI().toURL(), null);
         Assert.assertEquals(3, context.getEffectiveMajorVersion());
         Assert.assertEquals(1, context.getEffectiveMinorVersion());
         JspConfigDescriptor jspConfigDescriptor =
@@ -63,7 +63,7 @@ public class TestJspCServletContext {
     public void testWebapp_2_2() throws Exception {
         File appDir = new File("test/webapp-2.2");
         JspCServletContext context =
-                new JspCServletContext(null, appDir.toURI().toURL());
+                new JspCServletContext(null, appDir.toURI().toURL(), null);
         Assert.assertEquals(2, context.getEffectiveMajorVersion());
         Assert.assertEquals(2, context.getEffectiveMinorVersion());
     }
@@ -72,7 +72,7 @@ public class TestJspCServletContext {
     public void testWebapp_2_3() throws Exception {
         File appDir = new File("test/webapp-2.3");
         JspCServletContext context =
-                new JspCServletContext(null, appDir.toURI().toURL());
+                new JspCServletContext(null, appDir.toURI().toURL(), null);
         Assert.assertEquals(2, context.getEffectiveMajorVersion());
         Assert.assertEquals(3, context.getEffectiveMinorVersion());
     }
@@ -81,7 +81,7 @@ public class TestJspCServletContext {
     public void testWebapp_2_4() throws Exception {
         File appDir = new File("test/webapp-2.4");
         JspCServletContext context =
-                new JspCServletContext(null, appDir.toURI().toURL());
+                new JspCServletContext(null, appDir.toURI().toURL(), null);
         Assert.assertEquals(2, context.getEffectiveMajorVersion());
         Assert.assertEquals(4, context.getEffectiveMinorVersion());
     }
@@ -90,7 +90,7 @@ public class TestJspCServletContext {
     public void testWebapp_2_5() throws Exception {
         File appDir = new File("test/webapp-2.5");
         JspCServletContext context =
-                new JspCServletContext(null, appDir.toURI().toURL());
+                new JspCServletContext(null, appDir.toURI().toURL(), null);
         Assert.assertEquals(2, context.getEffectiveMajorVersion());
         Assert.assertEquals(5, context.getEffectiveMinorVersion());
     }
@@ -99,7 +99,7 @@ public class TestJspCServletContext {
     public void testWebapp_3_0() throws Exception {
         File appDir = new File("test/webapp-3.0");
         JspCServletContext context =
-                new JspCServletContext(null, appDir.toURI().toURL());
+                new JspCServletContext(null, appDir.toURI().toURL(), null);
         Assert.assertEquals(3, context.getEffectiveMajorVersion());
         Assert.assertEquals(0, context.getEffectiveMinorVersion());
     }
@@ -108,7 +108,7 @@ public class TestJspCServletContext {
     public void testWebapp_3_1() throws Exception {
         File appDir = new File("test/webapp-3.1");
         JspCServletContext context =
-                new JspCServletContext(null, appDir.toURI().toURL());
+                new JspCServletContext(null, appDir.toURI().toURL(), null);
         Assert.assertEquals(3, context.getEffectiveMajorVersion());
         Assert.assertEquals(1, context.getEffectiveMinorVersion());
     }
@@ -117,7 +117,7 @@ public class TestJspCServletContext {
     public void testWebresources() throws Exception {
         File appDir = new File("test/webresources/dir1");
         JspCServletContext context =
-                new JspCServletContext(null, appDir.toURI().toURL());
+                new JspCServletContext(null, appDir.toURI().toURL(), null);
         Assert.assertEquals(3, context.getEffectiveMajorVersion());
         Assert.assertEquals(1, context.getEffectiveMinorVersion());
     }



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org