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 2013/06/14 09:40:41 UTC
svn commit: r1492977 -
/tomcat/trunk/java/org/apache/tomcat/util/scan/StandardJarScanner.java
Author: markt
Date: Fri Jun 14 07:40:40 2013
New Revision: 1492977
URL: http://svn.apache.org/r1492977
Log:
Shared loader should be treated as a source of application JARs
Commons and Server loaders should be treated as a source of container
JARs
Modified:
tomcat/trunk/java/org/apache/tomcat/util/scan/StandardJarScanner.java
Modified: tomcat/trunk/java/org/apache/tomcat/util/scan/StandardJarScanner.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/scan/StandardJarScanner.java?rev=1492977&r1=1492976&r2=1492977&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/scan/StandardJarScanner.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/scan/StandardJarScanner.java Fri Jun 14 07:40:40 2013
@@ -220,8 +220,15 @@ public class StandardJarScanner implemen
// already scanned WEB-INF/lib and WEB-INF/classes
classLoader = classLoader.getParent();
+ // JARs are treated as application provided until the common class
+ // loader is reached.
+ boolean isWebapp = true;
+
while (classLoader != null && classLoader != stopLoader) {
if (classLoader instanceof URLClassLoader) {
+ if (isWebapp) {
+ isWebapp = isWebappClassLoader(classLoader);
+ }
URL[] urls = ((URLClassLoader) classLoader).getURLs();
for (int i=0; i<urls.length; i++) {
// Extract the jarName if there is one to be found
@@ -234,7 +241,7 @@ public class StandardJarScanner implemen
log.debug(sm.getString("jarScan.classloaderJarScan", urls[i]));
}
try {
- process(callback, urls[i], false);
+ process(callback, urls[i], isWebapp);
} catch (IOException ioe) {
log.warn(sm.getString(
"jarScan.classloaderFail",urls[i]), ioe);
@@ -251,6 +258,34 @@ public class StandardJarScanner implemen
}
}
+
+ /*
+ * Since class loader hierarchies can get complicated, this method attempts
+ * to apply the following rule: A class loader is a web application class
+ * loader unless it loaded this class (StandardJarScanner) or is a parent
+ * of the class loader that loaded this class.
+ *
+ * This should mean:
+ * the webapp class loader is an application class loader
+ * the shared class loader is an application class loader
+ * the server class loader is not an application class loader
+ * the common class loader is not an application class loader
+ * the system class loader is not an application class loader
+ * the bootstrap class loader is not an application class loader
+ */
+ private boolean isWebappClassLoader(ClassLoader classLoader) {
+ ClassLoader nonWebappLoader = StandardJarScanner.class.getClassLoader();
+
+ while (nonWebappLoader != null) {
+ if (nonWebappLoader == classLoader) {
+ return false;
+ }
+ nonWebappLoader = nonWebappLoader.getParent();
+ }
+ return true;
+ }
+
+
/*
* Scan a URL for JARs with the optional extensions to look at all files
* and all directories.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org