From 46faa59d439ef235d7691fc64d56eedc600ffa1a Mon Sep 17 00:00:00 2001
From: Mark Raynsford
* Generic description:
*
Date: Mon, 30 Jun 2014 12:49:39 +0000
Subject: Clean up native library loading and remove the ability to strip
prefixes.
Bug: 1023
Bug: 1024
---
.../com/jogamp/common/jvm/JNILibLoaderBase.java | 240 +++++++++++----------
1 file changed, 131 insertions(+), 109 deletions(-)
(limited to 'src/java/com/jogamp/common/jvm/JNILibLoaderBase.java')
diff --git a/src/java/com/jogamp/common/jvm/JNILibLoaderBase.java b/src/java/com/jogamp/common/jvm/JNILibLoaderBase.java
index 033f1a5..5106a27 100644
--- a/src/java/com/jogamp/common/jvm/JNILibLoaderBase.java
+++ b/src/java/com/jogamp/common/jvm/JNILibLoaderBase.java
@@ -150,66 +150,70 @@ public class JNILibLoaderBase {
loaderAction = action;
}
- /**
- *
- * @param classFromJavaJar
- * @param classJarURI
- * @param jarBasename jar basename w/ suffix
- * @param nativeJarBasename native jar basename w/ suffix
- * @param msg
- * @return
- * @throws IOException
- * @throws SecurityException
- * @throws URISyntaxException
- */
- /* pp */ static final boolean addNativeJarLibsImpl(Class> classFromJavaJar, URI classJarURI, String jarBasename, String nativeJarBasename, StringBuilder msg)
+ private static final boolean addNativeJarLibsImpl(Class> classFromJavaJar, URI classJarURI, String jarBasename, String nativeJarBasename)
throws IOException, SecurityException, URISyntaxException
{
- msg.setLength(0); // reset
- msg.append("addNativeJarLibsImpl(classFromJavaJar ").append(classFromJavaJar).append(", classJarURI ").append(classJarURI)
- .append(", nativeJarBaseName ").append(nativeJarBasename).append("): ");
+ if (DEBUG) {
+ StringBuilder msg = new StringBuilder();
+ msg.append("JNILibLoaderBase: addNativeJarLibsImpl(\n");
+ msg.append(" classFromJavaJar = ").append(classFromJavaJar).append("\n");
+ msg.append(" classJarURI = ").append(classJarURI).append("\n");
+ msg.append(" jarBasename = ").append(jarBasename).append("\n");
+ msg.append(" nativeJarBasename = ").append(nativeJarBasename).append("\n");
+ msg.append(")");
+ System.err.println(msg.toString());
+ }
+
boolean ok = false;
- if(TempJarCache.isInitialized()) {
- final URI jarSubURI = JarUtil.getJarSubURI( classJarURI );
- if(null == jarSubURI) {
- throw new IllegalArgumentException("JarSubURI is null of: "+classJarURI);
- }
- final String jarUriRoot_s = IOUtil.getURIDirname( jarSubURI.toString() );
- msg.append("[ ").append(jarSubURI.toString()).append(" -> ").append(jarUriRoot_s).append(" ] + ");
-
- final String nativeLibraryPath = "natives/"+PlatformPropsImpl.os_and_arch+"/";
- final ClassLoader cl = classFromJavaJar.getClassLoader();
- final URL nativeLibraryURI = cl.getResource(nativeLibraryPath);
- if( null != nativeLibraryURI ) {
- // We probably have one big-fat jar file, containing java classes
- // and all native platform libraries under 'natives/os.and.arch'!
- final URI nativeJarURI = JarUtil.getJarFileURI(jarUriRoot_s+jarBasename);
- if( TempJarCache.addNativeLibs(classFromJavaJar, nativeJarURI, nativeLibraryPath) ) {
- ok = true;
- msg.append(jarBasename).append(" -> fat: ").append(nativeJarURI);
+
+ final URI jarSubURI = JarUtil.getJarSubURI( classJarURI );
+ if (null == jarSubURI) {
+ throw new IllegalArgumentException("JarSubURI is null of: "+classJarURI);
+ }
+
+ final String jarUriRoot_s = IOUtil.getURIDirname( jarSubURI.toString() );
+
+ if (DEBUG) {
+ System.err.printf("JNILibLoaderBase: addNativeJarLibsImpl: initial: %s -> %s\n", jarSubURI, jarUriRoot_s);
+ }
+
+ final String nativeLibraryPath = String.format("natives/%s/", PlatformPropsImpl.os_and_arch);
+ final ClassLoader cl = classFromJavaJar.getClassLoader();
+ final URL nativeLibraryURI = cl.getResource(nativeLibraryPath);
+ if (null != nativeLibraryURI) {
+ // We probably have one big-fat jar file, containing java classes
+ // and all native platform libraries under 'natives/os.and.arch'!
+ final URI nativeJarURI = JarUtil.getJarFileURI(jarUriRoot_s+jarBasename);
+ if( TempJarCache.addNativeLibs(classFromJavaJar, nativeJarURI, nativeLibraryPath) ) {
+ ok = true;
+ if (DEBUG) {
+ System.err.printf("JNILibLoaderBase: addNativeJarLibsImpl: fat: %s -> %s\n", jarBasename, nativeJarURI);
}
}
- if( !ok ) {
- // We assume one slim native jar file per 'os.and.arch'!
- final URI nativeJarURI = JarUtil.getJarFileURI(jarUriRoot_s+nativeJarBasename);
- msg.append(nativeJarBasename).append(" -> slim: ").append(nativeJarURI);
- ok = TempJarCache.addNativeLibs(classFromJavaJar, nativeJarURI, null /* nativeLibraryPath */);
+ }
+ if (!ok) {
+ // We assume one slim native jar file per 'os.and.arch'!
+ final URI nativeJarURI = JarUtil.getJarFileURI(jarUriRoot_s+nativeJarBasename);
+
+ if (DEBUG) {
+ System.err.printf("JNILibLoaderBase: addNativeJarLibsImpl: slim: %s -> %s\n", nativeJarBasename, nativeJarURI);
}
- } else {
- msg.append("TempJarCache n/a");
+
+ ok = TempJarCache.addNativeLibs(classFromJavaJar, nativeJarURI, null /* nativeLibraryPath */);
}
- if(DEBUG) {
- System.err.println(msg.toString()+" - OK "+ok);
+
+ if (DEBUG) {
+ System.err.printf("JNILibLoaderBase: addNativeJarLibsImpl: ok: %b\n", ok);
}
return ok;
}
/**
* Loads and adds a JAR file's native library to the TempJarCache,
- * calling {@link JNILibLoaderBase#addNativeJarLibs(Class[], String, String[])}
+ * calling {@link JNILibLoaderBase#addNativeJarLibs(Class[], String)}
* with default JOGL deployment configuration:
*
- return JNILibLoaderBase.addNativeJarLibs(classesFromJavaJars, "-all", new String[] { "-noawt", "-mobile", "-core", "-android" } );
+ return JNILibLoaderBase.addNativeJarLibs(classesFromJavaJars, "-all");
*
* If Class1.class
is contained in a JAR file which name includes singleJarMarker
-all,
* implementation will attempt to resolve the native JAR file as follows:
@@ -223,10 +227,10 @@ public class JNILibLoaderBase {
*
@@ -247,20 +251,18 @@ public class JNILibLoaderBase {
*
- final ClassLoader cl = GLProfile.class.getClassLoader();
- final String newtFactoryClassName = "com.jogamp.newt.NewtFactory";
final Class>[] classesFromJavaJars = new Class>[] { Class1.class, Class2.class };
- JNILibLoaderBase.addNativeJarLibs(classesFromJavaJars, "-all", new String[] { "-suff1", "-suff2" } );
+ JNILibLoaderBase.addNativeJarLibs(classesFromJavaJars, "-all");
*
* If Class1.class
is contained in a JAR file which name includes singleJarMarker
, here -all,
* implementation will attempt to resolve the native JAR file as follows:
*
- *
* Otherwise the native JAR files will be resolved for each class's JAR file:
*
- *
*
@@ -272,94 +274,114 @@ public class JNILibLoaderBase { // only: jocl.jar -> jocl-natives-os.and.arch.jar addNativeJarLibs(new Class>[] { JOCLJNILibLoader.class }, null, null ); * - * - * Newt Only: - *
- // either: [jogl-all.jar, jogl-all-noawt.jar, jogl-all-mobile.jar, jogl-all-android.jar] -> jogl-all-natives-os.and.arch.jar - // or: nativewindow-core.jar -> nativewindow-natives-os.and.arch.jar, - // newt-core.jar -> newt-natives-os.and.arch.jar - JNILibLoaderBase.addNativeJarLibs(new Class>[] { NWJNILibLoader.class, NEWTJNILibLoader.class }, "-all", new String[] { "-noawt", "-mobile", "-core", "-android" } ); - ** *
* JOGL: *
final ClassLoader cl = GLProfile.class.getClassLoader(); - // either: [jogl-all.jar, jogl-all-noawt.jar, jogl-all-mobile.jar, jogl-all-android.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) + // jogl-all.jar -> jogl-all-natives-os.and.arch.jar + // jogl-all-noawt.jar -> jogl-all-noawt-natives-os.and.arch.jar + // jogl-all-mobile.jar -> jogl-all-mobile-natives-os.and.arch.jar + // jogl-all-android.jar -> jogl-all-android-natives-os.and.arch.jar + // nativewindow.jar -> nativewindow-natives-os.and.arch.jar + // jogl.jar -> jogl-natives-os.and.arch.jar + // newt.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", "-android" } ); + JNILibLoaderBase.addNativeJarLibs(classesFromJavaJars, "-all"); ** * * @param classesFromJavaJars For each given Class, load the native library JAR. * @param singleJarMarker Optional string marker like "-all" to identify the single 'all-in-one' JAR file * after which processing of the class array shall stop. - * @param stripBasenameSuffixes Optional substrings to be stripped of the base URI * * @return true if either the 'all-in-one' native JAR or all native JARs loaded successful or were loaded already, * false in case of an error */ - public static boolean addNativeJarLibs(Class>[] classesFromJavaJars, String singleJarMarker, String[] stripBasenameSuffixes) { + + public static boolean addNativeJarLibs(Class>[] classesFromJavaJars, String singleJarMarker) { + final StringBuilder msg = new StringBuilder(); + if(DEBUG) { - System.err.println("JNILibLoaderBase: addNativeJarLibs0(classesFromJavaJars "+Arrays.asList(classesFromJavaJars)+", singleJarMarker "+singleJarMarker+", stripBasenameSuffixes "+(null!=stripBasenameSuffixes?Arrays.asList(stripBasenameSuffixes):"none")); + msg.append("JNILibLoaderBase: addNativeJarLibs(\n"); + msg.append(" classesFromJavaJars = ").append(Arrays.asList(classesFromJavaJars)).append("\n"); + msg.append(" singleJarMarker = ").append(singleJarMarker).append("\n"); + msg.append(")"); + System.err.println(msg.toString()); } + boolean ok = false; - if(TempJarCache.isInitialized()) { - final StringBuilder msg = new StringBuilder(); - int count = 0; - try { - boolean done = false; - ok = true; - for(int i=0; !done && ok && i