From 9a94c47e87aad9c383191632443d7e06d8d802d9 Mon Sep 17 00:00:00 2001 From: markt Date: Thu, 24 Dec 2009 11:14:46 +0000 Subject: [PATCH] Move JAR scanning into a new JAR used by both Catalina and Jasper git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@893731 13f79535-47bb-0310-9956-ffa450edef68 --- build.xml | 14 +- java/org/apache/catalina/core/StandardContext.java | 2 +- .../apache/jasper/compiler/InternalJarScanner.java | 236 --------------------- .../apache/jasper/compiler/JarScannerFactory.java | 3 +- .../util/scan}/DefaultJarScanner.java | 5 +- java/org/apache/tomcat/util/scan/package.html | 14 ++ res/maven/mvn-pub.xml | 1 + res/maven/tomcat-catalina.pom | 6 + res/maven/tomcat-jasper.pom | 6 + res/maven/tomcat-util.pom | 24 +++ 10 files changed, 69 insertions(+), 242 deletions(-) delete mode 100644 java/org/apache/jasper/compiler/InternalJarScanner.java rename java/org/apache/{catalina/startup => tomcat/util/scan}/DefaultJarScanner.java (98%) create mode 100644 java/org/apache/tomcat/util/scan/package.html create mode 100644 res/maven/tomcat-util.pom diff --git a/build.xml b/build.xml index 53e587cf3..fb80562dc 100644 --- a/build.xml +++ b/build.xml @@ -84,6 +84,7 @@ + @@ -228,7 +229,11 @@ - + + + + + @@ -261,6 +266,8 @@ + + @@ -399,6 +406,11 @@ filesDir="${tomcat.classes}" filesId="files.tomcat-api" /> + + + Context interface. Each diff --git a/java/org/apache/jasper/compiler/InternalJarScanner.java b/java/org/apache/jasper/compiler/InternalJarScanner.java deleted file mode 100644 index 20feea657..000000000 --- a/java/org/apache/jasper/compiler/InternalJarScanner.java +++ /dev/null @@ -1,236 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.jasper.compiler; - -import java.io.File; -import java.io.IOException; -import java.net.JarURLConnection; -import java.net.URISyntaxException; -import java.net.URL; -import java.net.URLClassLoader; -import java.net.URLConnection; -import java.util.Iterator; -import java.util.Set; - -import javax.servlet.ServletContext; - -import org.apache.juli.logging.Log; -import org.apache.juli.logging.LogFactory; -import org.apache.tomcat.JarScanner; -import org.apache.tomcat.JarScannerCallback; - -/** - * The default {@link JarScanner} implementation scans the WEB-INF/lib directory - * followed by the provided classloader and then works up the classloader - * hierarchy. This implementation is sufficient to meet the requirements of the - * Servlet 3.0 specification as well as to provide a number of Tomcat specific - * extensions. The extensions are: - *
    - *
  • Scanning the classloader hierarchy (enabled by default)
  • - *
  • Testing all files to see if they are JARs (disabled by default)
  • - *
  • Testing all directories to see if they are exploded JARs - * (disabled by default)
  • - *
- * All of the extensions may be controlled via configuration. - * - * Keep in sync with org.apache.catalina.startup.DefaultJarScanner - */ -public class InternalJarScanner implements JarScanner { - - private static final String JAR_EXT = ".jar"; - private static final String WEB_INF_LIB = "/WEB-INF/lib/"; - - private static final Log log = LogFactory.getLog(InternalJarScanner.class); - - /** - * Controls the classpath scanning extension. - */ - private boolean scanClassPath = true; - public boolean isScanClassPath() { - return scanClassPath; - } - public void setScanClassPath(boolean scanClassPath) { - this.scanClassPath = scanClassPath; - } - - /** - * Controls the testing all files to see of they are JAR files extension. - */ - private boolean scanAllFiles = false; - public boolean isScanAllFiles() { - return scanAllFiles; - } - public void setScanAllFiles(boolean scanAllFiles) { - this.scanAllFiles = scanAllFiles; - } - - /** - * Controls the testing all directories to see of they are exploded JAR - * files extension. - */ - private boolean scanAllDirectories = false; - public boolean isScanAllDirectories() { - return scanAllDirectories; - } - public void setScanAllDirectories(boolean scanAllDirectories) { - this.scanAllDirectories = scanAllDirectories; - } - - /** - * {@inheritDoc} - */ - @Override - public void scan(ServletContext context, ClassLoader classloader, - JarScannerCallback callback, Set jarsToSkip) { - - if (log.isTraceEnabled()) { - log.trace(Localizer.getMessage("jsp.jarScan.webinflibStart")); - } - - // Scan WEB-INF/lib - Set dirList = context.getResourcePaths(WEB_INF_LIB); - if (dirList != null) { - Iterator it = dirList.iterator(); - while (it.hasNext()) { - String path = it.next(); - if (path.endsWith(JAR_EXT) && - !jarsToSkip.contains( - path.substring(path.lastIndexOf('/')))) { - // Need to scan this JAR - URL url = null; - try { - url = context.getResource(path); - process(callback, url); - } catch (IOException e) { - if (url == null) { - log.warn(Localizer.getMessage( - "jsp.jarScan.webinflibFail", - path), e); - } else { - log.warn(Localizer.getMessage( - "jsp.jarScan.webinflibFail", - url.toString()), e); - } - } - } - } - } - - // Scan the classpath - if (scanClassPath) { - if (log.isTraceEnabled()) { - log.trace(Localizer.getMessage("jsp.jarScan.classloaderStart")); - } - - ClassLoader loader = - Thread.currentThread().getContextClassLoader(); - - while (loader != null) { - if (loader instanceof URLClassLoader) { - URL[] urls = ((URLClassLoader) loader).getURLs(); - for (int i=0; i * * All of the extensions may be controlled via configuration. - * - * Keep in sync with org.apache.jasper.compiler.InternalJarScanner */ public class DefaultJarScanner implements JarScanner { diff --git a/java/org/apache/tomcat/util/scan/package.html b/java/org/apache/tomcat/util/scan/package.html new file mode 100644 index 000000000..bf69b24b3 --- /dev/null +++ b/java/org/apache/tomcat/util/scan/package.html @@ -0,0 +1,14 @@ + + + + + + +

+This package contains the common classes used to perform configuration scanning +for Catalina and Jasper. +

+ + diff --git a/res/maven/mvn-pub.xml b/res/maven/mvn-pub.xml index 16144e7c8..cad825dfb 100644 --- a/res/maven/mvn-pub.xml +++ b/res/maven/mvn-pub.xml @@ -142,6 +142,7 @@ + diff --git a/res/maven/tomcat-catalina.pom b/res/maven/tomcat-catalina.pom index aec744755..563a39cba 100644 --- a/res/maven/tomcat-catalina.pom +++ b/res/maven/tomcat-catalina.pom @@ -46,5 +46,11 @@ @MAVEN.DEPLOY.VERSION@ compile + + org.apache.tomcat + tomcat-util + @MAVEN.DEPLOY.VERSION@ + compile + diff --git a/res/maven/tomcat-jasper.pom b/res/maven/tomcat-jasper.pom index 09e4e42ca..6238c90cf 100644 --- a/res/maven/tomcat-jasper.pom +++ b/res/maven/tomcat-jasper.pom @@ -70,5 +70,11 @@ @MAVEN.DEPLOY.VERSION@ compile + + org.apache.tomcat + tomcat-util + @MAVEN.DEPLOY.VERSION@ + compile + diff --git a/res/maven/tomcat-util.pom b/res/maven/tomcat-util.pom new file mode 100644 index 000000000..67e486fae --- /dev/null +++ b/res/maven/tomcat-util.pom @@ -0,0 +1,24 @@ + + + + 4.0.0 + org.apache.tomcat + tomcat-util + @MAVEN.DEPLOY.VERSION@ + Common code shared by Catalina and Jasper + -- 2.11.0