diff options
author | Sven Gothel <[email protected]> | 2013-06-09 05:33:16 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2013-06-09 05:33:16 +0200 |
commit | b98825eb7cfb61aead4a7dff57471cd2d2c26823 (patch) | |
tree | 8190c7eaac697e4150e47424dc975be512a3979d /src/junit/com/jogamp/common | |
parent | 959d6d83ec26152343d538287c02eeebf0dcf238 (diff) |
Fix Bug 683 part1: IOUtil, JarUtil, TempJarCache, .. uses URI instead of URL to remove DNS Lookups etc ..
Diffstat (limited to 'src/junit/com/jogamp/common')
5 files changed, 180 insertions, 84 deletions
diff --git a/src/junit/com/jogamp/common/net/AssetURLConnectionRegisteredTest.java b/src/junit/com/jogamp/common/net/AssetURLConnectionRegisteredTest.java index edf1592..2db3fb3 100644 --- a/src/junit/com/jogamp/common/net/AssetURLConnectionRegisteredTest.java +++ b/src/junit/com/jogamp/common/net/AssetURLConnectionRegisteredTest.java @@ -1,6 +1,8 @@ package com.jogamp.common.net; import java.io.IOException; +import java.net.URI; +import java.net.URISyntaxException; import java.net.URL; import java.net.URLConnection; @@ -36,39 +38,39 @@ public class AssetURLConnectionRegisteredTest extends AssetURLConnectionBase { } @Test - public void assetRegisteredIOUtilGetResourceRel1_RT() throws IOException { + public void assetRegisteredIOUtilGetResourceRel1_RT() throws IOException, URISyntaxException { final URLConnection urlConn0 = IOUtil.getResource(test_asset_test2a_url, this.getClass().getClassLoader()); Assert.assertNotNull(urlConn0); Assert.assertEquals(test_asset_test2a_url, urlConn0.getURL().toExternalForm()); testAssetConnection(urlConn0, test_asset_test2_entry); - final URL url1 = IOUtil.getRelativeOf(urlConn0.getURL(), test_asset_test3_rel); - Assert.assertNotNull(url1); - Assert.assertEquals(test_asset_test3a_url, url1.toExternalForm()); - testAssetConnection(url1.openConnection(), test_asset_test3_entry); + final URI uri1 = IOUtil.getRelativeOf(urlConn0.getURL().toURI(), test_asset_test3_rel); + Assert.assertNotNull(uri1); + Assert.assertEquals(test_asset_test3a_url, uri1.toString()); + testAssetConnection(uri1.toURL().openConnection(), test_asset_test3_entry); - final URL url2 = IOUtil.getRelativeOf(urlConn0.getURL(), test_asset_test4_rel); - Assert.assertNotNull(url1); - Assert.assertEquals(test_asset_test4a_url, url2.toExternalForm()); - testAssetConnection(url2.openConnection(), test_asset_test4_entry); + final URI uri2 = IOUtil.getRelativeOf(urlConn0.getURL().toURI(), test_asset_test4_rel); + Assert.assertNotNull(uri2); + Assert.assertEquals(test_asset_test4a_url, uri2.toString()); + testAssetConnection(uri2.toURL().openConnection(), test_asset_test4_entry); } @Test - public void assetRegisteredIOUtilGetResourceRel2_RT() throws IOException { + public void assetRegisteredIOUtilGetResourceRel2_RT() throws IOException, URISyntaxException { final URLConnection urlConn0 = IOUtil.getResource(test_asset_test2b_url, this.getClass().getClassLoader()); Assert.assertNotNull(urlConn0); Assert.assertEquals(test_asset_test2b_url, urlConn0.getURL().toExternalForm()); testAssetConnection(urlConn0, test_asset_test2_entry); - final URL url1 = IOUtil.getRelativeOf(urlConn0.getURL(), test_asset_test3_rel); - Assert.assertNotNull(url1); - Assert.assertEquals(test_asset_test3b_url, url1.toExternalForm()); - testAssetConnection(url1.openConnection(), test_asset_test3_entry); + final URI uri1 = IOUtil.getRelativeOf(urlConn0.getURL().toURI(), test_asset_test3_rel); + Assert.assertNotNull(uri1); + Assert.assertEquals(test_asset_test3b_url, uri1.toString()); + testAssetConnection(uri1.toURL().openConnection(), test_asset_test3_entry); - final URL url2 = IOUtil.getRelativeOf(urlConn0.getURL(), test_asset_test4_rel); - Assert.assertNotNull(url1); - Assert.assertEquals(test_asset_test4b_url, url2.toExternalForm()); - testAssetConnection(url2.openConnection(), test_asset_test4_entry); + final URI uri2 = IOUtil.getRelativeOf(urlConn0.getURL().toURI(), test_asset_test4_rel); + Assert.assertNotNull(uri2); + Assert.assertEquals(test_asset_test4b_url, uri2.toString()); + testAssetConnection(uri2.toURL().openConnection(), test_asset_test4_entry); } URLConnection createAssetURLConnection(String path) throws IOException { diff --git a/src/junit/com/jogamp/common/net/AssetURLConnectionUnregisteredTest.java b/src/junit/com/jogamp/common/net/AssetURLConnectionUnregisteredTest.java index cf26da4..be32c98 100644 --- a/src/junit/com/jogamp/common/net/AssetURLConnectionUnregisteredTest.java +++ b/src/junit/com/jogamp/common/net/AssetURLConnectionUnregisteredTest.java @@ -1,6 +1,8 @@ package com.jogamp.common.net; import java.io.IOException; +import java.net.URI; +import java.net.URISyntaxException; import java.net.URL; import java.net.URLConnection; @@ -32,17 +34,17 @@ public class AssetURLConnectionUnregisteredTest extends AssetURLConnectionBase { } @Test - public void assetUnregisteredIOUtilGetResourceRel0_RT() throws IOException { + public void assetUnregisteredIOUtilGetResourceRel0_RT() throws IOException, URISyntaxException { final URLConnection urlConn0 = IOUtil.getResource(this.getClass(), test_asset_test2_rel); testAssetConnection(urlConn0, test_asset_test2_entry); - final URL url1 = IOUtil.getRelativeOf(urlConn0.getURL(), test_asset_test3_rel); - Assert.assertNotNull(url1); // JARFile URL .. - testAssetConnection(url1.openConnection(), test_asset_test3_entry); + final URI uri1 = IOUtil.getRelativeOf(urlConn0.getURL().toURI(), test_asset_test3_rel); + Assert.assertNotNull(uri1); // JARFile URL .. + testAssetConnection(uri1.toURL().openConnection(), test_asset_test3_entry); - final URL url2 = IOUtil.getRelativeOf(urlConn0.getURL(), test_asset_test4_rel); - Assert.assertNotNull(url1); - testAssetConnection(url2.openConnection(), test_asset_test4_entry); + final URI uri2 = IOUtil.getRelativeOf(urlConn0.getURL().toURI(), test_asset_test4_rel); + Assert.assertNotNull(uri2); + testAssetConnection(uri2.toURL().openConnection(), test_asset_test4_entry); } protected static URLConnection createAssetURLConnection(String path, ClassLoader cl) throws IOException { diff --git a/src/junit/com/jogamp/common/net/URLCompositionTest.java b/src/junit/com/jogamp/common/net/URLCompositionTest.java index 36b38ab..405e877 100644 --- a/src/junit/com/jogamp/common/net/URLCompositionTest.java +++ b/src/junit/com/jogamp/common/net/URLCompositionTest.java @@ -2,6 +2,8 @@ package com.jogamp.common.net; import java.io.IOException; import java.net.MalformedURLException; +import java.net.URI; +import java.net.URISyntaxException; import java.net.URL; import org.junit.Assert; @@ -27,41 +29,125 @@ public class URLCompositionTest extends JunitTracer { } @Test - public void showURLComponents() throws IOException { - testURLCompositioning(new URL("file:///rootDir/file1.txt")); - testURLCompositioning(new URL("file://host/rootDir/file1.txt")); - testURLCompositioning(new URL("jar:file:/web1/file1.jar!/rootDir/file1.txt")); - testURLCompositioning(new URL("asset:gluegen-test/info.txt")); - testURLCompositioning(new URL("asset:/gluegen-test/info.txt")); - testURLCompositioning(new URL("http://domain.com:1234/web1/index.html?lala=23&lili=24#anchor")); + public void showURLComponents0() throws IOException, URISyntaxException { + showURX("file:///rootDir/file1.txt"); + showURX("file://host/rootDir/file1.txt"); + showURX("jar:file:/web1/file1.jar!/rootDir/file1.txt"); + showURX("asset:gluegen-test/info.txt"); + showURX("asset:/gluegen-test/info.txt"); + showURX("http://domain.com/web1/index.html?lala=23&lili=24#anchor"); + showURX("http://domain.com:1234/web1/index.html?lala=23&lili=24#anchor"); + showURX("asset:jar:file:/web1/file1.jar!/rootDir/file1.txt"); + showURX("asset:jar:file:/web1/file1.jar!/rootDir/./file1.txt"); + showURX("asset:jar:file:/web1/file1.jar!/rootDir/dummyParent/../file1.txt"); + } + + static void showURX(String urx) throws MalformedURLException, URISyntaxException { + System.err.println("XXXXXX "+urx); + showURL(new URL(urx)); + showURI(new URI(urx)); + System.err.println("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"); + } + + static void showURL(URL url) { + System.err.println("YYYYYY URL "+url); + System.err.println("protocol: "+url.getProtocol()); + System.err.println("auth: "+url.getAuthority()); + System.err.println("host: "+url.getHost()); + System.err.println("port: "+url.getPort() + " ( " + url.getDefaultPort() + " ) " ); + System.err.println("file: "+url.getFile() + " ( path " + url.getPath() + ", query " + url.getQuery() + " ) " ); + System.err.println("ref: "+url.getRef()); + } + static void showURI(URI uri) { + System.err.println("ZZZZZZ URI "+uri); + // 1 [scheme:]scheme-specific-part[#fragment] + System.err.println("1 scheme: "+uri.getScheme()); + System.err.println("1 scheme-part: "+uri.getRawSchemeSpecificPart()); + System.err.println("1 fragment: "+uri.getRawFragment()); + + // 2 [scheme:][//authority][path][?query][#fragment] + System.err.println("2 scheme: "+uri.getScheme()); + System.err.println("2 auth: "+uri.getRawAuthority()); + System.err.println("2 path: "+uri.getRawPath()); + System.err.println("2 query: "+uri.getRawQuery()); + System.err.println("2 fragment: "+uri.getRawFragment()); + + // 3 [scheme:][//authority][path][?query][#fragment] + // authority: [user-info@]host[:port] + System.err.println("3 scheme: "+uri.getScheme()); + System.err.println("3 user-info: "+uri.getRawUserInfo()); + System.err.println("3 host: "+uri.getHost()); + System.err.println("3 port: "+uri.getPort()); + System.err.println("3 path: "+uri.getRawPath()); + System.err.println("3 query: "+uri.getRawQuery()); + System.err.println("3 fragment: "+uri.getRawFragment()); + } + + @Test + public void showURLComponents1() 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 testURLCompositioning(URL u) throws MalformedURLException { - testURLCompositioning(u, u); + + static void testURNCompositioning(String urn) throws MalformedURLException, URISyntaxException { + testURICompositioning( new URI(urn) ); + testURLCompositioning( new URL(urn) ); } - static void testURLCompositioning(URL refURL, URL u) throws MalformedURLException { - final String scheme = u.getProtocol(); - final String auth = u.getAuthority(); - String path = u.getPath(); - String query = u.getQuery(); - String fragment = u.getRef(); + 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+">, auth <"+auth+">, path <"+path+">, query <"+query+">, fragment <"+fragment+">"); - URL u2 = IOUtil.compose(scheme, auth, path, null, query, fragment); + 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("URL-equals: "+refURL.equals(u2)); - System.err.println("URL-same : "+refURL.sameFile(u2)); + 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 : <"+u+">"); - System.err.println("URL-comp : <"+u2+">"); - Assert.assertEquals(refURL, u2); - Assert.assertTrue(refURL.sameFile(u2)); + 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 { diff --git a/src/junit/com/jogamp/common/util/TestJarUtil.java b/src/junit/com/jogamp/common/util/TestJarUtil.java index ace2d7b..ab78556 100644 --- a/src/junit/com/jogamp/common/util/TestJarUtil.java +++ b/src/junit/com/jogamp/common/util/TestJarUtil.java @@ -30,6 +30,8 @@ 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; import java.net.URLConnection; @@ -92,10 +94,10 @@ public class TestJarUtil extends JunitTracer { } } - void validateJarFileURL(URL jarFileURL) throws IllegalArgumentException, IOException { - Assert.assertNotNull(jarFileURL); - URLConnection aURLc = jarFileURL.openConnection(); - Assert.assertTrue("jarFileURL has zero content: "+jarFileURL, aURLc.getContentLength()>0); + 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); System.err.println("URLConnection: "+aURLc); Assert.assertTrue("Not a JarURLConnection: "+aURLc, (aURLc instanceof JarURLConnection) ); JarURLConnection jURLc = (JarURLConnection) aURLc; @@ -103,18 +105,18 @@ public class TestJarUtil extends JunitTracer { validateJarFile(jarFile); } - void validateJarUtil(String expJarName, String clazzBinName, ClassLoader cl) throws IllegalArgumentException, IOException { + void validateJarUtil(String expJarName, String clazzBinName, ClassLoader cl) throws IllegalArgumentException, IOException, URISyntaxException { String jarName= JarUtil.getJarBasename(clazzBinName, cl); Assert.assertNotNull(jarName); Assert.assertEquals(expJarName, jarName); - URL jarSubURL = JarUtil.getJarSubURL(clazzBinName, cl); + URI jarSubURL = JarUtil.getJarSubURI(clazzBinName, cl); Assert.assertNotNull(jarSubURL); - URLConnection urlConn = jarSubURL.openConnection(); + URLConnection urlConn = jarSubURL.toURL().openConnection(); Assert.assertTrue("jarSubURL has zero content: "+jarSubURL, urlConn.getContentLength()>0); System.err.println("URLConnection of jarSubURL: "+urlConn); - URL jarFileURL = JarUtil.getJarFileURL(clazzBinName, cl); + URI jarFileURL = JarUtil.getJarFileURI(clazzBinName, cl); validateJarFileURL(jarFileURL); JarFile jarFile = JarUtil.getJarFile(clazzBinName, cl); @@ -122,14 +124,14 @@ public class TestJarUtil extends JunitTracer { } @Test - public void testJarUtilFlat01() throws IOException { + public void testJarUtilFlat01() throws IOException, IllegalArgumentException, URISyntaxException { System.err.println("XXXXXXXXXXXXXXXXXXXXXXXXXXXX"); validateJarUtil("TestJarsInJar.jar", "ClassInJar0", this.getClass().getClassLoader()); System.err.println("XXXXXXXXXXXXXXXXXXXXXXXXXXXX"); } @Test - public void testJarUtilJarInJar01() throws IOException, ClassNotFoundException { + public void testJarUtilJarInJar01() throws IOException, ClassNotFoundException, IllegalArgumentException, URISyntaxException { System.err.println("XXXXXXXXXXXXXXXXXXXXXXXXXXXX"); Assert.assertTrue(TempJarCache.initSingleton()); @@ -139,10 +141,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.getJarFileURL("ClassInJar0", rootCL)); + TempJarCache.addAll(GlueGenVersion.class, JarUtil.getJarFileURI("ClassInJar0", rootCL)); // Fetch and load the contained "ClassInJar1.jar" - final URL ClassInJar1_jarFileURL = JarUtil.getJarFileURL(TempJarCache.getResource("ClassInJar1.jar")); + final URL ClassInJar1_jarFileURL = JarUtil.getJarFileURI(TempJarCache.getResource("ClassInJar1.jar")).toURL(); final ClassLoader cl = new URLClassLoader(new URL[] { ClassInJar1_jarFileURL }, rootCL); Assert.assertNotNull(cl); validateJarUtil("ClassInJar1.jar", "ClassInJar1", cl); @@ -150,7 +152,7 @@ public class TestJarUtil extends JunitTracer { } @Test - public void testJarUtilJarInJar02() throws IOException, ClassNotFoundException { + public void testJarUtilJarInJar02() throws IOException, ClassNotFoundException, IllegalArgumentException, URISyntaxException { System.err.println("XXXXXXXXXXXXXXXXXXXXXXXXXXXX"); Assert.assertTrue(TempJarCache.initSingleton()); @@ -160,10 +162,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.getJarFileURL("ClassInJar0", rootCL)); + TempJarCache.addAll(GlueGenVersion.class, JarUtil.getJarFileURI("ClassInJar0", rootCL)); // Fetch and load the contained "ClassInJar1.jar" - final URL ClassInJar2_jarFileURL = JarUtil.getJarFileURL(TempJarCache.getResource("sub/ClassInJar2.jar")); + final URL ClassInJar2_jarFileURL = JarUtil.getJarFileURI(TempJarCache.getResource("sub/ClassInJar2.jar")).toURL(); final ClassLoader cl = new URLClassLoader(new URL[] { ClassInJar2_jarFileURL }, rootCL); Assert.assertNotNull(cl); validateJarUtil("ClassInJar2.jar", "ClassInJar2", cl); @@ -174,9 +176,11 @@ public class TestJarUtil extends JunitTracer { * Tests JarUtil's ability to resolve non-JAR URLs with a custom resolver. Meant to be used * in cases like an OSGi plugin, where all classes are loaded with custom classloaders and * therefore return URLs that don't start with "jar:". Adapted from test 02 above. + * @throws URISyntaxException + * @throws IllegalArgumentException */ @Test - public void testJarUtilJarInJar03() throws IOException, ClassNotFoundException { + public void testJarUtilJarInJar03() throws IOException, ClassNotFoundException, IllegalArgumentException, URISyntaxException { System.err.println("XXXXXXXXXXXXXXXXXXXXXXXXXXXX"); Assert.assertTrue(TempJarCache.initSingleton()); @@ -211,7 +215,7 @@ public class TestJarUtil extends JunitTracer { // shouldn't happen, since I create the URL correctly above Assert.assertTrue(false); } - return(urlReturn); + return urlReturn; } }; @@ -220,25 +224,25 @@ public class TestJarUtil extends JunitTracer { * by simply retrieving the JAR name from where we left it at the end of the URL. */ JarUtil.setResolver( new JarUtil.Resolver() { public URL resolve( URL url ) { - if(url.toString().startsWith("bundleresource")) { + if( url.getProtocol().equals("bundleresource") ) { try { - return(new URL("jar", "", url.getFile())); - } catch(IOException e) { - return(url); + return new URL( IOUtil.JAR_SCHEME, "", url.getFile() ); + } catch(MalformedURLException e) { + return url; } + } else { + return url; } - else - return(url); } } ); final ClassLoader rootCL = new CustomClassLoader(); // Get containing JAR file "TestJarsInJar.jar" and add it to the TempJarCache - TempJarCache.addAll(GlueGenVersion.class, JarUtil.getJarFileURL("ClassInJar0", rootCL)); + TempJarCache.addAll(GlueGenVersion.class, JarUtil.getJarFileURI("ClassInJar0", rootCL)); // Fetch and load the contained "ClassInJar1.jar" - final URL ClassInJar2_jarFileURL = JarUtil.getJarFileURL(TempJarCache.getResource("sub/ClassInJar2.jar")); + final URL ClassInJar2_jarFileURL = JarUtil.getJarFileURI(TempJarCache.getResource("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 5467e4c..7edb286 100644 --- a/src/junit/com/jogamp/common/util/TestTempJarCache.java +++ b/src/junit/com/jogamp/common/util/TestTempJarCache.java @@ -31,6 +31,8 @@ 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; import java.util.jar.JarFile; @@ -137,7 +139,7 @@ public class TestTempJarCache extends JunitTracer { } @Test - public void testJarUtil01a() throws IOException { + public void testJarUtil01a() throws IOException, IllegalArgumentException, URISyntaxException { if(AndroidVersion.isAvailable) { System.err.println("n/a on Android"); return; } JarFile jarFile = JarUtil.getJarFile(GlueGenVersion.class.getName(), this.getClass().getClassLoader()); Assert.assertNotNull(jarFile); @@ -168,11 +170,11 @@ public class TestTempJarCache extends JunitTracer { } @Test - public void testTempJarCache01LoadAllTestManifestAndClass() throws IOException { + public void testTempJarCache01LoadAllTestManifestAndClass() throws IOException, SecurityException, IllegalArgumentException, URISyntaxException { if(AndroidVersion.isAvailable) { System.err.println("n/a on Android"); return; } final ClassLoader cl = getClass().getClassLoader(); - TempJarCache.addAll(GlueGenVersion.class, JarUtil.getJarFileURL(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()); @@ -190,18 +192,18 @@ public class TestTempJarCache extends JunitTracer { } @Test - public void testTempJarCache02AddNativeLibs() throws IOException { + 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 String libBaseName = "gluegen-rt"; final ClassLoader cl = getClass().getClassLoader(); - URL jarUrlRoot = JarUtil.getJarSubURL(TempJarCache.class.getName(), cl); - jarUrlRoot = JarUtil.getURLDirname(jarUrlRoot); + URI jarUriRoot = JarUtil.getJarSubURI(TempJarCache.class.getName(), cl); + jarUriRoot = JarUtil.getURIDirname(jarUriRoot); - URL nativeJarURL = JarUtil.getJarFileURL(jarUrlRoot, nativeJarName); + URI nativeJarURI = JarUtil.getJarFileURI(jarUriRoot, nativeJarName); - TempJarCache.addNativeLibs(TempJarCache.class, nativeJarURL); + TempJarCache.addNativeLibs(TempJarCache.class, nativeJarURI); String libFullPath = TempJarCache.findLibrary(libBaseName); Assert.assertNotNull(libFullPath); Assert.assertEquals(libBaseName, NativeLibrary.isValidNativeLibraryName(libFullPath, true)); @@ -235,9 +237,9 @@ public class TestTempJarCache extends JunitTracer { } @Test - public void testTempJarCache04bDiffClassLoader() throws IOException { + public void testTempJarCache04bDiffClassLoader() throws IOException, IllegalArgumentException, URISyntaxException { if(AndroidVersion.isAvailable) { System.err.println("n/a on Android"); return; } - URL[] urls = new URL[] { JarUtil.getJarFileURL(TempJarCache.class.getName(), getClass().getClassLoader()) }; + URL[] urls = new URL[] { JarUtil.getJarFileURI(TempJarCache.class.getName(), getClass().getClassLoader()).toURL() }; System.err.println("url: "+urls[0]); ClassLoader cl2 = new TestClassLoader(urls, null); ClassLoader cl3 = new TestClassLoader(urls, null); |