jna/jna-3.0.2-loadlibrary.patch
2008-11-01 01:05:21 +00:00

122 lines
5.1 KiB
Diff

diff -ur jna-3.0.9/src/com/sun/jna/Native.java jna-3.0.9.orig/src/com/sun/jna/Native.java
--- jna-3.0.9/src/com/sun/jna/Native.java 2008-10-31 20:35:02.000000000 -0400
+++ jna-3.0.9.orig/src/com/sun/jna/Native.java 2008-10-31 20:42:23.000000000 -0400
@@ -504,109 +504,17 @@
}
/**
- * Loads the JNA stub library. It will first attempt to load this library
- * from the directories specified in jna.boot.library.path. If that fails,
- * it will fallback to loading from the system library paths. Finally it will
- * attempt to extract the stub library from from the JNA jar file, and load it.
- * <p>
- * The jna.boot.library.path property is mainly to support jna.jar being
- * included in -Xbootclasspath, where java.library.path and LD_LIBRARY_PATH
- * are ignored. It might also be useful in other situations.
- * </p>
+ * Loads the JNA stub library.
+ *
+ ** MODIFIED FROM UPSTREAM - we rip out all sorts of gunk here that is
+ ** unnecessary when JNA is properly installed with the OS.
*/
private static void loadNativeLibrary() {
- String libName = "jnidispatch";
- String bootPath = System.getProperty("jna.boot.library.path");
- if (bootPath != null) {
- String[] dirs = bootPath.split(File.pathSeparator);
- for (int i = 0; i < dirs.length; ++i) {
- String path = new File(new File(dirs[i]), System.mapLibraryName(libName)).getAbsolutePath();
- try {
- System.load(path);
- return;
- } catch (UnsatisfiedLinkError ex) {
- }
- if (Platform.isMac()) {
- String orig, ext;
- if (path.endsWith("dylib")) {
- orig = "dylib";
- ext = "jnilib";
- } else {
- orig = "jnilib";
- ext = "dylib";
- }
- try {
- System.load(path.substring(0, path.lastIndexOf(orig)) + ext);
- return;
- } catch (UnsatisfiedLinkError ex) {
- }
- }
- }
- }
try {
- System.loadLibrary(libName);
- }
- catch(UnsatisfiedLinkError e) {
- loadNativeLibraryFromJar();
- }
- }
-
- /**
- * Extracts and loads the JNA stub library from jna.jar
- */
- private static void loadNativeLibraryFromJar() {
- String libname = System.mapLibraryName("jnidispatch");
- String resourceName = getNativeLibraryResourcePath() + "/" + libname;
- URL url = Native.class.getResource(resourceName);
-
- // Add an ugly hack for OpenJDK (soylatte) - JNI libs use the usual .dylib extension
- if (url == null && Platform.isMac() && resourceName.endsWith(".dylib")) {
- resourceName = resourceName.substring(0, resourceName.lastIndexOf(".dylib")) + ".jnilib";
- url = Native.class.getResource(resourceName);
- }
- if (url == null) {
- throw new UnsatisfiedLinkError("jnidispatch (" + resourceName
- + ") not found in resource path");
- }
-
- File lib = null;
- if (url.getProtocol().toLowerCase().equals("file")) {
- // NOTE: use older API for 1.3 compatibility
- lib = new File(URLDecoder.decode(url.getPath()));
- }
- else {
- InputStream is = Native.class.getResourceAsStream(resourceName);
- if (is == null) {
- throw new Error("Can't obtain jnidispatch InputStream");
- }
-
- FileOutputStream fos = null;
- try {
- // Suffix is required on windows, or library fails to load
- // Let Java pick the suffix
- lib = File.createTempFile("jna", null);
- lib.deleteOnExit();
- if (Platform.deleteNativeLibraryAfterVMExit()) {
- Runtime.getRuntime().addShutdownHook(new DeleteNativeLibrary(lib));
- }
- fos = new FileOutputStream(lib);
- int count;
- byte[] buf = new byte[1024];
- while ((count = is.read(buf, 0, buf.length)) > 0) {
- fos.write(buf, 0, count);
- }
- }
- catch(IOException e) {
- throw new Error("Failed to create temporary file for jnidispatch library: " + e);
- }
- finally {
- try { is.close(); } catch(IOException e) { }
- if (fos != null) {
- try { fos.close(); } catch(IOException e) { }
- }
- }
+ System.load("@JNIPATH@/" + System.mapLibraryName("jnidispatch"));
+ } catch(UnsatisfiedLinkError e) {
+ throw new RuntimeException(e);
}
- System.load(lib.getAbsolutePath());
}
/**
Only in jna-3.0.9.orig/src/com/sun/jna: Native.java~