commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From skitch...@apache.org
Subject svn commit: r427797 - /jakarta/commons/proper/logging/trunk/src/test/org/apache/commons/logging/PathableClassLoader.java
Date Tue, 01 Aug 2006 23:45:58 GMT
Author: skitching
Date: Tue Aug  1 16:45:58 2006
New Revision: 427797

URL: http://svn.apache.org/viewvc?rev=427797&view=rev
Log:
When multiple jars on classpath match logical lib name, use jar with shortest name.
Also remove debug print statement.

Modified:
    jakarta/commons/proper/logging/trunk/src/test/org/apache/commons/logging/PathableClassLoader.java

Modified: jakarta/commons/proper/logging/trunk/src/test/org/apache/commons/logging/PathableClassLoader.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/logging/trunk/src/test/org/apache/commons/logging/PathableClassLoader.java?rev=427797&r1=427796&r2=427797&view=diff
==============================================================================
--- jakarta/commons/proper/logging/trunk/src/test/org/apache/commons/logging/PathableClassLoader.java
(original)
+++ jakarta/commons/proper/logging/trunk/src/test/org/apache/commons/logging/PathableClassLoader.java
Tue Aug  1 16:45:58 2006
@@ -245,6 +245,11 @@
      * jarfile in the path whose name starts with the logicalLib string is
      * considered a match. For example, passing "foo" will match a url
      * of <code>file:///some/where/foo-2.7.jar</code>.
+     * <p>
+     * When multiple classpath entries match the specified logicalLib string,
+     * the one with the shortest filename component is returned. This means that
+     * if "foo-1.1.jar" and "foobar-1.1.jar" are in the path, then a logicalLib
+     * name of "foo" will match the first entry above.
      */
     private URL libFromClasspath(String logicalLib) {
         ClassLoader cl = this.getClass().getClassLoader();
@@ -254,6 +259,8 @@
         
         URLClassLoader ucl = (URLClassLoader) cl;
         URL[] path = ucl.getURLs();
+        URL shortestMatch = null;
+        int shortestMatchLen = Integer.MAX_VALUE;
         for(int i=0; i<path.length; ++i) {
             URL u = path[i];
             
@@ -270,16 +277,17 @@
             }
             
             if (filename.startsWith(logicalLib)) {
-                System.out.println("found lib " + logicalLib + " at url " + u);
-                return u;
-            } else {
-                System.out.println("lib " + logicalLib + " does not match [" + filename +
"] at url " + u);
+                // ok, this is a candidate
+                if (filename.length() < shortestMatchLen) {
+                    shortestMatch = u;
+                    shortestMatchLen = filename.length();
+                }
             }
         }
         
-        return null;
-        
+        return shortestMatch;
     }
+
     /**
      * Override ClassLoader method.
      * <p>



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


Mime
View raw message