From 4376174ad35fdaf76f59430328582e913f468674 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Wed, 19 Jun 2013 04:44:14 +0200 Subject: Fix Bug 757: Regression of URL to URI conversion (Encoded path not compatible w/ file scheme. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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)' ++ --- .../com/jogamp/common/net/URLCompositionTest.java | 40 ++++++++++++++++++++++ src/junit/com/jogamp/common/util/TestJarUtil.java | 16 +++++---- .../com/jogamp/common/util/TestTempJarCache.java | 2 +- 3 files changed, 50 insertions(+), 8 deletions(-) (limited to 'src/junit/com') diff --git a/src/junit/com/jogamp/common/net/URLCompositionTest.java b/src/junit/com/jogamp/common/net/URLCompositionTest.java index 405e877..7ddd80c 100644 --- a/src/junit/com/jogamp/common/net/URLCompositionTest.java +++ b/src/junit/com/jogamp/common/net/URLCompositionTest.java @@ -83,8 +83,48 @@ public class URLCompositionTest extends JunitTracer { System.err.println("3 fragment: "+uri.getRawFragment()); } + @Test public void showURLComponents1() throws IOException, URISyntaxException { + testURI2URL("jar:file:/usr/local/projects/JOGL/gluegen/build-x86_64%20%c3%b6%c3%a4%20lala/gluegen-rt.jar!/com/jogamp/common/os/Platform.class", + "jar:file:/usr/local/projects/JOGL/gluegen/build-x86_64 öä lala/gluegen-rt.jar!/com/jogamp/common/os/Platform.class"); + + testURI2URL("jar:file:/usr/local/projects/JOGL/gluegen/build-x86_64%20%c3%b6%c3%a4%20lala/gluegen-rt.jar!/", + "jar:file:/usr/local/projects/JOGL/gluegen/build-x86_64 öä lala/gluegen-rt.jar!/"); + + testURI2URL("file:/usr/local/projects/JOGL/gluegen/build-x86_64%20%c3%b6%c3%a4%20lala/gluegen-rt.jar", + "file:/usr/local/projects/JOGL/gluegen/build-x86_64 öä lala/gluegen-rt.jar"); + + testURI2URL("jar:http:/usr/local/projects/JOGL/gluegen/build-x86_64%20%c3%b6%c3%a4%20lala/gluegen-rt.jar!/com/jogamp/common/os/Platform.class", + "jar:http:/usr/local/projects/JOGL/gluegen/build-x86_64%20%c3%b6%c3%a4%20lala/gluegen-rt.jar!/com/jogamp/common/os/Platform.class"); + + testURI2URL("jar:http:/usr/local/projects/JOGL/gluegen/build-x86_64%20%c3%b6%c3%a4%20lala/gluegen-rt.jar!/", + "jar:http:/usr/local/projects/JOGL/gluegen/build-x86_64%20%c3%b6%c3%a4%20lala/gluegen-rt.jar!/"); + + testURI2URL("http:/usr/local/projects/JOGL/gluegen/build-x86_64%20%c3%b6%c3%a4%20lala/gluegen-rt.jar", + "http:/usr/local/projects/JOGL/gluegen/build-x86_64%20%c3%b6%c3%a4%20lala/gluegen-rt.jar"); + + testURI2URL("jar:ftp:/usr/local/projects/JOGL/gluegen/build-x86_64%20%c3%b6%c3%a4%20lala/gluegen-rt.jar!/com/jogamp/common/os/Platform.class", + "jar:ftp:/usr/local/projects/JOGL/gluegen/build-x86_64%20%c3%b6%c3%a4%20lala/gluegen-rt.jar!/com/jogamp/common/os/Platform.class"); + + testURI2URL("ftp:/usr/local/projects/JOGL/gluegen/build-x86_64%20%c3%b6%c3%a4%20lala/gluegen-rt.jar", + "ftp:/usr/local/projects/JOGL/gluegen/build-x86_64%20%c3%b6%c3%a4%20lala/gluegen-rt.jar"); + } + + void testURI2URL(String source, String expected) throws IOException, URISyntaxException { + System.err.println("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"); + final URI uri0 = new URI(source); + System.err.println("uri: "+uri0.toString()); + + final URL url0 = IOUtil.toURL(uri0); + final String actual = url0.toExternalForm(); + System.err.println("url: "+actual); + Assert.assertEquals(expected, actual); + System.err.println("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"); + } + + @Test + public void showURLComponents2() throws IOException, URISyntaxException { testURNCompositioning("file:///rootDir/file1.txt"); testURNCompositioning("file://host/rootDir/file1.txt"); testURNCompositioning("jar:file:/web1/file1.jar!/rootDir/file1.txt"); diff --git a/src/junit/com/jogamp/common/util/TestJarUtil.java b/src/junit/com/jogamp/common/util/TestJarUtil.java index ab78556..fa45853 100644 --- a/src/junit/com/jogamp/common/util/TestJarUtil.java +++ b/src/junit/com/jogamp/common/util/TestJarUtil.java @@ -94,10 +94,11 @@ public class TestJarUtil extends JunitTracer { } } - void validateJarFileURL(URI jarFileURI) throws IllegalArgumentException, IOException { - Assert.assertNotNull(jarFileURI); - URLConnection aURLc = jarFileURI.toURL().openConnection(); - Assert.assertTrue("jarFileURI/URL has zero content: "+jarFileURI, aURLc.getContentLength()>0); + void validateJarFileURL(URI jarFileURI) throws IllegalArgumentException, IOException, URISyntaxException { + Assert.assertNotNull(jarFileURI); + final URL jarFileURL = IOUtil.toURL(jarFileURI); + URLConnection aURLc = jarFileURL.openConnection(); + Assert.assertTrue("jarFileURI/URL has zero content: "+jarFileURL, aURLc.getContentLength()>0); System.err.println("URLConnection: "+aURLc); Assert.assertTrue("Not a JarURLConnection: "+aURLc, (aURLc instanceof JarURLConnection) ); JarURLConnection jURLc = (JarURLConnection) aURLc; @@ -110,9 +111,10 @@ public class TestJarUtil extends JunitTracer { Assert.assertNotNull(jarName); Assert.assertEquals(expJarName, jarName); - URI jarSubURL = JarUtil.getJarSubURI(clazzBinName, cl); - Assert.assertNotNull(jarSubURL); - URLConnection urlConn = jarSubURL.toURL().openConnection(); + URI jarSubURI = JarUtil.getJarSubURI(clazzBinName, cl); + Assert.assertNotNull(jarSubURI); + final URL jarSubURL= IOUtil.toURL(jarSubURI); + URLConnection urlConn = jarSubURL.openConnection(); Assert.assertTrue("jarSubURL has zero content: "+jarSubURL, urlConn.getContentLength()>0); System.err.println("URLConnection of jarSubURL: "+urlConn); diff --git a/src/junit/com/jogamp/common/util/TestTempJarCache.java b/src/junit/com/jogamp/common/util/TestTempJarCache.java index 7edb286..62a916a 100644 --- a/src/junit/com/jogamp/common/util/TestTempJarCache.java +++ b/src/junit/com/jogamp/common/util/TestTempJarCache.java @@ -199,7 +199,7 @@ public class TestTempJarCache extends JunitTracer { final ClassLoader cl = getClass().getClassLoader(); URI jarUriRoot = JarUtil.getJarSubURI(TempJarCache.class.getName(), cl); - jarUriRoot = JarUtil.getURIDirname(jarUriRoot); + jarUriRoot = IOUtil.getDirname(jarUriRoot); URI nativeJarURI = JarUtil.getJarFileURI(jarUriRoot, nativeJarName); -- cgit v1.2.3