kinman 2002/08/28 16:00:19 Modified: jasper2/src/share/org/apache/jasper/compiler Compiler.java Generator.java JspDocumentParser.java PageInfo.java Parser.java ParserController.java TagFileProcessor.java TagLibraryInfoImpl.java jasper2/src/share/org/apache/jasper/runtime HttpJspBase.java jasper2/src/share/org/apache/jasper/servlet JspServletWrapper.java Added: jasper2/src/share/org/apache/jasper/runtime JspSourceDependent.java Log: - Fixed 12046: reloading of tag files - Fixed 11485: recompilation of jsp files when TLD is modified. - The generate servlet and tag handlers for the tag files now implements JspSourceDependent, which is used to provide dependency info at runtime. - Turned on include file dependency check. Added tag files and TLD to the dependency list. - Determined isTagFile property from TLD or implicit tag files. - Various minor fixes. Revision Changes Path 1.31 +7 -25 jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/Compiler.java Index: Compiler.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/Compiler.java,v retrieving revision 1.30 retrieving revision 1.31 diff -u -r1.30 -r1.31 --- Compiler.java 20 Aug 2002 23:35:30 -0000 1.30 +++ Compiler.java 28 Aug 2002 23:00:18 -0000 1.31 @@ -420,12 +420,13 @@ if( checkClass ) { targetFile = new File(ctxt.getClassFileName()); } else { - targetFile = new File( ctxt.getServletJavaFileName()); + targetFile = new File(ctxt.getServletJavaFileName()); } if (!targetFile.exists()) { return true; } + targetLastModified = targetFile.lastModified(); if (targetLastModified < jspRealLastModified) { if( log.isDebugEnabled() ) @@ -433,36 +434,18 @@ return true; } -/* XXX turn off derived dependencies for now - // determine if compile time includes have been changed + // determine if source dependent files (e.g. includes using include + // directives) have been changed. if( jsw==null ) { return false; } - Servlet servlet=null; - try { - servlet = jsw.getServlet(); - } catch( ServletException ex1 ) { - } catch( IOException ex2 ) { - } - if (servlet == null) { - // System.out.println("Compiler: outdated, no servlet " + targetFile ); - return true; - } - List includes = null; - // If the page contains a page directive with "extends" attribute - // it may not be an instance of HttpJspBase. - // For now only track dependencies on included files if this is not - // the case. A more complete solution is to generate the servlet - // to implement (say) JspInlcudes which contains getIncludes method. - if (servlet instanceof HttpJspBase) { - includes = ((HttpJspBase)servlet).getIncludes(); - } - if (includes == null) { + List depends = jsw.getDependants(); + if (depends == null) { return false; } - Iterator it = includes.iterator(); + Iterator it = depends.iterator(); while (it.hasNext()) { String include = (String)it.next(); try { @@ -481,7 +464,6 @@ return true; } } -*/ return false; } 1.83 +28 -23 jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/Generator.java Index: Generator.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/Generator.java,v retrieving revision 1.82 retrieving revision 1.83 diff -u -r1.82 -r1.83 --- Generator.java 28 Aug 2002 17:57:12 -0000 1.82 +++ Generator.java 28 Aug 2002 23:00:18 -0000 1.83 @@ -170,7 +170,6 @@ out.println(); page.visit(new DeclarationVisitor()); - out.println(); } /** @@ -360,25 +359,25 @@ /** * Generation of static initializers in preamble. - * For example, include list, el function map, prefix map. + * For example, dependant list, el function map, prefix map. * (shared by servlet and tag handler preamble generation) */ private void genPreambleStaticInitializers() throws JasperException { - // Static data for getIncludes() - out.printil("private static java.util.Vector _jspx_includes;"); + // Static data for getDependants() + out.printil("private static java.util.Vector _jspx_dependants;"); out.println(); - List includes = pageInfo.getIncludes(); - Iterator iter = includes.iterator(); - if( !includes.isEmpty() ) { + List dependants = pageInfo.getDependants(); + Iterator iter = dependants.iterator(); + if( !dependants.isEmpty() ) { out.printil("static {"); out.pushIndent(); - out.printin("_jspx_includes = new java.util.Vector("); - out.print(""+includes.size()); + out.printin("_jspx_dependants = new java.util.Vector("); + out.print(""+dependants.size()); out.println(");"); while (iter.hasNext()) { - out.printin("_jspx_includes.add(\""); + out.printin("_jspx_dependants.add(\""); out.print((String)iter.next()); out.println("\");"); } @@ -423,10 +422,10 @@ private void genPreambleMethods() throws JasperException { - // Method used to get compile time include file dependencies - out.printil("public java.util.List getIncludes() {"); + // Method used to get compile time file dependencies + out.printil("public java.util.List getDependants() {"); out.pushIndent(); - out.printil("return _jspx_includes;"); + out.printil("return _jspx_dependants;"); out.popIndent(); out.printil("}"); out.println(); @@ -456,10 +455,12 @@ out.printin("public class "); out.print (servletClassName); out.print (" extends "); - out.print (pageInfo.getExtends()); + out.println(pageInfo.getExtends()); + out.printil(" implements javax.servlet.jsp.el.FunctionMapper, "); + out.printin(" org.apache.jasper.runtime.JspSourceDependent"); if (!pageInfo.isThreadSafe()) { - out.print("implements SingleThreadModel, " + - "javax.servlet.jsp.el.FunctionMapper"); + out.println(","); + out.printin(" SingleThreadModel"); } out.println(" {"); out.pushIndent(); @@ -628,6 +629,7 @@ out.printil( " prefix + \":\" + localName );" ); out.popIndent(); out.printil( "}" ); + out.println(); } @@ -2892,10 +2894,13 @@ // Generate class declaration out.printin("public class "); out.print(tagInfo.getTagName()); - out.print(" extends javax.servlet.jsp.tagext.SimpleTagSupport"); - if (tagInfo.hasDynamicAttributes()) - out.print(" implements javax.servlet.jsp.tagext.DynamicAttributes, " + - "javax.servlet.jsp.el.FunctionMapper" ); + out.println(" extends javax.servlet.jsp.tagext.SimpleTagSupport"); + out.printil(" implements javax.servlet.jsp.el.FunctionMapper, "); + out.printin(" org.apache.jasper.runtime.JspSourceDependent"); + if (tagInfo.hasDynamicAttributes()) { + out.println(","); + out.printin(" javax.servlet.jsp.tagext.DynamicAttributes"); + } out.println(" {"); out.println(); out.pushIndent(); 1.17 +4 -4 jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/JspDocumentParser.java Index: JspDocumentParser.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/JspDocumentParser.java,v retrieving revision 1.16 retrieving revision 1.17 diff -u -r1.16 -r1.17 --- JspDocumentParser.java 24 Aug 2002 21:42:34 -0000 1.16 +++ JspDocumentParser.java 28 Aug 2002 23:00:19 -0000 1.17 @@ -223,7 +223,7 @@ node = new Node.IncludeDirective(attrsCopy, start, current); String file = attrsCopy.getValue("file"); try { - parserController.parse(file, node); + parserController.parse(file, node, false); } catch (FileNotFoundException fnfe) { throw new SAXParseException( err.getString("jsp.error.file.not.found", file), 1.10 +10 -9 jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/PageInfo.java Index: PageInfo.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/PageInfo.java,v retrieving revision 1.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- PageInfo.java 21 Aug 2002 01:53:28 -0000 1.9 +++ PageInfo.java 28 Aug 2002 23:00:19 -0000 1.10 @@ -73,7 +73,7 @@ class PageInfo { private Vector imports; - private Vector includes; + private Vector dependants; private BeanRepository beanRepository; private Hashtable tagLibraries; @@ -105,7 +105,7 @@ this.beanRepository = beanRepository; this.tagLibraries = new Hashtable(); this.imports = new Vector(); - this.includes = new Vector(); + this.dependants = new Vector(); this.includePrelude = new Vector(); this.includeCoda = new Vector(); @@ -122,12 +122,13 @@ return imports; } - public void addInclude(String include) { - this.includes.add(include); + public void addDependant(String d) { + if (!dependants.contains(d)) + dependants.add(d); } - public List getIncludes() { - return includes; + public List getDependants() { + return dependants; } public BeanRepository getBeanRepository() { 1.26 +4 -4 jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/Parser.java Index: Parser.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/Parser.java,v retrieving revision 1.25 retrieving revision 1.26 diff -u -r1.25 -r1.26 --- Parser.java 24 Aug 2002 21:42:34 -0000 1.25 +++ Parser.java 28 Aug 2002 23:00:19 -0000 1.26 @@ -330,7 +330,7 @@ } try { - parserController.parse(file, parent); + parserController.parse(file, parent, false); } catch (FileNotFoundException ex) { err.jspError(start, "jsp.error.file.not.found", file); } catch (Exception ex) { 1.16 +7 -11 jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/ParserController.java Index: ParserController.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/ParserController.java,v retrieving revision 1.15 retrieving revision 1.16 diff -u -r1.15 -r1.16 --- ParserController.java 24 Aug 2002 00:48:22 -0000 1.15 +++ ParserController.java 28 Aug 2002 23:00:19 -0000 1.16 @@ -157,7 +157,7 @@ */ public Node.Nodes parse(String inFileName) throws FileNotFoundException, JasperException, IOException { - return parse(inFileName, null); + return parse(inFileName, null, false); } /** @@ -167,13 +167,17 @@ * @param inFileName The name of the jsp file to be parsed. * @param parent The node for the 'include' directive. */ - public Node.Nodes parse(String inFileName, Node parent) + public Node.Nodes parse(String inFileName, Node parent, boolean isTagFile) throws FileNotFoundException, JasperException, IOException { + this.isTagFile = isTagFile; Node.Nodes parsedPage = null; String encoding = topFileEncoding; InputStreamReader reader = null; String absFileName = resolveFileName(inFileName); + if (isTagFile) { + isTopFile = true; + } JarFile jarFile = (JarFile) ctxt.getTagFileJars().get(inFileName); @@ -189,7 +193,7 @@ topFileEncoding = encoding; isTopFile = false; } else { - compiler.getPageInfo().addInclude(absFileName); + compiler.getPageInfo().addDependant(absFileName); } try { reader.close(); @@ -237,15 +241,7 @@ throws JasperException { newEncoding = null; - - // FIXME: Actually we should know that we are compiling a tag file - // if we begin the compilation from either the tag file - // element in a tld OR tagdir attribute in a tag directive. - isTagFile = file.startsWith( "/WEB-INF/tags" ) || - file.startsWith( "/META-INF/tags" ); - PageInfo pageInfo = compiler.getPageInfo(); - boolean isXmlFound = false; if (pageInfo.isXmlSpecified()) { // If <is-xml> is specified in a <jsp-property-group>, it is used. 1.19 +9 -5 jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/TagFileProcessor.java Index: TagFileProcessor.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/TagFileProcessor.java,v retrieving revision 1.18 retrieving revision 1.19 diff -u -r1.18 -r1.19 --- TagFileProcessor.java 25 Aug 2002 23:49:49 -0000 1.18 +++ TagFileProcessor.java 28 Aug 2002 23:00:19 -0000 1.19 @@ -312,7 +312,7 @@ Node.Nodes page = null; try { - page = pc.parse(tagfile); + page = pc.parse(tagfile, null, true); } catch (FileNotFoundException e) { pc.getCompiler().getErrorDispatcher().jspError( "jsp.error.file.not.found", tagfile); @@ -364,15 +364,18 @@ static class TagFileLoaderVisitor extends Node.Visitor { private JspCompilationContext ctxt; + private PageInfo pageInfo; - TagFileLoaderVisitor(JspCompilationContext ctxt) { + TagFileLoaderVisitor(JspCompilationContext ctxt, PageInfo pageInfo) { this.ctxt = ctxt; + this.pageInfo = pageInfo; } public void visit(Node.CustomTag n) throws JasperException { TagFileInfo tagFileInfo = n.getTagFileInfo(); if (tagFileInfo != null) { String tagFilePath = tagFileInfo.getPath(); + pageInfo.addDependant(tagFilePath); Class c = loadTagFile(ctxt, tagFilePath, n.getTagInfo(), n.getTagData()); n.setTagHandlerClass(c); @@ -384,7 +387,8 @@ throws JasperException { JspCompilationContext ctxt = compiler.getCompilationContext(); - page.visit(new TagFileLoaderVisitor(ctxt)); + PageInfo pageInfo = compiler.getPageInfo(); + page.visit(new TagFileLoaderVisitor(ctxt, pageInfo)); } } 1.14 +8 -3 jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/TagLibraryInfoImpl.java Index: TagLibraryInfoImpl.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/TagLibraryInfoImpl.java,v retrieving revision 1.13 retrieving revision 1.14 diff -u -r1.13 -r1.14 --- TagLibraryInfoImpl.java 25 Aug 2002 23:13:18 -0000 1.13 +++ TagLibraryInfoImpl.java 28 Aug 2002 23:00:19 -0000 1.14 @@ -193,6 +193,11 @@ } // Now parse the tld. parseTLD(ctxt, location[0], in, null); + // Add the TLD to dependency list + PageInfo pageInfo = ctxt.createCompiler().getPageInfo(); + if (pageInfo != null) { + pageInfo.addDependant(location[0]); + } } else { // Location points to a jar file // tag library in jar file 1.4 +0 -10 jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/runtime/HttpJspBase.java Index: HttpJspBase.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/runtime/HttpJspBase.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- HttpJspBase.java 14 Jun 2002 20:45:55 -0000 1.3 +++ HttpJspBase.java 28 Aug 2002 23:00:19 -0000 1.4 @@ -142,16 +142,6 @@ public void jspDestroy() { } - /** - * Get the list of compile time included files used - * by the JSP file. - * - * Overridden by generated JSP java source files. - * - * @return List compile time includes - */ - public abstract List getIncludes(); - public abstract void _jspService(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException; 1.1 jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/runtime/JspSourceDependent.java Index: JspSourceDependent.java =================================================================== /* * The Apache Software License, Version 1.1 * * Copyright (c) 1999 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, if * any, must include the following acknowlegement: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software * Foundation" must not be used to endorse or promote products derived * from this software without prior written permission. For written * permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache" * nor may "Apache" appear in their names without prior written * permission of the Apache Group. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. * */ package org.apache.jasper.runtime; /** * Interface for tracking the source files dependencies, for the purpose * of compiling out of date pages. This is used for * 1) files that are included by pge directives * 2) Files that are included by include-prelude and include-coda in jsp:config * 3) Files that are tag files and referenced */ public interface JspSourceDependent { /** * Returns a list of files names that the current page has a source * dependency on. */ public java.util.List getDependants(); } 1.15 +29 -4 jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/servlet/JspServletWrapper.java Index: JspServletWrapper.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/servlet/JspServletWrapper.java,v retrieving revision 1.14 retrieving revision 1.15 diff -u -r1.14 -r1.15 --- JspServletWrapper.java 21 Aug 2002 17:05:52 -0000 1.14 +++ JspServletWrapper.java 28 Aug 2002 23:00:19 -0000 1.15 @@ -83,7 +83,7 @@ import org.apache.jasper.Options; import org.apache.jasper.JspCompilationContext; import org.apache.jasper.compiler.JspRuntimeContext; -import org.apache.jasper.runtime.HttpJspBase; +import org.apache.jasper.runtime.JspSourceDependent; import org.apache.jasper.logging.Logger; /** @@ -113,6 +113,7 @@ private long available = 0L; private ServletConfig config; private Options options; + private boolean isTagFile; /* * JspServletWrapper for JSP pages. @@ -121,6 +122,7 @@ boolean isErrorPage, JspRuntimeContext rctxt) throws JasperException { + this.isTagFile = false; this.config = config; this.options = options; this.jspUri = jspUri; @@ -139,6 +141,7 @@ Hashtable tagFileJars) throws JasperException { + this.isTagFile = true; this.config = null; // not used this.options = options; this.jspUri = tagFilePath; @@ -217,6 +220,28 @@ } return tagHandlerClass; + } + + /** + * Get a list of files that the current page has source dependency on. + */ + public java.util.List getDependants() { + try { + Object target; + if (isTagFile) { + if (ctxt.isReload()) { + tagHandlerClass = ctxt.load(); + } + target = tagHandlerClass.newInstance(); + } else { + target = getServlet(); + } + if (target != null && target instanceof JspSourceDependent) { + return ((JspSourceDependent) target).getDependants(); + } + } catch (Throwable ex) { + } + return null; } public void service(HttpServletRequest request,
-- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>