1 /* 2 * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 /* 25 * @test 26 * @bug 8132734 8194070 27 * @summary Test the System properties for JarFile that support multi-release jar files 28 * @library /lib/testlibrary/java/util/jar 29 * @modules jdk.jartool 30 * jdk.compiler 31 * jdk.httpserver 32 * @build Compiler JarBuilder CreateMultiReleaseTestJars SimpleHttpServer 33 * @run testng MultiReleaseJarHttpProperties 34 * @run testng/othervm -Djdk.util.jar.version=0 MultiReleaseJarHttpProperties 35 * @run testng/othervm -Djdk.util.jar.version=8 MultiReleaseJarHttpProperties 36 * @run testng/othervm -Djdk.util.jar.version=9 MultiReleaseJarHttpProperties 37 * @run testng/othervm -Djdk.util.jar.version=100 MultiReleaseJarHttpProperties 38 * @run testng/othervm -Djdk.util.jar.version=8 -Djdk.util.jar.enableMultiRelease=false MultiReleaseJarHttpProperties 39 * @run testng/othervm -Djdk.util.jar.version=9 -Djdk.util.jar.enableMultiRelease=false MultiReleaseJarHttpProperties 40 * @run testng/othervm -Djdk.util.jar.version=8 -Djdk.util.jar.enableMultiRelease=force MultiReleaseJarHttpProperties 41 * @run testng/othervm -Djdk.util.jar.version=9 -Djdk.util.jar.enableMultiRelease=force MultiReleaseJarHttpProperties 42 * @run testng/othervm -Djdk.util.jar.enableMultiRelease=false MultiReleaseJarHttpProperties 43 * @run testng/othervm -Djdk.util.jar.enableMultiRelease=force MultiReleaseJarHttpProperties 44 */ 45 46 import java.io.IOException; 47 import java.net.URL; 48 import java.net.URLClassLoader; 49 50 import org.testng.Assert; 51 import org.testng.annotations.AfterClass; 52 import org.testng.annotations.BeforeClass; 53 import org.testng.annotations.Test; 54 55 public class MultiReleaseJarHttpProperties extends MultiReleaseJarProperties { 56 private SimpleHttpServer server; 57 58 @BeforeClass 59 public void initialize() throws Exception { 60 server = new SimpleHttpServer(); 61 server.start(); 62 super.initialize(); 63 } 64 65 @Override 66 protected void initializeClassLoader() throws Exception { 67 URL[] urls = new URL[]{ 68 new URL("http://localhost:" + server.getPort() + "/multi-release.jar") 69 }; 70 cldr = new URLClassLoader(urls); 71 // load any class, Main is convenient and in the root entries 72 rootClass = cldr.loadClass("version.Main"); 73 } 74 75 @AfterClass 76 public void close() throws IOException { 77 // Windows requires server to stop before file is deleted 78 if (server != null) 79 server.stop(); 80 super.close(); 81 } 82 83 /* 84 * jdk.util.jar.enableMultiRelease=force is a no-op for URLClassLoader 85 */ 86 87 @Test 88 public void testURLClassLoader() throws Throwable { 89 Class<?> vcls = cldr.loadClass("version.Version"); 90 invokeMethod(vcls, rtVersion); 91 } 92 93 @Test 94 public void testGetResourceAsStream() throws Exception { 95 String resource = rtVersion == 9 ? "/version/PackagePrivate.java" : "/version/Version.java"; 96 // use rootClass as a base for getting resources 97 getResourceAsStream(rootClass, resource); 98 } 99 100 @Test 101 public void testGetResource() throws Exception { 102 String resource = rtVersion == 9 ? "/version/PackagePrivate.java" : "/version/Version.java"; 103 // use rootClass as a base for getting resources 104 getResource(rootClass, resource); 105 } 106 }