diff options
Diffstat (limited to 'src')
5 files changed, 69 insertions, 50 deletions
diff --git a/src/java/com/jogamp/common/jvm/JNILibLoaderBase.java b/src/java/com/jogamp/common/jvm/JNILibLoaderBase.java index c0addfc..a2bb859 100644 --- a/src/java/com/jogamp/common/jvm/JNILibLoaderBase.java +++ b/src/java/com/jogamp/common/jvm/JNILibLoaderBase.java @@ -159,11 +159,7 @@ public class JNILibLoaderBase { if(DEBUG) { System.err.println("JNILibLoaderBase: addNativeJarLibs: "+nativeJarBaseName+": nativeJarURL "+nativeJarURL); } - JarFile nativeJar = JarUtil.getJarFile(nativeJarURL, cl); - if(DEBUG) { - System.err.println("JNILibLoaderBase: addNativeJarLibs: "+nativeJarBaseName+": nativeJar "+nativeJar.getName()); - } - TempJarCache.addNativeLibs(classFromJavaJar, nativeJar); + TempJarCache.addNativeLibs(classFromJavaJar, nativeJarURL, cl); return true; } catch (IOException ioe) { ioe.printStackTrace(); diff --git a/src/java/com/jogamp/common/os/Platform.java b/src/java/com/jogamp/common/os/Platform.java index f4bd6c1..af795d1 100644 --- a/src/java/com/jogamp/common/os/Platform.java +++ b/src/java/com/jogamp/common/os/Platform.java @@ -309,8 +309,7 @@ public class Platform { final URL jarUrlRoot = JarUtil.getURLDirname( JarUtil.getJarSubURL(Platform.class.getName(), cl) ); final URL nativeJarURL = JarUtil.getJarFileURL(jarUrlRoot, nativeJarName); - final JarFile nativeJar = JarUtil.getJarFile(nativeJarURL, cl); - TempJarCache.bootstrapNativeLib(Platform.class, libBaseName, nativeJar); + TempJarCache.bootstrapNativeLib(Platform.class, libBaseName, nativeJarURL, cl); } catch (IOException ioe) { ioe.printStackTrace(); } diff --git a/src/java/com/jogamp/common/util/cache/TempJarCache.java b/src/java/com/jogamp/common/util/cache/TempJarCache.java index f0512dc..431971c 100644 --- a/src/java/com/jogamp/common/util/cache/TempJarCache.java +++ b/src/java/com/jogamp/common/util/cache/TempJarCache.java @@ -45,11 +45,15 @@ import java.util.Set; import java.util.jar.JarEntry; import java.util.jar.JarFile; +import jogamp.common.Debug; + import com.jogamp.common.os.NativeLibrary; import com.jogamp.common.util.IOUtil; import com.jogamp.common.util.JarUtil; public class TempJarCache { + private static final boolean DEBUG = Debug.debug("TempJarCache"); + // A HashMap of native libraries that can be loaded with System.load() // The key is the string name of the library as passed into the loadLibrary // call; it is the file name without the directory or the platform-dependent @@ -58,9 +62,9 @@ public class TempJarCache { private static Map<String, String> nativeLibMap; // Set of native jar files added - private static Set<JarFile> nativeLibJars; - private static Set<JarFile> classFileJars; - private static Set<JarFile> resourceFileJars; + private static Set<URL> nativeLibJars; + private static Set<URL> classFileJars; + private static Set<URL> resourceFileJars; private static TempFileCache tmpFileCache; @@ -87,9 +91,9 @@ public class TempJarCache { if(!staticInitError) { // Initialize the collections of resources nativeLibMap = new HashMap<String, String>(); - nativeLibJars = new HashSet<JarFile>(); - classFileJars = new HashSet<JarFile>(); - resourceFileJars = new HashSet<JarFile>(); + nativeLibJars = new HashSet<URL>(); + classFileJars = new HashSet<URL>(); + resourceFileJars = new HashSet<URL>(); } } } @@ -147,37 +151,41 @@ public class TempJarCache { return tmpFileCache; } - public static boolean containsNativeLibs(JarFile jarFile) throws IOException { + public static boolean containsNativeLibs(URL jarURL) throws IOException { checkInitialized(); - return nativeLibJars.contains(jarFile); + return nativeLibJars.contains(jarURL); } - public static boolean containsClasses(JarFile jarFile) throws IOException { + public static boolean containsClasses(URL jarURL) throws IOException { checkInitialized(); - return classFileJars.contains(jarFile); + return classFileJars.contains(jarURL); } - public static boolean containsResources(JarFile jarFile) throws IOException { + public static boolean containsResources(URL jarURL) throws IOException { checkInitialized(); - return resourceFileJars.contains(jarFile); + return resourceFileJars.contains(jarURL); } /** * Adds native libraries, if not yet added. * * @param certClass if class is certified, the JarFile entries needs to have the same certificate - * @param jarFile + * @param jarURL * * @throws IOException * @throws SecurityException */ - public static final void addNativeLibs(Class<?> certClass, JarFile jarFile) throws IOException, SecurityException { + public static final void addNativeLibs(Class<?> certClass, URL jarURL, ClassLoader cl) throws IOException, SecurityException { checkInitialized(); - if(!nativeLibJars.contains(jarFile)) { + if(!nativeLibJars.contains(jarURL)) { + final JarFile jarFile = JarUtil.getJarFile(jarURL, cl); + if(DEBUG) { + System.err.println("TempJarCache: addNativeLibs: "+jarURL+": nativeJar "+jarFile.getName()); + } validateCertificates(certClass, jarFile); JarUtil.extract(tmpFileCache.getTempDir(), nativeLibMap, jarFile, true, false, false); - nativeLibJars.add(jarFile); + nativeLibJars.add(jarURL); } } @@ -193,13 +201,17 @@ public class TempJarCache { * @throws IOException * @throws SecurityException */ - public static final void addClasses(Class<?> certClass, JarFile jarFile) throws IOException, SecurityException { + public static final void addClasses(Class<?> certClass, URL jarURL, ClassLoader cl) throws IOException, SecurityException { checkInitialized(); - if(!classFileJars.contains(jarFile)) { + if(!classFileJars.contains(jarURL)) { + final JarFile jarFile = JarUtil.getJarFile(jarURL, cl); + if(DEBUG) { + System.err.println("TempJarCache: addClasses: "+jarURL+": nativeJar "+jarFile.getName()); + } validateCertificates(certClass, jarFile); JarUtil.extract(tmpFileCache.getTempDir(), null, jarFile, false, true, false); - classFileJars.add(jarFile); + classFileJars.add(jarURL); } } @@ -213,13 +225,17 @@ public class TempJarCache { * @throws IOException * @throws SecurityException */ - public static final void addResources(Class<?> certClass, JarFile jarFile) throws IOException, SecurityException { + public static final void addResources(Class<?> certClass, URL jarURL, ClassLoader cl) throws IOException, SecurityException { checkInitialized(); - if(!resourceFileJars.contains(jarFile)) { + if(!resourceFileJars.contains(jarURL)) { + final JarFile jarFile = JarUtil.getJarFile(jarURL, cl); + if(DEBUG) { + System.err.println("TempJarCache: addResources: "+jarURL+": nativeJar "+jarFile.getName()); + } validateCertificates(certClass, jarFile); JarUtil.extract(tmpFileCache.getTempDir(), null, jarFile, false, false, true); - resourceFileJars.add(jarFile); + resourceFileJars.add(jarURL); } } @@ -236,25 +252,29 @@ public class TempJarCache { * @throws IOException * @throws SecurityException */ - public static final void addAll(Class<?> certClass, JarFile jarFile) throws IOException, SecurityException { + public static final void addAll(Class<?> certClass, URL jarURL, ClassLoader cl) throws IOException, SecurityException { checkInitialized(); - if(!nativeLibJars.contains(jarFile) || - !classFileJars.contains(jarFile) || - !resourceFileJars.contains(jarFile)) { - final boolean extractNativeLibraries = !nativeLibJars.contains(jarFile); - final boolean extractClassFiles = !classFileJars.contains(jarFile); - final boolean extractOtherFiles = !resourceFileJars.contains(jarFile); + if(!nativeLibJars.contains(jarURL) || + !classFileJars.contains(jarURL) || + !resourceFileJars.contains(jarURL)) { + final JarFile jarFile = JarUtil.getJarFile(jarURL, cl); + if(DEBUG) { + System.err.println("TempJarCache: addAll: "+jarURL+": nativeJar "+jarFile.getName()); + } + final boolean extractNativeLibraries = !nativeLibJars.contains(jarURL); + final boolean extractClassFiles = !classFileJars.contains(jarURL); + final boolean extractOtherFiles = !resourceFileJars.contains(jarURL); validateCertificates(certClass, jarFile); JarUtil.extract(tmpFileCache.getTempDir(), nativeLibMap, jarFile, extractNativeLibraries, extractClassFiles, extractOtherFiles); if(extractNativeLibraries) { - nativeLibJars.add(jarFile); + nativeLibJars.add(jarURL); } if(extractClassFiles) { - classFileJars.add(jarFile); + classFileJars.add(jarURL); } if(extractOtherFiles) { - resourceFileJars.add(jarFile); + resourceFileJars.add(jarURL); } } } @@ -319,12 +339,16 @@ public class TempJarCache { * @throws IOException * @throws SecurityException */ - public static final void bootstrapNativeLib(Class<?> certClass, String libBaseName, JarFile jarFile) + public static final void bootstrapNativeLib(Class<?> certClass, String libBaseName, URL jarURL, ClassLoader cl) throws IOException, SecurityException { checkInitialized(); - if(!nativeLibJars.contains(jarFile) && !nativeLibMap.containsKey(libBaseName) ) { - validateCertificates(certClass, jarFile); - final Enumeration<JarEntry> entries = jarFile.entries(); + if(!nativeLibJars.contains(jarURL) && !nativeLibMap.containsKey(libBaseName) ) { + final JarFile jarFile = JarUtil.getJarFile(jarURL, cl); + if(DEBUG) { + System.err.println("TempJarCache: bootstrapNativeLib: "+jarURL+": nativeJar "+jarFile.getName()+" - libBaseName: "+libBaseName); + } + validateCertificates(certClass, jarFile); + final Enumeration<JarEntry> entries = jarFile.entries(); while (entries.hasMoreElements()) { final JarEntry entry = (JarEntry) entries.nextElement(); final String entryName = entry.getName(); @@ -348,7 +372,7 @@ public class TempJarCache { } finally { in.close(); out.close(); } if (numBytes>0) { nativeLibMap.put(libBaseName, destFile.getAbsolutePath()); - nativeLibJars.add(jarFile); + nativeLibJars.add(jarURL); } } } diff --git a/src/junit/com/jogamp/common/util/TestJarUtil.java b/src/junit/com/jogamp/common/util/TestJarUtil.java index fd3b93e..9eef97d 100644 --- a/src/junit/com/jogamp/common/util/TestJarUtil.java +++ b/src/junit/com/jogamp/common/util/TestJarUtil.java @@ -130,7 +130,7 @@ public class TestJarUtil { final ClassLoader rootCL = this.getClass().getClassLoader(); // Get containing JAR file "TestJarsInJar.jar" and add it to the TempJarCache - TempJarCache.addAll(GlueGenVersion.class, JarUtil.getJarFile("ClassInJar0", rootCL)); + TempJarCache.addAll(GlueGenVersion.class, JarUtil.getJarFileURL("ClassInJar0", rootCL), rootCL); // Fetch and load the contained "ClassInJar1.jar" final URL ClassInJar1_jarFileURL = JarUtil.getJarFileURL(TempJarCache.getResource("ClassInJar1.jar")); @@ -151,7 +151,7 @@ public class TestJarUtil { final ClassLoader rootCL = this.getClass().getClassLoader(); // Get containing JAR file "TestJarsInJar.jar" and add it to the TempJarCache - TempJarCache.addAll(GlueGenVersion.class, JarUtil.getJarFile("ClassInJar0", rootCL)); + TempJarCache.addAll(GlueGenVersion.class, JarUtil.getJarFileURL("ClassInJar0", rootCL), rootCL); // Fetch and load the contained "ClassInJar1.jar" final URL ClassInJar2_jarFileURL = JarUtil.getJarFileURL(TempJarCache.getResource("sub/ClassInJar2.jar")); diff --git a/src/junit/com/jogamp/common/util/TestTempJarCache.java b/src/junit/com/jogamp/common/util/TestTempJarCache.java index 199d0aa..f1630d4 100644 --- a/src/junit/com/jogamp/common/util/TestTempJarCache.java +++ b/src/junit/com/jogamp/common/util/TestTempJarCache.java @@ -161,8 +161,9 @@ public class TestTempJarCache { Assert.assertTrue(TempJarCache.initSingleton()); Assert.assertTrue(TempCacheReg.isTempJarCacheUsed()); Assert.assertTrue(TempJarCache.isInitialized()); - - TempJarCache.addAll(GlueGenVersion.class, JarUtil.getJarFile(GlueGenVersion.class.getName(), getClass().getClassLoader())); + + final ClassLoader cl = getClass().getClassLoader(); + TempJarCache.addAll(GlueGenVersion.class, JarUtil.getJarFileURL(GlueGenVersion.class.getName(), cl), cl); File f0 = new File(TempJarCache.getTempFileCache().getTempDir(), "META-INF/MANIFEST.MF"); Assert.assertTrue(f0.exists()); @@ -189,9 +190,8 @@ public class TestTempJarCache { jarUrlRoot = JarUtil.getURLDirname(jarUrlRoot); URL nativeJarURL = JarUtil.getJarFileURL(jarUrlRoot, nativeJarName); - JarFile nativeJar = JarUtil.getJarFile(nativeJarURL, cl); - TempJarCache.addNativeLibs(TempJarCache.class, nativeJar); + TempJarCache.addNativeLibs(TempJarCache.class, nativeJarURL, cl); String libFullPath = TempJarCache.findLibrary(libBaseName); Assert.assertNotNull(libFullPath); Assert.assertEquals(libBaseName, NativeLibrary.isValidNativeLibraryName(libFullPath, true)); |