From 9a211fe6cfb4150d97b50325c1778b7f5d3419af Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Thu, 5 Jan 2012 08:55:06 +0100 Subject: Further fix for bug 537 - Catch IllegalArgumentException in Platform.loadGlueGenRTImpl(), Reuse JarUtil (same methodology) to determine whether we run from JarURL --- src/java/com/jogamp/common/util/JarUtil.java | 66 ++++++++++++++++++++++------ 1 file changed, 52 insertions(+), 14 deletions(-) (limited to 'src/java/com/jogamp/common/util/JarUtil.java') diff --git a/src/java/com/jogamp/common/util/JarUtil.java b/src/java/com/jogamp/common/util/JarUtil.java index 4beda94..bd63a56 100644 --- a/src/java/com/jogamp/common/util/JarUtil.java +++ b/src/java/com/jogamp/common/util/JarUtil.java @@ -51,31 +51,76 @@ import jogamp.common.Debug; public class JarUtil { private static final boolean DEBUG = Debug.debug("JarUtil"); + /** + * Returns true if the Class's "com.jogamp.common.GlueGenVersion" + * is loaded from a JarFile and hence has a Jar URL like + * URL jar:sub_protocol:/some/path/gluegen-rt.jar!/com/jogamp/common/GlueGenVersion.class". + *

+ * sub_protocol may be "file", "http", etc.. + *

+ * + * @param clazzBinName "com.jogamp.common.GlueGenVersion" + * @param cl + * @return true if the class is loaded from a Jar file, otherwise false. + * @see {@link #getJarURL(String, ClassLoader)} + */ + public static boolean hasJarURL(String clazzBinName, ClassLoader cl) { + try { + final URL url = getJarURL(clazzBinName, cl); + return null != url; + } catch (Exception e) { /* ignore */ } + return false; + } + /** * The Class's "com.jogamp.common.GlueGenVersion" * URL jar:sub_protocol:/some/path/gluegen-rt.jar!/com/jogamp/common/GlueGenVersion.class" - * Jar basename gluegen-rt.jar will be returned. + * will be returned. *

* sub_protocol may be "file", "http", etc.. *

* * @param clazzBinName "com.jogamp.common.GlueGenVersion" * @param cl - * @return "gluegen-rt.jar" + * @return "jar:sub_protocol:/some/path/gluegen-rt.jar!/com/jogamp/common/GlueGenVersion.class" * @throws IllegalArgumentException if the URL doesn't match the expected formatting * @throws IOException * @see {@link IOUtil#getClassURL(String, ClassLoader)} */ - public static String getJarBasename(String clazzBinName, ClassLoader cl) throws IllegalArgumentException, IOException { + public static URL getJarURL(String clazzBinName, ClassLoader cl) throws IllegalArgumentException, IOException { URL url = IOUtil.getClassURL(clazzBinName, cl); if(null != url) { String urlS = url.toExternalForm(); if(DEBUG) { - System.out.println("getJarName "+url+", extForm: "+urlS); + System.out.println("getJarURL "+url+", extForm: "+urlS); } if(!urlS.startsWith("jar:")) { throw new IllegalArgumentException("JAR URL doesn't start with 'jar:', got <"+urlS+">"); - } + } + } + return url; + } + + + /** + * The Class's "com.jogamp.common.GlueGenVersion" + * URL jar:sub_protocol:/some/path/gluegen-rt.jar!/com/jogamp/common/GlueGenVersion.class" + * Jar basename gluegen-rt.jar will be returned. + *

+ * sub_protocol may be "file", "http", etc.. + *

+ * + * @param clazzBinName "com.jogamp.common.GlueGenVersion" + * @param cl + * @return "gluegen-rt.jar" + * @throws IllegalArgumentException if the URL doesn't match the expected formatting + * @throws IOException + * @see {@link IOUtil#getClassURL(String, ClassLoader)} + */ + public static String getJarBasename(String clazzBinName, ClassLoader cl) throws IllegalArgumentException, IOException { + URL url = getJarURL(clazzBinName, cl); + if(null != url) { + String urlS = url.toExternalForm(); urlS = urlS.substring(4, urlS.length()); // exclude 'jar:' // from @@ -130,15 +175,9 @@ public class JarUtil { * @see {@link IOUtil#getClassURL(String, ClassLoader)} */ public static URL getJarSubURL(String clazzBinName, ClassLoader cl) throws IllegalArgumentException, IOException { - URL url = IOUtil.getClassURL(clazzBinName, cl); + URL url = getJarURL(clazzBinName, cl); if(null != url) { String urlS = url.toExternalForm(); - if(DEBUG) { - System.out.println("getJarSubURL "+url+", extForm: "+urlS); - } - if(!urlS.startsWith("jar:")) { - throw new IllegalArgumentException("JAR URL doesn't start with 'jar:', got <"+urlS+">"); - } urlS = urlS.substring(4, urlS.length()); // exclude 'jar:' // from @@ -266,7 +305,6 @@ public class JarUtil { } /** - * * @param clazzBinName com.jogamp.common.util.cache.TempJarCache * @param cl domain * @return JarFile containing the named class within the given ClassLoader @@ -274,7 +312,7 @@ public class JarUtil { * @see {@link #getJarFileURL(String, ClassLoader)} */ public static JarFile getJarFile(String clazzBinName, ClassLoader cl) throws IOException { - return getJarFile(getJarFileURL(clazzBinName, cl), cl); + return getJarFile(getJarFileURL(clazzBinName, cl), cl); } /** -- cgit v1.2.3