From 3a33ef77434f8fcba95a1fa4380f4a52e9debe37 Mon Sep 17 00:00:00 2001 From: remm Date: Tue, 9 May 2006 14:05:23 +0000 Subject: [PATCH] - Use the ignore annotation flag. - It needs recompilation in case the value is changed. It could do without, but would need additional code in the generated servlets (a field, read a servlet context param), so it would generally be (even) more intrusive :( git-svn-id: https://svn.apache.org/repos/asf/tomcat/tc6.0.x/trunk@405437 13f79535-47bb-0310-9956-ffa450edef68 --- java/org/apache/jasper/EmbeddedServletOptions.java | 17 +++++ java/org/apache/jasper/JspC.java | 15 ++++ java/org/apache/jasper/Options.java | 5 ++ java/org/apache/jasper/compiler/Generator.java | 80 ++++++++++++---------- java/org/apache/jasper/runtime/TagHandlerPool.java | 33 ++++++--- 5 files changed, 104 insertions(+), 46 deletions(-) diff --git a/java/org/apache/jasper/EmbeddedServletOptions.java b/java/org/apache/jasper/EmbeddedServletOptions.java index 1ddf06655..8059b33a1 100644 --- a/java/org/apache/jasper/EmbeddedServletOptions.java +++ b/java/org/apache/jasper/EmbeddedServletOptions.java @@ -174,6 +174,11 @@ public final class EmbeddedServletOptions implements Options { */ private boolean xpoweredBy; + /** + * Should annotations be ignored? + */ + private boolean ignoreAnnotations = false; + public String getProperty(String name ) { return settings.getProperty( name ); } @@ -245,6 +250,13 @@ public final class EmbeddedServletOptions implements Options { } /** + * Should annotations on tags be ignored? + */ + public boolean getIgnoreAnnotations() { + return ignoreAnnotations; + } + + /** * Is the generation of SMAP info for JSR45 debuggin suppressed? */ public boolean isSmapSuppressed() { @@ -384,6 +396,11 @@ public final class EmbeddedServletOptions implements Options { String validating=config.getInitParameter( "validating"); if( "false".equals( validating )) ParserUtils.validating=false; + String annotations = config.getInitParameter("org.apache.jasper.IGNORE_ANNOTATIONS"); + if ("true".equals(annotations)) { + ignoreAnnotations = true; + } + String keepgen = config.getInitParameter("keepgenerated"); if (keepgen != null) { if (keepgen.equalsIgnoreCase("true")) { diff --git a/java/org/apache/jasper/JspC.java b/java/org/apache/jasper/JspC.java index a073e321b..cede8b4c6 100644 --- a/java/org/apache/jasper/JspC.java +++ b/java/org/apache/jasper/JspC.java @@ -159,6 +159,7 @@ public class JspC implements Options { private boolean smapSuppressed = true; private boolean smapDumped = false; private boolean caching = true; + private boolean ignoreAnnotations = false; private Map cache = new HashMap(); private String compiler = null; @@ -590,6 +591,20 @@ public class JspC implements Options { compilerSourceVM = vm; } + /** + * Should annotations on tags be ignored? + */ + public boolean getIgnoreAnnotations() { + return ignoreAnnotations; + } + + /** + * Should annotations on tags be ignored? + */ + public void setIgnoreAnnotations(boolean ignoreAnnotations) { + this.ignoreAnnotations = ignoreAnnotations; + } + public TldLocationsCache getTldLocationsCache() { return tldLocationsCache; } diff --git a/java/org/apache/jasper/Options.java b/java/org/apache/jasper/Options.java index 9eef4d683..56e48dc3d 100644 --- a/java/org/apache/jasper/Options.java +++ b/java/org/apache/jasper/Options.java @@ -92,6 +92,11 @@ public interface Options { public boolean getTrimSpaces(); /** + * Should annotations on tags be ignored? + */ + public boolean getIgnoreAnnotations(); + + /** * Class ID for use in the plugin tag when the browser is IE. */ public String getIeClassId(); diff --git a/java/org/apache/jasper/compiler/Generator.java b/java/org/apache/jasper/compiler/Generator.java index 744b9d9ce..dfd6a5267 100644 --- a/java/org/apache/jasper/compiler/Generator.java +++ b/java/org/apache/jasper/compiler/Generator.java @@ -2143,9 +2143,11 @@ class Generator { out.print("new "); out.print(tagHandlerClassName); out.println("();"); - out.printin("org.apache.jasper.runtime.AnnotationProcessor.postConstruct("); - out.print(tagHandlerVar); - out.println(");"); + if (!ctxt.getOptions().getIgnoreAnnotations()) { + out.printin("org.apache.jasper.runtime.AnnotationProcessor.postConstruct("); + out.print(tagHandlerVar); + out.println(");"); + } } // includes setting the context @@ -2291,19 +2293,21 @@ class Generator { } else { out.printin(tagHandlerVar); out.println(".release();"); - out.printil("try {"); - out.pushIndent(); - out.printin("org.apache.jasper.runtime.AnnotationProcessor.preDestroy("); - out.print(tagHandlerVar); - out.println(");"); - out.popIndent(); - out.printil("} catch (Exception e) {"); - out.pushIndent(); - out.printin("log(\"Error processing preDestroy on tag instance of \" +"); - out.print(tagHandlerVar); - out.println(".getClass().getName());"); - out.popIndent(); - out.printil("}"); + if (!ctxt.getOptions().getIgnoreAnnotations()) { + out.printil("try {"); + out.pushIndent(); + out.printin("org.apache.jasper.runtime.AnnotationProcessor.preDestroy("); + out.print(tagHandlerVar); + out.println(");"); + out.popIndent(); + out.printil("} catch (Exception e) {"); + out.pushIndent(); + out.printin("log(\"Error processing preDestroy on tag instance of \" +"); + out.print(tagHandlerVar); + out.println(".getClass().getName());"); + out.popIndent(); + out.printil("}"); + } } } if (isTagFile || isFragment) { @@ -2346,19 +2350,21 @@ class Generator { } else { out.printin(tagHandlerVar); out.println(".release();"); - out.printil("try {"); - out.pushIndent(); - out.printin("org.apache.jasper.runtime.AnnotationProcessor.preDestroy("); - out.print(tagHandlerVar); - out.println(");"); - out.popIndent(); - out.printil("} catch (Exception e) {"); - out.pushIndent(); - out.printin("log(\"Error processing preDestroy on tag instance of \" +"); - out.print(tagHandlerVar); - out.println(".getClass().getName());"); - out.popIndent(); - out.printil("}"); + if (!ctxt.getOptions().getIgnoreAnnotations()) { + out.printil("try {"); + out.pushIndent(); + out.printin("org.apache.jasper.runtime.AnnotationProcessor.preDestroy("); + out.print(tagHandlerVar); + out.println(");"); + out.popIndent(); + out.printil("} catch (Exception e) {"); + out.pushIndent(); + out.printin("log(\"Error processing preDestroy on tag instance of \" +"); + out.print(tagHandlerVar); + out.println(".getClass().getName());"); + out.popIndent(); + out.printil("}"); + } } if (n.implementsTryCatchFinally()) { @@ -2399,9 +2405,11 @@ class Generator { out.println("();"); // Resource injection - out.printin("org.apache.jasper.runtime.AnnotationProcessor.postConstruct("); - out.print(tagHandlerVar); - out.println(");"); + if (!ctxt.getOptions().getIgnoreAnnotations()) { + out.printin("org.apache.jasper.runtime.AnnotationProcessor.postConstruct("); + out.print(tagHandlerVar); + out.println(");"); + } generateSetters(n, tagHandlerVar, handlerInfo, true); @@ -2447,9 +2455,11 @@ class Generator { syncScriptingVars(n, VariableInfo.AT_END); // Resource injection - out.printin("org.apache.jasper.runtime.AnnotationProcessor.preDestroy("); - out.print(tagHandlerVar); - out.println(");"); + if (!ctxt.getOptions().getIgnoreAnnotations()) { + out.printin("org.apache.jasper.runtime.AnnotationProcessor.preDestroy("); + out.print(tagHandlerVar); + out.println(");"); + } n.setEndJavaLine(out.getJavaLine()); } diff --git a/java/org/apache/jasper/runtime/TagHandlerPool.java b/java/org/apache/jasper/runtime/TagHandlerPool.java index 5574ccf78..8e2d341e4 100644 --- a/java/org/apache/jasper/runtime/TagHandlerPool.java +++ b/java/org/apache/jasper/runtime/TagHandlerPool.java @@ -40,6 +40,7 @@ public class TagHandlerPool { // index of next available tag handler private int current; + private boolean ignoreAnnotations = false; public static TagHandlerPool getTagHandlerPool( ServletConfig config) { TagHandlerPool result=null; @@ -75,6 +76,10 @@ public class TagHandlerPool { } this.handlers = new Tag[maxSize]; this.current = -1; + String annotations = getOption(config, "org.apache.jasper.IGNORE_ANNOTATIONS", null); + if ("true".equals(annotations)) { + ignoreAnnotations = true; + } } /** @@ -119,7 +124,9 @@ public class TagHandlerPool { // wait for us to construct a tag for this thread. try { Tag instance = (Tag) handlerClass.newInstance(); - AnnotationProcessor.postConstruct(instance); + if (!ignoreAnnotations) { + AnnotationProcessor.postConstruct(instance); + } return instance; } catch (Exception e) { throw new JspException(e.getMessage(), e); @@ -142,11 +149,13 @@ public class TagHandlerPool { } // There is no need for other threads to wait for us to release handler.release(); - try { - AnnotationProcessor.preDestroy(handler); - } catch (Exception e) { - log.warn("Error processing preDestroy on tag instance of " - + handler.getClass().getName(), e); + if (!ignoreAnnotations) { + try { + AnnotationProcessor.preDestroy(handler); + } catch (Exception e) { + log.warn("Error processing preDestroy on tag instance of " + + handler.getClass().getName(), e); + } } } @@ -157,11 +166,13 @@ public class TagHandlerPool { public synchronized void release() { for (int i = current; i >= 0; i--) { handlers[i].release(); - try { - AnnotationProcessor.preDestroy(handlers[i]); - } catch (Exception e) { - log.warn("Error processing preDestroy on tag instance of " - + handlers[i].getClass().getName(), e); + if (!ignoreAnnotations) { + try { + AnnotationProcessor.preDestroy(handlers[i]); + } catch (Exception e) { + log.warn("Error processing preDestroy on tag instance of " + + handlers[i].getClass().getName(), e); + } } } } -- 2.11.0