You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by ri...@apache.org on 2011/01/19 18:58:17 UTC

svn commit: r1060887 - in /felix/trunk/framework/src/main/java/org/apache/felix/framework/util/manifestparser: ManifestParser.java R4Library.java

Author: rickhall
Date: Wed Jan 19 17:58:17 2011
New Revision: 1060887

URL: http://svn.apache.org/viewvc?rev=1060887&view=rev
Log:
Fix native library extension matching; previously it was skipping
the last extension. (FELIX-2789)

Modified:
    felix/trunk/framework/src/main/java/org/apache/felix/framework/util/manifestparser/ManifestParser.java
    felix/trunk/framework/src/main/java/org/apache/felix/framework/util/manifestparser/R4Library.java

Modified: felix/trunk/framework/src/main/java/org/apache/felix/framework/util/manifestparser/ManifestParser.java
URL: http://svn.apache.org/viewvc/felix/trunk/framework/src/main/java/org/apache/felix/framework/util/manifestparser/ManifestParser.java?rev=1060887&r1=1060886&r2=1060887&view=diff
==============================================================================
--- felix/trunk/framework/src/main/java/org/apache/felix/framework/util/manifestparser/ManifestParser.java (original)
+++ felix/trunk/framework/src/main/java/org/apache/felix/framework/util/manifestparser/ManifestParser.java Wed Jan 19 17:58:17 2011
@@ -1516,7 +1516,7 @@ public class ManifestParser
      * included in the set of delimiter characters.
      * @param value the delimited string to parse.
      * @param delim the characters delimiting the tokens.
-     * @return an array of string tokens or null if there were no tokens.
+     * @return a list of string or an empty list if there are none.
     **/
     public static List<String> parseDelimitedString(String value, String delim)
     {

Modified: felix/trunk/framework/src/main/java/org/apache/felix/framework/util/manifestparser/R4Library.java
URL: http://svn.apache.org/viewvc/felix/trunk/framework/src/main/java/org/apache/felix/framework/util/manifestparser/R4Library.java?rev=1060887&r1=1060886&r2=1060887&view=diff
==============================================================================
--- felix/trunk/framework/src/main/java/org/apache/felix/framework/util/manifestparser/R4Library.java (original)
+++ felix/trunk/framework/src/main/java/org/apache/felix/framework/util/manifestparser/R4Library.java Wed Jan 19 17:58:17 2011
@@ -18,6 +18,7 @@
  */
 package org.apache.felix.framework.util.manifestparser;
 
+import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
 import org.osgi.framework.Constants;
@@ -84,43 +85,50 @@ public class R4Library
     **/
     public boolean match(Map configMap, String name)
     {
+        // First, check for an exact match.
+        boolean matched = false;
+        if (m_libraryFile.equals(name) || m_libraryFile.endsWith("/" + name))
+        {
+            matched = true;
+        }
+
+        // Then check the mapped name.
         String libname = System.mapLibraryName(name);
+        // As well as any additional library file extensions.
         List<String> exts = ManifestParser.parseDelimitedString(
             (String) configMap.get(Constants.FRAMEWORK_LIBRARY_EXTENSIONS), ",");
-        int extIdx = 0;
-
-        // First try to match the default name, then try to match any additionally
-        // specified library extensions.
-        do
+        if (exts == null)
         {
+            exts = new ArrayList<String>();
+        }
+        // For Mac OSX, try dylib too.
+        if (libname.endsWith(".jnilib") && m_libraryFile.endsWith(".dylib"))
+        {
+            exts.add("dylib");
+        }
+        // Loop until we find a match or not.
+        int extIdx = -1;
+        while (!matched && (extIdx < exts.size()))
+        {
+            // Check if the current name matches.
             if (m_libraryFile.equals(libname) || m_libraryFile.endsWith("/" + libname))
             {
-                return true;
-            }
-            else if (libname.endsWith(".jnilib") && m_libraryFile.endsWith(".dylib"))
-            {
-                libname = libname.substring(0, libname.length() - 6) + "dylib";
-                if (m_libraryFile.equals(libname) || m_libraryFile.endsWith("/" + libname))
-                {
-                    return true;
-                }
-            }
-            else if (m_libraryFile.equals(name) || m_libraryFile.endsWith("/" + name))
-            {
-                return true;
+                matched = true;
             }
 
+            // Increment extension index.
+            extIdx++;
+
             // If we have other native library extensions to try, then
             // calculate the new native library name.
-            if ((exts != null) && (extIdx < exts.size()))
+            if (!matched && (extIdx < exts.size()))
             {
                 int idx = libname.lastIndexOf(".");
                 libname = (idx < 0)
-                    ? libname + "." + exts.get(extIdx++)
-                    : libname.substring(0, idx) + "." + exts.get(extIdx++);
+                    ? libname + "." + exts.get(extIdx)
+                    : libname.substring(0, idx + 1) + exts.get(extIdx);
             }
         }
-        while ((exts != null) && (extIdx < exts.size()));
 
         return false;
     }