Blame SOURCES/jna-3.5.2-loadlibrary.patch

67ea67
diff -up ./src/com/sun/jna/Native.java.loadlib ./src/com/sun/jna/Native.java
67ea67
--- ./src/com/sun/jna/Native.java.loadlib	2013-04-29 15:23:30.988702267 +0200
67ea67
+++ ./src/com/sun/jna/Native.java	2013-04-29 15:25:55.409671266 +0200
67ea67
@@ -670,99 +670,22 @@ public final class Native {
67ea67
 
67ea67
     /**
67ea67
      * Loads the JNA stub library.
67ea67
-     * First tries jna.boot.library.path, then the system path, then from the
67ea67
-     * jar file.
67ea67
+     * MODIFIED FROM UPSTREAM - we rip out all sorts of gunk here that is
67ea67
+     * unnecessary when JNA is properly installed with the OS.
67ea67
      */
67ea67
     private static void loadNativeLibrary() {
67ea67
         removeTemporaryFiles();
67ea67
 
67ea67
-        String libName = System.getProperty("jna.boot.library.name", "jnidispatch");
67ea67
-        String bootPath = System.getProperty("jna.boot.library.path");
67ea67
-        if (bootPath != null) {
67ea67
-            // String.split not available in 1.4
67ea67
-            StringTokenizer dirs = new StringTokenizer(bootPath, File.pathSeparator);
67ea67
-            while (dirs.hasMoreTokens()) {
67ea67
-                String dir = dirs.nextToken();
67ea67
-                File file = new File(new File(dir), System.mapLibraryName(libName));
67ea67
-                String path = file.getAbsolutePath();
67ea67
-                if (file.exists()) {
67ea67
-                    try {
67ea67
-                        System.load(path);
67ea67
-                        nativeLibraryPath = path;
67ea67
-                        return;
67ea67
-                    } catch (UnsatisfiedLinkError ex) {
67ea67
-                        // Not a problem if already loaded in anoteher class loader
67ea67
-                        // Unfortunately we can't distinguish the difference...
67ea67
-                        //System.out.println("File found at " + file + " but not loadable: " + ex.getMessage());
67ea67
-                    }
67ea67
-                }
67ea67
-                if (Platform.isMac()) {
67ea67
-                    String orig, ext;
67ea67
-                    if (path.endsWith("dylib")) {
67ea67
-                        orig = "dylib";
67ea67
-                        ext = "jnilib";
67ea67
-                    } else {
67ea67
-                        orig = "jnilib";
67ea67
-                        ext = "dylib";
67ea67
-                    }
67ea67
-                    path = path.substring(0, path.lastIndexOf(orig)) + ext;
67ea67
-                    if (new File(path).exists()) {
67ea67
-                        try {
67ea67
-                            System.load(path);
67ea67
-                            nativeLibraryPath = path;
67ea67
-                            return;
67ea67
-                        } catch (UnsatisfiedLinkError ex) {
67ea67
-                            System.err.println("File found at " + path + " but not loadable: " + ex.getMessage());
67ea67
-                        }
67ea67
-                    }
67ea67
-                }
67ea67
-            }
67ea67
-        }
67ea67
-        if (Platform.isAndroid()) {
67ea67
-            // Native libraries on android must be bundled with the APK
67ea67
-            System.setProperty("jna.nounpack", "true");
67ea67
-        }
67ea67
         try {
67ea67
-            if (!Boolean.getBoolean("jna.nosys")) {
67ea67
-                System.loadLibrary(libName);
67ea67
-                return;
67ea67
-            }
67ea67
+            System.load("@JNIPATH@/" + System.mapLibraryName("jnidispatch"));
67ea67
+            nativeLibraryPath = "@JNIPATH@/" + System.mapLibraryName("jnidispatch");
67ea67
         }
67ea67
         catch(UnsatisfiedLinkError e) {
67ea67
-            if (Boolean.getBoolean("jna.nounpack")) {
67ea67
-                throw e;
67ea67
-            }
67ea67
-        }
67ea67
-        if (!Boolean.getBoolean("jna.nounpack")) {
67ea67
-            loadNativeLibraryFromJar();
67ea67
-            return;
67ea67
+            throw new RuntimeException(e);
67ea67
         }
67ea67
-        throw new UnsatisfiedLinkError("Native jnidispatch library not found");
67ea67
     }
67ea67
 
67ea67
     static final String JNA_TMPLIB_PREFIX = "jna";
67ea67
-    /**
67ea67
-     * Attempts to load the native library resource from the filesystem,
67ea67
-     * extracting the JNA stub library from jna.jar if not already available.
67ea67
-     */
67ea67
-    private static void loadNativeLibraryFromJar() {
67ea67
-        try {
67ea67
-            String prefix = "com/sun/jna/" + getNativeLibraryResourcePrefix();
67ea67
-            File lib = extractFromResourcePath("jnidispatch", prefix, Native.class.getClassLoader());
67ea67
-            System.load(lib.getAbsolutePath());
67ea67
-            nativeLibraryPath = lib.getAbsolutePath();
67ea67
-            // Attempt to delete immediately once jnidispatch is successfully
67ea67
-            // loaded.  This avoids the complexity of trying to do so on "exit",
67ea67
-            // which point can vary under different circumstances (native
67ea67
-            // compilation, dynamically loaded modules, normal application, etc).
67ea67
-            if (isUnpacked(lib)) {
67ea67
-                deleteLibrary(lib);
67ea67
-            }
67ea67
-        }
67ea67
-        catch(IOException e) {
67ea67
-            throw new UnsatisfiedLinkError(e.getMessage());
67ea67
-        }
67ea67
-    }
67ea67
 
67ea67
     /** Identify temporary files unpacked from classpath jar files. */
67ea67
     static boolean isUnpacked(File file) {