Author: markt
Date: Fri Feb 18 21:44:13 2011
New Revision: 1072160
URL: http://svn.apache.org/viewvc?rev=1072160&view=rev
Log:
Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=48870
Re-factor to remove parallel arrays.
Modify fix for 48863 to remove use of StringManager as it is not available in
Bootstrap
Modified:
tomcat/trunk/build.xml
tomcat/trunk/java/org/apache/catalina/startup/Bootstrap.java
tomcat/trunk/java/org/apache/catalina/startup/ClassLoaderFactory.java
tomcat/trunk/java/org/apache/catalina/startup/LocalStrings.properties
tomcat/trunk/webapps/docs/changelog.xml
Modified: tomcat/trunk/build.xml
URL:
http://svn.apache.org/viewvc/tomcat/trunk/build.xml?rev=1072160&r1=1072159&r2=1072160&view=diff
==============================================================================
--- tomcat/trunk/build.xml (original)
+++ tomcat/trunk/build.xml Fri Feb 18 21:44:13 2011
@@ -259,8 +259,7 @@
<include name="org/apache/catalina/startup/catalina.properties" />
<include name="org/apache/catalina/startup/CatalinaProperties.*" />
<include name="org/apache/catalina/startup/ClassLoaderFactory.*" />
- <include name="org/apache/catalina/startup/ClassLoaderFactory$1.*" />
- <include name="org/apache/catalina/startup/ClassLoaderFactory$2.*" />
+ <include name="org/apache/catalina/startup/ClassLoaderFactory$*.*" />
<include name="org/apache/catalina/startup/Tool.*" />
<include name="org/apache/catalina/loader/StandardClassLoader*.*" />
<include name="org/apache/catalina/loader/Extension.*" />
Modified: tomcat/trunk/java/org/apache/catalina/startup/Bootstrap.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/startup/Bootstrap.java?rev=1072160&r1=1072159&r2=1072160&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/startup/Bootstrap.java (original)
+++ tomcat/trunk/java/org/apache/catalina/startup/Bootstrap.java Fri Feb 18
21:44:13 2011
@@ -26,6 +26,7 @@ import java.lang.reflect.Method;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
+import java.util.List;
import java.util.StringTokenizer;
import javax.management.MBeanServer;
@@ -34,6 +35,8 @@ import javax.management.ObjectName;
import org.apache.catalina.Globals;
import org.apache.catalina.security.SecurityClassLoad;
+import org.apache.catalina.startup.ClassLoaderFactory.Repository;
+import org.apache.catalina.startup.ClassLoaderFactory.RepositoryType;
import org.apache.juli.logging.Log;
import org.apache.juli.logging.LogFactory;
@@ -113,8 +116,7 @@ public final class Bootstrap {
if ((value == null) || (value.equals("")))
return parent;
- ArrayList<String> repositoryLocations = new ArrayList<String>();
- ArrayList<Integer> repositoryTypes = new ArrayList<Integer>();
+ List<Repository> repositories = new ArrayList<Repository>();
int i;
StringTokenizer tokenizer = new StringTokenizer(value, ",");
@@ -150,8 +152,8 @@ public final class Bootstrap {
// Check for a JAR URL repository
try {
new URL(repository);
- repositoryLocations.add(repository);
- repositoryTypes.add(ClassLoaderFactory.IS_URL);
+ repositories.add(
+ new Repository(repository, RepositoryType.URL));
continue;
} catch (MalformedURLException e) {
// Ignore
@@ -160,22 +162,19 @@ public final class Bootstrap {
if (repository.endsWith("*.jar")) {
repository = repository.substring
(0, repository.length() - "*.jar".length());
- repositoryLocations.add(repository);
- repositoryTypes.add(ClassLoaderFactory.IS_GLOB);
+ repositories.add(
+ new Repository(repository, RepositoryType.GLOB));
} else if (repository.endsWith(".jar")) {
- repositoryLocations.add(repository);
- repositoryTypes.add(ClassLoaderFactory.IS_JAR);
+ repositories.add(
+ new Repository(repository, RepositoryType.JAR));
} else {
- repositoryLocations.add(repository);
- repositoryTypes.add(ClassLoaderFactory.IS_DIR);
+ repositories.add(
+ new Repository(repository, RepositoryType.DIR));
}
}
- String[] locations = repositoryLocations.toArray(new String[0]);
- Integer[] types = repositoryTypes.toArray(new Integer[0]);
-
ClassLoader classLoader = ClassLoaderFactory.createClassLoader
- (locations, types, parent);
+ (repositories, parent);
// Retrieving MBean server
MBeanServer mBeanServer = null;
Modified: tomcat/trunk/java/org/apache/catalina/startup/ClassLoaderFactory.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/startup/ClassLoaderFactory.java?rev=1072160&r1=1072159&r2=1072160&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/startup/ClassLoaderFactory.java
(original)
+++ tomcat/trunk/java/org/apache/catalina/startup/ClassLoaderFactory.java Fri
Feb 18 21:44:13 2011
@@ -24,13 +24,13 @@ import java.net.URL;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.LinkedHashSet;
+import java.util.List;
import java.util.Locale;
import java.util.Set;
import org.apache.catalina.loader.StandardClassLoader;
import org.apache.juli.logging.Log;
import org.apache.juli.logging.LogFactory;
-import org.apache.tomcat.util.res.StringManager;
/**
@@ -57,14 +57,6 @@ public final class ClassLoaderFactory {
private static final Log log = LogFactory.getLog(ClassLoaderFactory.class);
- private static final StringManager sm =
- StringManager.getManager(Constants.Package);
-
- protected static final Integer IS_DIR = Integer.valueOf(0);
- protected static final Integer IS_JAR = Integer.valueOf(1);
- protected static final Integer IS_GLOB = Integer.valueOf(2);
- protected static final Integer IS_URL = Integer.valueOf(3);
-
// --------------------------------------------------------- Public Methods
@@ -159,8 +151,7 @@ public final class ClassLoaderFactory {
*
* @exception Exception if an error occurs constructing the class loader
*/
- public static ClassLoader createClassLoader(String locations[],
- Integer types[],
+ public static ClassLoader createClassLoader(List<Repository> repositories,
final ClassLoader parent)
throws Exception {
@@ -170,16 +161,15 @@ public final class ClassLoaderFactory {
// Construct the "class path" for this class loader
Set<URL> set = new LinkedHashSet<URL>();
- if (locations != null && types != null && locations.length ==
types.length) {
- for (int i = 0; i < locations.length; i++) {
- String location = locations[i];
- if ( types[i] == IS_URL ) {
- URL url = new URL(location);
+ if (repositories != null) {
+ for (Repository repository : repositories) {
+ if (repository.getType() == RepositoryType.URL) {
+ URL url = new URL(repository.getLocation());
if (log.isDebugEnabled())
log.debug(" Including URL " + url);
set.add(url);
- } else if ( types[i] == IS_DIR ) {
- File directory = new File(location);
+ } else if (repository.getType() == RepositoryType.DIR) {
+ File directory = new File(repository.getLocation());
directory = new File(directory.getCanonicalPath());
if (!directory.exists() || !directory.isDirectory() ||
!directory.canRead())
@@ -188,8 +178,8 @@ public final class ClassLoaderFactory {
if (log.isDebugEnabled())
log.debug(" Including directory " + url);
set.add(url);
- } else if ( types[i] == IS_JAR ) {
- File file=new File(location);
+ } else if (repository.getType() == RepositoryType.JAR) {
+ File file=new File(repository.getLocation());
file = new File(file.getCanonicalPath());
if (!file.exists() || !file.canRead())
continue;
@@ -197,15 +187,15 @@ public final class ClassLoaderFactory {
if (log.isDebugEnabled())
log.debug(" Including jar file " + url);
set.add(url);
- } else if ( types[i] == IS_GLOB ) {
- File directory=new File(location);
+ } else if (repository.getType() == RepositoryType.GLOB) {
+ File directory=new File(repository.getLocation());
if (!directory.exists() || !directory.isDirectory() ||
!directory.canRead()) {
-
log.warn(sm.getString("classLoaderFactory.badDirectory",
- directory.getAbsolutePath(),
- Boolean.valueOf(directory.exists()),
- Boolean.valueOf(directory.isDirectory()),
- Boolean.valueOf(directory.canRead())));
+ log.warn("Problem with directory [" +
+ directory.getAbsolutePath() + "], exists: [" +
+ directory.exists() + "], isDirectory: [" +
+ directory.isDirectory() + "], canRead: [" +
+ directory.canRead() + "]");
continue;
}
if (log.isDebugEnabled())
@@ -250,4 +240,28 @@ public final class ClassLoaderFactory {
}
+ public static enum RepositoryType {
+ DIR,
+ GLOB,
+ JAR,
+ URL
+ }
+
+ public static class Repository {
+ private String location;
+ private RepositoryType type;
+
+ public Repository(String location, RepositoryType type) {
+ this.location = location;
+ this.type = type;
+ }
+
+ public String getLocation() {
+ return location;
+ }
+
+ public RepositoryType getType() {
+ return type;
+ }
+ }
}
Modified: tomcat/trunk/java/org/apache/catalina/startup/LocalStrings.properties
URL:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/startup/LocalStrings.properties?rev=1072160&r1=1072159&r2=1072160&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/startup/LocalStrings.properties
(original)
+++ tomcat/trunk/java/org/apache/catalina/startup/LocalStrings.properties Fri
Feb 18 21:44:13 2011
@@ -16,7 +16,6 @@
catalina.configFail=Unable to load server configuration from [{0}]
catalina.shutdownHookFail=The shutdown hook experienced an error while trying
to stop the server
catalina.stopServer=No shutdown port configured. Shut down server through OS
signal. Server not shut down.
-classLoaderFactory.badDirectory=Problem with directory [{0}], exists: [{1}],
isDirectory: [{2}], canRead: [{4}]
contextConfig.altDDNotFound=alt-dd file {0} not found
contextConfig.applicationUrl=Unable to determine URL for application web.xml
contextConfig.applicationMissing=Missing application web.xml, using defaults
only
Modified: tomcat/trunk/webapps/docs/changelog.xml
URL:
http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/changelog.xml?rev=1072160&r1=1072159&r2=1072160&view=diff
==============================================================================
--- tomcat/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/trunk/webapps/docs/changelog.xml Fri Feb 18 21:44:13 2011
@@ -49,6 +49,9 @@
<bug>48863</bug>: Better logging when specifying an invalid directory
for a class loader. Based on a patch by Ralf Hauser. (markt)
</fix>
+ <fix>
+ <bug>48870</bug>: Refactor to remove use of parallel arrays. (markt)
+ </fix>
<add>
Enhance the RemoteIpFilter and RemoteIpValve so that the modified
remote
address, remote host, protocol and server port may be used in an access
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]