From 1a8d2c627dbab5234aea72a458c00b6bba28add0 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Tue, 1 Oct 2013 10:30:08 +0200 Subject: Fix Bug 844: Cannot ctor URI w/ scheme alone, use string-based concatenation native URI root and jar file. --- .../com/jogamp/common/jvm/JNILibLoaderBase.java | 10 ++++++--- src/java/com/jogamp/common/util/IOUtil.java | 25 +++++++++++++++++++--- src/java/com/jogamp/common/util/JarUtil.java | 13 +++++++++++ 3 files changed, 42 insertions(+), 6 deletions(-) (limited to 'src/java/com/jogamp/common') diff --git a/src/java/com/jogamp/common/jvm/JNILibLoaderBase.java b/src/java/com/jogamp/common/jvm/JNILibLoaderBase.java index caa8702..022ec0e 100644 --- a/src/java/com/jogamp/common/jvm/JNILibLoaderBase.java +++ b/src/java/com/jogamp/common/jvm/JNILibLoaderBase.java @@ -156,9 +156,13 @@ public class JNILibLoaderBase { if(TempJarCache.isInitialized()) { final String nativeJarName = nativeJarBasename+"-natives-"+PlatformPropsImpl.os_and_arch+".jar"; msg.append(nativeJarName); - final URI jarUriRoot = IOUtil.getDirname( JarUtil.getJarSubURI( classJarURI ) ); - msg.append(" + ").append(jarUriRoot); - final URI nativeJarURI = JarUtil.getJarFileURI(jarUriRoot, 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(" + ").append(jarUriRoot_s); + final URI nativeJarURI = JarUtil.getJarFileURI(jarUriRoot_s+nativeJarName); msg.append(" -> ").append(nativeJarURI); if(DEBUG) { System.err.println(msg.toString()); diff --git a/src/java/com/jogamp/common/util/IOUtil.java b/src/java/com/jogamp/common/util/IOUtil.java index 17bf136..6b9eef8 100644 --- a/src/java/com/jogamp/common/util/IOUtil.java +++ b/src/java/com/jogamp/common/util/IOUtil.java @@ -444,7 +444,7 @@ public class IOUtil { * @throws IllegalArgumentException if the URI doesn't match the expected formatting, or is null * @throws URISyntaxException */ - public static URI getDirname(URI uri) throws IllegalArgumentException, URISyntaxException { + public static URI getURIDirname(URI uri) throws IllegalArgumentException, URISyntaxException { if(null == uri) { throw new IllegalArgumentException("URI is null"); } @@ -452,6 +452,25 @@ public class IOUtil { if( DEBUG ) { System.out.println("getURIDirname "+uri+", extForm: "+uriS); } + return new URI( getURIDirname(uriS) ); + } + + /** + * The URI's protocol:/some/path/gluegen-rt.jar + * parent dirname URI protocol:/some/path/ will be returned. + *

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

+ * + * @param uri "protocol:/some/path/gluegen-rt.jar" + * @return "protocol:/some/path/" + * @throws IllegalArgumentException if the URI doesn't match the expected formatting, or is null + * @throws URISyntaxException + */ + public static String getURIDirname(String uriS) throws IllegalArgumentException, URISyntaxException { + if(null == uriS) { + throw new IllegalArgumentException("uriS is null"); + } // from // file:/some/path/gluegen-rt.jar _or_ rsrc:gluegen-rt.jar // to @@ -461,7 +480,7 @@ public class IOUtil { // no abs-path, check for protocol terminator ':' idx = uriS.lastIndexOf(':'); if(0 > idx) { - throw new IllegalArgumentException("URI does not contain protocol terminator ':', in <"+uri+">"); + throw new IllegalArgumentException("URI does not contain protocol terminator ':', in <"+uriS+">"); } } uriS = uriS.substring(0, idx+1); // exclude jar name, include terminal '/' or ':' @@ -469,7 +488,7 @@ public class IOUtil { if( DEBUG ) { System.out.println("getJarURIDirname res: "+uriS); } - return new URI(uriS); + return uriS; } /** diff --git a/src/java/com/jogamp/common/util/JarUtil.java b/src/java/com/jogamp/common/util/JarUtil.java index 145368f..41d68d4 100644 --- a/src/java/com/jogamp/common/util/JarUtil.java +++ b/src/java/com/jogamp/common/util/JarUtil.java @@ -392,6 +392,19 @@ public class JarUtil { return new URI(IOUtil.JAR_SCHEME, jarSubUri.toString()+"!/", null); } + /** + * @param jarSubUriS file:/some/path/gluegen-rt.jar + * @return jar:file:/some/path/gluegen-rt.jar!/ + * @throws IllegalArgumentException null arguments + * @throws URISyntaxException + */ + public static URI getJarFileURI(String jarSubUriS) throws IllegalArgumentException, URISyntaxException { + if(null == jarSubUriS) { + throw new IllegalArgumentException("jarSubURIS is null"); + } + return new URI(IOUtil.JAR_SCHEME, jarSubUriS+"!/", null); + } + /** * @param jarFileURI jar:file:/some/path/gluegen-rt.jar!/ * @param jarEntry com/jogamp/common/GlueGenVersion.class -- cgit v1.2.3