Author: markt
Date: Wed Nov 27 20:33:31 2013
New Revision: 1546185

URL: http://svn.apache.org/r1546185
Log:
Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=55807
The JSP compiler used a last modified time of -1 for TLDs in JARs expanded in 
to WEB-INF/classes (IDEs often do this expansion) when creating the dependency 
list for JSPs that used that TLD. This meant JSPs using that TLD were 
recompiled on every access.

Added:
    tomcat/tc7.0.x/trunk/test/webapp-3.0/WEB-INF/classes/META-INF/bug55807.tld
      - copied, changed from r1546176, 
tomcat/trunk/test/webapp/WEB-INF/classes/META-INF/bug55807.tld
    tomcat/tc7.0.x/trunk/test/webapp-3.0/bug5nnnn/bug55807.jsp
      - copied, changed from r1546176, 
tomcat/trunk/test/webapp/bug5nnnn/bug55807.jsp
Modified:
    tomcat/tc7.0.x/trunk/   (props changed)
    tomcat/tc7.0.x/trunk/java/org/apache/jasper/JspCompilationContext.java
    tomcat/tc7.0.x/trunk/test/org/apache/jasper/compiler/TestCompiler.java
    tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml

Propchange: tomcat/tc7.0.x/trunk/
------------------------------------------------------------------------------
  Merged /tomcat/trunk:r1546172

Modified: tomcat/tc7.0.x/trunk/java/org/apache/jasper/JspCompilationContext.java
URL: 
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/jasper/JspCompilationContext.java?rev=1546185&r1=1546184&r2=1546185&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/java/org/apache/jasper/JspCompilationContext.java 
(original)
+++ tomcat/tc7.0.x/trunk/java/org/apache/jasper/JspCompilationContext.java Wed 
Nov 27 20:33:31 2013
@@ -22,6 +22,8 @@ import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.net.JarURLConnection;
 import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URISyntaxException;
 import java.net.URL;
 import java.net.URLClassLoader;
 import java.net.URLConnection;
@@ -432,6 +434,15 @@ public class JspCompilationContext {
 
     public Long getLastModified(String resource) {
         long result = -1;
+        if (resource.startsWith("file:/")) {
+            File f;
+            try {
+                f = new File(new URI(resource));
+            } catch (URISyntaxException e) {
+                return Long.valueOf(-1);
+            }
+            return Long.valueOf(f.lastModified());
+        }
         URLConnection uc = null;
         try {
             URL jspUrl = getResource(resource);

Modified: tomcat/tc7.0.x/trunk/test/org/apache/jasper/compiler/TestCompiler.java
URL: 
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/test/org/apache/jasper/compiler/TestCompiler.java?rev=1546185&r1=1546184&r2=1546185&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/test/org/apache/jasper/compiler/TestCompiler.java 
(original)
+++ tomcat/tc7.0.x/trunk/test/org/apache/jasper/compiler/TestCompiler.java Wed 
Nov 27 20:33:31 2013
@@ -25,11 +25,14 @@ import java.util.Map;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
 
+import org.junit.Assert;
 import org.junit.Test;
 
+import org.apache.catalina.Context;
 import org.apache.catalina.startup.Tomcat;
 import org.apache.catalina.startup.TomcatBaseTest;
 import org.apache.tomcat.util.buf.ByteChunk;
+import org.apache.tomcat.util.scan.StandardJarScanner;
 
 public class TestCompiler extends TomcatBaseTest {
 
@@ -220,6 +223,39 @@ public class TestCompiler extends Tomcat
         // it fails
     }
 
+    @Test
+    public void testBug55807() throws Exception {
+        Tomcat tomcat = getTomcatInstance();
+
+        File appDir = new File("test/webapp-3.0");
+        Context context = tomcat.addWebapp(null, "/test", 
appDir.getAbsolutePath());
+        ((StandardJarScanner) 
context.getJarScanner()).setScanAllDirectories(true);
+        tomcat.start();
+
+        ByteChunk res = new ByteChunk();
+        Map<String,List<String>> headers = new HashMap<String,List<String>>();
+
+        getUrl("http://localhost:"; + getPort() + "/test/bug5nnnn/bug55807.jsp",
+                res, headers);
+
+        // Check request completed
+        String result = res.toString();
+        assertEcho(result, "OK");
+
+        // Check the dependencies count
+        Assert.assertTrue(result.contains("<p>DependenciesCount: 1</p>"));
+
+        // Check the right timestamp was used in the dependency
+        File tld = new 
File("test/webapp-3.0/WEB-INF/classes/META-INF/bug55807.tld");
+        String expected = "/WEB-INF/classes/META-INF/bug55807.tld : " +
+                tld.lastModified() + "</p>";
+        Assert.assertTrue(result.contains(expected));
+
+
+        // Check content type
+        
Assert.assertTrue(headers.get("Content-Type").get(0).startsWith("text/html"));
+    }
+
     /** Assertion for text printed by tags:echo */
     private static void assertEcho(String result, String expected) {
         assertTrue(result, result.indexOf("<p>" + expected + "</p>") > 0);

Copied: 
tomcat/tc7.0.x/trunk/test/webapp-3.0/WEB-INF/classes/META-INF/bug55807.tld 
(from r1546176, tomcat/trunk/test/webapp/WEB-INF/classes/META-INF/bug55807.tld)
URL: 
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/test/webapp-3.0/WEB-INF/classes/META-INF/bug55807.tld?p2=tomcat/tc7.0.x/trunk/test/webapp-3.0/WEB-INF/classes/META-INF/bug55807.tld&p1=tomcat/trunk/test/webapp/WEB-INF/classes/META-INF/bug55807.tld&r1=1546176&r2=1546185&rev=1546185&view=diff
==============================================================================
    (empty)

Copied: tomcat/tc7.0.x/trunk/test/webapp-3.0/bug5nnnn/bug55807.jsp (from 
r1546176, tomcat/trunk/test/webapp/bug5nnnn/bug55807.jsp)
URL: 
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/test/webapp-3.0/bug5nnnn/bug55807.jsp?p2=tomcat/tc7.0.x/trunk/test/webapp-3.0/bug5nnnn/bug55807.jsp&p1=tomcat/trunk/test/webapp/bug5nnnn/bug55807.jsp&r1=1546176&r2=1546185&rev=1546185&view=diff
==============================================================================
    (empty)

Modified: tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml
URL: 
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml?rev=1546185&r1=1546184&r2=1546185&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml Wed Nov 27 20:33:31 2013
@@ -222,6 +222,17 @@
       </add>
     </changelog>
   </subsection>
+  <subsection name="Jasper">
+    <changelog>
+      <fix>
+        <bug>55807</bug>: The JSP compiler used a last modified time of -1 for
+        TLDs in JARs expanded in to WEB-INF/classes (IDEs often do this
+        expansion) when creating the dependency list for JSPs that used that
+        TLD. This meant JSPs using that TLD were recompiled on every access.
+        (markt)
+      </fix>
+    </changelog>
+  </subsection>
   <subsection name="Cluster">
     <changelog>
       <add>



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

Reply via email to