From dde91a061cb0bc209442fe0e74a532b91d1bb4b8 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Mon, 8 Sep 2014 05:09:02 +0200 Subject: Bug 1063: Complete Uri impl. and adoption throughout GlueGen - Uri: - Add error correction (fix) of path at ctor in case a a contained Uri is requested from an opaque one. The latter might come from URI/URL and is not properly encoded! See Uri.PARSE_HINT_FIX_PATH - Simplify conversion methods: - valueOf(URI/URL): Re-encode only if not opaque - getNativeFilePath() -> toFile() - Move IOUtil Uri related constants to class Uri - Add DEBUG and DEBUG_SHOWFIX - Complete adoption of URI -> Uri changes - IOUtil, JarUtil and TempJarCache still holds some left over deprecated methods, which will be removed after officially starting 2.3.0 (JOGL dependencies) - Otherwise not URI utilization left - Tests - Cleaned ip TestUri01 and TestUri03Resolving - TestUri03Resolving also tests URL -> Uri, and hence mentioned Uri.PARSE_HINT_FIX_PATH --- src/junit/com/jogamp/common/util/TestJarUtil.java | 40 ++++++++++++++-------- .../com/jogamp/common/util/TestTempJarCache.java | 29 ++++++++++++---- 2 files changed, 47 insertions(+), 22 deletions(-) (limited to 'src/junit/com/jogamp/common/util') diff --git a/src/junit/com/jogamp/common/util/TestJarUtil.java b/src/junit/com/jogamp/common/util/TestJarUtil.java index db5c268..06a2e43 100644 --- a/src/junit/com/jogamp/common/util/TestJarUtil.java +++ b/src/junit/com/jogamp/common/util/TestJarUtil.java @@ -30,7 +30,6 @@ package com.jogamp.common.util; import java.io.IOException; import java.net.MalformedURLException; -import java.net.URI; import java.net.URISyntaxException; import java.net.URL; import java.net.URLClassLoader; @@ -46,6 +45,8 @@ import org.junit.BeforeClass; import org.junit.Test; import com.jogamp.common.GlueGenVersion; +import com.jogamp.common.net.URIDumpUtil; +import com.jogamp.common.net.Uri; import com.jogamp.common.os.AndroidVersion; import com.jogamp.common.util.cache.TempCacheReg; import com.jogamp.common.util.cache.TempFileCache; @@ -97,7 +98,7 @@ public class TestJarUtil extends JunitTracer { } } - void validateJarFileURL(final URI jarFileURI) throws IllegalArgumentException, IOException, URISyntaxException { + void validateJarFileURL(final Uri jarFileURI) throws IllegalArgumentException, IOException, URISyntaxException { Assert.assertNotNull(jarFileURI); final URL jarFileURL = jarFileURI.toURL(); final URLConnection aURLc = jarFileURL.openConnection(); @@ -110,18 +111,27 @@ public class TestJarUtil extends JunitTracer { } void validateJarUtil(final String expJarName, final String clazzBinName, final ClassLoader cl) throws IllegalArgumentException, IOException, URISyntaxException { - final String jarName= JarUtil.getJarBasename(clazzBinName, cl); + final Uri.Encoded expJarNameE = Uri.Encoded.cast(expJarName); + final Uri.Encoded jarName= JarUtil.getJarBasename(clazzBinName, cl); Assert.assertNotNull(jarName); - Assert.assertEquals(expJarName, jarName); + Assert.assertEquals(expJarNameE, jarName); - final URI jarSubURI = JarUtil.getJarSubURI(clazzBinName, cl); - Assert.assertNotNull(jarSubURI); - final URL jarSubURL= jarSubURI.toURL(); + final Uri jarUri = JarUtil.getJarUri(clazzBinName, cl); + Assert.assertNotNull(jarUri); + System.err.println("1 - jarUri:"); + URIDumpUtil.showUri(jarUri); + + final Uri jarSubUri = jarUri.getContainedUri(); + Assert.assertNotNull(jarSubUri); + System.err.println("2 - jarSubUri:"); + URIDumpUtil.showUri(jarSubUri); + + final URL jarSubURL= jarSubUri.toURL(); final URLConnection urlConn = jarSubURL.openConnection(); Assert.assertTrue("jarSubURL has zero content: "+jarSubURL, urlConn.getContentLength()>0); System.err.println("URLConnection of jarSubURL: "+urlConn); - final URI jarFileURL = JarUtil.getJarFileURI(clazzBinName, cl); + final Uri jarFileURL = JarUtil.getJarFileUri(clazzBinName, cl); validateJarFileURL(jarFileURL); final JarFile jarFile = JarUtil.getJarFile(clazzBinName, cl); @@ -146,10 +156,10 @@ public class TestJarUtil extends JunitTracer { final ClassLoader rootCL = this.getClass().getClassLoader(); // Get containing JAR file "TestJarsInJar.jar" and add it to the TempJarCache - TempJarCache.addAll(GlueGenVersion.class, JarUtil.getJarFileURI("ClassInJar0", rootCL)); + TempJarCache.addAll(GlueGenVersion.class, JarUtil.getJarFileUri("ClassInJar0", rootCL)); // Fetch and load the contained "ClassInJar1.jar" - final URL ClassInJar1_jarFileURL = JarUtil.getJarFileURI(TempJarCache.getResource("ClassInJar1.jar")).toURL(); + final URL ClassInJar1_jarFileURL = JarUtil.getJarFileUri(TempJarCache.getResourceUri("ClassInJar1.jar")).toURL(); final ClassLoader cl = new URLClassLoader(new URL[] { ClassInJar1_jarFileURL }, rootCL); Assert.assertNotNull(cl); validateJarUtil("ClassInJar1.jar", "ClassInJar1", cl); @@ -167,10 +177,10 @@ public class TestJarUtil extends JunitTracer { final ClassLoader rootCL = this.getClass().getClassLoader(); // Get containing JAR file "TestJarsInJar.jar" and add it to the TempJarCache - TempJarCache.addAll(GlueGenVersion.class, JarUtil.getJarFileURI("ClassInJar0", rootCL)); + TempJarCache.addAll(GlueGenVersion.class, JarUtil.getJarFileUri("ClassInJar0", rootCL)); // Fetch and load the contained "ClassInJar1.jar" - final URL ClassInJar2_jarFileURL = JarUtil.getJarFileURI(TempJarCache.getResource("sub/ClassInJar2.jar")).toURL(); + final URL ClassInJar2_jarFileURL = JarUtil.getJarFileUri(TempJarCache.getResourceUri("sub/ClassInJar2.jar")).toURL(); final ClassLoader cl = new URLClassLoader(new URL[] { ClassInJar2_jarFileURL }, rootCL); Assert.assertNotNull(cl); validateJarUtil("ClassInJar2.jar", "ClassInJar2", cl); @@ -231,7 +241,7 @@ public class TestJarUtil extends JunitTracer { public URL resolve( final URL url ) { if( url.getProtocol().equals("bundleresource") ) { try { - return new URL( IOUtil.JAR_SCHEME, "", url.getFile() ); + return new URL( Uri.JAR_SCHEME, "", url.getFile() ); } catch(final MalformedURLException e) { return url; } @@ -244,10 +254,10 @@ public class TestJarUtil extends JunitTracer { final ClassLoader rootCL = new CustomClassLoader(); // Get containing JAR file "TestJarsInJar.jar" and add it to the TempJarCache - TempJarCache.addAll(GlueGenVersion.class, JarUtil.getJarFileURI("ClassInJar0", rootCL)); + TempJarCache.addAll(GlueGenVersion.class, JarUtil.getJarFileUri("ClassInJar0", rootCL)); // Fetch and load the contained "ClassInJar1.jar" - final URL ClassInJar2_jarFileURL = JarUtil.getJarFileURI(TempJarCache.getResource("sub/ClassInJar2.jar")).toURL(); + final URL ClassInJar2_jarFileURL = JarUtil.getJarFileUri(TempJarCache.getResourceUri("sub/ClassInJar2.jar")).toURL(); final ClassLoader cl = new URLClassLoader(new URL[] { ClassInJar2_jarFileURL }, rootCL); Assert.assertNotNull(cl); validateJarUtil("ClassInJar2.jar", "ClassInJar2", cl); diff --git a/src/junit/com/jogamp/common/util/TestTempJarCache.java b/src/junit/com/jogamp/common/util/TestTempJarCache.java index cd825fe..474a17a 100644 --- a/src/junit/com/jogamp/common/util/TestTempJarCache.java +++ b/src/junit/com/jogamp/common/util/TestTempJarCache.java @@ -31,7 +31,6 @@ package com.jogamp.common.util; import java.io.File; import java.io.IOException; import java.lang.reflect.Method; -import java.net.URI; import java.net.URISyntaxException; import java.net.URL; import java.net.URLClassLoader; @@ -44,6 +43,8 @@ import org.junit.Test; import org.junit.runners.MethodSorters; import com.jogamp.common.GlueGenVersion; +import com.jogamp.common.net.URIDumpUtil; +import com.jogamp.common.net.Uri; import com.jogamp.common.os.AndroidVersion; import com.jogamp.common.os.NativeLibrary; import com.jogamp.common.os.Platform; @@ -175,7 +176,7 @@ public class TestTempJarCache extends JunitTracer { if(AndroidVersion.isAvailable) { System.err.println("n/a on Android"); return; } final ClassLoader cl = getClass().getClassLoader(); - TempJarCache.addAll(GlueGenVersion.class, JarUtil.getJarFileURI(GlueGenVersion.class.getName(), cl)); + TempJarCache.addAll(GlueGenVersion.class, JarUtil.getJarFileUri(GlueGenVersion.class.getName(), cl)); File f0 = new File(TempJarCache.getTempFileCache().getTempDir(), "META-INF/MANIFEST.MF"); Assert.assertTrue(f0.exists()); @@ -195,14 +196,28 @@ public class TestTempJarCache extends JunitTracer { @Test public void testTempJarCache02AddNativeLibs() throws IOException, IllegalArgumentException, URISyntaxException { if(AndroidVersion.isAvailable) { System.err.println("n/a on Android"); return; } - final String nativeJarName = "gluegen-rt-natives-"+Platform.getOSAndArch()+".jar"; + final Uri.Encoded nativeJarName = Uri.Encoded.cast("gluegen-rt-natives-"+Platform.getOSAndArch()+".jar"); final String libBaseName = "gluegen-rt"; final ClassLoader cl = getClass().getClassLoader(); - URI jarUriRoot = JarUtil.getJarSubURI(TempJarCache.class.getName(), cl); - jarUriRoot = IOUtil.getURIDirname(jarUriRoot); + final Uri jarUri = JarUtil.getJarUri(TempJarCache.class.getName(), cl); + Assert.assertNotNull(jarUri); + System.err.println("1 - jarUri:"); + URIDumpUtil.showUri(jarUri); - final URI nativeJarURI = JarUtil.getJarFileURI(jarUriRoot, nativeJarName); + final Uri jarFileUri = jarUri.getContainedUri(); + Assert.assertNotNull(jarFileUri); + System.err.println("2 - jarFileUri:"); + URIDumpUtil.showUri(jarFileUri); + + final Uri jarFileDir = jarFileUri.getParent(); + Assert.assertNotNull(jarFileDir); + System.err.println("3 - jarFileDir:"); + URIDumpUtil.showUri(jarFileDir); + + final Uri nativeJarURI = JarUtil.getJarFileUri(jarFileDir, nativeJarName); + System.err.println("4 - nativeJarURI:"); + URIDumpUtil.showUri(nativeJarURI); TempJarCache.addNativeLibs(TempJarCache.class, nativeJarURI, null /* nativeLibraryPath */); final String libFullPath = TempJarCache.findLibrary(libBaseName); @@ -225,7 +240,7 @@ public class TestTempJarCache extends JunitTracer { @Test public void testTempJarCache04bDiffClassLoader() throws IOException, IllegalArgumentException, URISyntaxException { if(AndroidVersion.isAvailable) { System.err.println("n/a on Android"); return; } - final URL[] urls = new URL[] { JarUtil.getJarFileURI(TempJarCache.class.getName(), getClass().getClassLoader()).toURL() }; + final URL[] urls = new URL[] { JarUtil.getJarFileUri(TempJarCache.class.getName(), getClass().getClassLoader()).toURL() }; System.err.println("url: "+urls[0]); final ClassLoader cl2 = new TestClassLoader(urls, null); final ClassLoader cl3 = new TestClassLoader(urls, null); -- cgit v1.2.3