summaryrefslogtreecommitdiffstats
path: root/src/java/com/jogamp/common/util
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2012-01-05 08:55:06 +0100
committerSven Gothel <[email protected]>2012-01-05 08:55:06 +0100
commit9a211fe6cfb4150d97b50325c1778b7f5d3419af (patch)
treefc37b492bc29a77286ca7b185029d48e96720e56 /src/java/com/jogamp/common/util
parent3eb4fd96cd65e49625663fdb6421a2f1cf2204dc (diff)
Further fix for bug 537 - Catch IllegalArgumentException in Platform.loadGlueGenRTImpl(), Reuse JarUtil (same methodology) to determine whether we run from JarURL
Diffstat (limited to 'src/java/com/jogamp/common/util')
-rw-r--r--src/java/com/jogamp/common/util/JarUtil.java66
-rw-r--r--src/java/com/jogamp/common/util/cache/TempJarCache.java1
2 files changed, 52 insertions, 15 deletions
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
@@ -52,30 +52,75 @@ public class JarUtil {
private static final boolean DEBUG = Debug.debug("JarUtil");
/**
+ * Returns <code>true</code> if the Class's <code>"com.jogamp.common.GlueGenVersion"</code>
+ * is loaded from a JarFile and hence has a Jar URL like
+ * URL <code>jar:<i>sub_protocol</i>:/some/path/gluegen-rt.jar!/com/jogamp/common/GlueGenVersion.class"</code>.
+ * <p>
+ * <i>sub_protocol</i> may be "file", "http", etc..
+ * </p>
+ *
+ * @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 <code>"com.jogamp.common.GlueGenVersion"</code>
* URL <code>jar:<i>sub_protocol</i>:/some/path/gluegen-rt.jar!/com/jogamp/common/GlueGenVersion.class"</code>
- * Jar basename <code>gluegen-rt.jar</code> will be returned.
+ * will be returned.
* <p>
* <i>sub_protocol</i> may be "file", "http", etc..
* </p>
*
* @param clazzBinName "com.jogamp.common.GlueGenVersion"
* @param cl
- * @return "gluegen-rt.jar"
+ * @return "jar:<i>sub_protocol</i>:/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 <code>"com.jogamp.common.GlueGenVersion"</code>
+ * URL <code>jar:<i>sub_protocol</i>:/some/path/gluegen-rt.jar!/com/jogamp/common/GlueGenVersion.class"</code>
+ * Jar basename <code>gluegen-rt.jar</code> will be returned.
+ * <p>
+ * <i>sub_protocol</i> may be "file", "http", etc..
+ * </p>
+ *
+ * @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);
}
/**
diff --git a/src/java/com/jogamp/common/util/cache/TempJarCache.java b/src/java/com/jogamp/common/util/cache/TempJarCache.java
index 431971c..dd3e306 100644
--- a/src/java/com/jogamp/common/util/cache/TempJarCache.java
+++ b/src/java/com/jogamp/common/util/cache/TempJarCache.java
@@ -133,7 +133,6 @@ public class TempJarCache {
} */
/**
- *
* @return true if this class has been properly initialized, ie. is in use, otherwise false.
*/
public static boolean isInitialized() {