NativeLibraryLoader: Allow specifying the filename that the extracted library should have (needed for certain workarounds..)

experimental
shadowislord 10 years ago
parent 643e88cbf7
commit 8f9dfcc7c1
  1. 21
      jme3-desktop/src/main/java/com/jme3/system/NativeLibrary.java
  2. 71
      jme3-desktop/src/main/java/com/jme3/system/NativeLibraryLoader.java

@ -40,8 +40,8 @@ final class NativeLibrary {
private final String name; private final String name;
private final Platform platform; private final Platform platform;
private final boolean isJNI;
private final String pathInNativesJar; private final String pathInNativesJar;
private final String extractedAsFileName;
/** /**
* Key for map to find a library for a name and platform. * Key for map to find a library for a name and platform.
@ -98,12 +98,17 @@ final class NativeLibrary {
} }
/** /**
* If this library is a JNI library. * The filename that the library should be extracted as.
* *
* @return True if JNI library, false if native code (e.g. C/C++) library. * In some cases can be different than {@link #getPathInNativesJar() path in natives jar},
* since the names of the libraries specified in the jars are often incorrect.
* If set to <code>null</code>, then the same name as the filename in
* natives jar shall be used.
*
* @return the name that should be given to the extracted file.
*/ */
public boolean isJNI() { public String getExtractedAsName() {
return isJNI; return extractedAsFileName;
} }
/** /**
@ -121,17 +126,17 @@ final class NativeLibrary {
/** /**
* Create a new NativeLibrary. * Create a new NativeLibrary.
*/ */
public NativeLibrary(String name, Platform platform, String pathInNativesJar, boolean isJNI) { public NativeLibrary(String name, Platform platform, String pathInNativesJar, String extractedAsFileName) {
this.name = name; this.name = name;
this.platform = platform; this.platform = platform;
this.pathInNativesJar = pathInNativesJar; this.pathInNativesJar = pathInNativesJar;
this.isJNI = isJNI; this.extractedAsFileName = extractedAsFileName;
} }
/** /**
* Create a new NativeLibrary. * Create a new NativeLibrary.
*/ */
public NativeLibrary(String name, Platform platform, String pathInNativesJar) { public NativeLibrary(String name, Platform platform, String pathInNativesJar) {
this(name, platform, pathInNativesJar, true); this(name, platform, pathInNativesJar, null);
} }
} }

