Author: markt
Date: Mon Sep 10 19:03:46 2012
New Revision: 1383049
URL: http://svn.apache.org/viewvc?rev=1383049&view=rev
Log:
Modifications to JarScanner to:
- Stop 'double scanning' WEB-INF
- Correctly scan WEB-INF classes for with new Resources implementation
Modified:
tomcat/sandbox/trunk-resources/java/org/apache/catalina/startup/ContextConfig.java
tomcat/sandbox/trunk-resources/java/org/apache/catalina/startup/TldConfig.java
tomcat/sandbox/trunk-resources/java/org/apache/jasper/compiler/TldLocationsCache.java
tomcat/sandbox/trunk-resources/java/org/apache/tomcat/JarScannerCallback.java
tomcat/sandbox/trunk-resources/java/org/apache/tomcat/util/scan/LocalStrings.properties
tomcat/sandbox/trunk-resources/java/org/apache/tomcat/util/scan/StandardJarScanner.java
Modified:
tomcat/sandbox/trunk-resources/java/org/apache/catalina/startup/ContextConfig.java
URL:
http://svn.apache.org/viewvc/tomcat/sandbox/trunk-resources/java/org/apache/catalina/startup/ContextConfig.java?rev=1383049&r1=1383048&r2=1383049&view=diff
==============================================================================
---
tomcat/sandbox/trunk-resources/java/org/apache/catalina/startup/ContextConfig.java
(original)
+++
tomcat/sandbox/trunk-resources/java/org/apache/catalina/startup/ContextConfig.java
Mon Sep 10 19:03:46 2012
@@ -2525,6 +2525,14 @@ for (String interfaceName : cacheEntry.g
}
}
+
+ @Override
+ public void scanWebInfClasses() {
+ // NO-OP. Fragments unpacked in WEB-INF classes are not handled,
+ // mainly because if there are multiple fragments there is no way
to
+ // handle multiple web-fragment.xml files.
+ }
+
public Map<String,WebXml> getFragments() {
return fragments;
}
Modified:
tomcat/sandbox/trunk-resources/java/org/apache/catalina/startup/TldConfig.java
URL:
http://svn.apache.org/viewvc/tomcat/sandbox/trunk-resources/java/org/apache/catalina/startup/TldConfig.java?rev=1383049&r1=1383048&r2=1383049&view=diff
==============================================================================
---
tomcat/sandbox/trunk-resources/java/org/apache/catalina/startup/TldConfig.java
(original)
+++
tomcat/sandbox/trunk-resources/java/org/apache/catalina/startup/TldConfig.java
Mon Sep 10 19:03:46 2012
@@ -59,8 +59,10 @@ public final class TldConfig implements
private static final String TLD_EXT = ".tld";
private static final String WEB_INF = "/WEB-INF/";
+ private static final String WEB_INF_CLASSES = "/WEB-INF/classes/";
private static final String WEB_INF_LIB = "/WEB-INF/lib/";
+
// Names of JARs that are known not to contain any TLDs
private static volatile Set<String> noTldJars = null;
@@ -255,7 +257,7 @@ public final class TldConfig implements
tldScanWebXml();
// Stage 3a - TLDs under WEB-INF (not lib or classes)
- tldScanResourcePaths(WEB_INF);
+ tldScanResourcePaths(WEB_INF, false);
// Stages 3b & 4
JarScanner jarScanner = context.getJarScanner();
@@ -295,6 +297,11 @@ public final class TldConfig implements
tldScanDir(metaInf);
}
}
+
+ @Override
+ public void scanWebInfClasses() throws IOException {
+ tldScanResourcePaths(WEB_INF_CLASSES, true);
+ }
}
// -------------------------------------------------------- Private Methods
@@ -363,11 +370,12 @@ public final class TldConfig implements
*
* Initially, rootPath equals /WEB-INF/. The /WEB-INF/classes and
* /WEB-INF/lib sub-directories are excluded from the search, as per the
- * JSP 2.0 spec.
+ * JSP 2.0 spec unless the JarScanner is configured to treat
+ * /WEB-INF/classes/ as an exploded JAR.
*
* Keep in sync with o.a.j.comiler.TldLocationsCache
*/
- private void tldScanResourcePaths(String startPath) {
+ private void tldScanResourcePaths(String startPath, boolean webInfAsJar) {
if (log.isTraceEnabled()) {
log.trace(sm.getString("tldConfig.webinfScan", startPath));
@@ -382,7 +390,8 @@ public final class TldConfig implements
String path = it.next();
if (!path.endsWith(TLD_EXT)
&& (path.startsWith(WEB_INF_LIB)
- || path.startsWith("/WEB-INF/classes/"))) {
+ || path.startsWith("/WEB-INF/classes/")
+ && !webInfAsJar)) {
continue;
}
if (path.endsWith(TLD_EXT)) {
@@ -407,7 +416,7 @@ public final class TldConfig implements
}
}
} else {
- tldScanResourcePaths(path);
+ tldScanResourcePaths(path, false);
}
}
}
Modified:
tomcat/sandbox/trunk-resources/java/org/apache/jasper/compiler/TldLocationsCache.java
URL:
http://svn.apache.org/viewvc/tomcat/sandbox/trunk-resources/java/org/apache/jasper/compiler/TldLocationsCache.java?rev=1383049&r1=1383048&r2=1383049&view=diff
==============================================================================
---
tomcat/sandbox/trunk-resources/java/org/apache/jasper/compiler/TldLocationsCache.java
(original)
+++
tomcat/sandbox/trunk-resources/java/org/apache/jasper/compiler/TldLocationsCache.java
Mon Sep 10 19:03:46 2012
@@ -90,6 +90,7 @@ public class TldLocationsCache {
public static final int NOROOT_REL_URI = 2;
private static final String WEB_INF = "/WEB-INF/";
+ private static final String WEB_INF_CLASSES = "/WEB-INF/classes/";
private static final String WEB_INF_LIB = "/WEB-INF/lib/";
private static final String JAR_EXT = ".jar";
private static final String TLD_EXT = ".tld";
@@ -237,7 +238,7 @@ public class TldLocationsCache {
if (initialized) return;
try {
tldScanWebXml();
- tldScanResourcePaths(WEB_INF);
+ tldScanResourcePaths(WEB_INF, false);
JarScanner jarScanner = JarScannerFactory.getJarScanner(ctxt);
if (jarScanner != null) {
@@ -267,6 +268,11 @@ public class TldLocationsCache {
tldScanDir(metaInf);
}
}
+
+ @Override
+ public void scanWebInfClasses() throws IOException {
+ tldScanResourcePaths(WEB_INF_CLASSES, true);
+ }
}
/*
@@ -336,12 +342,13 @@ public class TldLocationsCache {
*
* Initially, rootPath equals /WEB-INF/. The /WEB-INF/classes and
* /WEB-INF/lib sub-directories are excluded from the search, as per the
- * JSP 2.0 spec.
+ * JSP 2.0 spec unless the JarScanner is configured to treat
+ * /WEB-INF/classes/ as an exploded JAR.
*
* Keep code in sync with o.a.c.startup.TldConfig
*/
- private void tldScanResourcePaths(String startPath)
- throws Exception {
+ private void tldScanResourcePaths(String startPath, boolean webInfAsJar)
+ throws IOException {
Set<String> dirList = ctxt.getResourcePaths(startPath);
if (dirList != null) {
@@ -350,7 +357,8 @@ public class TldLocationsCache {
String path = it.next();
if (!path.endsWith(TLD_EXT)
&& (path.startsWith(WEB_INF_LIB)
- || path.startsWith("/WEB-INF/classes/"))) {
+ || path.startsWith("/WEB-INF/classes/")
+ && !webInfAsJar)) {
continue;
}
if (path.endsWith(TLD_EXT)) {
@@ -371,7 +379,7 @@ public class TldLocationsCache {
}
}
} else {
- tldScanResourcePaths(path);
+ tldScanResourcePaths(path, false);
}
}
}
Modified:
tomcat/sandbox/trunk-resources/java/org/apache/tomcat/JarScannerCallback.java
URL:
http://svn.apache.org/viewvc/tomcat/sandbox/trunk-resources/java/org/apache/tomcat/JarScannerCallback.java?rev=1383049&r1=1383048&r2=1383049&view=diff
==============================================================================
---
tomcat/sandbox/trunk-resources/java/org/apache/tomcat/JarScannerCallback.java
(original)
+++
tomcat/sandbox/trunk-resources/java/org/apache/tomcat/JarScannerCallback.java
Mon Sep 10 19:03:46 2012
@@ -14,22 +14,40 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.apache.tomcat;
import java.io.File;
import java.io.IOException;
import java.net.JarURLConnection;
+/**
+ * This interface is implemented by clients of the {@link JatScanner} to enable
+ * them to receive notification of a discovered JAR.
+ */
public interface JarScannerCallback {
/**
+ * A JAR was found (probably packaged in a WAR) and may be accessed for
+ * further processing via the provided URL connection.
*
- * @param urlConn
- * @throws IOException
+ * @param urlConn The connection to the identified JAR
*/
public void scan(JarURLConnection urlConn) throws IOException;
- public void scan(File file) throws IOException ;
+ /**
+ * A JAR was found (probably in an unpacked WAR or possibly elsewhere on
the
+ * class path) and may be accessed for further processing via the provided
+ * file.
+ *
+ * @param file The file for the identified JAR.
+ */
+ public void scan(File file) throws IOException;
+ /**
+ * A directory structure was found within the web application at
+ * /WEB-INF/classes that should be handled as an unpacked JAR. Note that
all
+ * resource access must be via the ServletContext to ensure that any
+ * additional resources are visible.
+ */
+ public void scanWebInfClasses() throws IOException;
}
Modified:
tomcat/sandbox/trunk-resources/java/org/apache/tomcat/util/scan/LocalStrings.properties
URL:
http://svn.apache.org/viewvc/tomcat/sandbox/trunk-resources/java/org/apache/tomcat/util/scan/LocalStrings.properties?rev=1383049&r1=1383048&r2=1383049&view=diff
==============================================================================
---
tomcat/sandbox/trunk-resources/java/org/apache/tomcat/util/scan/LocalStrings.properties
(original)
+++
tomcat/sandbox/trunk-resources/java/org/apache/tomcat/util/scan/LocalStrings.properties
Mon Sep 10 19:03:46 2012
@@ -18,7 +18,8 @@ jarScan.classloaderStart=Scanning for JA
jarScan.classloaderJarScan=Scanning JAR [{0}] from classpath
jarScan.classloaderJarNoScan=Not scanning JAR [{0}] from classpath
jarScan.jarUrlStart=Scanning JAR at URL [{0}]
-jarScan.webinflibFail=Failed to scan JAR [{0}] from WEB-INF/lib
-jarScan.webinflibStart=Scanning WEB-INF/lib for JARs
-jarScan.webinflibJarScan=Scanning JAR [{0}] from WEB-INF/lib
-jarScan.webinflibJarNoScan=Not scanning JAR [{0}] from WEB-INF/lib
+jarScan.webinfclassesFail=Failed to scan /WEB-INF/classes
+jarScan.webinflibFail=Failed to scan JAR [{0}] from /WEB-INF/lib
+jarScan.webinflibStart=Scanning /WEB-INF/lib for JARs
+jarScan.webinflibJarScan=Scanning JAR [{0}] from /WEB-INF/lib
+jarScan.webinflibJarNoScan=Not scanning JAR [{0}] from /WEB-INF/lib
Modified:
tomcat/sandbox/trunk-resources/java/org/apache/tomcat/util/scan/StandardJarScanner.java
URL:
http://svn.apache.org/viewvc/tomcat/sandbox/trunk-resources/java/org/apache/tomcat/util/scan/StandardJarScanner.java?rev=1383049&r1=1383048&r2=1383049&view=diff
==============================================================================
---
tomcat/sandbox/trunk-resources/java/org/apache/tomcat/util/scan/StandardJarScanner.java
(original)
+++
tomcat/sandbox/trunk-resources/java/org/apache/tomcat/util/scan/StandardJarScanner.java
Mon Sep 10 19:03:46 2012
@@ -20,6 +20,7 @@ package org.apache.tomcat.util.scan;
import java.io.File;
import java.io.IOException;
import java.net.JarURLConnection;
+import java.net.MalformedURLException;
import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLClassLoader;
@@ -175,14 +176,31 @@ public class StandardJarScanner implemen
}
}
+ // Scan WEB-INF/classes
+ if (scanAllDirectories) {
+ try {
+ URL url = context.getResource("/WEB-INF/classes/META-INF");
+ if (url != null) {
+ try {
+ callback.scanWebInfClasses();
+ } catch (IOException e) {
+ log.warn(sm.getString("jarScan.webinfclassesFail"), e);
+ }
+ }
+ } catch (MalformedURLException e) {
+ // Ignore
+ }
+ }
+
// Scan the classpath
- if (scanClassPath) {
+ if (scanClassPath && classloader != null) {
if (log.isTraceEnabled()) {
log.trace(sm.getString("jarScan.classloaderStart"));
}
- ClassLoader loader =
- Thread.currentThread().getContextClassLoader();
+ // No need to scan the web application class loader - we have
+ // already scanned WEB-INF/lib and WEB-INF/classes
+ ClassLoader loader = classloader.getParent();
while (loader != null) {
if (loader instanceof URLClassLoader) {
@@ -215,7 +233,6 @@ public class StandardJarScanner implemen
}
loader = loader.getParent();
}
-
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]