diff options
author | Sven Gothel <[email protected]> | 2012-05-04 01:12:25 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2012-05-04 01:12:25 +0200 |
commit | cc76889a6fe96cffb91c9a3aa7934878c0ecd97e (patch) | |
tree | 229403dd5b617a60065e2f77ecee48158a1d5e6a /src/java/com/jogamp/common/os | |
parent | ce9ace37ca883a844fbab7aef8c85197282442ed (diff) |
Use ClassLoader to find JNI native libraries. ClassLoader was only used for tool native libraries.
NativeLibrary: Expose 'String findLibrary(String libName, ClassLoader loader)',
allowing utilization of System.load(loader.findLibrary(libName)).
JNILibLoaderBase.loadLibrary(): Add optional ClassLoader argument, used to locate the library
DynamicLibraryBundle: Use DynamicLibraryInfo's ClassLoader to find native libraries (tool + jni)
Diffstat (limited to 'src/java/com/jogamp/common/os')
-rwxr-xr-x | src/java/com/jogamp/common/os/DynamicLibraryBundle.java | 16 | ||||
-rwxr-xr-x | src/java/com/jogamp/common/os/NativeLibrary.java | 17 | ||||
-rw-r--r-- | src/java/com/jogamp/common/os/Platform.java | 4 |
3 files changed, 21 insertions, 16 deletions
diff --git a/src/java/com/jogamp/common/os/DynamicLibraryBundle.java b/src/java/com/jogamp/common/os/DynamicLibraryBundle.java index fc302e9..427f522 100755 --- a/src/java/com/jogamp/common/os/DynamicLibraryBundle.java +++ b/src/java/com/jogamp/common/os/DynamicLibraryBundle.java @@ -42,8 +42,8 @@ import com.jogamp.common.util.RunnableExecutor; /** * Provides bundling of:<br> * <ul> - * <li>The to-be-glued native library, eg OpenGL32.dll. From hereon this is referred as the Tool.</li> - * <li>The JNI glue-code native library, eg jogl_desktop.dll. From heron this is referred as the Glue</li> + * <li>The to-be-glued native library, eg OpenGL32.dll. From here on this is referred as the Tool.</li> + * <li>The JNI glue-code native library, eg jogl_desktop.dll. From here on this is referred as the Glue</li> * </ul><br> * An instance provides a complete {@link com.jogamp.common.os.DynamicLookupHelper} * to {@link com.jogamp.gluegen.runtime.ProcAddressTable#reset(com.jogamp.common.os.DynamicLookupHelper) reset} @@ -52,7 +52,7 @@ import com.jogamp.common.util.RunnableExecutor; * <ul> * <li> loads the Tool native library via * {@link com.jogamp.common.os.NativeLibrary#open(java.lang.String, java.lang.ClassLoader, boolean) NativeLibrary's open method}</li> - * <li> loads the {@link com.jogamp.common.jvm.JNILibLoaderBase#loadLibrary(java.lang.String, java.lang.String[], boolean) Glue native library}</li> + * <li> loads the {@link com.jogamp.common.jvm.JNILibLoaderBase#loadLibrary(java.lang.String, java.lang.String[], boolean, ClassLoader) Glue native library}</li> * <li> resolves the Tool's {@link com.jogamp.common.os.DynamicLibraryBundleInfo#getToolGetProcAddressFuncNameList() GetProcAddress}. (optional)</li> * </ul> */ @@ -251,13 +251,13 @@ public class DynamicLibraryBundle implements DynamicLookupHelper { } toolLibLoadedNumber = 0; - ClassLoader loader = getClass().getClassLoader(); + final ClassLoader cl = info.getClass().getClassLoader(); NativeLibrary lib = null; for (i=0; i < toolLibNames.size(); i++) { final List<String> libNames = toolLibNames.get(i); if( null != libNames && libNames.size() > 0 ) { - lib = loadFirstAvailable(libNames, loader, info.shallLinkGlobal()); + lib = loadFirstAvailable(libNames, cl, info.shallLinkGlobal()); if ( null == lib ) { if(DEBUG) { System.err.println("Unable to load any Tool library of: "+libNames); @@ -285,7 +285,7 @@ public class DynamicLibraryBundle implements DynamicLookupHelper { boolean ignoreError = true; boolean res; try { - res = GlueJNILibLoader.loadLibrary(libName, ignoreError); + res = GlueJNILibLoader.loadLibrary(libName, ignoreError, cl); if(DEBUG && !res) { System.err.println("Info: Could not load JNI/Glue library: "+libName); } @@ -375,8 +375,8 @@ public class DynamicLibraryBundle implements DynamicLookupHelper { /** Inherit access */ static class GlueJNILibLoader extends JNILibLoaderBase { - protected static synchronized boolean loadLibrary(String libname, boolean ignoreError) { - return JNILibLoaderBase.loadLibrary(libname, ignoreError); + protected static synchronized boolean loadLibrary(String libname, boolean ignoreError, ClassLoader cl) { + return JNILibLoaderBase.loadLibrary(libname, ignoreError, cl); } } } diff --git a/src/java/com/jogamp/common/os/NativeLibrary.java b/src/java/com/jogamp/common/os/NativeLibrary.java index 69d69b6..d0b135e 100755 --- a/src/java/com/jogamp/common/os/NativeLibrary.java +++ b/src/java/com/jogamp/common/os/NativeLibrary.java @@ -299,10 +299,7 @@ public class NativeLibrary implements DynamicLookupHelper { // The idea to ask the ClassLoader to find the library is borrowed // from the LWJGL library - String clPath = getPathFromClassLoader(libName, loader); - if (DEBUG) { - System.err.println("NativeLibrary Class loader path to " + libName + ": " + clPath); - } + final String clPath = findLibrary(libName, loader); if (clPath != null) { paths.add(clPath); } @@ -422,9 +419,10 @@ public class NativeLibrary implements DynamicLookupHelper { private static boolean initializedFindLibraryMethod = false; private static Method findLibraryMethod = null; - private static String getPathFromClassLoader(final String libName, final ClassLoader loader) { - if (loader == null) + private static String findLibraryImpl(final String libName, final ClassLoader loader) { + if (loader == null) { return null; + } if (!initializedFindLibraryMethod) { AccessController.doPrivileged(new PrivilegedAction<Object>() { public Object run() { @@ -460,4 +458,11 @@ public class NativeLibrary implements DynamicLookupHelper { } return null; } + public static String findLibrary(final String libName, final ClassLoader loader) { + final String res = findLibraryImpl(libName, loader); + if (DEBUG) { + System.err.println("NativeLibrary.findLibrary(<"+libName+">, "+loader+"): "+res); + } + return res; + } } diff --git a/src/java/com/jogamp/common/os/Platform.java b/src/java/com/jogamp/common/os/Platform.java index fa565a0..49ae512 100644 --- a/src/java/com/jogamp/common/os/Platform.java +++ b/src/java/com/jogamp/common/os/Platform.java @@ -378,9 +378,9 @@ public class Platform { private static void loadGlueGenRTImpl() { AccessController.doPrivileged(new PrivilegedAction<Object>() { public Object run() { + final ClassLoader cl = Platform.class.getClassLoader(); if(USE_TEMP_JAR_CACHE && TempJarCache.initSingleton()) { final String nativeJarName = libBaseName+"-natives-"+os_and_arch+".jar"; - final ClassLoader cl = Platform.class.getClassLoader(); try { final URL jarUrlRoot = JarUtil.getURLDirname( JarUtil.getJarSubURL(Platform.class.getName(), cl) ); @@ -391,7 +391,7 @@ public class Platform { System.err.println("Catched: "+e0.getMessage()); } } - DynamicLibraryBundle.GlueJNILibLoader.loadLibrary(libBaseName, false); + DynamicLibraryBundle.GlueJNILibLoader.loadLibrary(libBaseName, false, cl); return null; } }); |