aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/com/jogamp/common/util/JarUtil.java
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2013-06-19 04:44:14 +0200
committerSven Gothel <[email protected]>2013-06-19 04:44:14 +0200
commit4376174ad35fdaf76f59430328582e913f468674 (patch)
treeeb1faa41eb440b1fec0c5f9932007050e5bd7e8b /src/java/com/jogamp/common/util/JarUtil.java
parent88dca02541d96f68a892ae7824e9e1b29793ae55 (diff)
Fix Bug 757: Regression of URL to URI conversion (Encoded path not compatible w/ file scheme.
Regression of (Bug 683, Commit b98825eb7cfb61aead4a7dff57471cd2d2c26823). The URI encoded path cannot be read by File I/O (if file scheme), since the latter requests an UTF8/16 name, not an URI encoded name (i.e. %20 for space). The encoded URL is produced if calling 'uri.toURL()' and hence the new 'IOUtil.toURL(URI)' provides a custom conversion recovering the UTF name via 'new File(uri).getPath()'. Tested w/ - synthetic URI/URL coposition (unit test) - manual w/ moving 'build' to 'build öä lala' for gluegen, joal and jogl. +++ Misc.: - 'URI JarUtil.getURIDirname(URI)' -> 'URI IOUtil.getDirname(URI)' ++
Diffstat (limited to 'src/java/com/jogamp/common/util/JarUtil.java')
-rw-r--r--src/java/com/jogamp/common/util/JarUtil.java87
1 files changed, 39 insertions, 48 deletions
diff --git a/src/java/com/jogamp/common/util/JarUtil.java b/src/java/com/jogamp/common/util/JarUtil.java
index 4045cfa..9ea6f70 100644
--- a/src/java/com/jogamp/common/util/JarUtil.java
+++ b/src/java/com/jogamp/common/util/JarUtil.java
@@ -142,10 +142,10 @@ public class JarUtil {
final URL url = IOUtil.getClassURL(clazzBinName, cl);
final String scheme = url.getProtocol();
if( null != resolver &&
- !scheme.startsWith( IOUtil.JAR_SCHEME ) &&
- !scheme.startsWith( IOUtil.FILE_SCHEME ) &&
- !scheme.startsWith( IOUtil.HTTP_SCHEME ) &&
- !scheme.startsWith( IOUtil.HTTPS_SCHEME ) )
+ !scheme.equals( IOUtil.JAR_SCHEME ) &&
+ !scheme.equals( IOUtil.FILE_SCHEME ) &&
+ !scheme.equals( IOUtil.HTTP_SCHEME ) &&
+ !scheme.equals( IOUtil.HTTPS_SCHEME ) )
{
final URL _url = resolver.resolve( url );
uri = _url.toURI();
@@ -252,7 +252,6 @@ public class JarUtil {
*
* @param classJarURI as retrieved w/ {@link #getJarURI(String, ClassLoader) getJarURI("com.jogamp.common.GlueGenVersion", cl).toURI()},
* i.e. <code>jar:<i>sub_protocol</i>:/some/path/gluegen-rt.jar!/com/jogamp/common/GlueGenVersion.class</code>
- * @param cl
* @return <code><i>sub_protocol</i>:/some/path/gluegen-rt.jar</code>
* @throws IllegalArgumentException if the URI doesn't match the expected formatting or is null
* @throws URISyntaxException if the URI could not be translated into a RFC 2396 URI
@@ -286,6 +285,36 @@ public class JarUtil {
}
return new URI(uriS);
}
+
+ /**
+ * The Class's Jar URI <code>jar:<i>sub_protocol</i>:/some/path/gluegen-rt.jar!/com/jogamp/common/GlueGenVersion.class</code>
+ * Jar file's entry <code>/com/jogamp/common/GlueGenVersion.class</code> will be returned.
+ *
+ * @param classJarURI as retrieved w/ {@link #getJarURI(String, ClassLoader) getJarURI("com.jogamp.common.GlueGenVersion", cl).toURI()},
+ * i.e. <code>jar:<i>sub_protocol</i>:/some/path/gluegen-rt.jar!/com/jogamp/common/GlueGenVersion.class</code>
+ * @return <code>/com/jogamp/common/GlueGenVersion.class</code>
+ * @see {@link IOUtil#getClassURL(String, ClassLoader)}
+ */
+ public static String getJarEntry(URI classJarURI) {
+ if(null == classJarURI) {
+ throw new IllegalArgumentException("URI is null");
+ }
+ if( !classJarURI.getScheme().equals(IOUtil.JAR_SCHEME) ) {
+ throw new IllegalArgumentException("URI is not a using scheme "+IOUtil.JAR_SCHEME+": <"+classJarURI+">");
+ }
+ String uriS = classJarURI.getRawSchemeSpecificPart();
+
+ // from
+ // file:/some/path/gluegen-rt.jar!/com/jogamp/common/GlueGenVersion.class
+ // to
+ // file:/some/path/gluegen-rt.jar
+ int idx = uriS.lastIndexOf('!');
+ if (0 <= idx) {
+ return uriS.substring(idx+1); // right of '!'
+ } else {
+ throw new IllegalArgumentException("JAR URI does not contain jar uri terminator '!', uri <"+classJarURI+">");
+ }
+ }
/**
* The Class's <code>com.jogamp.common.GlueGenVersion</code>
@@ -335,46 +364,6 @@ public class JarUtil {
}
/**
- * The URI's <code><i>protocol</i>:/some/path/gluegen-rt.jar</code>
- * parent dirname URI <code><i>protocol</i>:/some/path/</code> will be returned.
- * <p>
- * <i>protocol</i> may be "file", "http", etc..
- * </p>
- *
- * @param aURI "<i>protocol</i>:/some/path/gluegen-rt.jar"
- * @return "<i>protocol</i>:/some/path/"
- * @throws IllegalArgumentException if the URI doesn't match the expected formatting, or is null
- * @throws URISyntaxException
- */
- public static URI getURIDirname(URI aURI) throws IllegalArgumentException, URISyntaxException {
- if(null == aURI) {
- throw new IllegalArgumentException("URI is null");
- }
- String uriS = aURI.toString();
- if(DEBUG) {
- System.out.println("getURIDirname "+aURI+", extForm: "+uriS);
- }
- // from
- // file:/some/path/gluegen-rt.jar _or_ rsrc:gluegen-rt.jar
- // to
- // file:/some/path/ _or_ rsrc:
- int idx = uriS.lastIndexOf('/');
- if(0 > idx) {
- // no abs-path, check for protocol terminator ':'
- idx = uriS.lastIndexOf(':');
- if(0 > idx) {
- throw new IllegalArgumentException("URI does not contain protocol terminator ':', in <"+aURI+">");
- }
- }
- uriS = uriS.substring(0, idx+1); // exclude jar name, include terminal '/' or ':'
-
- if(DEBUG) {
- System.out.println("getJarURIDirname res: "+uriS);
- }
- return new URI(uriS);
- }
-
- /**
* @param baseUri file:/some/path/
* @param jarFileName gluegen-rt.jar
* @return jar:file:/some/path/gluegen-rt.jar!/
@@ -433,15 +422,17 @@ public class JarUtil {
* @return JarFile as named by URI within the given ClassLoader
* @throws IllegalArgumentException null arguments
* @throws IOException if the Jar file could not been found
+ * @throws URISyntaxException
*/
- public static JarFile getJarFile(URI jarFileURI) throws IOException, IllegalArgumentException {
+ public static JarFile getJarFile(URI jarFileURI) throws IOException, IllegalArgumentException, URISyntaxException {
if(null == jarFileURI) {
throw new IllegalArgumentException("null jarFileURI");
}
if(DEBUG) {
- System.out.println("getJarFile: "+jarFileURI);
+ System.out.println("getJarFile: "+jarFileURI.toString());
}
- final URL jarFileURL = jarFileURI.toURL();
+ final URL jarFileURL = IOUtil.toURL(jarFileURI);
+ // final URL jarFileURL = jarFileURI.toURL(); // doesn't work due to encoded path even w/ file schema!
final URLConnection urlc = jarFileURL.openConnection();
if(urlc instanceof JarURLConnection) {
JarURLConnection jarConnection = (JarURLConnection)jarFileURL.openConnection();