Add support for configurable native library extensions. (FELIX-1298)


git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@790963 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/framework/src/main/java/org/apache/felix/framework/ModuleImpl.java b/framework/src/main/java/org/apache/felix/framework/ModuleImpl.java
index 802f7f5..07875fc 100644
--- a/framework/src/main/java/org/apache/felix/framework/ModuleImpl.java
+++ b/framework/src/main/java/org/apache/felix/framework/ModuleImpl.java
@@ -1876,7 +1876,7 @@
             R4Library[] libs = getNativeLibraries();
             for (int i = 0; (libs != null) && (i < libs.length); i++)
             {
-                if (libs[i].match(name))
+                if (libs[i].match(m_configMap, name))
                 {
                     return getContent().getEntryAsNativeLibrary(libs[i].getEntryName());
                 }
diff --git a/framework/src/main/java/org/apache/felix/framework/util/manifestparser/R4Library.java b/framework/src/main/java/org/apache/felix/framework/util/manifestparser/R4Library.java
index b89e30c..e47ffc4 100644
--- a/framework/src/main/java/org/apache/felix/framework/util/manifestparser/R4Library.java
+++ b/framework/src/main/java/org/apache/felix/framework/util/manifestparser/R4Library.java
@@ -18,6 +18,7 @@
  */
 package org.apache.felix.framework.util.manifestparser;
 
+import java.util.Map;
 import org.osgi.framework.Constants;
 
 public class R4Library
@@ -80,26 +81,41 @@
      * @return <tt>true</tt> if this native library name matches this native
      *         library definition; <tt>false</tt> otherwise.
     **/
-    public boolean match(String name)
+    public boolean match(Map configMap, String name)
     {
         String libname = System.mapLibraryName(name);
-        if (m_libraryFile.equals(libname) || m_libraryFile.endsWith("/" + libname))
+        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
         {
-            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 (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;
+            }
+
+            int idx = libname.lastIndexOf(".");
+            libname = (idx < 0)
+                ? libname + "." + exts[extIdx++]
+                : libname.substring(0, idx) + "." + exts[extIdx++];
         }
-        else if (m_libraryFile.equals(name) || m_libraryFile.endsWith("/" + name))
-        {
-            return true;
-        }
+        while ((exts != null) && (extIdx < exts.length));
+
         return false;
     }