summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2013-10-01 15:34:05 +0200
committerSven Gothel <[email protected]>2013-10-01 15:34:05 +0200
commitb05f716cbcbc379588050c8f3d91579b3a14ec88 (patch)
tree6bb720e5dc500225d4a12bf3b6dc93f4d85f04fb
parent4aa1478b2e4f1401b08d093461b37a14c9501c29 (diff)
Bug 845: Fix JNILibLoaderBase.addNativeJarLibsImpl(..) fat-jar case.
Always use the jar-basename when calling TempJarCache.addNativeLibs(..), otherwise it is mapped and loaded multiple times leading to different native libraries. Simplify addNativeJarLibsImpl(..) argument semantics by passing complete jarBasename and nativeJarBasename (w/ suffix). Added manual test scripts validating [gluegen + jogl] usage with multi (Bug 843) and fat (Bug 845) jar configurations.
-rw-r--r--src/java/com/jogamp/common/jvm/JNILibLoaderBase.java46
-rw-r--r--src/java/com/jogamp/common/util/cache/TempJarCache.java5
-rw-r--r--test/TestMultiAndFatJar/make-fat_and_multi.sh45
-rw-r--r--test/TestMultiAndFatJar/run-fat.sh9
-rw-r--r--test/TestMultiAndFatJar/run-multi.sh9
5 files changed, 98 insertions, 16 deletions
diff --git a/src/java/com/jogamp/common/jvm/JNILibLoaderBase.java b/src/java/com/jogamp/common/jvm/JNILibLoaderBase.java
index f0ff69d..90969bb 100644
--- a/src/java/com/jogamp/common/jvm/JNILibLoaderBase.java
+++ b/src/java/com/jogamp/common/jvm/JNILibLoaderBase.java
@@ -148,22 +148,43 @@ public class JNILibLoaderBase {
loaderAction = action;
}
- /* pp */ static final boolean addNativeJarLibsImpl(Class<?> classFromJavaJar, URI classJarURI, String nativeJarBasename, StringBuilder msg)
+ /**
+ *
+ * @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)
throws IOException, SecurityException, URISyntaxException
{
msg.setLength(0); // reset
msg.append("addNativeJarLibsImpl(classFromJavaJar ").append(classFromJavaJar).append(", classJarURI ").append(classJarURI).append(", nativeJarBaseName ").append(nativeJarBasename).append("): ");
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() );
+
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'!
- if( TempJarCache.addNativeLibs(classFromJavaJar, classJarURI, nativeLibraryPath) ) {
+ final URI nativeJarURI = JarUtil.getJarFileURI(jarUriRoot_s+jarBasename);
+ if( TempJarCache.addNativeLibs(classFromJavaJar, nativeJarURI, nativeLibraryPath) ) {
ok = true;
- msg.append(classJarURI).append(" (fat)");
+ msg.append(jarBasename);
+ msg.append(" + ").append(jarUriRoot_s);
+ msg.append(" -> fat: ").append(jarBasename);
if(DEBUG) {
System.err.println(msg.toString());
}
@@ -171,16 +192,10 @@ public class JNILibLoaderBase {
}
if( !ok ) {
// We assume one slim native jar file per 'os.and.arch'!
- final String nativeJarName = nativeJarBasename+"-natives-"+PlatformPropsImpl.os_and_arch+".jar";
- msg.append(nativeJarName);
- 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(nativeJarBasename);
msg.append(" + ").append(jarUriRoot_s);
- final URI nativeJarURI = JarUtil.getJarFileURI(jarUriRoot_s+nativeJarName);
- msg.append(" -> ").append(nativeJarURI).append(" (slim)");
+ final URI nativeJarURI = JarUtil.getJarFileURI(jarUriRoot_s+nativeJarBasename);
+ msg.append(" -> slim: ").append(nativeJarURI);
if(DEBUG) {
System.err.println(msg.toString());
}
@@ -214,7 +229,8 @@ public class JNILibLoaderBase {
final StringBuilder msg = new StringBuilder();
try {
final URI classJarURI = JarUtil.getJarURI(classFromJavaJar.getName(), classFromJavaJar.getClassLoader());
- return addNativeJarLibsImpl(classFromJavaJar, classJarURI, nativeJarBasename, msg);
+ final String jarName = JarUtil.getJarBasename(classJarURI);
+ return addNativeJarLibsImpl(classFromJavaJar, classJarURI, jarName, nativeJarBasename+"-natives-"+PlatformPropsImpl.os_and_arch+".jar", msg);
} catch (Exception e0) {
// IllegalArgumentException, IOException
System.err.println("Catched "+e0.getClass().getSimpleName()+": "+e0.getMessage()+", while "+msg.toString());
@@ -348,9 +364,9 @@ public class JNILibLoaderBase {
ok = null != jarName;
if(ok) {
final String jarBasename = jarName.substring(0, jarName.indexOf(".jar")); // ".jar" already validated w/ JarUtil.getJarBasename(..)
- final String nativeJarBasename = stripName(jarBasename, stripBasenameSuffixes);
+ final String nativeJarBasename = stripName(jarBasename, stripBasenameSuffixes)+"-natives-"+PlatformPropsImpl.os_and_arch+".jar";
done = null != singleJarMarker && jarBasename.indexOf(singleJarMarker) >= 0; // done if single-jar ('all' variant)
- ok = JNILibLoaderBase.addNativeJarLibsImpl(classesFromJavaJars[i], classJarURI, nativeJarBasename, msg);
+ ok = JNILibLoaderBase.addNativeJarLibsImpl(classesFromJavaJars[i], classJarURI, jarName, nativeJarBasename, msg);
if(ok) { count++; }
if(DEBUG && done) {
System.err.println("JNILibLoaderBase: addNativeJarLibs0: end after all-in-one JAR: "+jarBasename);
diff --git a/src/java/com/jogamp/common/util/cache/TempJarCache.java b/src/java/com/jogamp/common/util/cache/TempJarCache.java
index e2a33e0..ecf6e56 100644
--- a/src/java/com/jogamp/common/util/cache/TempJarCache.java
+++ b/src/java/com/jogamp/common/util/cache/TempJarCache.java
@@ -210,13 +210,16 @@ public class TempJarCache {
nativeLibJars.put(jarURI, LoadState.LOOKED_UP);
final JarFile jarFile = JarUtil.getJarFile(jarURI);
if(DEBUG) {
- System.err.println("TempJarCache: addNativeLibs: "+jarURI+": nativeJar "+jarFile.getName());
+ System.err.println("TempJarCache: addNativeLibs: "+jarURI+": nativeJar "+jarFile.getName()+" (NEW)");
}
validateCertificates(certClass, jarFile);
final int num = JarUtil.extract(tmpFileCache.getTempDir(), nativeLibMap, jarFile, nativeLibraryPath, true, false, false);
nativeLibJars.put(jarURI, LoadState.LOADED);
return num > 0;
} else if( testLoadState(nativeLibJarsLS, LoadState.LOADED) ) {
+ if(DEBUG) {
+ System.err.println("TempJarCache: addNativeLibs: "+jarURI+": nativeJar "+jarURI+" (REUSE)");
+ }
return true;
}
throw new IOException("TempJarCache: addNativeLibs: "+jarURI+", previous load attempt failed");
diff --git a/test/TestMultiAndFatJar/make-fat_and_multi.sh b/test/TestMultiAndFatJar/make-fat_and_multi.sh
new file mode 100644
index 0000000..945d29b
--- /dev/null
+++ b/test/TestMultiAndFatJar/make-fat_and_multi.sh
@@ -0,0 +1,45 @@
+THISDIR=`pwd`
+GLUEGEN=$THISDIR/../../../gluegen
+JOGL=$THISDIR/../../../jogl
+
+bdir=build-x86_64
+
+rm -rf temp
+
+#
+# make fat
+#
+rm -f jogl-fat.jar
+mkdir temp
+cd temp
+unzip -o $GLUEGEN/$bdir/gluegen-rt.jar
+unzip -o $GLUEGEN/$bdir/gluegen-rt-natives-linux-amd64.jar
+unzip -o $JOGL/$bdir/jar/jogl-all.jar
+unzip -o $JOGL/$bdir/jar/jogl-all-natives-linux-amd64.jar
+mkdir -p natives/linux-amd64
+mv lib*.so natives/linux-amd64/
+rm -rf META-INF
+jar cf ../jogl-fat.jar *
+cd ..
+rm -rf temp
+
+#
+# make multi
+#
+rm -f jogl-multi.jar jogl-multi-natives-linux-amd64.jar
+mkdir temp
+cd temp
+unzip -o $GLUEGEN/$bdir/gluegen-rt.jar
+unzip -o $JOGL/$bdir/jar/jogl-all.jar
+rm -rf META-INF
+jar cf ../jogl-multi.jar *
+rm -rf *
+unzip -o $GLUEGEN/$bdir/gluegen-rt-natives-linux-amd64.jar
+unzip -o $JOGL/$bdir/jar/jogl-all-natives-linux-amd64.jar
+mkdir -p natives/linux-amd64
+mv lib*.so natives/linux-amd64/
+rm -rf META-INF
+jar cf ../jogl-multi-natives-linux-amd64.jar *
+cd ..
+rm -rf temp
+
diff --git a/test/TestMultiAndFatJar/run-fat.sh b/test/TestMultiAndFatJar/run-fat.sh
new file mode 100644
index 0000000..60247a6
--- /dev/null
+++ b/test/TestMultiAndFatJar/run-fat.sh
@@ -0,0 +1,9 @@
+
+D_ARGS="-Djogamp.debug.JNILibLoader -Djogamp.debug.TempFileCache -Djogamp.debug.JarUtil -Djogamp.debug.TempJarCache"
+#D_ARGS="-Djogamp.debug.ProcAddressHelper -Djogamp.debug.NativeLibrary -Djogamp.debug.NativeLibrary.Lookup"
+#D_ARGS="-Djogamp.debug.JNILibLoader -Djogamp.debug.TempFileCache -Djogamp.debug.JarUtil -Djogamp.debug.TempJarCache -Djogamp.debug.NativeLibrary -Djogamp.debug.NativeLibrary.Lookup -Djogl.debug=all"
+
+#T_CLASS="com.jogamp.opengl.JoglVersion"
+T_CLASS="com.jogamp.newt.opengl.GLWindow"
+
+java -cp jogl-fat.jar $D_ARGS $T_CLASS 2>&1 | tee run-fat.log
diff --git a/test/TestMultiAndFatJar/run-multi.sh b/test/TestMultiAndFatJar/run-multi.sh
new file mode 100644
index 0000000..0cca10c
--- /dev/null
+++ b/test/TestMultiAndFatJar/run-multi.sh
@@ -0,0 +1,9 @@
+
+#D_ARGS="-Djogamp.debug.JNILibLoader -Djogamp.debug.TempFileCache -Djogamp.debug.JarUtil -Djogamp.debug.TempJarCache"
+#D_ARGS="-Djogamp.debug.ProcAddressHelper -Djogamp.debug.NativeLibrary -Djogamp.debug.NativeLibrary.Lookup"
+D_ARGS="-Djogamp.debug.JNILibLoader -Djogamp.debug.TempFileCache -Djogamp.debug.JarUtil -Djogamp.debug.TempJarCache -Djogamp.debug.NativeLibrary"
+
+#T_CLASS="com.jogamp.opengl.JoglVersion"
+T_CLASS="com.jogamp.newt.opengl.GLWindow"
+
+java -cp jogl-multi.jar $D_ARGS $T_CLASS 2>&1 | tee run-multi.log