/
githubmirror
/
panama-vector
Обзор
Документация
Войти
/
githubmirror
/
panama-vector
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
test/jdk/java/util/jar/JarFile/mrjar/MultiReleaseJarHttpProperties.java
125 строк
5 KB
Justin Lu
8378111: Migrate java/util/jar tests to JUnit
02 мар 2026, 20:22
02 мар 2026, 20:22
0baeccd
Код
Авторство
О чём код?
/* * Copyright (c) 2015, 2026, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ /* * @test * @bug 8132734 8194070 * @summary Test the System properties for JarFile that support multi-release jar files * @library /lib/testlibrary/java/util/jar /test/lib * @modules jdk.jartool * jdk.compiler * @build CreateMultiReleaseTestJars * jdk.test.lib.compiler.Compiler * jdk.test.lib.util.JarBuilder * @run junit MultiReleaseJarHttpProperties * @run junit/othervm -Djdk.util.jar.version=0 MultiReleaseJarHttpProperties * @run junit/othervm -Djdk.util.jar.version=8 MultiReleaseJarHttpProperties * @run junit/othervm -Djdk.util.jar.version=9 MultiReleaseJarHttpProperties * @run junit/othervm -Djdk.util.jar.version=100 MultiReleaseJarHttpProperties * @run junit/othervm -Djdk.util.jar.version=8 -Djdk.util.jar.enableMultiRelease=false MultiReleaseJarHttpProperties * @run junit/othervm -Djdk.util.jar.version=9 -Djdk.util.jar.enableMultiRelease=false MultiReleaseJarHttpProperties * @run junit/othervm -Djdk.util.jar.version=8 -Djdk.util.jar.enableMultiRelease=force MultiReleaseJarHttpProperties * @run junit/othervm -Djdk.util.jar.version=9 -Djdk.util.jar.enableMultiRelease=force MultiReleaseJarHttpProperties * @run junit/othervm -Djdk.util.jar.enableMultiRelease=false MultiReleaseJarHttpProperties * @run junit/othervm -Djdk.util.jar.enableMultiRelease=force MultiReleaseJarHttpProperties */ import java.io.IOException; import java.net.InetAddress; import java.net.InetSocketAddress; import java.net.URL; import java.net.URLClassLoader; import java.nio.file.Path; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import com.sun.net.httpserver.HttpServer; import com.sun.net.httpserver.SimpleFileServer; import jdk.test.lib.net.URIBuilder; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestInstance; @TestInstance(TestInstance.Lifecycle.PER_CLASS) public class MultiReleaseJarHttpProperties extends MultiReleaseJarProperties { private HttpServer server; private ExecutorService executor; static final String TESTCONTEXT = "/multi-release.jar"; //mapped to local file path @BeforeAll public void initialize() throws Exception { server = SimpleFileServer.createFileServer(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0), Path.of(System.getProperty("user.dir", ".")), SimpleFileServer.OutputLevel.INFO); executor = Executors.newCachedThreadPool(); server.setExecutor(executor); server.start(); super.initialize(); } @Override protected void initializeClassLoader() throws Exception { URL[] urls = new URL[]{ URIBuilder.newBuilder().scheme("http").port(server.getAddress().getPort()).loopback() .path(TESTCONTEXT).toURL(), }; cldr = new URLClassLoader(urls); // load any class, Main is convenient and in the root entries rootClass = cldr.loadClass("version.Main"); } @AfterAll public void close() throws IOException { // Windows requires server to stop before file is deleted if (server != null) { server.stop(0); executor.shutdown(); } super.close(); } /* * jdk.util.jar.enableMultiRelease=force is a no-op for URLClassLoader */ @Test public void testURLClassLoader() throws Throwable { Class<?> vcls = cldr.loadClass("version.Version"); invokeMethod(vcls, rtVersion); } @Test public void testGetResourceAsStream() throws Exception { String resource = rtVersion == 9 ? "/version/PackagePrivate.java" : "/version/Version.java"; // use rootClass as a base for getting resources getResourceAsStream(rootClass, resource); } @Test public void testGetResource() throws Exception { String resource = rtVersion == 9 ? "/version/PackagePrivate.java" : "/version/Version.java"; // use rootClass as a base for getting resources getResource(rootClass, resource); } }