Author: rjung Date: Fri Jul 16 11:13:37 2010 New Revision: 964763 URL: http://svn.apache.org/viewvc?rev=964763&view=rev Log: Add support for *.jar pattern in VirtualWebappLoader.
Also perform trimming of the tokens. Backport of r958615 except for the removal of the "not for production" warning in Javadoc. Modified: tomcat/tc6.0.x/trunk/STATUS.txt tomcat/tc6.0.x/trunk/java/org/apache/catalina/loader/LocalStrings.properties tomcat/tc6.0.x/trunk/java/org/apache/catalina/loader/VirtualWebappLoader.java tomcat/tc6.0.x/trunk/webapps/docs/changelog.xml Modified: tomcat/tc6.0.x/trunk/STATUS.txt URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/STATUS.txt?rev=964763&r1=964762&r2=964763&view=diff ============================================================================== --- tomcat/tc6.0.x/trunk/STATUS.txt (original) +++ tomcat/tc6.0.x/trunk/STATUS.txt Fri Jul 16 11:13:37 2010 @@ -142,14 +142,6 @@ PATCHES PROPOSED TO BACKPORT: +1: markt -1: -* Add support for *.jar pattern in VirtualWebappLoader - and perform trimming of the tokens. - I propose the following patch, but without removing the "not for production" - warning from JavaDoc: - http://svn.apache.org/viewvc?rev=958615&view=rev - +1: kkolinko, rjung, kfujino, pero - -1: - * Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=49217 Ensure EL identifiers conform to the Java Language Specification with an option to disable this check. Modified: tomcat/tc6.0.x/trunk/java/org/apache/catalina/loader/LocalStrings.properties URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/catalina/loader/LocalStrings.properties?rev=964763&r1=964762&r2=964763&view=diff ============================================================================== --- tomcat/tc6.0.x/trunk/java/org/apache/catalina/loader/LocalStrings.properties (original) +++ tomcat/tc6.0.x/trunk/java/org/apache/catalina/loader/LocalStrings.properties Fri Jul 16 11:13:37 2010 @@ -28,6 +28,12 @@ standardLoader.reloading=Reloading check standardLoader.removeRepository=Removing repository {0} standardLoader.starting=Starting this Loader standardLoader.stopping=Stopping this Loader +virtualWebappLoader.token=Processing token [{0}] +virtualWebappLoader.token.file=Adding location: [{0}] +virtualWebappLoader.token.glob.dir=Listing files in a directory: [{0}] +virtualWebappLoader.token.notDirectory=Path is skipped, because it does not exist or is not a directory: [{0}] +virtualWebappLoader.token.notExists=Path is skipped, because it does not exist: [{0}] +virtualWebappLoader.token.notFile=Path is skipped, because it does not exist or is not a file: [{0}] webappClassLoader.illegalJarPath=Illegal JAR entry detected with name {0} webappClassLoader.jdbcRemoveFailed=JDBC driver de-registration failed for web application [{0}] webappClassLoader.jdbcRemoveStreamError=Exception closing input stream during JDBC driver de-registration for web application [{0}] Modified: tomcat/tc6.0.x/trunk/java/org/apache/catalina/loader/VirtualWebappLoader.java URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/catalina/loader/VirtualWebappLoader.java?rev=964763&r1=964762&r2=964763&view=diff ============================================================================== --- tomcat/tc6.0.x/trunk/java/org/apache/catalina/loader/VirtualWebappLoader.java (original) +++ tomcat/tc6.0.x/trunk/java/org/apache/catalina/loader/VirtualWebappLoader.java Fri Jul 16 11:13:37 2010 @@ -17,12 +17,16 @@ package org.apache.catalina.loader; import java.io.File; +import java.util.Arrays; +import java.util.LinkedHashSet; +import java.util.Locale; +import java.util.Set; import java.util.StringTokenizer; import org.apache.catalina.LifecycleException; /** - * Simple webapp classloader that allows a customized classpath to be added + * A WebappLoader that allows a customized classpath to be added * through configuration in context xml. Any additional classpath entry will be * added to the default webapp classpath, making easy to emulate a standard * webapp without the need for assembly all the webapp dependencies as jars in @@ -31,7 +35,7 @@ import org.apache.catalina.LifecycleExce * <pre> * <Context docBase="\webapps\mydocbase"> * <Loader className="org.apache.catalina.loader.VirtualWebappLoader" - * virtualClasspath="\dir\classes;\somedir\somejar.jar"/> + * virtualClasspath="/dir/classes;/somedir/somejar.jar;/somedir/*.jar"/> * </Context> * </pre> * @@ -40,6 +44,10 @@ import org.apache.catalina.LifecycleExce * Its meant to ease development with IDE's without the * need for fully republishing jars in WEB-INF/lib</strong> * + * <p>The <code>*.jar</code> suffix can be used to include all JAR files in a + * certain directory. If a file or a directory does not exist, it will be + * skipped. + * </p> * * * @author Fabrizio Giustina @@ -47,6 +55,9 @@ import org.apache.catalina.LifecycleExce */ public class VirtualWebappLoader extends WebappLoader { + private static final org.apache.juli.logging.Log log= + org.apache.juli.logging.LogFactory.getLog( VirtualWebappLoader.class ); + /** * <code>;</code> separated list of additional path elements. */ @@ -86,12 +97,75 @@ public class VirtualWebappLoader extends // just add any jar/directory set in virtual classpath to the // repositories list before calling start on the standard WebappLoader StringTokenizer tkn = new StringTokenizer(virtualClasspath, ";"); + Set<String> set = new LinkedHashSet<String>(); while (tkn.hasMoreTokens()) { - File file = new File(tkn.nextToken()); - if (!file.exists()) { - continue; + String token = tkn.nextToken().trim(); + + if (log.isDebugEnabled()) + log.debug(sm.getString("virtualWebappLoader.token", token)); + + if (token.endsWith("*.jar")) { + // glob + token = token.substring(0, token.length() - "*.jar".length()); + + File directory = new File(token); + if (!directory.isDirectory()) { + if (log.isDebugEnabled()) { + log.debug(sm.getString( + "virtualWebappLoader.token.notDirectory", + directory.getAbsolutePath())); + } + continue; + } + if (log.isDebugEnabled()) { + log.debug(sm.getString( + "virtualWebappLoader.token.glob.dir", + directory.getAbsolutePath())); + } + String filenames[] = directory.list(); + Arrays.sort(filenames); + for (int j = 0; j < filenames.length; j++) { + String filename = filenames[j].toLowerCase(Locale.ENGLISH); + if (!filename.endsWith(".jar")) + continue; + File file = new File(directory, filenames[j]); + if (!file.isFile()) { + if (log.isDebugEnabled()) { + log.debug(sm.getString( + "virtualWebappLoader.token.notFile", + file.getAbsolutePath())); + } + continue; + } + if (log.isDebugEnabled()) { + log.debug(sm.getString( + "virtualWebappLoader.token.file", + file.getAbsolutePath())); + } + set.add(file.toURI().toString()); + } + } else { + // single file or directory + File file = new File(token); + if (!file.exists()) { + if (log.isDebugEnabled()) { + log.debug(sm.getString( + "virtualWebappLoader.token.notExists", + file.getAbsolutePath())); + } + continue; + } + if (log.isDebugEnabled()) { + log.debug(sm.getString( + "virtualWebappLoader.token.file", + file.getAbsolutePath())); + } + set.add(file.toURI().toString()); } - addRepository(file.toURI().toString()); + } + + for (String repository: set) { + addRepository(repository); } super.start(); Modified: tomcat/tc6.0.x/trunk/webapps/docs/changelog.xml URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/webapps/docs/changelog.xml?rev=964763&r1=964762&r2=964763&view=diff ============================================================================== --- tomcat/tc6.0.x/trunk/webapps/docs/changelog.xml (original) +++ tomcat/tc6.0.x/trunk/webapps/docs/changelog.xml Fri Jul 16 11:13:37 2010 @@ -59,6 +59,10 @@ <fix> Fix order when listing Webapp loader search URLs. (rjung) </fix> + <add> + Add support for <code>*.jar</code> pattern in VirtualWebappLoader. + (kkolinko) + </add> </changelog> </subsection> </section> --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org