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/02/28 01:25:02 UTC

svn commit: r1451053 - /tomcat/trunk/java/org/apache/catalina/loader/WebappLoader.java

Author: markt
Date: Thu Feb 28 00:25:01 2013
New Revision: 1451053

URL: http://svn.apache.org/r1451053
Log:
Refactor to make the fix for BZ54585 cleaner

Modified:
    tomcat/trunk/java/org/apache/catalina/loader/WebappLoader.java

Modified: tomcat/trunk/java/org/apache/catalina/loader/WebappLoader.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/loader/WebappLoader.java?rev=1451053&r1=1451052&r2=1451053&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/loader/WebappLoader.java (original)
+++ tomcat/trunk/java/org/apache/catalina/loader/WebappLoader.java Thu Feb 28 00:25:01 2013
@@ -811,40 +811,9 @@ public class WebappLoader extends Lifecy
 
         // Assemble the class path information from our class loader chain
         ClassLoader loader = getClassLoader();
-        int n = 0;
         while (loader != null) {
-            if (!(loader instanceof URLClassLoader)) {
-                String cp=getClasspath( loader );
-                if( cp==null ) {
-                    log.info( "Unknown loader " + loader + " " + loader.getClass());
-                } else {
-                    if (n > 0)
-                        classpath.append(File.pathSeparator);
-                    classpath.append(cp);
-                    n++;
-                }
+            if (!buildClassPath(servletContext, classpath, loader)) {
                 break;
-                //continue;
-            }
-            URL repositories[] =
-                ((URLClassLoader) loader).getURLs();
-            for (int i = 0; i < repositories.length; i++) {
-                String repository = repositories[i].toString();
-                if (repository.startsWith("file://"))
-                    repository = utf8Decode(repository.substring(7));
-                else if (repository.startsWith("file:"))
-                    repository = utf8Decode(repository.substring(5));
-                else if (repository.startsWith("jndi:"))
-                    repository =
-                        servletContext.getRealPath(repository.substring(5));
-                else
-                    continue;
-                if (repository == null)
-                    continue;
-                if (n > 0)
-                    classpath.append(File.pathSeparator);
-                classpath.append(repository);
-                n++;
             }
             loader = loader.getParent();
         }
@@ -857,6 +826,43 @@ public class WebappLoader extends Lifecy
 
     }
 
+
+    private boolean buildClassPath(ServletContext servletContext,
+            StringBuilder classpath, ClassLoader loader) {
+        if (loader instanceof URLClassLoader) {
+            URL repositories[] =
+                    ((URLClassLoader) loader).getURLs();
+                for (int i = 0; i < repositories.length; i++) {
+                    String repository = repositories[i].toString();
+                    if (repository.startsWith("file://"))
+                        repository = utf8Decode(repository.substring(7));
+                    else if (repository.startsWith("file:"))
+                        repository = utf8Decode(repository.substring(5));
+                    else if (repository.startsWith("jndi:"))
+                        repository =
+                            servletContext.getRealPath(repository.substring(5));
+                    else
+                        continue;
+                    if (repository == null)
+                        continue;
+                    if (classpath.length() > 0)
+                        classpath.append(File.pathSeparator);
+                    classpath.append(repository);
+                }
+        } else {
+            String cp = getClasspath(loader);
+            if (cp == null) {
+                log.info( "Unknown loader " + loader + " " + loader.getClass());
+            } else {
+                if (classpath.length() > 0)
+                    classpath.append(File.pathSeparator);
+                classpath.append(cp);
+            }
+            return false;
+        }
+        return true;
+    }
+
     private String utf8Decode(String input) {
         String result = null;
         try {



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org