From c9093e491d4b78b12973ec1614bf3146fce26a83 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Fri, 18 Oct 2013 22:09:43 +0200 Subject: Fix Bug 857: GlueGen produces erroneous file URI on Windows, which breaks Netbeans's JarURLStreamHandler - 'URL IOUtil.toURL(URI)' - Needs to encode the file-path portion on Windows(*) if exists. The file-path here shall only be encoded as follows: - backslash -> slash - ensure starting with slash (*) We perform above action for all OS, if 'false == File.separator.equals("/")' - Added high verbosity in DEBUG mode to easy debugging for future cases .. - Cleanup URI/URL unit tests, i.e. split URLCompositionTest into: - TestIOUtilURICompose - TestIOUtilURIHandling (Now covers Bug 857 as well) - TestUrisWithAssetHandler - TestURIQueryProps Tested all unit tests manually on GNU/Linux and Windows w/ JRE 7u45 --- .../jogamp/common/util/TestIOUtilURICompose.java | 92 +++++++++++++ .../jogamp/common/util/TestIOUtilURIHandling.java | 150 +++++++++++++++++++++ 2 files changed, 242 insertions(+) create mode 100644 src/junit/com/jogamp/common/util/TestIOUtilURICompose.java create mode 100644 src/junit/com/jogamp/common/util/TestIOUtilURIHandling.java (limited to 'src/junit/com/jogamp/common/util') diff --git a/src/junit/com/jogamp/common/util/TestIOUtilURICompose.java b/src/junit/com/jogamp/common/util/TestIOUtilURICompose.java new file mode 100644 index 0000000..0809599 --- /dev/null +++ b/src/junit/com/jogamp/common/util/TestIOUtilURICompose.java @@ -0,0 +1,92 @@ +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 org.junit.Assert; +import org.junit.Test; + +import com.jogamp.common.util.IOUtil; +import com.jogamp.junit.util.JunitTracer; + +import org.junit.FixMethodOrder; +import org.junit.runners.MethodSorters; + +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class TestIOUtilURICompose extends JunitTracer { + + @Test + public void test01URLCompositioning() throws IOException, URISyntaxException { + testURNCompositioning("file:///rootDir/file1.txt"); + testURNCompositioning("file://host/rootDir/file1.txt"); + testURNCompositioning("jar:file:/web1/file1.jar!/rootDir/file1.txt"); + testURNCompositioning("asset:gluegen-test/info.txt"); + testURNCompositioning("asset:/gluegen-test/info.txt"); + testURNCompositioning("http://domain.com/web1/index.html?lala=23&lili=24#anchor"); + testURNCompositioning("http://domain.com:1234/web1/index.html?lala=23&lili=24#anchor"); + + final URI file1URI = new URI("asset:jar:file:/web1/file1.jar!/rootDir/file1.txt"); + testURICompositioning(file1URI); + testURICompositioning(file1URI, new URI("asset:jar:file:/web1/file1.jar!/rootDir/./file1.txt")); + testURICompositioning(file1URI, new URI("asset:jar:file:/web1/file1.jar!/rootDir/dummyParent/../file1.txt")); + + final URL file1URL = new URL("asset:jar:file:/web1/file1.jar!/rootDir/file1.txt"); + testURLCompositioning(file1URL); + testURLCompositioning(file1URL, new URL("asset:jar:file:/web1/file1.jar!/rootDir/./file1.txt")); + testURLCompositioning(file1URL, new URL("asset:jar:file:/web1/file1.jar!/rootDir/dummyParent/../file1.txt")); + } + + static void testURNCompositioning(String urn) throws MalformedURLException, URISyntaxException { + testURICompositioning( new URI(urn) ); + testURLCompositioning( new URL(urn) ); + } + + static void testURICompositioning(URI uri) throws MalformedURLException, URISyntaxException { + testURICompositioning(uri, uri); + } + static void testURICompositioning(URI refURI, URI uri1) throws MalformedURLException, URISyntaxException { + final String scheme = uri1.getScheme(); + final String ssp = uri1.getRawSchemeSpecificPart(); + final String fragment = uri1.getRawFragment(); + + System.err.println("scheme <"+scheme+">, ssp <"+ssp+">, fragment <"+fragment+">"); + final URI uri2 = IOUtil.compose(scheme, ssp, null, fragment); + + System.err.println("URL-equals: "+refURI.equals(uri2)); + System.err.println("URL-ref : <"+refURI+">"); + System.err.println("URL-orig : <"+uri1+">"); + System.err.println("URL-comp : <"+uri2+">"); + Assert.assertEquals(refURI, uri2); + } + + static void testURLCompositioning(URL url) throws MalformedURLException, URISyntaxException { + testURLCompositioning(url, url); + } + static void testURLCompositioning(URL refURL, URL url1) throws MalformedURLException, URISyntaxException { + final URI uri1 = url1.toURI(); + final String scheme = uri1.getScheme(); + final String ssp = uri1.getRawSchemeSpecificPart(); + final String fragment = uri1.getRawFragment(); + + System.err.println("scheme <"+scheme+">, ssp <"+ssp+">, fragment <"+fragment+">"); + final URI uri2 = IOUtil.compose(scheme, ssp, null, fragment); + + System.err.println("URL-equals(1): "+refURL.toURI().equals(uri2)); + System.err.println("URL-equals(2): "+refURL.equals(uri2.toURL())); + System.err.println("URL-same : "+refURL.sameFile(uri2.toURL())); + System.err.println("URL-ref : <"+refURL+">"); + System.err.println("URL-orig : <"+url1+">"); + System.err.println("URL-comp : <"+uri2+">"); + Assert.assertEquals(refURL.toURI(), uri2); + Assert.assertEquals(refURL, uri2.toURL()); + Assert.assertTrue(refURL.sameFile(uri2.toURL())); + } + + public static void main(String args[]) throws IOException { + String tstname = TestIOUtilURICompose.class.getName(); + org.junit.runner.JUnitCore.main(tstname); + } +} diff --git a/src/junit/com/jogamp/common/util/TestIOUtilURIHandling.java b/src/junit/com/jogamp/common/util/TestIOUtilURIHandling.java new file mode 100644 index 0000000..73f6ce7 --- /dev/null +++ b/src/junit/com/jogamp/common/util/TestIOUtilURIHandling.java @@ -0,0 +1,150 @@ +package com.jogamp.common.util; + +import static com.jogamp.common.net.URIDumpUtil.showURX; + +import java.io.IOException; +import java.net.URI; +import java.net.URISyntaxException; +import java.net.URL; +import java.net.URLConnection; + +import org.junit.Assert; +import org.junit.Test; + +import com.jogamp.common.os.Platform; +import com.jogamp.common.util.IOUtil; +import com.jogamp.junit.util.JunitTracer; + +import org.junit.FixMethodOrder; +import org.junit.runners.MethodSorters; + +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class TestIOUtilURIHandling extends JunitTracer { + + static final String[][] uriHttpSArray = new String[][] { + new String[] {"http://localhost/gluegen/build-x86_64/gluegen-rt.jar", + "http://localhost/gluegen/build-x86_64/gluegen-rt.jar"}, + + new String[] {"http://localhost/gluegen/build-x86_64%20%c3%b6%c3%a4%20lala/gluegen-rt.jar", + "http://localhost/gluegen/build-x86_64%20%c3%b6%c3%a4%20lala/gluegen-rt.jar" + // "http://localhost/gluegen/build-x86_64 öä lala/gluegen-rt.jar" + }, + + new String[] {"jar:http://localhost/gluegen/build-x86_64/gluegen-rt.jar!/", + "jar:http://localhost/gluegen/build-x86_64/gluegen-rt.jar!/" }, + + new String[] {"jar:http://localhost/gluegen/build-x86_64%20%c3%b6%c3%a4%20lala/gluegen-rt.jar!/", + "jar:http://localhost/gluegen/build-x86_64%20%c3%b6%c3%a4%20lala/gluegen-rt.jar!/" + // "jar:http://localhost/gluegen/build-x86_64 öä lala/gluegen-rt.jar!/" + }, + + new String[] {"jar:http://localhost/gluegen/build-x86_64/gluegen-rt.jar!/com/jogamp/common/os/Platform.class", + "jar:http://localhost/gluegen/build-x86_64/gluegen-rt.jar!/com/jogamp/common/os/Platform.class" }, + + new String[] {"jar:http://localhost/gluegen/build-x86_64%20%c3%b6%c3%a4%20lala/gluegen-rt.jar!/com/jogamp/common/os/Platform.class", + "jar:http://localhost/gluegen/build-x86_64%20%c3%b6%c3%a4%20lala/gluegen-rt.jar!/com/jogamp/common/os/Platform.class" + // "jar:http://localhost/gluegen/build-x86_64 öä lala/gluegen-rt.jar!/com/jogamp/common/os/Platform.class" + }, + }; + + static final String[][] uriFileSArrayUnix = new String[][] { + new String[] {"file:/gluegen/build-x86_64/gluegen-rt.jar", + "file:/gluegen/build-x86_64/gluegen-rt.jar"}, + + new String[] {"file:/gluegen/build-x86_64%20%c3%b6%c3%a4%20lala/gluegen-rt.jar", + "file:/gluegen/build-x86_64 öä lala/gluegen-rt.jar"}, + + new String[] {"jar:file:/gluegen/build-x86_64/gluegen-rt.jar!/", + "jar:file:/gluegen/build-x86_64/gluegen-rt.jar!/" }, + + new String[] {"jar:file:/gluegen/build-x86_64%20%c3%b6%c3%a4%20lala/gluegen-rt.jar!/", + "jar:file:/gluegen/build-x86_64 öä lala/gluegen-rt.jar!/" }, + + new String[] {"jar:file:/gluegen/build-x86_64/gluegen-rt.jar!/com/jogamp/common/os/Platform.class", + "jar:file:/gluegen/build-x86_64/gluegen-rt.jar!/com/jogamp/common/os/Platform.class" }, + + new String[] {"jar:file:/gluegen/build-x86_64%20%c3%b6%c3%a4%20lala/gluegen-rt.jar!/com/jogamp/common/os/Platform.class", + "jar:file:/gluegen/build-x86_64 öä lala/gluegen-rt.jar!/com/jogamp/common/os/Platform.class" }, + }; + + static final String[][] uriFileSArrayWindows = new String[][] { + new String[] {"file:/C:/gluegen/build-x86_64/gluegen-rt.jar", + "file:/C:/gluegen/build-x86_64/gluegen-rt.jar"}, + + new String[] {"file:/C:/gluegen/build-x86_64%20%c3%b6%c3%a4%20lala/gluegen-rt.jar", + "file:/C:/gluegen/build-x86_64 öä lala/gluegen-rt.jar"}, + + new String[] {"jar:file:/C:/gluegen/build-x86_64/gluegen-rt.jar!/", + "jar:file:/C:/gluegen/build-x86_64/gluegen-rt.jar!/" }, + + new String[] {"jar:file:/C:/gluegen/build-x86_64%20%c3%b6%c3%a4%20lala/gluegen-rt.jar!/", + "jar:file:/C:/gluegen/build-x86_64 öä lala/gluegen-rt.jar!/" }, + + new String[] {"jar:file:/C:/gluegen/build-x86_64/gluegen-rt.jar!/com/jogamp/common/os/Platform.class", + "jar:file:/C:/gluegen/build-x86_64/gluegen-rt.jar!/com/jogamp/common/os/Platform.class" }, + + new String[] {"jar:file:/C:/gluegen/build-x86_64%20%c3%b6%c3%a4%20lala/gluegen-rt.jar!/com/jogamp/common/os/Platform.class", + "jar:file:/C:/gluegen/build-x86_64 öä lala/gluegen-rt.jar!/com/jogamp/common/os/Platform.class" }, + }; + + @Test + public void test01HttpURI2URL() throws IOException, URISyntaxException { + testURI2URL(uriHttpSArray, false /*usesFile*/, false /*matchOS*/); + } + + @Test + public void test02FileUnixURI2URL() throws IOException, URISyntaxException { + testURI2URL(uriFileSArrayUnix, true /*usesFile*/, Platform.OSType.WINDOWS != Platform.getOSType() /*matchOS*/); + } + + @Test + public void test02FileWindowsURI2URL() throws IOException, URISyntaxException { + testURI2URL(uriFileSArrayWindows, true /*usesFile*/, Platform.OSType.WINDOWS == Platform.getOSType() /*matchOS*/); + } + + static void testURI2URL(String[][] uriSArray, boolean usesFile, boolean matchOS) throws IOException, URISyntaxException { + for(int i=0; i