diff options
author | Sven Gothel <[email protected]> | 2012-06-26 10:39:23 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2012-06-26 10:39:23 +0200 |
commit | 9a71703904ebfec343fb2c7266343d37a2e4c3db (patch) | |
tree | 7ca65a063f218064059743ca5cda7744cfc75c20 /src/java/com/jogamp/common/os | |
parent | 2a10f604b65f12ae5e8987bfa73cffcc1d5f796e (diff) |
Implement Bug #598 - JOGL ALL JAR File Change incl. it's Native Jar URL Derivation
+++
JNILibLoaderBase.addNativeJarLibs(..): Add API doc
JNILibLoaderBase:
"addNativeJarLibs(Class<?> classFromJavaJar, String allNativeJarBaseName, String[] atomicNativeJarBaseNames)" ->
"addNativeJarLibs(Class<?>[] classesFromJavaJars, String singleJarMarker, String[] stripBasenameSuffixes)"
Derive the 'all' (1st choice) native JAR URL solely on the given class's JAR URL.
Examples:
JOCL:
// only: jocl.jar -> jocl-natives-'os.and.arch'.jar
addNativeJarLibs(new Class<?>[] { JOCLJNILibLoader.class }, null, null );
JOGL:
final ClassLoader cl = GLProfile.class.getClassLoader();
// either: [jogl-all.jar, jogl-all-noawt.jar, jogl-all-mobile.jar] -> jogl-all-natives-<os.and.arch>.jar
// or: nativewindow-core.jar -> nativewindow-natives-<os.and.arch>.jar,
// jogl-core.jar -> jogl-natives-<os.and.arch>.jar,
// (newt-core.jar -> newt-natives-<os.and.arch>.jar)? (if available)
final String newtFactoryClassName = "com.jogamp.newt.NewtFactory";
final Class<?>[] classesFromJavaJars = new Class<?>[] { NWJNILibLoader.class, GLProfile.class, null };
if( ReflectionUtil.isClassAvailable(newtFactoryClassName, cl) ) {
classesFromJavaJars[2] = ReflectionUtil.getClass(newtFactoryClassName, false, cl);
}
JNILibLoaderBase.addNativeJarLibs(classesFromJavaJars, "-all", new String[] { "-noawt", "-mobile", "-core" } );
Efficiency / Performance:
- Reduced JAR URL lookup calls JarUtil.getJarURL(..) - JNILibLoaderBase, Platform, JarUtil
- Attempt loading Jar files (native, class, ..) only once - TempJarCache
Code Cleanup (IOUtil, JarUtil, :
- IOException if not found
- IllegalArgumentException if null argument
+++
jogamp.android-launcher.jar -> jogamp-android-launcher.jar
+++
Diffstat (limited to 'src/java/com/jogamp/common/os')
-rw-r--r-- | src/java/com/jogamp/common/os/Platform.java | 43 |
1 files changed, 26 insertions, 17 deletions
diff --git a/src/java/com/jogamp/common/os/Platform.java b/src/java/com/jogamp/common/os/Platform.java index a42ab25..ba89474 100644 --- a/src/java/com/jogamp/common/os/Platform.java +++ b/src/java/com/jogamp/common/os/Platform.java @@ -162,9 +162,21 @@ public class Platform extends PlatformPropsImpl { /** <code>true</code> if AWT is available and not in headless mode, otherwise <code>false</code>. */ public static final boolean AWT_AVAILABLE; + private static final URL platformClassJarURL; + static { PlatformPropsImpl.initSingleton(); // just documenting the order of static initialization - + + { + URL _platformClassJarURL; + try { + _platformClassJarURL = JarUtil.getJarURL(Platform.class.getName(), Platform.class.getClassLoader()); + } catch (Exception e) { + _platformClassJarURL = null; + } + platformClassJarURL = _platformClassJarURL; + } + USE_TEMP_JAR_CACHE = (OS_TYPE != OSType.ANDROID) && isRunningFromJarURL() && Debug.getBooleanProperty(useTempJarCachePropName, true, true); @@ -209,35 +221,32 @@ public class Platform extends PlatformPropsImpl { private Platform() {} /** - * Preemptively avoids initializing and using {@link TempJarCache} in case we are <b>not</b> running - * from a Jar URL, ie. plain class files. Used to set {@link USE_TEMP_JAR_CACHE}. - * <p> - * Impact: Less overhead and more robustness. - * </p> - * * @return true if we're running from a Jar URL, otherwise false */ - private static final boolean isRunningFromJarURL() { - return JarUtil.hasJarURL(Platform.class.getName(), Platform.class.getClassLoader()); + public static final boolean isRunningFromJarURL() { + return null != platformClassJarURL; } private static final 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"; + String nativeJarName = null; + URL jarUrlRoot = null; + URL nativeJarURL = null; try { - final URL jarUrlRoot = JarUtil.getURLDirname( - JarUtil.getJarSubURL(Platform.class.getName(), cl) ); - final URL nativeJarURL = JarUtil.getJarFileURL(jarUrlRoot, nativeJarName); - TempJarCache.bootstrapNativeLib(Platform.class, libBaseName, nativeJarURL, cl); + final String jarName = JarUtil.getJarBasename(platformClassJarURL); + final String nativeJarBasename = jarName.substring(0, jarName.indexOf(".jar")); // ".jar" already validated w/ JarUtil.getJarBasename(..) + nativeJarName = nativeJarBasename+"-natives-"+PlatformPropsImpl.os_and_arch+".jar"; + jarUrlRoot = JarUtil.getURLDirname( JarUtil.getJarSubURL(platformClassJarURL) ); + nativeJarURL = JarUtil.getJarFileURL(jarUrlRoot, nativeJarName); + TempJarCache.bootstrapNativeLib(Platform.class, libBaseName, nativeJarURL); } catch (Exception e0) { // IllegalArgumentException, IOException - System.err.println("Catched: "+e0.getMessage()); + System.err.println("Catched "+e0.getClass().getSimpleName()+": "+e0.getMessage()+", while TempJarCache.bootstrapNativeLib() of "+nativeJarURL+" ("+jarUrlRoot+" + "+nativeJarName+")"); } } - DynamicLibraryBundle.GlueJNILibLoader.loadLibrary(libBaseName, false, cl); + DynamicLibraryBundle.GlueJNILibLoader.loadLibrary(libBaseName, false, Platform.class.getClassLoader()); return null; } }); |