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 MultiReleaseJarIterators |
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.Enumeration; |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
39 |
import java.util.HashMap; |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
40 |
import java.util.Map; |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
41 |
import java.util.jar.JarEntry; |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
42 |
import java.util.jar.JarFile; |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
43 |
import java.util.stream.Collectors; |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
44 |
import java.util.zip.ZipFile; |
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 static java.util.jar.JarFile.Release; |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
47 |
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
|
48 |
|
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
49 |
import org.testng.Assert; |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
50 |
import org.testng.annotations.AfterClass; |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
51 |
import org.testng.annotations.BeforeClass; |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
52 |
import org.testng.annotations.Test; |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
53 |
|
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
54 |
|
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
55 |
public class MultiReleaseJarIterators { |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
56 |
String userdir = System.getProperty("user.dir", "."); |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
57 |
File unversioned = new File(userdir, "unversioned.jar"); |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
58 |
File multirelease = new File(userdir, "multi-release.jar"); |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
59 |
Map<String,JarEntry> uvEntries = new HashMap<>(); |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
60 |
Map<String,JarEntry> mrEntries = new HashMap<>(); |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
61 |
Map<String,JarEntry> baseEntries = new HashMap<>(); |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
62 |
Map<String,JarEntry> v9Entries = new HashMap<>(); |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
63 |
Map<String, JarEntry> v10Entries = new HashMap<>(); |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
64 |
|
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
65 |
@BeforeClass |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
66 |
public void initialize() throws Exception { |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
67 |
CreateMultiReleaseTestJars creator = new CreateMultiReleaseTestJars(); |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
68 |
creator.compileEntries(); |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
69 |
creator.buildUnversionedJar(); |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
70 |
creator.buildMultiReleaseJar(); |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
71 |
|
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
72 |
try (JarFile jf = new JarFile(multirelease)) { |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
73 |
for (Enumeration<JarEntry> e = jf.entries(); e.hasMoreElements(); ) { |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
74 |
JarEntry je = e.nextElement(); |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
75 |
String name = je.getName(); |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
76 |
mrEntries.put(name, je); |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
77 |
if (name.startsWith("META-INF/versions/")) { |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
78 |
if (name.startsWith("META-INF/versions/9/")) { |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
79 |
v9Entries.put(name.substring(20), je); |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
80 |
} else if (name.startsWith("META-INF/versions/10/")) { |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
81 |
v10Entries.put(name.substring(21), je); |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
82 |
} |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
83 |
} else { |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
84 |
baseEntries.put(name, je); |
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 |
} |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
88 |
Assert.assertEquals(mrEntries.size(), 14); |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
89 |
Assert.assertEquals(baseEntries.size(), 6); |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
90 |
Assert.assertEquals(v9Entries.size(), 5); |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
91 |
Assert.assertEquals(v10Entries.size(), 3); |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
92 |
|
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
93 |
try (JarFile jf = new JarFile(unversioned)) { |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
94 |
jf.entries().asIterator().forEachRemaining(je -> uvEntries.put(je.getName(), je)); |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
95 |
} |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
96 |
Assert.assertEquals(uvEntries.size(), 6); |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
97 |
} |
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 |
@AfterClass |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
100 |
public void close() throws IOException { |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
101 |
Files.delete(unversioned.toPath()); |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
102 |
Files.delete(multirelease.toPath()); |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
103 |
} |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
104 |
|
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
105 |
@Test |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
106 |
public void testMultiReleaseJar() throws IOException { |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
107 |
try (JarFile jf = new JarFile(multirelease, true, ZipFile.OPEN_READ)) { |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
108 |
testEnumeration(jf, mrEntries); |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
109 |
testStream(jf, mrEntries); |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
110 |
} |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
111 |
|
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
112 |
try (JarFile jf = new JarFile(multirelease, true, ZipFile.OPEN_READ, Release.BASE)) { |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
113 |
testEnumeration(jf, baseEntries); |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
114 |
testStream(jf, baseEntries); |
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 |
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
|
118 |
testEnumeration(jf, v9Entries); |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
119 |
testStream(jf, v9Entries); |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
120 |
} |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
121 |
|
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
122 |
try (JarFile jf = new JarFile(multirelease, true, ZipFile.OPEN_READ, Release.RUNTIME)) { |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
123 |
Map<String,JarEntry> expectedEntries; |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
124 |
switch (jdkMajorVersion()) { |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
125 |
case 9: |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
126 |
expectedEntries = v9Entries; |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
127 |
break; |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
128 |
case 10: // won't get here until JDK 10 |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
129 |
expectedEntries = v10Entries; |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
130 |
break; |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
131 |
default: |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
132 |
expectedEntries = baseEntries; |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
133 |
break; |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
134 |
} |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
135 |
|
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
136 |
testEnumeration(jf, expectedEntries); |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
137 |
testStream(jf, expectedEntries); |
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 |
} |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
140 |
|
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
141 |
@Test |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
142 |
public void testUnversionedJar() throws IOException { |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
143 |
try (JarFile jf = new JarFile(unversioned, true, ZipFile.OPEN_READ)) { |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
144 |
testEnumeration(jf, uvEntries); |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
145 |
testStream(jf, uvEntries); |
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 |
try (JarFile jf = new JarFile(unversioned, true, ZipFile.OPEN_READ, Release.BASE)) { |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
149 |
testEnumeration(jf, uvEntries); |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
150 |
testStream(jf, uvEntries); |
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 |
|
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
153 |
try (JarFile jf = new JarFile(unversioned, true, ZipFile.OPEN_READ, Release.VERSION_9)) { |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
154 |
testEnumeration(jf, uvEntries); |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
155 |
testStream(jf, uvEntries); |
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 |
|
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
158 |
try (JarFile jf = new JarFile(unversioned, true, ZipFile.OPEN_READ, Release.RUNTIME)) { |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
159 |
testEnumeration(jf, uvEntries); |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
160 |
testStream(jf, uvEntries); |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
161 |
} |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
162 |
} |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
163 |
|
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
164 |
private void testEnumeration(JarFile jf, Map<String,JarEntry> expectedEntries) { |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
165 |
Map<String, JarEntry> actualEntries = new HashMap<>(); |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
166 |
for (Enumeration<JarEntry> e = jf.entries(); e.hasMoreElements(); ) { |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
167 |
JarEntry je = e.nextElement(); |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
168 |
actualEntries.put(je.getName(), je); |
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 |
|
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
171 |
testEntries(jf, actualEntries, expectedEntries); |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
172 |
} |
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 |
|
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
175 |
private void testStream(JarFile jf, Map<String,JarEntry> expectedEntries) { |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
176 |
Map<String,JarEntry> actualEntries = jf.stream().collect(Collectors.toMap(je -> je.getName(), je -> je)); |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
177 |
|
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
178 |
testEntries(jf, actualEntries, expectedEntries); |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
179 |
} |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
180 |
|
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
181 |
private void testEntries(JarFile jf, Map<String,JarEntry> actualEntries, Map<String,JarEntry> expectedEntries) { |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
182 |
/* For multi-release jar files constructed with a Release object, |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
183 |
* actualEntries contain versionedEntries that are considered part of the |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
184 |
* public API. They have a 1-1 correspondence with baseEntries, |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
185 |
* so entries that are not part of the public API won't be present, |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
186 |
* i.e. those entries with a name that starts with version/PackagePrivate |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
187 |
* in this particular jar file (multi-release.jar) |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
188 |
*/ |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
189 |
|
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
190 |
Map<String,JarEntry> entries; |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
191 |
if (expectedEntries == mrEntries) { |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
192 |
Assert.assertEquals(actualEntries.size(), mrEntries.size()); |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
193 |
entries = mrEntries; |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
194 |
} else if (expectedEntries == uvEntries) { |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
195 |
Assert.assertEquals(actualEntries.size(), uvEntries.size()); |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
196 |
entries = uvEntries; |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
197 |
} else { |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
198 |
Assert.assertEquals(actualEntries.size(), baseEntries.size()); // this is correct |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
199 |
entries = baseEntries; |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
200 |
} |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
201 |
|
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
202 |
entries.keySet().forEach(name -> { |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
203 |
JarEntry ee = expectedEntries.get(name); |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
204 |
if (ee == null) ee = entries.get(name); |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
205 |
JarEntry ae = actualEntries.get(name); |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
206 |
try { |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
207 |
compare(jf, ae, ee); |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
208 |
} catch (IOException x) { |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
209 |
throw new RuntimeException(x); |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
210 |
} |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
211 |
}); |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
212 |
} |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
213 |
|
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
214 |
private void compare(JarFile jf, JarEntry actual, JarEntry expected) throws IOException { |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
215 |
byte[] abytes; |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
216 |
byte[] ebytes; |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
217 |
|
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
218 |
try (InputStream is = jf.getInputStream(actual)) { |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
219 |
abytes = is.readAllBytes(); |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
220 |
} |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
221 |
|
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
222 |
try (InputStream is = jf.getInputStream(expected)) { |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
223 |
ebytes = is.readAllBytes(); |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
224 |
} |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
225 |
|
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
226 |
Assert.assertEquals(abytes, ebytes); |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
227 |
} |
332b49163fc9
8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents:
diff
changeset
|
228 |
} |