You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2015/04/28 23:20:00 UTC

svn commit: r1676633 - in /tomcat/tc7.0.x/trunk: java/org/apache/catalina/startup/LocalStrings.properties java/org/apache/catalina/startup/TldConfig.java webapps/docs/changelog.xml

Author: markt
Date: Tue Apr 28 21:20:00 2015
New Revision: 1676633

URL: http://svn.apache.org/r1676633
Log:
Partial fix for https://bz.apache.org/bugzilla/show_bug.cgi?id=56438
Add logging for unnecessary TLD scans in JARs

Modified:
    tomcat/tc7.0.x/trunk/java/org/apache/catalina/startup/LocalStrings.properties
    tomcat/tc7.0.x/trunk/java/org/apache/catalina/startup/TldConfig.java
    tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml

Modified: tomcat/tc7.0.x/trunk/java/org/apache/catalina/startup/LocalStrings.properties
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/catalina/startup/LocalStrings.properties?rev=1676633&r1=1676632&r2=1676633&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/java/org/apache/catalina/startup/LocalStrings.properties (original)
+++ tomcat/tc7.0.x/trunk/java/org/apache/catalina/startup/LocalStrings.properties Tue Apr 28 21:20:00 2015
@@ -124,8 +124,11 @@ tldConfig.addListeners=Adding {0} listen
 tldConfig.cce=Lifecycle event data object {0} is not a Context
 tldConfig.dirFail=Failed to process directory [{0}] for TLD files
 tldConfig.dirScan=Scanning for TLD files in directory [{0}]
+tldConfig.noTldInDir=No TLD files were found in directory [{0}].
 tldConfig.execute=Error processing TLD files for context with name [{0}]
 tldConfig.jarFail=Failed to process JAR [{0}] for TLD files
+tldConfig.noTldInJar=No TLD files were found in [{0}]. Consider adding the JAR to the org.apache.catalina.startup.TldConfig.jarsToSkip property in CATALINA_BASE/conf/catalina.properties file.
+tldConfig.noTldSummary=At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
 tldConfig.webinfFail=Failed to process TLD found at [{0}]
 tldConfig.webinfScan=Scanning WEB-INF for TLD files in [{0}]
 tldConfig.webxmlAdd=Adding path [{0}] for URI [{1}]

Modified: tomcat/tc7.0.x/trunk/java/org/apache/catalina/startup/TldConfig.java
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/catalina/startup/TldConfig.java?rev=1676633&r1=1676632&r2=1676633&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/java/org/apache/catalina/startup/TldConfig.java (original)
+++ tomcat/tc7.0.x/trunk/java/org/apache/catalina/startup/TldConfig.java Tue Apr 28 21:20:00 2015
@@ -266,10 +266,13 @@ public final class TldConfig  implements
 
         // Stages 3b & 4
         JarScanner jarScanner = context.getJarScanner();
-        jarScanner.scan(context.getServletContext(),
-                context.getLoader().getClassLoader(),
-                new TldJarScannerCallback(), noTldJars);
         
+        TldJarScannerCallback tldCallBack = new TldJarScannerCallback();
+        jarScanner.scan(context.getServletContext(), context.getLoader().getClassLoader(),
+                tldCallBack, noTldJars);
+        if(tldCallBack.scanFoundNoTLDs()){
+            log.info(sm.getString("tldConfig.noTldSummary"));
+        }
         // Now add all the listeners we found to the listeners for this context
         String list[] = getTldListeners();
 
@@ -290,19 +293,24 @@ public final class TldConfig  implements
     }
 
     private class TldJarScannerCallback implements JarScannerCallback {
-
+        boolean tldFound = true;
+        
         @Override
         public void scan(JarURLConnection urlConn) throws IOException {
-            tldScanJar(urlConn);
+            tldFound = tldScanJar(urlConn);
         }
 
         @Override
         public void scan(File file) {
             File metaInf = new File(file, "META-INF");
             if (metaInf.isDirectory()) {
-                tldScanDir(metaInf);
+                tldFound = tldScanDir(metaInf);
             }
         }
+        
+        private boolean scanFoundNoTLDs() {
+            return !tldFound;
+        }
     }
 
     // -------------------------------------------------------- Private Methods
@@ -432,8 +440,9 @@ public final class TldConfig  implements
      *
      * Keep in sync with o.a.j.comiler.TldLocationsCache
      */
-    private void tldScanDir(File start) {
-
+    private boolean tldScanDir(File start) {
+        boolean isFound = false;
+        
         if (log.isTraceEnabled()) {
             log.trace(sm.getString("tldConfig.dirScan", start.getAbsolutePath()));
         }
@@ -446,6 +455,7 @@ public final class TldConfig  implements
                     tldScanDir(fileList[i]);
                 } else if (fileList[i].getAbsolutePath().endsWith(TLD_EXT)) {
                     InputStream stream = null;
+                    isFound = true;
                     try {
                         stream = new FileInputStream(fileList[i]);
                         XmlErrorHandler handler = tldScanStream(stream);
@@ -466,6 +476,12 @@ public final class TldConfig  implements
                 }
             }
         }
+        if(!isFound){
+            if (log.isDebugEnabled()) {
+                log.debug(sm.getString("tldConfig.noTldInDir", start.getAbsolutePath()));
+            }
+        }
+        return isFound;
     }
 
     /*
@@ -476,10 +492,11 @@ public final class TldConfig  implements
      * 
      * Keep in sync with o.a.j.comiler.TldLocationsCache
      */
-    private void tldScanJar(JarURLConnection jarConn) {
+    private boolean tldScanJar(JarURLConnection jarConn) {
 
         Jar jar = null;
         InputStream is;
+        boolean isFound = false;
         
         try {
             jar = JarFactory.newInstance(jarConn.getURL());
@@ -489,6 +506,7 @@ public final class TldConfig  implements
             while (entryName != null) {
                 if (entryName.startsWith("META-INF/") &&
                         entryName.endsWith(".tld")) {
+                    isFound = true;
                     is = null;
                     try {
                         is = jar.getEntryInputStream();
@@ -507,6 +525,12 @@ public final class TldConfig  implements
                 jar.nextEntry();
                 entryName = jar.getEntryName();
             }
+            if(!isFound){
+                if (log.isDebugEnabled()) {
+                    log.debug(sm.getString("tldConfig.noTldInJar",
+                            jarConn.getURL().getFile()));
+                }
+            }
         } catch (IOException ioe) {
             log.warn(sm.getString("tldConfig.jarFail", jarConn.getURL()), ioe);
         } finally {
@@ -514,6 +538,7 @@ public final class TldConfig  implements
                 jar.close();
             }
         }
+        return isFound;
     }
 
 

Modified: tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml?rev=1676633&r1=1676632&r2=1676633&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml Tue Apr 28 21:20:00 2015
@@ -275,6 +275,11 @@
         cipher suite ordering. This feature requires Java 8.
         Based upon patches provided by Ognjen Blagojevic. (schultz)
       </fix>
+      <add>
+        <bug>56438</bug>: Add logging that reports when a JAR is scanned for
+        TLDs but nothing is found so that Tomcat may be configured to skip this
+        JAR in future. Based on a patch by VIN. (markt)
+      </add>
       <fix>
         <bug>56848</bug>: Use <code>Locale.forLanguageTag</code> to process
         Locale headers when running on a Java 7 or later JRE. (markt)



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org