22 * |
22 * |
23 */ |
23 */ |
24 |
24 |
25 /* |
25 /* |
26 * @test MultiReleaseJars |
26 * @test MultiReleaseJars |
27 * @bug 8170105 |
|
28 * @summary Test multi-release jar with AppCDS. |
27 * @summary Test multi-release jar with AppCDS. |
29 * @requires vm.cds |
28 * @requires vm.cds |
30 * @library /test/lib |
29 * @library /test/lib |
31 * @modules java.base/jdk.internal.misc |
30 * @modules java.base/jdk.internal.misc |
32 * jdk.jartool/sun.tools.jar |
31 * jdk.jartool/sun.tools.jar |
33 * @run main/othervm MultiReleaseJars |
32 * @run main/othervm/timeout=2400 MultiReleaseJars |
34 */ |
33 */ |
35 |
34 |
36 import java.io.File; |
35 import java.io.File; |
37 import java.io.FileOutputStream; |
36 import java.io.FileOutputStream; |
38 import java.io.PrintStream; |
37 import java.io.PrintStream; |
154 String mainClass = "version.Main"; |
153 String mainClass = "version.Main"; |
155 String loadInfo = "[class,load] version.Version source: shared objects file"; |
154 String loadInfo = "[class,load] version.Version source: shared objects file"; |
156 String appClasses[] = {"version/Main", "version/Version"}; |
155 String appClasses[] = {"version/Main", "version/Version"}; |
157 String appJar = TestCommon.getTestJar("version.jar"); |
156 String appJar = TestCommon.getTestJar("version.jar"); |
158 String appJar2 = TestCommon.getTestJar("version2.jar"); |
157 String appJar2 = TestCommon.getTestJar("version2.jar"); |
159 String verboseMode = "-verbose:class"; |
|
160 String enableMultiRelease = "-Djdk.util.jar.enableMultiRelease=true"; |
158 String enableMultiRelease = "-Djdk.util.jar.enableMultiRelease=true"; |
161 String jarVersion = null; |
159 String jarVersion = null; |
162 String expectedOutput = null; |
160 String expectedOutput = null; |
163 |
161 |
164 // 1. default to highest version |
162 // 1. default to highest version |
166 // -Djdk.util.jar.enableMultiRelease passed to vm |
164 // -Djdk.util.jar.enableMultiRelease passed to vm |
167 OutputAnalyzer output = TestCommon.dump(appJar, appClasses); |
165 OutputAnalyzer output = TestCommon.dump(appJar, appClasses); |
168 output.shouldContain("Loading classes to share: done."); |
166 output.shouldContain("Loading classes to share: done."); |
169 output.shouldHaveExitValue(0); |
167 output.shouldHaveExitValue(0); |
170 |
168 |
171 output = TestCommon.exec(appJar, verboseMode, mainClass); |
169 output = TestCommon.exec(appJar, mainClass); |
172 checkExecOutput(output, "I am running on version " + MAJOR_VERSION_STRING); |
170 checkExecOutput(output, "I am running on version " + MAJOR_VERSION_STRING); |
173 |
171 |
174 // 2. Test versions 7 and the current major version. |
172 // 2. Test versions 7 and the current major version. |
175 // -Djdk.util.jar.enableMultiRelease=true (or force), default is true. |
173 // -Djdk.util.jar.enableMultiRelease=true (or force), default is true. |
176 // a) -Djdk.util.jar.version=7 does not exist in jar. |
174 // a) -Djdk.util.jar.version=7 does not exist in jar. |
181 expectedOutput = "I am running on version " + i; |
179 expectedOutput = "I am running on version " + i; |
182 output = TestCommon.dump(appJar, appClasses, enableMultiRelease, jarVersion); |
180 output = TestCommon.dump(appJar, appClasses, enableMultiRelease, jarVersion); |
183 output.shouldContain("Loading classes to share: done."); |
181 output.shouldContain("Loading classes to share: done."); |
184 output.shouldHaveExitValue(0); |
182 output.shouldHaveExitValue(0); |
185 |
183 |
186 output = TestCommon.exec(appJar, verboseMode, mainClass); |
184 output = TestCommon.exec(appJar, mainClass); |
187 checkExecOutput(output, expectedOutput); |
185 checkExecOutput(output, expectedOutput); |
188 } |
186 } |
189 |
187 |
190 // 3. For unsupported version, 5 and current major version + 1, the multiversion |
188 // 3. For unsupported version, 5 and current major version + 1, the multiversion |
191 // will be turned off, so it will use the default (root) version. |
189 // will be turned off, so it will use the default (root) version. |
195 output.shouldHaveExitValue(0); |
193 output.shouldHaveExitValue(0); |
196 // With the fix for 8172218, multi-release jar is being handled in |
194 // With the fix for 8172218, multi-release jar is being handled in |
197 // jdk corelib which doesn't emit the following warning message. |
195 // jdk corelib which doesn't emit the following warning message. |
198 //output.shouldContain("JDK" + i + " is not supported in multiple version jars"); |
196 //output.shouldContain("JDK" + i + " is not supported in multiple version jars"); |
199 |
197 |
200 output = TestCommon.exec(appJar, verboseMode, mainClass); |
198 output = TestCommon.exec(appJar, mainClass); |
201 if (i == 5) |
199 if (i == 5) |
202 checkExecOutput(output, "I am running on version 7"); |
200 checkExecOutput(output, "I am running on version 7"); |
203 else |
201 else |
204 checkExecOutput(output, "I am running on version " + MAJOR_VERSION_STRING); |
202 checkExecOutput(output, "I am running on version " + MAJOR_VERSION_STRING); |
205 } |
203 } |
210 for (int i = 6; i < MAJOR_VERSION + 1; i++) { |
208 for (int i = 6; i < MAJOR_VERSION + 1; i++) { |
211 jarVersion = "-Djdk.util.jar.version=" + i; |
209 jarVersion = "-Djdk.util.jar.version=" + i; |
212 output = TestCommon.dump(appJar, appClasses, "-Djdk.util.jar.enableMultiRelease=false", jarVersion); |
210 output = TestCommon.dump(appJar, appClasses, "-Djdk.util.jar.enableMultiRelease=false", jarVersion); |
213 output.shouldHaveExitValue(0); |
211 output.shouldHaveExitValue(0); |
214 |
212 |
215 output = TestCommon.exec(appJar, verboseMode, mainClass); |
213 output = TestCommon.exec(appJar, mainClass); |
216 expectedOutput = "I am running on version 7"; |
214 expectedOutput = "I am running on version 7"; |
217 checkExecOutput(output, expectedOutput); |
215 checkExecOutput(output, expectedOutput); |
218 } |
216 } |
219 |
217 |
220 // 5. Sanity test with -Xbootclasspath/a |
218 // 5. Sanity test with -Xbootclasspath/a |
222 // jar file in the -Xbootclasspath/a will be ignored. |
220 // jar file in the -Xbootclasspath/a will be ignored. |
223 output = TestCommon.dump(appJar, appClasses, "-Xbootclasspath/a:" + appJar, enableMultiRelease, jarVersion); |
221 output = TestCommon.dump(appJar, appClasses, "-Xbootclasspath/a:" + appJar, enableMultiRelease, jarVersion); |
224 output.shouldContain("Loading classes to share: done."); |
222 output.shouldContain("Loading classes to share: done."); |
225 output.shouldHaveExitValue(0); |
223 output.shouldHaveExitValue(0); |
226 |
224 |
227 output = TestCommon.exec(appJar, "-Xbootclasspath/a:" + appJar, verboseMode, mainClass); |
225 output = TestCommon.exec(appJar, "-Xbootclasspath/a:" + appJar, mainClass); |
228 checkExecOutput(output, "I am running on version 7"); |
226 checkExecOutput(output, "I am running on version 7"); |
229 |
227 |
230 // 6. Sanity test case-insensitive "Multi-Release" attribute name |
228 // 6. Sanity test case-insensitive "Multi-Release" attribute name |
231 output = TestCommon.dump(appJar2, appClasses); |
229 output = TestCommon.dump(appJar2, appClasses); |
232 output.shouldContain("Loading classes to share: done."); |
230 output.shouldContain("Loading classes to share: done."); |
233 output.shouldHaveExitValue(0); |
231 output.shouldHaveExitValue(0); |
234 |
232 |
235 output = TestCommon.exec(appJar2, verboseMode, mainClass); |
233 output = TestCommon.exec(appJar2, mainClass); |
236 checkExecOutput(output, "I am running on version " + MAJOR_VERSION_STRING); |
234 checkExecOutput(output, "I am running on version " + MAJOR_VERSION_STRING); |
237 } |
235 } |
238 } |
236 } |