summaryrefslogtreecommitdiffstats
path: root/src/java/com/jogamp/common/os
diff options
context:
space:
mode:
Diffstat (limited to 'src/java/com/jogamp/common/os')
-rw-r--r--src/java/com/jogamp/common/os/DynamicLibraryBundle.java14
-rw-r--r--src/java/com/jogamp/common/os/DynamicLibraryBundleInfo.java15
-rw-r--r--src/java/com/jogamp/common/os/NativeLibrary.java162
3 files changed, 129 insertions, 62 deletions
diff --git a/src/java/com/jogamp/common/os/DynamicLibraryBundle.java b/src/java/com/jogamp/common/os/DynamicLibraryBundle.java
index 2f51e2e..a3d6198 100644
--- a/src/java/com/jogamp/common/os/DynamicLibraryBundle.java
+++ b/src/java/com/jogamp/common/os/DynamicLibraryBundle.java
@@ -249,9 +249,12 @@ public class DynamicLibraryBundle implements DynamicLookupHelper {
return aptr;
}
- protected static final NativeLibrary loadFirstAvailable(final List<String> libNames, final ClassLoader loader, final boolean global) throws SecurityException {
+ protected static final NativeLibrary loadFirstAvailable(final List<String> libNames,
+ final boolean searchSystemPath,
+ final boolean searchSystemPathFirst,
+ final ClassLoader loader, final boolean global) throws SecurityException {
for (int i=0; i < libNames.size(); i++) {
- final NativeLibrary lib = NativeLibrary.open(libNames.get(i), loader, global);
+ final NativeLibrary lib = NativeLibrary.open(libNames.get(i), searchSystemPath, searchSystemPathFirst, loader, global);
if (lib != null) {
return lib;
}
@@ -269,7 +272,10 @@ public class DynamicLibraryBundle implements DynamicLookupHelper {
for (i=0; i < toolLibNames.size(); i++) {
final List<String> libNames = toolLibNames.get(i);
if( null != libNames && libNames.size() > 0 ) {
- lib = loadFirstAvailable(libNames, cl, info.shallLinkGlobal());
+ lib = loadFirstAvailable(libNames,
+ info.searchToolLibInSystemPath(),
+ info.searchToolLibSystemPathFirst(),
+ cl, info.shallLinkGlobal());
if ( null == lib ) {
if(DEBUG) {
System.err.println("Unable to load any Tool library of: "+libNames);
@@ -361,7 +367,7 @@ public class DynamicLibraryBundle implements DynamicLookupHelper {
final long addr = info.toolGetProcAddress(toolGetProcAddressHandle, funcName);
if(DEBUG_LOOKUP) {
if(0!=addr) {
- System.err.println("Lookup-Tool: <"+funcName+"> 0x"+Long.toHexString(addr));
+ System.err.println("Lookup-Tool: <"+funcName+"> 0x"+Long.toHexString(addr)+", via tool 0x"+Long.toHexString(toolGetProcAddressHandle));
}
}
return addr;
diff --git a/src/java/com/jogamp/common/os/DynamicLibraryBundleInfo.java b/src/java/com/jogamp/common/os/DynamicLibraryBundleInfo.java
index 7be5f25..01068b4 100644
--- a/src/java/com/jogamp/common/os/DynamicLibraryBundleInfo.java
+++ b/src/java/com/jogamp/common/os/DynamicLibraryBundleInfo.java
@@ -37,6 +37,21 @@ public interface DynamicLibraryBundleInfo {
public static final boolean DEBUG = DynamicLibraryBundle.DEBUG;
/**
+ * Returns {@code true} if tool libraries shall be searched in the system path <i>(default)</i>, otherwise {@code false}.
+ * @since 2.4.0
+ */
+ public boolean searchToolLibInSystemPath();
+
+ /**
+ * Returns {@code true} if system path shall be searched <i>first</i> <i>(default)</i>, rather than searching it last.
+ * <p>
+ * If {@link #searchToolLibInSystemPath()} is {@code false} the return value is ignored.
+ * </p>
+ * @since 2.4.0
+ */
+ public boolean searchToolLibSystemPathFirst();
+
+ /**
* If a {@link SecurityManager} is installed, user needs link permissions
* for the named libraries.
*
diff --git a/src/java/com/jogamp/common/os/NativeLibrary.java b/src/java/com/jogamp/common/os/NativeLibrary.java
index 747f92d..2ba2581 100644
--- a/src/java/com/jogamp/common/os/NativeLibrary.java
+++ b/src/java/com/jogamp/common/os/NativeLibrary.java
@@ -138,32 +138,47 @@ public final class NativeLibrary implements DynamicLookupHelper {
}
/** Opens the given native library, assuming it has the same base
- name on all platforms, looking first in the system's search
- path, 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.
- * @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, true, loader, true);
- }
-
- /** Opens the given native library, assuming it has the same base
- name on all platforms, looking first in the system's search
- path, 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.
+ name on all platforms.
+ <p>
+ The {@code searchSystemPath} argument changes the behavior to
+ either use the default system path or not at all.
+ </p>
+ <p>
+ Assuming {@code searchSystemPath} is {@code true},
+ the {@code searchSystemPathFirst} argument changes the behavior to first
+ search the default system path rather than searching it last.
+ </p>
+ * @param libName library name, with or without prefix and suffix
+ * @param searchSystemPath if {@code true} library shall be searched in the system path <i>(default)</i>, otherwise {@code false}.
+ * @param searchSystemPathFirst if {@code true} system path shall be searched <i>first</i> <i>(default)</i>, rather than searching it last.
+ * if {@code searchSystemPath} is {@code false} this argument is ignored.
+ * @param loader {@link ClassLoader} to locate the library
+ * @param global if {@code true} allows system wide access of the loaded library, otherwise access is restricted to the process.
+ * @return {@link NativeLibrary} instance or {@code null} if library could not be loaded.
* @throws SecurityException if user is not granted access for the named library.
+ * @since 2.4.0
*/
- public static final NativeLibrary open(final String libName, final ClassLoader loader, final boolean global) throws SecurityException {
- return open(libName, libName, libName, true, loader, global);
+ public static final NativeLibrary open(final String libName,
+ final boolean searchSystemPath,
+ final boolean searchSystemPathFirst,
+ final ClassLoader loader, final boolean global) throws SecurityException {
+ return open(libName, libName, libName, searchSystemPath, searchSystemPathFirst, loader, global);
}
/** Opens the given native library, assuming it has the given base
names (no "lib" prefix or ".dll/.so/.dylib" suffix) on the
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. The
- searchSystemPathFirst argument changes the behavior to first
+ the library in the case of e.g. Java Web Start.
+ <p>
+ The {@code searchSystemPath} argument changes the behavior to
+ either use the default system path or not at all.
+ </p>
+ <p>
+ Assuming {@code searchSystemPath} is {@code true},
+ 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,
@@ -171,28 +186,27 @@ public final class NativeLibrary implements DynamicLookupHelper {
ending in .so, for example .so.0), and in general if this
dynamic loading facility is used correctly the version number
will be irrelevant.
+ * @param windowsLibName windows library name, with or without prefix and suffix
+ * @param unixLibName unix library name, with or without prefix and suffix
+ * @param macOSXLibName mac-osx library name, with or without prefix and suffix
+ * @param searchSystemPath if {@code true} library shall be searched in the system path <i>(default)</i>, otherwise {@code false}.
+ * @param searchSystemPathFirst if {@code true} system path shall be searched <i>first</i> <i>(default)</i>, rather than searching it last.
+ * if {@code searchSystemPath} is {@code false} this argument is ignored.
+ * @param loader {@link ClassLoader} to locate the library
+ * @param global if {@code true} allows system wide access of the loaded library, otherwise access is restricted to the process.
+ * @return {@link NativeLibrary} instance or {@code null} if library could not be loaded.
* @throws SecurityException if user is not granted access for the named library.
*/
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, searchSystemPathFirst, loader, true);
- }
-
- /**
- * @throws SecurityException if user is not granted access for the named library.
- */
- public static final NativeLibrary open(final String windowsLibName,
- final String unixLibName,
- final String macOSXLibName,
+ final boolean searchSystemPath,
final boolean searchSystemPathFirst,
final ClassLoader loader, final boolean global) throws SecurityException {
final List<String> possiblePaths = enumerateLibraryPaths(windowsLibName,
unixLibName,
macOSXLibName,
- searchSystemPathFirst,
+ searchSystemPath, searchSystemPathFirst,
loader);
Platform.initSingleton(); // loads native gluegen-rt library
@@ -367,12 +381,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) {
@@ -388,11 +423,18 @@ public final class NativeLibrary implements DynamicLookupHelper {
final String[] baseNames = buildNames(libName);
- if (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]);
- }
+ 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
@@ -412,24 +454,25 @@ public final class NativeLibrary implements DynamicLookupHelper {
if(null != usrPath) {
count++;
}
- final String sysPath = System.getProperty("sun.boot.library.path");
- if(null != sysPath) {
- 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 (searchSystemPathFirst) {
- if(null != sysPath) {
- res[i++] = sysPath;
- }
+ if( null != sysPath && searchSystemPathFirst ) {
+ res[i++] = sysPath;
}
if(null != usrPath) {
res[i++] = usrPath;
}
- if (!searchSystemPathFirst) {
- if(null != sysPath) {
- res[i++] = sysPath;
- }
+ if( null != sysPath && !searchSystemPathFirst ) {
+ res[i++] = sysPath;
}
return res;
}
@@ -453,19 +496,22 @@ public final class NativeLibrary implements DynamicLookupHelper {
});
addPaths(userDir, baseNames, paths);
- if (!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 current working directory + natives/os-arch/ + library names
+ // 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);
- // 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);
+ 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;