author | vlivanov |
Wed, 02 Mar 2016 15:42:03 +0300 | |
changeset 36349 | 6cc8e6f596b2 |
parent 36129 | 332b49163fc9 |
child 36219 | 437e72684a42 |
permissions | -rw-r--r-- |
36129
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
1 |
/* |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
2 |
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. |
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 |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
26 |
* @bug 8132734 |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
27 |
* @summary Test the extended API and the aliasing additions in JarFile that |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
28 |
* support multi-release jar files |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
29 |
* @library /lib/testlibrary/java/util/jar |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
30 |
* @build Compiler JarBuilder CreateMultiReleaseTestJars |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
31 |
* @run testng MultiReleaseJarAPI |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
32 |
*/ |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
33 |
|
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
34 |
import java.io.File; |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
35 |
import java.io.IOException; |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
36 |
import java.io.InputStream; |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
37 |
import java.nio.file.Files; |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
38 |
import java.util.Arrays; |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
39 |
import java.util.jar.JarFile; |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
40 |
import java.util.zip.ZipEntry; |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
41 |
import java.util.zip.ZipFile; |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
42 |
|
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
43 |
import static java.util.jar.JarFile.Release; |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
44 |
import static sun.misc.Version.jdkMajorVersion; // fixme JEP 223 Version |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
45 |
|
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
46 |
import org.testng.Assert; |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
47 |
import org.testng.annotations.AfterClass; |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
48 |
import org.testng.annotations.BeforeClass; |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
49 |
import org.testng.annotations.Test; |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
50 |
|
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
51 |
|
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
52 |
public class MultiReleaseJarAPI { |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
53 |
String userdir = System.getProperty("user.dir","."); |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
54 |
File unversioned = new File(userdir, "unversioned.jar"); |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
55 |
File multirelease = new File(userdir, "multi-release.jar"); |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
56 |
File signedmultirelease = new File(userdir, "signed-multi-release.jar"); |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
57 |
Release[] values = JarFile.Release.values(); |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
58 |
|
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
59 |
|
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
60 |
@BeforeClass |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
61 |
public void initialize() throws Exception { |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
62 |
CreateMultiReleaseTestJars creator = new CreateMultiReleaseTestJars(); |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
63 |
creator.compileEntries(); |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
64 |
creator.buildUnversionedJar(); |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
65 |
creator.buildMultiReleaseJar(); |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
66 |
creator.buildSignedMultiReleaseJar(); |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
67 |
} |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
68 |
|
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
69 |
@AfterClass |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
70 |
public void close() throws IOException { |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
71 |
Files.delete(unversioned.toPath()); |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
72 |
Files.delete(multirelease.toPath()); |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
73 |
Files.delete(signedmultirelease.toPath()); |
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 |
@Test |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
77 |
public void isMultiReleaseJar() throws Exception { |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
78 |
try (JarFile jf = new JarFile(unversioned)) { |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
79 |
Assert.assertFalse(jf.isMultiRelease()); |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
80 |
} |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
81 |
|
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
82 |
try (JarFile jf = new JarFile(multirelease)) { |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
83 |
Assert.assertTrue(jf.isMultiRelease()); |
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 |
} |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
86 |
|
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
87 |
@Test |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
88 |
public void testVersioning() throws Exception { |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
89 |
// multi-release jar |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
90 |
JarFile jar = new JarFile(multirelease); |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
91 |
Assert.assertEquals(Release.BASE, jar.getVersion()); |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
92 |
jar.close(); |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
93 |
|
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
94 |
for (Release value : values) { |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
95 |
System.err.println("test versioning for Release " + value); |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
96 |
try (JarFile jf = new JarFile(multirelease, true, ZipFile.OPEN_READ, value)) { |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
97 |
Assert.assertEquals(value, jf.getVersion()); |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
98 |
} |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
99 |
} |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
100 |
|
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
101 |
// regular, unversioned, jar |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
102 |
for (Release value : values) { |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
103 |
try (JarFile jf = new JarFile(unversioned, true, ZipFile.OPEN_READ, value)) { |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
104 |
Assert.assertEquals(Release.BASE, jf.getVersion()); |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
105 |
} |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
106 |
} |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
107 |
|
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
108 |
// assure that we have a Release object corresponding to the actual runtime version |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
109 |
String version = "VERSION_" + jdkMajorVersion(); |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
110 |
boolean runtimeVersionExists = false; |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
111 |
for (Release value : values) { |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
112 |
if (version.equals(value.name())) runtimeVersionExists = true; |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
113 |
} |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
114 |
Assert.assertTrue(runtimeVersionExists); |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
115 |
} |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
116 |
|
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
117 |
@Test |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
118 |
public void testAliasing() throws Exception { |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
119 |
for (Release value : values) { |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
120 |
System.err.println("test aliasing for Release " + value); |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
121 |
String name = value.name(); |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
122 |
String prefix; |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
123 |
if (name.equals("BASE")) { |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
124 |
prefix = ""; |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
125 |
} else if (name.equals("RUNTIME")) { |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
126 |
prefix = "META-INF/versions/" + jdkMajorVersion() + "/"; |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
127 |
} else { |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
128 |
prefix = "META-INF/versions/" + name.substring(8) + "/"; |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
129 |
} |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
130 |
// test both multi-release jars |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
131 |
readAndCompare(multirelease, value, "README", prefix + "README"); |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
132 |
readAndCompare(multirelease, value, "version/Version.class", prefix + "version/Version.class"); |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
133 |
// and signed multi-release jars |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
134 |
readAndCompare(signedmultirelease, value, "README", prefix + "README"); |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
135 |
readAndCompare(signedmultirelease, value, "version/Version.class", prefix + "version/Version.class"); |
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 |
} |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
138 |
|
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
139 |
private void readAndCompare(File jar, Release version, String name, String realName) throws Exception { |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
140 |
byte[] baseBytes; |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
141 |
byte[] versionedBytes; |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
142 |
try (JarFile jf = new JarFile(jar, true, ZipFile.OPEN_READ, Release.BASE)) { |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
143 |
ZipEntry ze = jf.getEntry(realName); |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
144 |
try (InputStream is = jf.getInputStream(ze)) { |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
145 |
baseBytes = is.readAllBytes(); |
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 |
} |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
148 |
assert baseBytes.length > 0; |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
149 |
|
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
150 |
try (JarFile jf = new JarFile(jar, true, ZipFile.OPEN_READ, version)) { |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
151 |
ZipEntry ze = jf.getEntry(name); |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
152 |
try (InputStream is = jf.getInputStream(ze)) { |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
153 |
versionedBytes = is.readAllBytes(); |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
154 |
} |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
155 |
} |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
156 |
assert versionedBytes.length > 0; |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
157 |
|
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
158 |
Assert.assertTrue(Arrays.equals(baseBytes, versionedBytes)); |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
159 |
} |
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 |
@Test |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
162 |
public void testNames() throws Exception { |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
163 |
String rname = "version/Version.class"; |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
164 |
String vname = "META-INF/versions/9/version/Version.class"; |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
165 |
ZipEntry ze1; |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
166 |
ZipEntry ze2; |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
167 |
try (JarFile jf = new JarFile(multirelease)) { |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
168 |
ze1 = jf.getEntry(vname); |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
169 |
} |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
170 |
Assert.assertEquals(ze1.getName(), vname); |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
171 |
try (JarFile jf = new JarFile(multirelease, true, ZipFile.OPEN_READ, Release.VERSION_9)) { |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
172 |
ze2 = jf.getEntry(rname); |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
173 |
} |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
174 |
Assert.assertEquals(ze2.getName(), rname); |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
175 |
Assert.assertNotEquals(ze1.getName(), ze2.getName()); |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
176 |
} |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
177 |
} |