You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by mt...@apache.org on 2009/09/24 18:21:05 UTC

svn commit: r818534 - /commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Library.java

Author: mturk
Date: Thu Sep 24 16:21:04 2009
New Revision: 818534

URL: http://svn.apache.org/viewvc?rev=818534&view=rev
Log:
Use 32/64 resource paths

Modified:
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Library.java

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Library.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Library.java?rev=818534&r1=818533&r2=818534&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Library.java (original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Library.java Thu Sep 24 16:21:04 2009
@@ -62,10 +62,14 @@
         return so + "." + SystemId.getSoExtension();
     }
 
-    private static String getResName(String name)
+    private static String getResName(String name, boolean arch)
     {
-        String res = packageName + ".platform." + SystemId.getSysname() + ".";
-        return res.replace('.', '/') + name;
+        String res = packageName.replace('.', '/') + "/platform/" +
+                     SystemId.getSysname() + "/";
+        if (arch)
+            return res + SystemId.getDataModel() + "/" + name;
+        else
+            return res + name;
     }
 
     /**
@@ -92,10 +96,11 @@
         @]]JAVA5_CODE@
     }
 
-    private static File extractResource(InputStream is, String name)
+    private static File extractResource(InputStream is, String name,
+                                        boolean arch)
         throws IllegalArgumentException, IOException
     {
-        File f = Loader.libFile(System.mapLibraryName(name));
+        File f = Loader.libFile(System.mapLibraryName(name), arch);
         try {
             byte [] buf = new byte[4096];
             FileOutputStream os = new FileOutputStream(f);
@@ -178,11 +183,11 @@
             // Ignore
         }
         /* Step 3.
-         * Try to load from classpath.
+         * Try to load from classpath/platform/os/32|64/libname.
          */
         String resname;
         InputStream is = null;
-        resname = getResName(getSoName(libname));
+        resname = getResName(getSoName(libname), true);
         try {
             is = Library.class.getClassLoader().getResourceAsStream(resname);
         } catch (Exception ex) {
@@ -192,7 +197,7 @@
             /* We have found a libname.
              */
             try {
-                File f = extractResource(is, libname);
+                File f = extractResource(is, libname, true);
                 if (f != null) {
                     System.load(f.getPath());
                     Loader.add(libname, f);
@@ -201,6 +206,30 @@
             } catch (Exception ex) {
             }
         }
+
+        /* Step 4.
+         * Try to load from classpath/platform/os/libname.
+         */
+        resname = getResName(getSoName(libname), false);
+        try {
+            is = Library.class.getClassLoader().getResourceAsStream(resname);
+        } catch (Exception ex) {
+            // Ignore
+        }
+        if (is != null) {
+            /* We have found a libname.
+             */
+            try {
+                File f = extractResource(is, libname, false);
+                if (f != null) {
+                    System.load(f.getPath());
+                    Loader.add(libname, f);
+                    return true;
+                }
+            } catch (Exception ex) {
+            }
+        }
+
         /* No luck :(
          * Return false to the caller.
          */