summaryrefslogtreecommitdiffstats
path: root/src/java/com/jogamp
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2015-08-18 02:15:31 +0200
committerSven Gothel <[email protected]>2015-08-18 02:15:31 +0200
commit6557eedd0f0ec98d743c762a698bb028e88a9e16 (patch)
tree6577c817b825f5b7dc749b06b9688302e9d85e06 /src/java/com/jogamp
parent7d4b18401ff0a1a6b72237f8c482007fbd2623dd (diff)
Bug 1194: Reinstate system-lib search for NativeLibrary.open(..) and PlatformPropsImpl.findSysLib(..).
This patch partially reverts of commit d12e4d4ea279998b27457691038e709879dcaca6. NativeLibrary.open(..) requires search of system libraries, since it loads the actual 'tool library' for which we generate the JNI binding. The 'tool library' is preferably the system wide installed version, e.g. libGL.so etc. PlatformPropsImpl.findSysLib(..) also requires finding system libraries as needed for PlatformPropsImpl.queryElfFile(..), i.e. using libjava.so etc. Only the JNI 'glue library', glueing java calls to the 'tool library', shall not use the system wide library search since we shall only use JogAmp provided instances here. This patch also reinstates binary compatibility w/ prev. GlueGen JARs since NativeLibrary.enumerateLibraryPath(..) is public. +++ Further more 'NativeLibrary.enumerateLibraryPath(..)' now adds OSX system framework search _before_ the user path in case 'searchSystemPath && searchSystemPathFirst'. Original code always added this search to the end, which does not match the intended behavior (-> bug).
Diffstat (limited to 'src/java/com/jogamp')
-rw-r--r--src/java/com/jogamp/common/os/NativeLibrary.java83
1 files changed, 78 insertions, 5 deletions
diff --git a/src/java/com/jogamp/common/os/NativeLibrary.java b/src/java/com/jogamp/common/os/NativeLibrary.java
index 1570308..49e921f 100644
--- a/src/java/com/jogamp/common/os/NativeLibrary.java
+++ b/src/java/com/jogamp/common/os/NativeLibrary.java
@@ -144,7 +144,7 @@ public final class NativeLibrary implements DynamicLookupHelper {
* @throws SecurityException if user is not granted access for the named library.
*/
public static final NativeLibrary open(final String libName, final ClassLoader loader) throws SecurityException {
- return open(libName, libName, libName, loader, true);
+ return open(libName, libName, libName, true, loader, true);
}
/** Opens the given native library, assuming it has the same base
@@ -154,7 +154,7 @@ public final class NativeLibrary implements DynamicLookupHelper {
* @throws SecurityException if user is not granted access for the named library.
*/
public static final NativeLibrary open(final String libName, final ClassLoader loader, final boolean global) throws SecurityException {
- return open(libName, libName, libName, loader, global);
+ return open(libName, libName, libName, true, loader, global);
}
/** Opens the given native library, assuming it has the given base
@@ -162,6 +162,10 @@ public final class NativeLibrary implements DynamicLookupHelper {
Windows, Unix and Mac OS X platforms, respectively, and in the
context of the specified ClassLoader, which is used to help find
the library in the case of e.g. Java Web Start.
+ <p>
+ The {@code searchSystemPathFirst} argument changes the behavior to first
+ search the default system path rather than searching it last.
+ </p>
Note that we do not currently handle DSO versioning on Unix.
Experience with JOAL and OpenAL has shown that it is extremely
problematic to rely on a specific .so version (for one thing,
@@ -174,8 +178,9 @@ public final class NativeLibrary implements DynamicLookupHelper {
public static final NativeLibrary open(final String windowsLibName,
final String unixLibName,
final String macOSXLibName,
+ final boolean searchSystemPathFirst,
final ClassLoader loader) throws SecurityException {
- return open(windowsLibName, unixLibName, macOSXLibName, loader, true);
+ return open(windowsLibName, unixLibName, macOSXLibName, searchSystemPathFirst, loader, true);
}
/**
@@ -184,10 +189,13 @@ public final class NativeLibrary implements DynamicLookupHelper {
public static final NativeLibrary open(final String windowsLibName,
final String unixLibName,
final String macOSXLibName,
- final ClassLoader loader, final boolean global) throws SecurityException {
+ final boolean searchSystemPathFirst,
+ final ClassLoader loader,
+ final boolean global) throws SecurityException {
final List<String> possiblePaths = enumerateLibraryPaths(windowsLibName,
unixLibName,
macOSXLibName,
+ searchSystemPathFirst,
loader);
Platform.initSingleton(); // loads native gluegen-rt library
@@ -362,11 +370,33 @@ public final class NativeLibrary implements DynamicLookupHelper {
/** Given the base library names (no prefixes/suffixes) for the
various platforms, enumerate the possible locations and names of
- the indicated native library on the system. */
+ the indicated native library on the system not using the system path. */
public static final List<String> enumerateLibraryPaths(final String windowsLibName,
final String unixLibName,
final String macOSXLibName,
final ClassLoader loader) {
+ return enumerateLibraryPaths(windowsLibName, unixLibName, macOSXLibName,
+ false /* searchSystemPath */, false /* searchSystemPathFirst */,
+ loader);
+ }
+ /** Given the base library names (no prefixes/suffixes) for the
+ various platforms, enumerate the possible locations and names of
+ the indicated native library on the system using the system path. */
+ public static final List<String> enumerateLibraryPaths(final String windowsLibName,
+ final String unixLibName,
+ final String macOSXLibName,
+ final boolean searchSystemPathFirst,
+ final ClassLoader loader) {
+ return enumerateLibraryPaths(windowsLibName, unixLibName, macOSXLibName,
+ true /* searchSystemPath */, searchSystemPathFirst,
+ loader);
+ }
+ private static final List<String> enumerateLibraryPaths(final String windowsLibName,
+ final String unixLibName,
+ final String macOSXLibName,
+ final boolean searchSystemPath,
+ final boolean searchSystemPathFirst,
+ final ClassLoader loader) {
final List<String> paths = new ArrayList<String>();
final String libName = selectName(windowsLibName, unixLibName, macOSXLibName);
if (libName == null) {
@@ -382,6 +412,20 @@ public final class NativeLibrary implements DynamicLookupHelper {
final String[] baseNames = buildNames(libName);
+ if( searchSystemPath && searchSystemPathFirst ) {
+ // Add just the library names to use the OS's search algorithm
+ for (int i = 0; i < baseNames.length; i++) {
+ paths.add(baseNames[i]);
+ }
+ // Add probable Mac OS X-specific paths
+ if ( isOSX ) {
+ // Add historical location
+ addPaths("/Library/Frameworks/" + libName + ".Framework", baseNames, paths);
+ // Add current location
+ addPaths("/System/Library/Frameworks/" + libName + ".Framework", baseNames, paths);
+ }
+ }
+
// The idea to ask the ClassLoader to find the library is borrowed
// from the LWJGL library
final String clPath = findLibrary(libName, loader);
@@ -399,11 +443,26 @@ public final class NativeLibrary implements DynamicLookupHelper {
if(null != usrPath) {
count++;
}
+ final String sysPath;
+ if( searchSystemPath ) {
+ sysPath = System.getProperty("sun.boot.library.path");
+ if(null != sysPath) {
+ count++;
+ }
+ } else {
+ sysPath = null;
+ }
final String[] res = new String[count];
int i=0;
+ if( null != sysPath && searchSystemPathFirst ) {
+ res[i++] = sysPath;
+ }
if(null != usrPath) {
res[i++] = usrPath;
}
+ if( null != sysPath && !searchSystemPathFirst ) {
+ res[i++] = sysPath;
+ }
return res;
}
});
@@ -430,6 +489,20 @@ public final class NativeLibrary implements DynamicLookupHelper {
// to handle Bug 1145 cc1 using an unpacked fat-jar
addPaths(userDir+File.separator+"natives"+File.separator+PlatformPropsImpl.os_and_arch+File.separator, baseNames, paths);
+ if( searchSystemPath && !searchSystemPathFirst ) {
+ // Add just the library names to use the OS's search algorithm
+ for (int i = 0; i < baseNames.length; i++) {
+ paths.add(baseNames[i]);
+ }
+ // Add probable Mac OS X-specific paths
+ if ( isOSX ) {
+ // Add historical location
+ addPaths("/Library/Frameworks/" + libName + ".Framework", baseNames, paths);
+ // Add current location
+ addPaths("/System/Library/Frameworks/" + libName + ".Framework", baseNames, paths);
+ }
+ }
+
return paths;
}