author | amlu |
Wed, 22 Mar 2017 19:40:20 +0800 | |
changeset 44358 | d1d1a888d492 |
parent 41355 | f80c213ae8ff |
permissions | -rw-r--r-- |
36129
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
1 |
/* |
38432
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37785
diff
changeset
|
2 |
* Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved. |
36129
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
4 |
* |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
8 |
* |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
13 |
* accompanied this code). |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
14 |
* |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
18 |
* |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
21 |
* questions. |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
22 |
*/ |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
23 |
|
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
24 |
/* |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
25 |
* @test |
39052
6660a4142993
8159785: Add test that tests ClassLoader.getResource/getResources in Multi-Release Jar
mli
parents:
38557
diff
changeset
|
26 |
* @bug 8132734 8144062 8159785 |
36129
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
27 |
* @summary Test that URL connections to multi-release jars can be runtime versioned |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
28 |
* @library /lib/testlibrary/java/util/jar |
44358
d1d1a888d492
8177383: Wrong @modules in java/io/FilePermission/ReadFileOnPath.java
amlu
parents:
41355
diff
changeset
|
29 |
* @modules jdk.compiler |
38557 | 30 |
* jdk.httpserver |
31 |
* jdk.jartool |
|
37785
daf6dcc73e9d
8151542: URL resources for multi-release jar files have a #runtime fragment appended to them
sdrach
parents:
36236
diff
changeset
|
32 |
* @build Compiler JarBuilder CreateMultiReleaseTestJars SimpleHttpServer |
36129
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
33 |
* @run testng MultiReleaseJarURLConnection |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
34 |
*/ |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
35 |
|
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
36 |
import java.io.IOException; |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
37 |
import java.io.InputStream; |
37785
daf6dcc73e9d
8151542: URL resources for multi-release jar files have a #runtime fragment appended to them
sdrach
parents:
36236
diff
changeset
|
38 |
import java.lang.invoke.MethodHandle; |
daf6dcc73e9d
8151542: URL resources for multi-release jar files have a #runtime fragment appended to them
sdrach
parents:
36236
diff
changeset
|
39 |
import java.lang.invoke.MethodHandles; |
daf6dcc73e9d
8151542: URL resources for multi-release jar files have a #runtime fragment appended to them
sdrach
parents:
36236
diff
changeset
|
40 |
import java.lang.invoke.MethodType; |
36129
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
41 |
import java.net.JarURLConnection; |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
42 |
import java.net.URL; |
37785
daf6dcc73e9d
8151542: URL resources for multi-release jar files have a #runtime fragment appended to them
sdrach
parents:
36236
diff
changeset
|
43 |
import java.net.URLClassLoader; |
36129
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
44 |
import java.net.URLConnection; |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
45 |
import java.nio.file.Files; |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
46 |
import java.nio.file.Paths; |
39052
6660a4142993
8159785: Add test that tests ClassLoader.getResource/getResources in Multi-Release Jar
mli
parents:
38557
diff
changeset
|
47 |
import java.util.Enumeration; |
36129
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
48 |
import java.util.jar.JarFile; |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
49 |
|
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
50 |
import org.testng.Assert; |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
51 |
import org.testng.annotations.AfterClass; |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
52 |
import org.testng.annotations.BeforeClass; |
36236
eec5770c5b01
8150679: closed/javax/crypto/CryptoPermission/CallerIdentification.sh fails after fix for JDK-8132734
sdrach
parents:
36129
diff
changeset
|
53 |
import org.testng.annotations.DataProvider; |
36129
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
54 |
import org.testng.annotations.Test; |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
55 |
|
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
56 |
public class MultiReleaseJarURLConnection { |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
57 |
String userdir = System.getProperty("user.dir","."); |
37785
daf6dcc73e9d
8151542: URL resources for multi-release jar files have a #runtime fragment appended to them
sdrach
parents:
36236
diff
changeset
|
58 |
String unversioned = userdir + "/unversioned.jar"; |
daf6dcc73e9d
8151542: URL resources for multi-release jar files have a #runtime fragment appended to them
sdrach
parents:
36236
diff
changeset
|
59 |
String unsigned = userdir + "/multi-release.jar"; |
daf6dcc73e9d
8151542: URL resources for multi-release jar files have a #runtime fragment appended to them
sdrach
parents:
36236
diff
changeset
|
60 |
String signed = userdir + "/signed-multi-release.jar"; |
daf6dcc73e9d
8151542: URL resources for multi-release jar files have a #runtime fragment appended to them
sdrach
parents:
36236
diff
changeset
|
61 |
SimpleHttpServer server; |
36129
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
62 |
|
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
63 |
@BeforeClass |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
64 |
public void initialize() throws Exception { |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
65 |
CreateMultiReleaseTestJars creator = new CreateMultiReleaseTestJars(); |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
66 |
creator.compileEntries(); |
37785
daf6dcc73e9d
8151542: URL resources for multi-release jar files have a #runtime fragment appended to them
sdrach
parents:
36236
diff
changeset
|
67 |
creator.buildUnversionedJar(); |
36129
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
68 |
creator.buildMultiReleaseJar(); |
36236
eec5770c5b01
8150679: closed/javax/crypto/CryptoPermission/CallerIdentification.sh fails after fix for JDK-8132734
sdrach
parents:
36129
diff
changeset
|
69 |
creator.buildSignedMultiReleaseJar(); |
37785
daf6dcc73e9d
8151542: URL resources for multi-release jar files have a #runtime fragment appended to them
sdrach
parents:
36236
diff
changeset
|
70 |
|
daf6dcc73e9d
8151542: URL resources for multi-release jar files have a #runtime fragment appended to them
sdrach
parents:
36236
diff
changeset
|
71 |
server = new SimpleHttpServer(); |
daf6dcc73e9d
8151542: URL resources for multi-release jar files have a #runtime fragment appended to them
sdrach
parents:
36236
diff
changeset
|
72 |
server.start(); |
daf6dcc73e9d
8151542: URL resources for multi-release jar files have a #runtime fragment appended to them
sdrach
parents:
36236
diff
changeset
|
73 |
|
36129
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
74 |
} |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
75 |
|
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
76 |
@AfterClass |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
77 |
public void close() throws IOException { |
37785
daf6dcc73e9d
8151542: URL resources for multi-release jar files have a #runtime fragment appended to them
sdrach
parents:
36236
diff
changeset
|
78 |
// Windows requires server to stop before file is deleted |
daf6dcc73e9d
8151542: URL resources for multi-release jar files have a #runtime fragment appended to them
sdrach
parents:
36236
diff
changeset
|
79 |
if (server != null) |
daf6dcc73e9d
8151542: URL resources for multi-release jar files have a #runtime fragment appended to them
sdrach
parents:
36236
diff
changeset
|
80 |
server.stop(); |
daf6dcc73e9d
8151542: URL resources for multi-release jar files have a #runtime fragment appended to them
sdrach
parents:
36236
diff
changeset
|
81 |
Files.delete(Paths.get(unversioned)); |
daf6dcc73e9d
8151542: URL resources for multi-release jar files have a #runtime fragment appended to them
sdrach
parents:
36236
diff
changeset
|
82 |
Files.delete(Paths.get(unsigned)); |
daf6dcc73e9d
8151542: URL resources for multi-release jar files have a #runtime fragment appended to them
sdrach
parents:
36236
diff
changeset
|
83 |
Files.delete(Paths.get(signed)); |
36129
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
84 |
} |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
85 |
|
36236
eec5770c5b01
8150679: closed/javax/crypto/CryptoPermission/CallerIdentification.sh fails after fix for JDK-8132734
sdrach
parents:
36129
diff
changeset
|
86 |
@DataProvider(name = "data") |
eec5770c5b01
8150679: closed/javax/crypto/CryptoPermission/CallerIdentification.sh fails after fix for JDK-8132734
sdrach
parents:
36129
diff
changeset
|
87 |
public Object[][] createData() { |
eec5770c5b01
8150679: closed/javax/crypto/CryptoPermission/CallerIdentification.sh fails after fix for JDK-8132734
sdrach
parents:
36129
diff
changeset
|
88 |
return new Object[][]{ |
37785
daf6dcc73e9d
8151542: URL resources for multi-release jar files have a #runtime fragment appended to them
sdrach
parents:
36236
diff
changeset
|
89 |
{"unversioned", unversioned}, |
daf6dcc73e9d
8151542: URL resources for multi-release jar files have a #runtime fragment appended to them
sdrach
parents:
36236
diff
changeset
|
90 |
{"unsigned", unsigned}, |
daf6dcc73e9d
8151542: URL resources for multi-release jar files have a #runtime fragment appended to them
sdrach
parents:
36236
diff
changeset
|
91 |
{"signed", signed} |
36236
eec5770c5b01
8150679: closed/javax/crypto/CryptoPermission/CallerIdentification.sh fails after fix for JDK-8132734
sdrach
parents:
36129
diff
changeset
|
92 |
}; |
eec5770c5b01
8150679: closed/javax/crypto/CryptoPermission/CallerIdentification.sh fails after fix for JDK-8132734
sdrach
parents:
36129
diff
changeset
|
93 |
} |
eec5770c5b01
8150679: closed/javax/crypto/CryptoPermission/CallerIdentification.sh fails after fix for JDK-8132734
sdrach
parents:
36129
diff
changeset
|
94 |
|
eec5770c5b01
8150679: closed/javax/crypto/CryptoPermission/CallerIdentification.sh fails after fix for JDK-8132734
sdrach
parents:
36129
diff
changeset
|
95 |
@Test(dataProvider = "data") |
37785
daf6dcc73e9d
8151542: URL resources for multi-release jar files have a #runtime fragment appended to them
sdrach
parents:
36236
diff
changeset
|
96 |
public void testRuntimeVersioning(String style, String file) throws Exception { |
36236
eec5770c5b01
8150679: closed/javax/crypto/CryptoPermission/CallerIdentification.sh fails after fix for JDK-8132734
sdrach
parents:
36129
diff
changeset
|
97 |
String urlFile = "jar:file:" + file + "!/"; |
37785
daf6dcc73e9d
8151542: URL resources for multi-release jar files have a #runtime fragment appended to them
sdrach
parents:
36236
diff
changeset
|
98 |
String baseUrlEntry = urlFile + "version/Version.java"; |
38432
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37785
diff
changeset
|
99 |
String rtreturn = "return " + Runtime.version().major(); |
37785
daf6dcc73e9d
8151542: URL resources for multi-release jar files have a #runtime fragment appended to them
sdrach
parents:
36236
diff
changeset
|
100 |
|
daf6dcc73e9d
8151542: URL resources for multi-release jar files have a #runtime fragment appended to them
sdrach
parents:
36236
diff
changeset
|
101 |
Assert.assertTrue(readAndCompare(new URL(baseUrlEntry), "return 8")); |
daf6dcc73e9d
8151542: URL resources for multi-release jar files have a #runtime fragment appended to them
sdrach
parents:
36236
diff
changeset
|
102 |
// #runtime is "magic" for a multi-release jar, but not for unversioned jar |
daf6dcc73e9d
8151542: URL resources for multi-release jar files have a #runtime fragment appended to them
sdrach
parents:
36236
diff
changeset
|
103 |
Assert.assertTrue(readAndCompare(new URL(baseUrlEntry + "#runtime"), |
daf6dcc73e9d
8151542: URL resources for multi-release jar files have a #runtime fragment appended to them
sdrach
parents:
36236
diff
changeset
|
104 |
style.equals("unversioned") ? "return 8" : rtreturn)); |
daf6dcc73e9d
8151542: URL resources for multi-release jar files have a #runtime fragment appended to them
sdrach
parents:
36236
diff
changeset
|
105 |
// #fragment or any other fragment is not magic |
daf6dcc73e9d
8151542: URL resources for multi-release jar files have a #runtime fragment appended to them
sdrach
parents:
36236
diff
changeset
|
106 |
Assert.assertTrue(readAndCompare(new URL(baseUrlEntry + "#fragment"), "return 8")); |
daf6dcc73e9d
8151542: URL resources for multi-release jar files have a #runtime fragment appended to them
sdrach
parents:
36236
diff
changeset
|
107 |
// cached entities not affected |
daf6dcc73e9d
8151542: URL resources for multi-release jar files have a #runtime fragment appended to them
sdrach
parents:
36236
diff
changeset
|
108 |
Assert.assertTrue(readAndCompare(new URL(baseUrlEntry), "return 8")); |
36236
eec5770c5b01
8150679: closed/javax/crypto/CryptoPermission/CallerIdentification.sh fails after fix for JDK-8132734
sdrach
parents:
36129
diff
changeset
|
109 |
|
37785
daf6dcc73e9d
8151542: URL resources for multi-release jar files have a #runtime fragment appended to them
sdrach
parents:
36236
diff
changeset
|
110 |
// the following tests will not work with unversioned jars |
daf6dcc73e9d
8151542: URL resources for multi-release jar files have a #runtime fragment appended to them
sdrach
parents:
36236
diff
changeset
|
111 |
if (style.equals("unversioned")) return; |
daf6dcc73e9d
8151542: URL resources for multi-release jar files have a #runtime fragment appended to them
sdrach
parents:
36236
diff
changeset
|
112 |
|
daf6dcc73e9d
8151542: URL resources for multi-release jar files have a #runtime fragment appended to them
sdrach
parents:
36236
diff
changeset
|
113 |
// direct access to versioned entry |
38432
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37785
diff
changeset
|
114 |
String versUrlEntry = urlFile + "META-INF/versions/" + Runtime.version().major() |
37785
daf6dcc73e9d
8151542: URL resources for multi-release jar files have a #runtime fragment appended to them
sdrach
parents:
36236
diff
changeset
|
115 |
+ "/version/Version.java"; |
daf6dcc73e9d
8151542: URL resources for multi-release jar files have a #runtime fragment appended to them
sdrach
parents:
36236
diff
changeset
|
116 |
Assert.assertTrue(readAndCompare(new URL(versUrlEntry), rtreturn)); |
daf6dcc73e9d
8151542: URL resources for multi-release jar files have a #runtime fragment appended to them
sdrach
parents:
36236
diff
changeset
|
117 |
// adding any fragment does not change things |
daf6dcc73e9d
8151542: URL resources for multi-release jar files have a #runtime fragment appended to them
sdrach
parents:
36236
diff
changeset
|
118 |
Assert.assertTrue(readAndCompare(new URL(versUrlEntry + "#runtime"), rtreturn)); |
daf6dcc73e9d
8151542: URL resources for multi-release jar files have a #runtime fragment appended to them
sdrach
parents:
36236
diff
changeset
|
119 |
Assert.assertTrue(readAndCompare(new URL(versUrlEntry + "#fragment"), rtreturn)); |
daf6dcc73e9d
8151542: URL resources for multi-release jar files have a #runtime fragment appended to them
sdrach
parents:
36236
diff
changeset
|
120 |
|
daf6dcc73e9d
8151542: URL resources for multi-release jar files have a #runtime fragment appended to them
sdrach
parents:
36236
diff
changeset
|
121 |
// it really doesn't change things |
daf6dcc73e9d
8151542: URL resources for multi-release jar files have a #runtime fragment appended to them
sdrach
parents:
36236
diff
changeset
|
122 |
versUrlEntry = urlFile + "META-INF/versions/10/version/Version.java"; |
daf6dcc73e9d
8151542: URL resources for multi-release jar files have a #runtime fragment appended to them
sdrach
parents:
36236
diff
changeset
|
123 |
Assert.assertTrue(readAndCompare(new URL(versUrlEntry), "return 10")); |
daf6dcc73e9d
8151542: URL resources for multi-release jar files have a #runtime fragment appended to them
sdrach
parents:
36236
diff
changeset
|
124 |
Assert.assertTrue(readAndCompare(new URL(versUrlEntry + "#runtime"), "return 10")); |
daf6dcc73e9d
8151542: URL resources for multi-release jar files have a #runtime fragment appended to them
sdrach
parents:
36236
diff
changeset
|
125 |
Assert.assertTrue(readAndCompare(new URL(versUrlEntry + "#fragment"), "return 10")); |
36129
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
126 |
} |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
127 |
|
36236
eec5770c5b01
8150679: closed/javax/crypto/CryptoPermission/CallerIdentification.sh fails after fix for JDK-8132734
sdrach
parents:
36129
diff
changeset
|
128 |
@Test(dataProvider = "data") |
37785
daf6dcc73e9d
8151542: URL resources for multi-release jar files have a #runtime fragment appended to them
sdrach
parents:
36236
diff
changeset
|
129 |
public void testCachedJars(String style, String file) throws Exception { |
36236
eec5770c5b01
8150679: closed/javax/crypto/CryptoPermission/CallerIdentification.sh fails after fix for JDK-8132734
sdrach
parents:
36129
diff
changeset
|
130 |
String urlFile = "jar:file:" + file + "!/"; |
eec5770c5b01
8150679: closed/javax/crypto/CryptoPermission/CallerIdentification.sh fails after fix for JDK-8132734
sdrach
parents:
36129
diff
changeset
|
131 |
|
36129
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
132 |
URL rootUrl = new URL(urlFile); |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
133 |
JarURLConnection juc = (JarURLConnection)rootUrl.openConnection(); |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
134 |
JarFile rootJar = juc.getJarFile(); |
39646
2bf99fe5023b
8150680: JarFile.Release enum needs reconsideration with respect to it's values
sdrach
parents:
39052
diff
changeset
|
135 |
Runtime.Version root = rootJar.getVersion(); |
36129
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
136 |
|
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
137 |
URL runtimeUrl = new URL(urlFile + "#runtime"); |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
138 |
juc = (JarURLConnection)runtimeUrl.openConnection(); |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
139 |
JarFile runtimeJar = juc.getJarFile(); |
39646
2bf99fe5023b
8150680: JarFile.Release enum needs reconsideration with respect to it's values
sdrach
parents:
39052
diff
changeset
|
140 |
Runtime.Version runtime = runtimeJar.getVersion(); |
37785
daf6dcc73e9d
8151542: URL resources for multi-release jar files have a #runtime fragment appended to them
sdrach
parents:
36236
diff
changeset
|
141 |
if (style.equals("unversioned")) { |
daf6dcc73e9d
8151542: URL resources for multi-release jar files have a #runtime fragment appended to them
sdrach
parents:
36236
diff
changeset
|
142 |
Assert.assertEquals(root, runtime); |
daf6dcc73e9d
8151542: URL resources for multi-release jar files have a #runtime fragment appended to them
sdrach
parents:
36236
diff
changeset
|
143 |
} else { |
daf6dcc73e9d
8151542: URL resources for multi-release jar files have a #runtime fragment appended to them
sdrach
parents:
36236
diff
changeset
|
144 |
Assert.assertNotEquals(root, runtime); |
daf6dcc73e9d
8151542: URL resources for multi-release jar files have a #runtime fragment appended to them
sdrach
parents:
36236
diff
changeset
|
145 |
} |
36129
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
146 |
|
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
147 |
juc = (JarURLConnection)rootUrl.openConnection(); |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
148 |
JarFile jar = juc.getJarFile(); |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
149 |
Assert.assertEquals(jar.getVersion(), root); |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
150 |
Assert.assertEquals(jar, rootJar); |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
151 |
|
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
152 |
juc = (JarURLConnection)runtimeUrl.openConnection(); |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
153 |
jar = juc.getJarFile(); |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
154 |
Assert.assertEquals(jar.getVersion(), runtime); |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
155 |
Assert.assertEquals(jar, runtimeJar); |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
156 |
|
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
157 |
rootJar.close(); |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
158 |
runtimeJar.close(); |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
159 |
jar.close(); // probably not needed |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
160 |
} |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
161 |
|
37785
daf6dcc73e9d
8151542: URL resources for multi-release jar files have a #runtime fragment appended to them
sdrach
parents:
36236
diff
changeset
|
162 |
@DataProvider(name = "resourcedata") |
daf6dcc73e9d
8151542: URL resources for multi-release jar files have a #runtime fragment appended to them
sdrach
parents:
36236
diff
changeset
|
163 |
public Object[][] createResourceData() throws Exception { |
daf6dcc73e9d
8151542: URL resources for multi-release jar files have a #runtime fragment appended to them
sdrach
parents:
36236
diff
changeset
|
164 |
return new Object[][]{ |
daf6dcc73e9d
8151542: URL resources for multi-release jar files have a #runtime fragment appended to them
sdrach
parents:
36236
diff
changeset
|
165 |
{"unversioned", Paths.get(unversioned).toUri().toURL()}, |
daf6dcc73e9d
8151542: URL resources for multi-release jar files have a #runtime fragment appended to them
sdrach
parents:
36236
diff
changeset
|
166 |
{"unsigned", Paths.get(unsigned).toUri().toURL()}, |
daf6dcc73e9d
8151542: URL resources for multi-release jar files have a #runtime fragment appended to them
sdrach
parents:
36236
diff
changeset
|
167 |
{"signed", Paths.get(signed).toUri().toURL()}, |
daf6dcc73e9d
8151542: URL resources for multi-release jar files have a #runtime fragment appended to them
sdrach
parents:
36236
diff
changeset
|
168 |
{"unversioned", new URL("file:" + unversioned)}, |
daf6dcc73e9d
8151542: URL resources for multi-release jar files have a #runtime fragment appended to them
sdrach
parents:
36236
diff
changeset
|
169 |
{"unsigned", new URL("file:" + unsigned)}, |
daf6dcc73e9d
8151542: URL resources for multi-release jar files have a #runtime fragment appended to them
sdrach
parents:
36236
diff
changeset
|
170 |
{"signed", new URL("file:" + signed)}, |
daf6dcc73e9d
8151542: URL resources for multi-release jar files have a #runtime fragment appended to them
sdrach
parents:
36236
diff
changeset
|
171 |
{"unversioned", new URL("jar:file:" + unversioned + "!/")}, |
daf6dcc73e9d
8151542: URL resources for multi-release jar files have a #runtime fragment appended to them
sdrach
parents:
36236
diff
changeset
|
172 |
{"unsigned", new URL("jar:file:" + unsigned + "!/")}, |
daf6dcc73e9d
8151542: URL resources for multi-release jar files have a #runtime fragment appended to them
sdrach
parents:
36236
diff
changeset
|
173 |
{"signed", new URL("jar:file:" + signed + "!/")}, |
daf6dcc73e9d
8151542: URL resources for multi-release jar files have a #runtime fragment appended to them
sdrach
parents:
36236
diff
changeset
|
174 |
// external jar received via http protocol |
daf6dcc73e9d
8151542: URL resources for multi-release jar files have a #runtime fragment appended to them
sdrach
parents:
36236
diff
changeset
|
175 |
{"http", new URL("jar:http://localhost:" + server.getPort() + "/multi-release.jar!/")}, |
daf6dcc73e9d
8151542: URL resources for multi-release jar files have a #runtime fragment appended to them
sdrach
parents:
36236
diff
changeset
|
176 |
{"http", new URL("http://localhost:" + server.getPort() + "/multi-release.jar")}, |
daf6dcc73e9d
8151542: URL resources for multi-release jar files have a #runtime fragment appended to them
sdrach
parents:
36236
diff
changeset
|
177 |
|
daf6dcc73e9d
8151542: URL resources for multi-release jar files have a #runtime fragment appended to them
sdrach
parents:
36236
diff
changeset
|
178 |
}; |
daf6dcc73e9d
8151542: URL resources for multi-release jar files have a #runtime fragment appended to them
sdrach
parents:
36236
diff
changeset
|
179 |
} |
daf6dcc73e9d
8151542: URL resources for multi-release jar files have a #runtime fragment appended to them
sdrach
parents:
36236
diff
changeset
|
180 |
|
daf6dcc73e9d
8151542: URL resources for multi-release jar files have a #runtime fragment appended to them
sdrach
parents:
36236
diff
changeset
|
181 |
@Test(dataProvider = "resourcedata") |
daf6dcc73e9d
8151542: URL resources for multi-release jar files have a #runtime fragment appended to them
sdrach
parents:
36236
diff
changeset
|
182 |
public void testResources(String style, URL url) throws Throwable { |
daf6dcc73e9d
8151542: URL resources for multi-release jar files have a #runtime fragment appended to them
sdrach
parents:
36236
diff
changeset
|
183 |
//System.out.println(" testing " + style + " url: " + url); |
daf6dcc73e9d
8151542: URL resources for multi-release jar files have a #runtime fragment appended to them
sdrach
parents:
36236
diff
changeset
|
184 |
URL[] urls = {url}; |
daf6dcc73e9d
8151542: URL resources for multi-release jar files have a #runtime fragment appended to them
sdrach
parents:
36236
diff
changeset
|
185 |
URLClassLoader cldr = new URLClassLoader(urls); |
daf6dcc73e9d
8151542: URL resources for multi-release jar files have a #runtime fragment appended to them
sdrach
parents:
36236
diff
changeset
|
186 |
Class<?> vcls = cldr.loadClass("version.Version"); |
daf6dcc73e9d
8151542: URL resources for multi-release jar files have a #runtime fragment appended to them
sdrach
parents:
36236
diff
changeset
|
187 |
|
daf6dcc73e9d
8151542: URL resources for multi-release jar files have a #runtime fragment appended to them
sdrach
parents:
36236
diff
changeset
|
188 |
// verify we are loading a runtime versioned class |
daf6dcc73e9d
8151542: URL resources for multi-release jar files have a #runtime fragment appended to them
sdrach
parents:
36236
diff
changeset
|
189 |
MethodType mt = MethodType.methodType(int.class); |
daf6dcc73e9d
8151542: URL resources for multi-release jar files have a #runtime fragment appended to them
sdrach
parents:
36236
diff
changeset
|
190 |
MethodHandle mh = MethodHandles.lookup().findVirtual(vcls, "getVersion", mt); |
daf6dcc73e9d
8151542: URL resources for multi-release jar files have a #runtime fragment appended to them
sdrach
parents:
36236
diff
changeset
|
191 |
Assert.assertEquals((int)mh.invoke(vcls.newInstance()), |
38432
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37785
diff
changeset
|
192 |
style.equals("unversioned") ? 8 : Runtime.version().major()); |
37785
daf6dcc73e9d
8151542: URL resources for multi-release jar files have a #runtime fragment appended to them
sdrach
parents:
36236
diff
changeset
|
193 |
|
daf6dcc73e9d
8151542: URL resources for multi-release jar files have a #runtime fragment appended to them
sdrach
parents:
36236
diff
changeset
|
194 |
// now get a resource and verify that we don't have a fragment attached |
39052
6660a4142993
8159785: Add test that tests ClassLoader.getResource/getResources in Multi-Release Jar
mli
parents:
38557
diff
changeset
|
195 |
Enumeration<URL> vclsUrlEnum = cldr.getResources("version/Version.class"); |
6660a4142993
8159785: Add test that tests ClassLoader.getResource/getResources in Multi-Release Jar
mli
parents:
38557
diff
changeset
|
196 |
Assert.assertTrue(vclsUrlEnum.hasMoreElements()); |
6660a4142993
8159785: Add test that tests ClassLoader.getResource/getResources in Multi-Release Jar
mli
parents:
38557
diff
changeset
|
197 |
URL vclsUrls[] = new URL[] { |
6660a4142993
8159785: Add test that tests ClassLoader.getResource/getResources in Multi-Release Jar
mli
parents:
38557
diff
changeset
|
198 |
vcls.getResource("/version/Version.class"), |
6660a4142993
8159785: Add test that tests ClassLoader.getResource/getResources in Multi-Release Jar
mli
parents:
38557
diff
changeset
|
199 |
vcls.getResource("Version.class"), |
6660a4142993
8159785: Add test that tests ClassLoader.getResource/getResources in Multi-Release Jar
mli
parents:
38557
diff
changeset
|
200 |
cldr.getResource("version/Version.class"), |
6660a4142993
8159785: Add test that tests ClassLoader.getResource/getResources in Multi-Release Jar
mli
parents:
38557
diff
changeset
|
201 |
vclsUrlEnum.nextElement() |
6660a4142993
8159785: Add test that tests ClassLoader.getResource/getResources in Multi-Release Jar
mli
parents:
38557
diff
changeset
|
202 |
}; |
6660a4142993
8159785: Add test that tests ClassLoader.getResource/getResources in Multi-Release Jar
mli
parents:
38557
diff
changeset
|
203 |
Assert.assertFalse(vclsUrlEnum.hasMoreElements()); |
6660a4142993
8159785: Add test that tests ClassLoader.getResource/getResources in Multi-Release Jar
mli
parents:
38557
diff
changeset
|
204 |
for (URL vclsUrl : vclsUrls) { |
6660a4142993
8159785: Add test that tests ClassLoader.getResource/getResources in Multi-Release Jar
mli
parents:
38557
diff
changeset
|
205 |
String fragment = vclsUrl.getRef(); |
6660a4142993
8159785: Add test that tests ClassLoader.getResource/getResources in Multi-Release Jar
mli
parents:
38557
diff
changeset
|
206 |
Assert.assertNull(fragment); |
37785
daf6dcc73e9d
8151542: URL resources for multi-release jar files have a #runtime fragment appended to them
sdrach
parents:
36236
diff
changeset
|
207 |
|
39052
6660a4142993
8159785: Add test that tests ClassLoader.getResource/getResources in Multi-Release Jar
mli
parents:
38557
diff
changeset
|
208 |
// and verify that the the url is a reified pointer to the runtime entry |
6660a4142993
8159785: Add test that tests ClassLoader.getResource/getResources in Multi-Release Jar
mli
parents:
38557
diff
changeset
|
209 |
String rep = vclsUrl.toString(); |
6660a4142993
8159785: Add test that tests ClassLoader.getResource/getResources in Multi-Release Jar
mli
parents:
38557
diff
changeset
|
210 |
//System.out.println(" getResource(\"/version/Version.class\") returned: " + rep); |
6660a4142993
8159785: Add test that tests ClassLoader.getResource/getResources in Multi-Release Jar
mli
parents:
38557
diff
changeset
|
211 |
if (style.equals("http")) { |
6660a4142993
8159785: Add test that tests ClassLoader.getResource/getResources in Multi-Release Jar
mli
parents:
38557
diff
changeset
|
212 |
Assert.assertTrue(rep.startsWith("jar:http:")); |
6660a4142993
8159785: Add test that tests ClassLoader.getResource/getResources in Multi-Release Jar
mli
parents:
38557
diff
changeset
|
213 |
} else { |
6660a4142993
8159785: Add test that tests ClassLoader.getResource/getResources in Multi-Release Jar
mli
parents:
38557
diff
changeset
|
214 |
Assert.assertTrue(rep.startsWith("jar:file:")); |
6660a4142993
8159785: Add test that tests ClassLoader.getResource/getResources in Multi-Release Jar
mli
parents:
38557
diff
changeset
|
215 |
} |
6660a4142993
8159785: Add test that tests ClassLoader.getResource/getResources in Multi-Release Jar
mli
parents:
38557
diff
changeset
|
216 |
String suffix; |
6660a4142993
8159785: Add test that tests ClassLoader.getResource/getResources in Multi-Release Jar
mli
parents:
38557
diff
changeset
|
217 |
if (style.equals("unversioned")) { |
6660a4142993
8159785: Add test that tests ClassLoader.getResource/getResources in Multi-Release Jar
mli
parents:
38557
diff
changeset
|
218 |
suffix = ".jar!/version/Version.class"; |
6660a4142993
8159785: Add test that tests ClassLoader.getResource/getResources in Multi-Release Jar
mli
parents:
38557
diff
changeset
|
219 |
} else { |
6660a4142993
8159785: Add test that tests ClassLoader.getResource/getResources in Multi-Release Jar
mli
parents:
38557
diff
changeset
|
220 |
suffix = ".jar!/META-INF/versions/" + Runtime.version().major() |
6660a4142993
8159785: Add test that tests ClassLoader.getResource/getResources in Multi-Release Jar
mli
parents:
38557
diff
changeset
|
221 |
+ "/version/Version.class"; |
6660a4142993
8159785: Add test that tests ClassLoader.getResource/getResources in Multi-Release Jar
mli
parents:
38557
diff
changeset
|
222 |
} |
6660a4142993
8159785: Add test that tests ClassLoader.getResource/getResources in Multi-Release Jar
mli
parents:
38557
diff
changeset
|
223 |
Assert.assertTrue(rep.endsWith(suffix)); |
37785
daf6dcc73e9d
8151542: URL resources for multi-release jar files have a #runtime fragment appended to them
sdrach
parents:
36236
diff
changeset
|
224 |
} |
daf6dcc73e9d
8151542: URL resources for multi-release jar files have a #runtime fragment appended to them
sdrach
parents:
36236
diff
changeset
|
225 |
cldr.close(); |
daf6dcc73e9d
8151542: URL resources for multi-release jar files have a #runtime fragment appended to them
sdrach
parents:
36236
diff
changeset
|
226 |
} |
daf6dcc73e9d
8151542: URL resources for multi-release jar files have a #runtime fragment appended to them
sdrach
parents:
36236
diff
changeset
|
227 |
|
daf6dcc73e9d
8151542: URL resources for multi-release jar files have a #runtime fragment appended to them
sdrach
parents:
36236
diff
changeset
|
228 |
|
36129
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
229 |
private boolean readAndCompare(URL url, String match) throws Exception { |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
230 |
boolean result; |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
231 |
// necessary to do it this way, instead of openStream(), so we can |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
232 |
// close underlying JarFile, otherwise windows can't delete the file |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
233 |
URLConnection conn = url.openConnection(); |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
234 |
try (InputStream is = conn.getInputStream()) { |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
235 |
byte[] bytes = is.readAllBytes(); |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
236 |
result = (new String(bytes)).contains(match); |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
237 |
} |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
238 |
if (conn instanceof JarURLConnection) { |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
239 |
((JarURLConnection)conn).getJarFile().close(); |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
240 |
} |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
241 |
return result; |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
242 |
} |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
243 |
} |