Author: markt Date: Sat Jan 31 09:35:46 2009 New Revision: 739530 URL: http://svn.apache.org/viewvc?rev=739530&view=rev Log: Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=46471 Use jar url and tag file path to uniquely ID a tag file to prevent naming clashes
Modified: tomcat/tc6.0.x/trunk/ (props changed) tomcat/tc6.0.x/trunk/STATUS.txt tomcat/tc6.0.x/trunk/java/org/apache/jasper/compiler/ImplicitTagLibraryInfo.java tomcat/tc6.0.x/trunk/java/org/apache/jasper/compiler/JspUtil.java tomcat/tc6.0.x/trunk/java/org/apache/jasper/compiler/ParserController.java tomcat/tc6.0.x/trunk/java/org/apache/jasper/compiler/TagFileProcessor.java tomcat/tc6.0.x/trunk/java/org/apache/jasper/compiler/TagLibraryInfoImpl.java tomcat/tc6.0.x/trunk/webapps/docs/changelog.xml Propchange: tomcat/tc6.0.x/trunk/ ------------------------------------------------------------------------------ --- svn:mergeinfo (original) +++ svn:mergeinfo Sat Jan 31 09:35:46 2009 @@ -1 +1 @@ -/tomcat/trunk:601180,606992,612607,630314,652744,653247,673796,673820,683982,684001,684081,684234,684269-684270,685177,687503,687645,690781,691392,691805,692748,695053,695311,696780,696782,698012,698227,698236,698613,699427,699634,701355,709294,709811,709816,710063,710066,710125,710205,711126,711600,712461,712467,718360,719602,719626,719628,720046,720069,721040,723404,723738,726052,727303,728032,728768,728947,729057,729567,729569,729571,729809,729815,729934,730250,730590,732859 +/tomcat/trunk:601180,606992,612607,630314,652744,653247,673796,673820,683982,684001,684081,684234,684269-684270,685177,687503,687645,690781,691392,691805,692748,695053,695311,696780,696782,698012,698227,698236,698613,699427,699634,701355,709294,709811,709816,710063,710066,710125,710205,711126,711600,712461,712467,718360,719602,719626,719628,720046,720069,721040,723404,723738,726052,727303,728032,728768,728947,729057,729567,729569,729571,729809,729815,729934,730250,730590,731651,732859,732863 Modified: tomcat/tc6.0.x/trunk/STATUS.txt URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/STATUS.txt?rev=739530&r1=739529&r2=739530&view=diff ============================================================================== --- tomcat/tc6.0.x/trunk/STATUS.txt (original) +++ tomcat/tc6.0.x/trunk/STATUS.txt Sat Jan 31 09:35:46 2009 @@ -126,14 +126,6 @@ 0: funkman - ditto -1: -* Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=46471 - Use jar url and tag file path to uniquely ID a tag file to prevent naming - clashes - http://svn.apache.org/viewvc?rev=731651&view=rev - http://svn.apache.org/viewvc?rev=732863&view=rev - +1: markt, remm, fhanik - -1: - * Deprecate unused code (with a view to deleting it in TC7 http://svn.apache.org/viewvc?view=rev&revision=719119 http://svn.apache.org/viewvc?view=rev&revision=719124 Modified: tomcat/tc6.0.x/trunk/java/org/apache/jasper/compiler/ImplicitTagLibraryInfo.java URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/jasper/compiler/ImplicitTagLibraryInfo.java?rev=739530&r1=739529&r2=739530&view=diff ============================================================================== --- tomcat/tc6.0.x/trunk/java/org/apache/jasper/compiler/ImplicitTagLibraryInfo.java (original) +++ tomcat/tc6.0.x/trunk/java/org/apache/jasper/compiler/ImplicitTagLibraryInfo.java Sat Jan 31 09:35:46 2009 @@ -194,6 +194,7 @@ tagInfo = TagFileProcessor.parseTagFileDirectives(pc, shortName, path, + pc.getJspCompilationContext().getTagFileJarUrl(path), this); } catch (JasperException je) { throw new RuntimeException(je.toString(), je); Modified: tomcat/tc6.0.x/trunk/java/org/apache/jasper/compiler/JspUtil.java URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/jasper/compiler/JspUtil.java?rev=739530&r1=739529&r2=739530&view=diff ============================================================================== --- tomcat/tc6.0.x/trunk/java/org/apache/jasper/compiler/JspUtil.java (original) +++ tomcat/tc6.0.x/trunk/java/org/apache/jasper/compiler/JspUtil.java Sat Jan 31 09:35:46 2009 @@ -861,10 +861,31 @@ * * @return Fully-qualified class name of the tag handler corresponding to * the given tag file path + * + * @deprecated Use {...@link #getTagHandlerClassName(String, String, + * ErrorDispatcher) + * See https://issues.apache.org/bugzilla/show_bug.cgi?id=46471 */ public static String getTagHandlerClassName(String path, ErrorDispatcher err) throws JasperException { + return getTagHandlerClassName(path, null, err); + } + + /** + * Gets the fully-qualified class name of the tag handler corresponding to + * the given tag file path. + * + * @param path + * Tag file path + * @param err + * Error dispatcher + * + * @return Fully-qualified class name of the tag handler corresponding to + * the given tag file path + */ + public static String getTagHandlerClassName(String path, String urn, + ErrorDispatcher err) throws JasperException { String className = null; int begin = 0; @@ -890,20 +911,29 @@ className = "org.apache.jsp.tag.web."; begin = index + WEB_INF_TAGS.length(); } else { - index = path.indexOf(META_INF_TAGS); - if (index != -1) { - className = "org.apache.jsp.tag.meta."; - begin = index + META_INF_TAGS.length(); - } else { - err.jspError("jsp.error.tagfile.illegalPath", path); + index = path.indexOf(META_INF_TAGS); + if (index != -1) { + className = getClassNameBase(urn); + begin = index + META_INF_TAGS.length(); + } else { + err.jspError("jsp.error.tagfile.illegalPath", path); + } } - } className += makeJavaPackage(path.substring(begin)); return className; } + private static String getClassNameBase(String urn) { + StringBuffer base = new StringBuffer("org.apache.jsp.tag.meta."); + if (urn != null) { + base.append(makeJavaPackage(urn)); + base.append('.'); + } + return base.toString(); + } + /** * Converts the given path to a Java package or fully-qualified class name * Modified: tomcat/tc6.0.x/trunk/java/org/apache/jasper/compiler/ParserController.java URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/jasper/compiler/ParserController.java?rev=739530&r1=739529&r2=739530&view=diff ============================================================================== --- tomcat/tc6.0.x/trunk/java/org/apache/jasper/compiler/ParserController.java (original) +++ tomcat/tc6.0.x/trunk/java/org/apache/jasper/compiler/ParserController.java Sat Jan 31 09:35:46 2009 @@ -144,15 +144,31 @@ * This is invoked by the compiler * * @param inFileName The name of the tag file to be parsed. + * @deprecated Use {...@link #parseTagFileDirectives(String, URL)} + * See https://issues.apache.org/bugzilla/show_bug.cgi?id=46471 */ public Node.Nodes parseTagFileDirectives(String inFileName) throws FileNotFoundException, JasperException, IOException { + return parseTagFileDirectives( + inFileName, ctxt.getTagFileJarUrl(inFileName)); + } + + /** + * Extracts tag file directive information from the given tag file. + * + * This is invoked by the compiler + * + * @param inFileName The name of the tag file to be parsed. + * @param tagFileJarUrl The location of the tag file. + */ + public Node.Nodes parseTagFileDirectives(String inFileName, + URL tagFileJarUrl) + throws FileNotFoundException, JasperException, IOException { boolean isTagFileSave = isTagFile; boolean directiveOnlySave = directiveOnly; isTagFile = true; directiveOnly = true; - Node.Nodes page = doParse(inFileName, null, - ctxt.getTagFileJarUrl(inFileName)); + Node.Nodes page = doParse(inFileName, null, tagFileJarUrl); directiveOnly = directiveOnlySave; isTagFile = isTagFileSave; return page; Modified: tomcat/tc6.0.x/trunk/java/org/apache/jasper/compiler/TagFileProcessor.java URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/jasper/compiler/TagFileProcessor.java?rev=739530&r1=739529&r2=739530&view=diff ============================================================================== --- tomcat/tc6.0.x/trunk/java/org/apache/jasper/compiler/TagFileProcessor.java (original) +++ tomcat/tc6.0.x/trunk/java/org/apache/jasper/compiler/TagFileProcessor.java Sat Jan 31 09:35:46 2009 @@ -19,6 +19,8 @@ import java.io.FileNotFoundException; import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URL; import java.net.URLClassLoader; import java.util.Iterator; import java.util.List; @@ -379,7 +381,8 @@ bodycontent = TagInfo.BODY_CONTENT_SCRIPTLESS; } - String tagClassName = JspUtil.getTagHandlerClassName(path, err); + String tagClassName = JspUtil.getTagHandlerClassName( + path, tagLibInfo.getReliableURN(), err); TagVariableInfo[] tagVariableInfos = new TagVariableInfo[variableVector .size()]; @@ -502,16 +505,45 @@ * @param tagLibInfo * the TagLibraryInfo object associated with this TagInfo * @return a TagInfo object assembled from the directives in the tag file. + * @deprecated Use {...@link TagFileProcessor#parseTagFileDirectives( + * ParserController, String, String, URL, TagLibraryInfo)} + * See https://issues.apache.org/bugzilla/show_bug.cgi?id=46471 */ public static TagInfo parseTagFileDirectives(ParserController pc, String name, String path, TagLibraryInfo tagLibInfo) throws JasperException { + return parseTagFileDirectives(pc, name, path, + pc.getJspCompilationContext().getTagFileJarUrl(path), + tagLibInfo); + } + + /** + * Parses the tag file, and collects information on the directives included + * in it. The method is used to obtain the info on the tag file, when the + * handler that it represents is referenced. The tag file is not compiled + * here. + * + * @param pc + * the current ParserController used in this compilation + * @param name + * the tag name as specified in the TLD + * @param tagfile + * the path for the tagfile + * @param tagFileJarUrl + * the url for the Jar containign the tag file + * @param tagLibInfo + * the TagLibraryInfo object associated with this TagInfo + * @return a TagInfo object assembled from the directives in the tag file. + */ + public static TagInfo parseTagFileDirectives(ParserController pc, + String name, String path, URL tagFileJarUrl, TagLibraryInfo tagLibInfo) + throws JasperException { ErrorDispatcher err = pc.getCompiler().getErrorDispatcher(); Node.Nodes page = null; try { - page = pc.parseTagFileDirectives(path); + page = pc.parseTagFileDirectives(path, tagFileJarUrl); } catch (FileNotFoundException e) { err.jspError("jsp.error.file.not.found", path); } catch (IOException e) { @@ -532,17 +564,33 @@ private Class loadTagFile(Compiler compiler, String tagFilePath, TagInfo tagInfo, PageInfo parentPageInfo) throws JasperException { + URL tagFileJarUrl = null; + if (tagFilePath.startsWith("/META-INF/")) { + try { + tagFileJarUrl = new URL("jar:" + + compiler.getCompilationContext().getTldLocation( + tagInfo.getTagLibrary().getURI())[0] + "!/"); + } catch (MalformedURLException e) { + // Ignore - tagFileJarUrl will be null + } + } + String tagFileJarPath; + if (tagFileJarUrl == null) { + tagFileJarPath = ""; + } else { + tagFileJarPath = tagFileJarUrl.toString(); + } + JspCompilationContext ctxt = compiler.getCompilationContext(); JspRuntimeContext rctxt = ctxt.getRuntimeContext(); - JspServletWrapper wrapper = (JspServletWrapper) rctxt - .getWrapper(tagFilePath); + JspServletWrapper wrapper = rctxt.getWrapper(tagFileJarPath + tagFilePath); synchronized (rctxt) { if (wrapper == null) { wrapper = new JspServletWrapper(ctxt.getServletContext(), ctxt .getOptions(), tagFilePath, tagInfo, ctxt - .getRuntimeContext(), ctxt.getTagFileJarUrl(tagFilePath)); - rctxt.addWrapper(tagFilePath, wrapper); + .getRuntimeContext(), tagFileJarUrl); + rctxt.addWrapper(tagFileJarPath + tagFilePath, wrapper); // Use same classloader and classpath for compiling tag files wrapper.getJspEngineContext().setClassLoader( Modified: tomcat/tc6.0.x/trunk/java/org/apache/jasper/compiler/TagLibraryInfoImpl.java URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/jasper/compiler/TagLibraryInfoImpl.java?rev=739530&r1=739529&r2=739530&view=diff ============================================================================== --- tomcat/tc6.0.x/trunk/java/org/apache/jasper/compiler/TagLibraryInfoImpl.java (original) +++ tomcat/tc6.0.x/trunk/java/org/apache/jasper/compiler/TagLibraryInfoImpl.java Sat Jan 31 09:35:46 2009 @@ -477,13 +477,16 @@ if (path.startsWith("/META-INF/tags")) { // Tag file packaged in JAR + // See https://issues.apache.org/bugzilla/show_bug.cgi?id=46471 + // This needs to be removed once all the broken code that depends on + // it has been removed ctxt.setTagFileJarUrl(path, jarFileUrl); } else if (!path.startsWith("/WEB-INF/tags")) { err.jspError("jsp.error.tagfile.illegalPath", path); } TagInfo tagInfo = TagFileProcessor.parseTagFileDirectives( - parserController, name, path, this); + parserController, name, path, jarFileUrl, this); return new TagFileInfo(name, path, tagInfo); } @@ -685,7 +688,7 @@ } else if ("param-value".equals(tname)) { initParam[1] = element.getBody(); } else if ("description".equals(tname)) { - ; // Do nothing + // Do nothing } else { if (log.isWarnEnabled()) { log.warn(Localizer.getMessage( Modified: tomcat/tc6.0.x/trunk/webapps/docs/changelog.xml URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/webapps/docs/changelog.xml?rev=739530&r1=739529&r2=739530&view=diff ============================================================================== --- tomcat/tc6.0.x/trunk/webapps/docs/changelog.xml (original) +++ tomcat/tc6.0.x/trunk/webapps/docs/changelog.xml Sat Jan 31 09:35:46 2009 @@ -397,6 +397,10 @@ <bug>46462</bug>: Limit package test to just the o.a.jsp package to allow use of packages such as o.a.jspwiki. (markt) </fix> + <fix> + <bug>46471</bug>: Fix naming clash when tags in different libraries have + the same name. (markt) + </fix> </changelog> </subsection> <subsection name="Cluster"> --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org