42 import java.net.URL; |
42 import java.net.URL; |
43 import java.net.URLClassLoader; |
43 import java.net.URLClassLoader; |
44 import java.net.URLConnection; |
44 import java.net.URLConnection; |
45 import java.nio.file.Files; |
45 import java.nio.file.Files; |
46 import java.nio.file.Paths; |
46 import java.nio.file.Paths; |
|
47 import java.util.Enumeration; |
47 import java.util.jar.JarFile; |
48 import java.util.jar.JarFile; |
48 |
49 |
49 import org.testng.Assert; |
50 import org.testng.Assert; |
50 import org.testng.annotations.AfterClass; |
51 import org.testng.annotations.AfterClass; |
51 import org.testng.annotations.BeforeClass; |
52 import org.testng.annotations.BeforeClass; |
189 MethodHandle mh = MethodHandles.lookup().findVirtual(vcls, "getVersion", mt); |
190 MethodHandle mh = MethodHandles.lookup().findVirtual(vcls, "getVersion", mt); |
190 Assert.assertEquals((int)mh.invoke(vcls.newInstance()), |
191 Assert.assertEquals((int)mh.invoke(vcls.newInstance()), |
191 style.equals("unversioned") ? 8 : Runtime.version().major()); |
192 style.equals("unversioned") ? 8 : Runtime.version().major()); |
192 |
193 |
193 // now get a resource and verify that we don't have a fragment attached |
194 // now get a resource and verify that we don't have a fragment attached |
194 URL vclsUrl = vcls.getResource("/version/Version.class"); |
195 Enumeration<URL> vclsUrlEnum = cldr.getResources("version/Version.class"); |
195 String fragment = vclsUrl.getRef(); |
196 Assert.assertTrue(vclsUrlEnum.hasMoreElements()); |
196 Assert.assertNull(fragment); |
197 URL vclsUrls[] = new URL[] { |
197 |
198 vcls.getResource("/version/Version.class"), |
198 // and verify that the the url is a reified pointer to the runtime entry |
199 vcls.getResource("Version.class"), |
199 String rep = vclsUrl.toString(); |
200 cldr.getResource("version/Version.class"), |
200 //System.out.println(" getResource(\"/version/Version.class\") returned: " + rep); |
201 vclsUrlEnum.nextElement() |
201 if (style.equals("http")) { |
202 }; |
202 Assert.assertTrue(rep.startsWith("jar:http:")); |
203 Assert.assertFalse(vclsUrlEnum.hasMoreElements()); |
203 } else { |
204 for (URL vclsUrl : vclsUrls) { |
204 Assert.assertTrue(rep.startsWith("jar:file:")); |
205 String fragment = vclsUrl.getRef(); |
205 } |
206 Assert.assertNull(fragment); |
206 String suffix; |
207 |
207 if (style.equals("unversioned")) { |
208 // and verify that the the url is a reified pointer to the runtime entry |
208 suffix = ".jar!/version/Version.class"; |
209 String rep = vclsUrl.toString(); |
209 } else { |
210 //System.out.println(" getResource(\"/version/Version.class\") returned: " + rep); |
210 suffix = ".jar!/META-INF/versions/" + Runtime.version().major() |
211 if (style.equals("http")) { |
211 + "/version/Version.class"; |
212 Assert.assertTrue(rep.startsWith("jar:http:")); |
212 } |
213 } else { |
213 Assert.assertTrue(rep.endsWith(suffix)); |
214 Assert.assertTrue(rep.startsWith("jar:file:")); |
|
215 } |
|
216 String suffix; |
|
217 if (style.equals("unversioned")) { |
|
218 suffix = ".jar!/version/Version.class"; |
|
219 } else { |
|
220 suffix = ".jar!/META-INF/versions/" + Runtime.version().major() |
|
221 + "/version/Version.class"; |
|
222 } |
|
223 Assert.assertTrue(rep.endsWith(suffix)); |
|
224 } |
214 cldr.close(); |
225 cldr.close(); |
215 } |
226 } |
216 |
227 |
217 |
228 |
218 private boolean readAndCompare(URL url, String match) throws Exception { |
229 private boolean readAndCompare(URL url, String match) throws Exception { |