@ -94,13 +94,13 @@ public final class NativeLibraryLoader {
* @param path The path inside the natives-jar or classpath * @param path The path inside the natives-jar or classpath
* corresponding to this library. Must be compatible with the platform * corresponding to this library. Must be compatible with the platform
* argument. * argument.
* @param isJNI True if this is a JNI library, false if this is a regular * @param extractAsName The filename that the library should be extracted as,
* native (C/C++) library. * if null, use the same name as in the path.
*/ */
public static void registerNativeLibrary(String name, Platform platform, public static void registerNativeLibrary(String name, Platform platform,
String path, boolean isJNI) { String path, String extractAsName) {
nativeLibraryMap.put(new NativeLibrary.Key(name, platform), nativeLibraryMap.put(new NativeLibrary.Key(name, platform),
new NativeLibrary(name, platform, path, isJNI)); new NativeLibrary(name, platform, path, extractAsName));
} }
/** /**
@ -121,7 +121,7 @@ public final class NativeLibraryLoader {
*/ */
public static void registerNativeLibrary(String name, Platform platform, public static void registerNativeLibrary(String name, Platform platform,
String path) { String path) {
registerNativeLibrary(name, platform, path, true); registerNativeLibrary(name, platform, path, null);
} }
static { static {
@ -134,12 +134,13 @@ public final class NativeLibraryLoader {
registerNativeLibrary("lwjgl", Platform.MacOSX64, "native/macosx/liblwjgl.dylib"); registerNativeLibrary("lwjgl", Platform.MacOSX64, "native/macosx/liblwjgl.dylib");
// OpenAL // OpenAL
registerNativeLibrary("openal", Platform.Windows32, "native/windows/OpenAL32.dll", false); // For OSX: Need to add lib prefix when extracting
registerNativeLibrary("openal", Platform.Windows64, "native/windows/OpenAL64.dll", false); registerNativeLibrary("openal", Platform.Windows32, "native/windows/OpenAL32.dll");
registerNativeLibrary("openal", Platform.Linux32, "native/linux/libopenal.so", false); registerNativeLibrary("openal", Platform.Windows64, "native/windows/OpenAL64.dll");
registerNativeLibrary("openal", Platform.Linux64, "native/linux/libopenal64.so", false); registerNativeLibrary("openal", Platform.Linux32, "native/linux/libopenal.so");
registerNativeLibrary("openal", Platform.MacOSX32, "native/macosx/openal.dylib", false); registerNativeLibrary("openal", Platform.Linux64, "native/linux/libopenal64.so");
registerNativeLibrary("openal", Platform.MacOSX64, "native/macosx/openal.dylib", false); registerNativeLibrary("openal", Platform.MacOSX32, "native/macosx/openal.dylib", "libopenal.dylib");
registerNativeLibrary("openal", Platform.MacOSX64, "native/macosx/openal.dylib", "libopenal.dylib");
// BulletJme // BulletJme
registerNativeLibrary("bulletjme", Platform.Windows32, "native/windows/x86/bulletjme.dll"); registerNativeLibrary("bulletjme", Platform.Windows32, "native/windows/x86/bulletjme.dll");
@ -150,12 +151,13 @@ public final class NativeLibraryLoader {
registerNativeLibrary("bulletjme", Platform.MacOSX64, "native/osx/x86_64/libbulletjme.dylib"); registerNativeLibrary("bulletjme", Platform.MacOSX64, "native/osx/x86_64/libbulletjme.dylib");
// JInput // JInput
// For OSX: Need to rename extension jnilib -> dylib when extracting
registerNativeLibrary("jinput", Platform.Windows32, "native/windows/jinput-raw.dll"); registerNativeLibrary("jinput", Platform.Windows32, "native/windows/jinput-raw.dll");
registerNativeLibrary("jinput", Platform.Windows64, "native/windows/jinput-raw_64.dll"); registerNativeLibrary("jinput", Platform.Windows64, "native/windows/jinput-raw_64.dll");
registerNativeLibrary("jinput", Platform.Linux32, "native/windows/libjinput-linux.so"); registerNativeLibrary("jinput", Platform.Linux32, "native/windows/libjinput-linux.so");
registerNativeLibrary("jinput", Platform.Linux64, "native/windows/libjinput-linux64.so"); registerNativeLibrary("jinput", Platform.Linux64, "native/windows/libjinput-linux64.so");
registerNativeLibrary("jinput", Platform.MacOSX32, "native/macosx/libjinput-osx.jnilib"); registerNativeLibrary("jinput", Platform.MacOSX32, "native/macosx/libjinput-osx.jnilib", "libjinput-osx.dylib");
registerNativeLibrary("jinput", Platform.MacOSX64, "native/macosx/libjinput-osx.jnilib"); registerNativeLibrary("jinput", Platform.MacOSX64, "native/macosx/libjinput-osx.jnilib", "libjinput-osx.dylib");
// JInput Auxiliary (only required on Windows) // JInput Auxiliary (only required on Windows)
registerNativeLibrary("jinput-dx8", Platform.Windows32, "native/windows/jinput-dx8.dll"); registerNativeLibrary("jinput-dx8", Platform.Windows32, "native/windows/jinput-dx8.dll");
@ -407,23 +409,8 @@ public final class NativeLibraryLoader {
} }
String loadedAsFileName; String loadedAsFileName;
if (library.isJNI()) { if (library.getExtractedAsName() != null) {
String fileNameInJarWithoutExtension loadedAsFileName = library.getExtractedAsName();
= fileNameInJar.substring(0, fileNameInJar.lastIndexOf("."));
// if (platform.is64Bit() && !fileNameInJarWithoutExtension.endsWith("64")) {
// fileNameInJarWithoutExtension += "64";
// }
String systemJniExtension;
String dummyLib = mapLibraryName_emulated("", platform);
if (dummyLib.contains(".")) {
systemJniExtension = dummyLib.substring(dummyLib.lastIndexOf("."));
} else {
systemJniExtension = "";
}
loadedAsFileName = fileNameInJarWithoutExtension + systemJniExtension;
} else { } else {
loadedAsFileName = fileNameInJar; loadedAsFileName = fileNameInJar;
} }
@ -538,29 +525,9 @@ public final class NativeLibraryLoader {
// The library has been found and is ready to be extracted. // The library has been found and is ready to be extracted.
// Determine what filename it should be extracted as. // Determine what filename it should be extracted as.
String loadedAsFileName; String loadedAsFileName;
if (library.isJNI()) { if (library.getExtractedAsName() != null) {
// JNI libraries on Mac / JDK6 use jnilib extension. loadedAsFileName = library.getExtractedAsName();
// JNI libraries on Mac / JDK7 use dylib extension.
String fileNameInJarWithoutExtension
= fileNameInJar.substring(0, fileNameInJar.lastIndexOf("."));
// if (platform.is64Bit() && !fileNameInJarWithoutExtension.endsWith("64")) {
// // This is to avoid conflicts with 32-bit versions of the
// // same library when extracting.
// fileNameInJarWithoutExtension += "64";
// }
String systemJniExtension;
String dummyLib = System.mapLibraryName("");
if (dummyLib.contains(".")) {
systemJniExtension = dummyLib.substring(dummyLib.lastIndexOf("."));
} else {
systemJniExtension = "";
}
loadedAsFileName = fileNameInJarWithoutExtension + systemJniExtension;
} else { } else {
// Not a JNI library.
// Just use the original filename as it is in the JAR. // Just use the original filename as it is in the JAR.
loadedAsFileName = fileNameInJar; loadedAsFileName = fileNameInJar;
} }

Loading…
Cancel
Save