From: markt Date: Mon, 4 Feb 2008 22:58:21 +0000 (+0000) Subject: Fix for bug 43741. Correctly handle dependencies for tag files in JARs. X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=0bb94d74232a866c3ab4abc5140b054cdccdc87a;p=tomcat7.0 Fix for bug 43741. Correctly handle dependencies for tag files in JARs. git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@618481 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/java/org/apache/jasper/JspCompilationContext.java b/java/org/apache/jasper/JspCompilationContext.java index 0fe40f3db..fe667c876 100644 --- a/java/org/apache/jasper/JspCompilationContext.java +++ b/java/org/apache/jasper/JspCompilationContext.java @@ -279,9 +279,29 @@ public class JspCompilationContext { public URL getResource(String res) throws MalformedURLException { - return context.getResource(canonicalURI(res)); + URL result = null; + + if (res.startsWith("/META-INF/")) { + // This is a tag file packaged in a jar that is being compiled + URL jarUrl = tagFileJarUrls.get(res); + if (jarUrl == null) { + jarUrl = tagFileJarUrl; + } + if (jarUrl != null) { + result = new URL(jarUrl.toExternalForm() + res.substring(1)); + } + } else if (res.startsWith("jar:file:")) { + // This is a tag file packaged in a jar that is being checked + // for a dependency + result = new URL(res); + + } else { + result = context.getResource(canonicalURI(res)); + } + return result; } + public Set getResourcePaths(String path) { return context.getResourcePaths(canonicalURI(path)); } @@ -554,7 +574,7 @@ public class JspCompilationContext { public void compile() throws JasperException, FileNotFoundException { createCompiler(); - if (isPackagedTagFile || jspCompiler.isOutDated()) { + if (jspCompiler.isOutDated()) { try { jspCompiler.removeGeneratedFiles(); jspLoader = null; diff --git a/java/org/apache/jasper/compiler/Compiler.java b/java/org/apache/jasper/compiler/Compiler.java index 8b4e32fdc..353750faa 100644 --- a/java/org/apache/jasper/compiler/Compiler.java +++ b/java/org/apache/jasper/compiler/Compiler.java @@ -23,6 +23,7 @@ import java.io.FileOutputStream; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.io.UnsupportedEncodingException; +import java.net.JarURLConnection; import java.net.URL; import java.net.URLConnection; import java.util.Iterator; @@ -384,7 +385,12 @@ public abstract class Compiler { return false; } URLConnection uc = jspUrl.openConnection(); - jspRealLastModified = uc.getLastModified(); + if (uc instanceof JarURLConnection) { + jspRealLastModified = + ((JarURLConnection) uc).getJarEntry().getTime(); + } else { + jspRealLastModified = uc.getLastModified(); + } uc.getInputStream().close(); } catch (Exception e) { return true; @@ -435,9 +441,15 @@ public abstract class Compiler { return true; } - URLConnection includeUconn = includeUrl.openConnection(); - long includeLastModified = includeUconn.getLastModified(); - includeUconn.getInputStream().close(); + URLConnection iuc = includeUrl.openConnection(); + long includeLastModified = 0; + if (iuc instanceof JarURLConnection) { + includeLastModified = + ((JarURLConnection) iuc).getJarEntry().getTime(); + } else { + includeLastModified = iuc.getLastModified(); + } + iuc.getInputStream().close(); if (includeLastModified > targetLastModified) { return true; diff --git a/java/org/apache/jasper/compiler/TagFileProcessor.java b/java/org/apache/jasper/compiler/TagFileProcessor.java index 9eb6890eb..565f5276b 100644 --- a/java/org/apache/jasper/compiler/TagFileProcessor.java +++ b/java/org/apache/jasper/compiler/TagFileProcessor.java @@ -619,9 +619,18 @@ class TagFileProcessor { TagFileInfo tagFileInfo = n.getTagFileInfo(); if (tagFileInfo != null) { String tagFilePath = tagFileInfo.getPath(); - JspCompilationContext ctxt = compiler.getCompilationContext(); - if (ctxt.getTagFileJarUrl(tagFilePath) == null) { - // Omit tag file dependency info on jar files for now. + if (tagFilePath.startsWith("/META-INF/")) { + // For tags in JARs, add the TLD and the tag as a dependency + String[] location = + compiler.getCompilationContext().getTldLocation( + tagFileInfo.getTagInfo().getTagLibrary().getURI()); + // Add TLD + pageInfo.addDependant("jar:" + location[0] + "!/" + + location[1]); + // Add Tag + pageInfo.addDependant("jar:" + location[0] + "!" + + tagFilePath); + } else { pageInfo.addDependant(tagFilePath); } Class c = loadTagFile(compiler, tagFilePath, n.getTagInfo(),