[displaytag-cvs] displaytag/src/test/java/org/apache/jasper/compiler Compiler.java,1.1,1.2
Brought to you by:
fgiust
|
From: fabrizio g. <fg...@us...> - 2005-10-16 20:35:01
|
Update of /cvsroot/displaytag/displaytag/src/test/java/org/apache/jasper/compiler In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18315/src/test/java/org/apache/jasper/compiler Modified Files: Compiler.java Log Message: committing DISPL-245 WYSIWYG Exports - from Jorge L. Barroso + some changes and fixes Index: Compiler.java =================================================================== RCS file: /cvsroot/displaytag/displaytag/src/test/java/org/apache/jasper/compiler/Compiler.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Compiler.java 3 Sep 2005 17:53:30 -0000 1.1 --- Compiler.java 16 Oct 2005 20:34:39 -0000 1.2 *************** *** 33,45 **** import org.apache.jasper.servlet.JspServletWrapper; /** * <p> ! * <strong>This is a copy of the <code>Compiler</code> class included in tomcat 5.5.9. ! * The check for dependant files (tlds) reloading has been changed in order to work correctly for files outside the ! * root of the web application. (fgiust) * </p> - * * Main JSP compiler class. This class uses Ant for compiling. - * * @author Anil K. Vijendran * @author Mandar Raje --- 33,44 ---- import org.apache.jasper.servlet.JspServletWrapper; + /** * <p> ! * <strong>This is a copy of the <code>Compiler</code> class included in tomcat 5.5.9. The check for dependant files ! * (tlds) reloading has been changed in order to work correctly for files outside the root of the web application. ! * (fgiust) * </p> * Main JSP compiler class. This class uses Ant for compiling. * @author Anil K. Vijendran * @author Mandar Raje *************** *** 49,71 **** * @author Mark Roth */ ! public abstract class Compiler { ! protected org.apache.commons.logging.Log log= ! org.apache.commons.logging.LogFactory.getLog( Compiler.class ); ! // ----------------------------------------------------------------- Static // Some javac are not thread safe; use a lock to serialize compilation, static Object javacLock = new Object(); - // ----------------------------------------------------- Instance Variables - protected JspCompilationContext ctxt; protected ErrorDispatcher errDispatcher; protected PageInfo pageInfo; protected JspServletWrapper jsw; protected TagFileProcessor tfp; --- 48,71 ---- * @author Mark Roth */ ! public abstract class Compiler ! { ! protected org.apache.commons.logging.Log log = org.apache.commons.logging.LogFactory.getLog(Compiler.class); + // ----------------------------------------------------------------- Static // Some javac are not thread safe; use a lock to serialize compilation, static Object javacLock = new Object(); // ----------------------------------------------------- Instance Variables protected JspCompilationContext ctxt; protected ErrorDispatcher errDispatcher; + protected PageInfo pageInfo; + protected JspServletWrapper jsw; + protected TagFileProcessor tfp; *************** *** 73,79 **** protected Node.Nodes pageNodes; // ------------------------------------------------------------ Constructor ! public void init(JspCompilationContext ctxt, JspServletWrapper jsw) { this.jsw = jsw; this.ctxt = ctxt; --- 73,81 ---- protected Node.Nodes pageNodes; + // ------------------------------------------------------------ Constructor ! public void init(JspCompilationContext ctxt, JspServletWrapper jsw) ! { this.jsw = jsw; this.ctxt = ctxt; *************** *** 83,93 **** // --------------------------------------------------------- Public Methods - /** * Compile the jsp file into equivalent servlet in .java file ! * @return a smap for the current JSP page, if one is generated, ! * null otherwise */ ! protected String[] generateJava() throws Exception { String[] smapStr = null; --- 85,94 ---- // --------------------------------------------------------- Public Methods /** * Compile the jsp file into equivalent servlet in .java file ! * @return a smap for the current JSP page, if one is generated, null otherwise */ ! protected String[] generateJava() throws Exception ! { String[] smapStr = null; *************** *** 97,127 **** t1 = t2 = t3 = t4 = 0; ! if (log.isDebugEnabled()) { t1 = System.currentTimeMillis(); } // Setup page info area ! pageInfo = new PageInfo(new BeanRepository(ctxt.getClassLoader(), ! errDispatcher), ! ctxt.getJspFile()); JspConfig jspConfig = options.getJspConfig(); ! JspConfig.JspProperty jspProperty = ! jspConfig.findJspProperty(ctxt.getJspFile()); /* ! * If the current uri is matched by a pattern specified in ! * a jsp-property-group in web.xml, initialize pageInfo with ! * those properties. */ ! pageInfo.setELIgnored(JspUtil.booleanValue( ! jspProperty.isELIgnored())); ! pageInfo.setScriptingInvalid(JspUtil.booleanValue( ! jspProperty.isScriptingInvalid())); ! if (jspProperty.getIncludePrelude() != null) { pageInfo.setIncludePrelude(jspProperty.getIncludePrelude()); } ! if (jspProperty.getIncludeCoda() != null) { ! pageInfo.setIncludeCoda(jspProperty.getIncludeCoda()); } --- 98,125 ---- t1 = t2 = t3 = t4 = 0; ! if (log.isDebugEnabled()) ! { t1 = System.currentTimeMillis(); } // Setup page info area ! pageInfo = new PageInfo(new BeanRepository(ctxt.getClassLoader(), errDispatcher), ctxt.getJspFile()); JspConfig jspConfig = options.getJspConfig(); ! JspConfig.JspProperty jspProperty = jspConfig.findJspProperty(ctxt.getJspFile()); /* ! * If the current uri is matched by a pattern specified in a jsp-property-group in web.xml, initialize pageInfo ! * with those properties. */ ! pageInfo.setELIgnored(JspUtil.booleanValue(jspProperty.isELIgnored())); ! pageInfo.setScriptingInvalid(JspUtil.booleanValue(jspProperty.isScriptingInvalid())); ! if (jspProperty.getIncludePrelude() != null) ! { pageInfo.setIncludePrelude(jspProperty.getIncludePrelude()); } ! if (jspProperty.getIncludeCoda() != null) ! { ! pageInfo.setIncludeCoda(jspProperty.getIncludeCoda()); } *************** *** 129,143 **** ServletWriter writer = null; ! try { // Setup the ServletWriter String javaEncoding = ctxt.getOptions().getJavaEncoding(); OutputStreamWriter osw = null; ! try { ! osw = new OutputStreamWriter( ! new FileOutputStream(javaFileName), javaEncoding); ! } catch (UnsupportedEncodingException ex) { ! errDispatcher.jspError("jsp.error.needAlternateJavaEncoding", ! javaEncoding); } --- 127,143 ---- ServletWriter writer = null; ! try ! { // Setup the ServletWriter String javaEncoding = ctxt.getOptions().getJavaEncoding(); OutputStreamWriter osw = null; ! try ! { ! osw = new OutputStreamWriter(new FileOutputStream(javaFileName), javaEncoding); ! } ! catch (UnsupportedEncodingException ex) ! { ! errDispatcher.jspError("jsp.error.needAlternateJavaEncoding", javaEncoding); } *************** *** 148,156 **** JspUtil.resetTemporaryVariableName(); ! // Parse the file ! ParserController parserCtl = new ParserController(ctxt, this); ! pageNodes = parserCtl.parse(ctxt.getJspFile()); ! if (ctxt.isPrototypeMode()) { // generate prototype .java file for the tag file Generator.generate(writer, this, pageNodes); --- 148,157 ---- JspUtil.resetTemporaryVariableName(); ! // Parse the file ! ParserController parserCtl = new ParserController(ctxt, this); ! pageNodes = parserCtl.parse(ctxt.getJspFile()); ! if (ctxt.isPrototypeMode()) ! { // generate prototype .java file for the tag file Generator.generate(writer, this, pageNodes); *************** *** 163,167 **** Validator.validate(this, pageNodes); ! if (log.isDebugEnabled()) { t2 = System.currentTimeMillis(); } --- 164,169 ---- Validator.validate(this, pageNodes); ! if (log.isDebugEnabled()) ! { t2 = System.currentTimeMillis(); } *************** *** 175,179 **** tfp.loadTagFiles(this, pageNodes); ! if (log.isDebugEnabled()) { t3 = System.currentTimeMillis(); } --- 177,182 ---- tfp.loadTagFiles(this, pageNodes); ! if (log.isDebugEnabled()) ! { t3 = System.currentTimeMillis(); } *************** *** 202,218 **** ctxt.setWriter(null); ! if (log.isDebugEnabled()) { t4 = System.currentTimeMillis(); ! log.debug("Generated "+ javaFileName + " total=" ! + (t4-t1) + " generate=" + (t4-t3) ! + " validate=" + (t2-t1)); } ! } catch (Exception e) { ! if (writer != null) { ! try { writer.close(); writer = null; ! } catch (Exception e1) { // do nothing } --- 205,233 ---- ctxt.setWriter(null); ! if (log.isDebugEnabled()) ! { t4 = System.currentTimeMillis(); ! log.debug("Generated " ! + javaFileName ! + " total=" ! + (t4 - t1) ! + " generate=" ! + (t4 - t3) ! + " validate=" ! + (t2 - t1)); } ! } ! catch (Exception e) ! { ! if (writer != null) ! { ! try ! { writer.close(); writer = null; ! } ! catch (Exception e1) ! { // do nothing } *************** *** 221,229 **** new File(javaFileName).delete(); throw e; ! } finally { ! if (writer != null) { ! try { writer.close(); ! } catch (Exception e2) { // do nothing } --- 236,250 ---- new File(javaFileName).delete(); throw e; ! } ! finally ! { ! if (writer != null) ! { ! try ! { writer.close(); ! } ! catch (Exception e2) ! { // do nothing } *************** *** 232,236 **** // JSR45 Support ! if (! options.isSmapSuppressed()) { smapStr = SmapUtil.generateSmap(ctxt, pageNodes); } --- 253,258 ---- // JSR45 Support ! if (!options.isSmapSuppressed()) ! { smapStr = SmapUtil.generateSmap(ctxt, pageNodes); } *************** *** 249,261 **** * Compile the servlet from .java file to .class file */ ! protected abstract void generateClass(String[] smap) ! throws FileNotFoundException, JasperException, Exception; ! /** * Compile the jsp file from the current engine context */ ! public void compile() ! throws FileNotFoundException, JasperException, Exception { compile(true); --- 271,280 ---- * Compile the servlet from .java file to .class file */ ! protected abstract void generateClass(String[] smap) throws FileNotFoundException, JasperException, Exception; /** * Compile the jsp file from the current engine context */ ! public void compile() throws FileNotFoundException, JasperException, Exception { compile(true); *************** *** 263,273 **** /** ! * Compile the jsp file from the current engine context. As an side- ! * effect, tag files that are referenced by this page are also compiled. ! * @param compileClass If true, generate both .java and .class file ! * If false, generate only .java file */ ! public void compile(boolean compileClass) ! throws FileNotFoundException, JasperException, Exception { compile(compileClass, false); --- 282,290 ---- /** ! * Compile the jsp file from the current engine context. As an side- effect, tag files that are referenced by this ! * page are also compiled. ! * @param compileClass If true, generate both .java and .class file If false, generate only .java file */ ! public void compile(boolean compileClass) throws FileNotFoundException, JasperException, Exception { compile(compileClass, false); *************** *** 275,299 **** /** ! * Compile the jsp file from the current engine context. As an side- ! * effect, tag files that are referenced by this page are also compiled. ! * ! * @param compileClass If true, generate both .java and .class file ! * If false, generate only .java file * @param jspcMode true if invoked from JspC, false otherwise */ ! public void compile(boolean compileClass, boolean jspcMode) ! throws FileNotFoundException, JasperException, Exception { ! if (errDispatcher == null) { this.errDispatcher = new ErrorDispatcher(jspcMode); } ! try { String[] smap = generateJava(); ! if (compileClass) { generateClass(smap); } ! } finally { ! if (tfp != null) { tfp.removeProtoTypeFiles(null); } --- 292,320 ---- /** ! * Compile the jsp file from the current engine context. As an side- effect, tag files that are referenced by this ! * page are also compiled. ! * @param compileClass If true, generate both .java and .class file If false, generate only .java file * @param jspcMode true if invoked from JspC, false otherwise */ ! public void compile(boolean compileClass, boolean jspcMode) throws FileNotFoundException, JasperException, ! Exception { ! if (errDispatcher == null) ! { this.errDispatcher = new ErrorDispatcher(jspcMode); } ! try ! { String[] smap = generateJava(); ! if (compileClass) ! { generateClass(smap); } ! } ! finally ! { ! if (tfp != null) ! { tfp.removeProtoTypeFiles(null); } *************** *** 306,310 **** pageInfo = null; pageNodes = null; ! if (ctxt.getWriter() != null) { ctxt.getWriter().close(); ctxt.setWriter(null); --- 327,332 ---- pageInfo = null; pageNodes = null; ! if (ctxt.getWriter() != null) ! { ctxt.getWriter().close(); ctxt.setWriter(null); *************** *** 314,346 **** /** ! * This is a protected method intended to be overridden by ! * subclasses of Compiler. This is used by the compile method ! * to do all the compilation. */ ! public boolean isOutDated() { ! return isOutDated( true ); } /** ! * Determine if a compilation is necessary by checking the time stamp ! * of the JSP page with that of the corresponding .class or .java file. ! * If the page has dependencies, the check is also extended to its ! * dependeants, and so on. * This method can by overidden by a subclasses of Compiler. ! * @param checkClass If true, check against .class file, ! * if false, check against .java file. */ ! public boolean isOutDated(boolean checkClass) { String jsp = ctxt.getJspFile(); ! if (jsw != null ! && (ctxt.getOptions().getModificationTestInterval() > 0)) { ! if (jsw.getLastModificationTest() ! + (ctxt.getOptions().getModificationTestInterval() * 1000) ! > System.currentTimeMillis()) { return false; ! } else { jsw.setLastModificationTest(System.currentTimeMillis()); } --- 336,368 ---- /** ! * This is a protected method intended to be overridden by subclasses of Compiler. This is used by the compile ! * method to do all the compilation. */ ! public boolean isOutDated() ! { ! return isOutDated(true); } /** ! * Determine if a compilation is necessary by checking the time stamp of the JSP page with that of the corresponding ! * .class or .java file. If the page has dependencies, the check is also extended to its dependeants, and so on. * This method can by overidden by a subclasses of Compiler. ! * @param checkClass If true, check against .class file, if false, check against .java file. */ ! public boolean isOutDated(boolean checkClass) ! { String jsp = ctxt.getJspFile(); ! if (jsw != null && (ctxt.getOptions().getModificationTestInterval() > 0)) ! { ! if (jsw.getLastModificationTest() + (ctxt.getOptions().getModificationTestInterval() * 1000) > System ! .currentTimeMillis()) ! { return false; ! } ! else ! { jsw.setLastModificationTest(System.currentTimeMillis()); } *************** *** 348,354 **** long jspRealLastModified = 0; ! try { URL jspUrl = ctxt.getResource(jsp); ! if (jspUrl == null) { ctxt.incrementRemoved(); return false; --- 370,378 ---- long jspRealLastModified = 0; ! try ! { URL jspUrl = ctxt.getResource(jsp); ! if (jspUrl == null) ! { ctxt.incrementRemoved(); return false; *************** *** 357,361 **** jspRealLastModified = uc.getLastModified(); uc.getInputStream().close(); ! } catch (Exception e) { e.printStackTrace(); return true; --- 381,387 ---- jspRealLastModified = uc.getLastModified(); uc.getInputStream().close(); ! } ! catch (Exception e) ! { e.printStackTrace(); return true; *************** *** 365,386 **** File targetFile; ! if( checkClass ) { targetFile = new File(ctxt.getClassFileName()); ! } else { targetFile = new File(ctxt.getServletJavaFileName()); } ! if (!targetFile.exists()) { return true; } targetLastModified = targetFile.lastModified(); ! if (checkClass && jsw != null) { jsw.setServletClassLastModifiedTime(targetLastModified); } ! if (targetLastModified < jspRealLastModified) { ! if( log.isDebugEnabled() ) { ! log.debug("Compiler: outdated: " + targetFile + " " + ! targetLastModified ); } return true; --- 391,418 ---- File targetFile; ! if (checkClass) ! { targetFile = new File(ctxt.getClassFileName()); ! } ! else ! { targetFile = new File(ctxt.getServletJavaFileName()); } ! if (!targetFile.exists()) ! { return true; } targetLastModified = targetFile.lastModified(); ! if (checkClass && jsw != null) ! { jsw.setServletClassLastModifiedTime(targetLastModified); } ! if (targetLastModified < jspRealLastModified) ! { ! if (log.isDebugEnabled()) ! { ! log.debug("Compiler: outdated: " + targetFile + " " + targetLastModified); } return true; *************** *** 389,410 **** // determine if source dependent files (e.g. includes using include // directives) have been changed. ! if( jsw==null ) { return false; } List depends = jsw.getDependants(); ! if (depends == null) { return false; } Iterator it = depends.iterator(); ! while (it.hasNext()) { ! String include = (String)it.next(); ! try { // changed by fgiust // URL includeUrl = ctxt.getResource(include); URL includeUrl = new File(ctxt.getRealPath(include)).toURL(); ! if (includeUrl == null) { return true; } --- 421,447 ---- // determine if source dependent files (e.g. includes using include // directives) have been changed. ! if (jsw == null) ! { return false; } List depends = jsw.getDependants(); ! if (depends == null) ! { return false; } Iterator it = depends.iterator(); ! while (it.hasNext()) ! { ! String include = (String) it.next(); ! try ! { // changed by fgiust // URL includeUrl = ctxt.getResource(include); URL includeUrl = new File(ctxt.getRealPath(include)).toURL(); ! if (includeUrl == null) ! { return true; } *************** *** 414,421 **** includeUconn.getInputStream().close(); ! if (includeLastModified > targetLastModified) { return true; } ! } catch (Exception e) { e.printStackTrace(); return true; --- 451,461 ---- includeUconn.getInputStream().close(); ! if (includeLastModified > targetLastModified) ! { return true; } ! } ! catch (Exception e) ! { e.printStackTrace(); return true; *************** *** 427,490 **** } - /** * Gets the error dispatcher. */ ! public ErrorDispatcher getErrorDispatcher() { ! return errDispatcher; } - /** * Gets the info about the page under compilation */ ! public PageInfo getPageInfo() { ! return pageInfo; } ! ! public JspCompilationContext getCompilationContext() { ! return ctxt; } - /** * Remove generated files */ ! public void removeGeneratedFiles() { ! try { String classFileName = ctxt.getClassFileName(); ! if (classFileName != null) { File classFile = new File(classFileName); ! if( log.isDebugEnabled() ) ! log.debug( "Deleting " + classFile ); classFile.delete(); } ! } catch (Exception e) { // Remove as much as possible, ignore possible exceptions } ! try { String javaFileName = ctxt.getServletJavaFileName(); ! if (javaFileName != null) { File javaFile = new File(javaFileName); ! if( log.isDebugEnabled() ) ! log.debug( "Deleting " + javaFile ); javaFile.delete(); } ! } catch (Exception e) { // Remove as much as possible, ignore possible exceptions } } ! public void removeGeneratedClassFiles() { ! try { String classFileName = ctxt.getClassFileName(); ! if (classFileName != null) { File classFile = new File(classFileName); ! if( log.isDebugEnabled() ) ! log.debug( "Deleting " + classFile ); classFile.delete(); } ! } catch (Exception e) { // Remove as much as possible, ignore possible exceptions } --- 467,543 ---- } /** * Gets the error dispatcher. */ ! public ErrorDispatcher getErrorDispatcher() ! { ! return errDispatcher; } /** * Gets the info about the page under compilation */ ! public PageInfo getPageInfo() ! { ! return pageInfo; } ! public JspCompilationContext getCompilationContext() ! { ! return ctxt; } /** * Remove generated files */ ! public void removeGeneratedFiles() ! { ! try ! { String classFileName = ctxt.getClassFileName(); ! if (classFileName != null) ! { File classFile = new File(classFileName); ! if (log.isDebugEnabled()) ! log.debug("Deleting " + classFile); classFile.delete(); } ! } ! catch (Exception e) ! { // Remove as much as possible, ignore possible exceptions } ! try ! { String javaFileName = ctxt.getServletJavaFileName(); ! if (javaFileName != null) ! { File javaFile = new File(javaFileName); ! if (log.isDebugEnabled()) ! log.debug("Deleting " + javaFile); javaFile.delete(); } ! } ! catch (Exception e) ! { // Remove as much as possible, ignore possible exceptions } } ! public void removeGeneratedClassFiles() ! { ! try ! { String classFileName = ctxt.getClassFileName(); ! if (classFileName != null) ! { File classFile = new File(classFileName); ! if (log.isDebugEnabled()) ! log.debug("Deleting " + classFile); classFile.delete(); } ! } ! catch (Exception e) ! { // Remove as much as possible, ignore possible exceptions } |