/* * Copyright (c) 2016, 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 * @library /lib/testlibrary * @modules java.base/jdk.internal.module * @build MultiReleaseJarTest JarUtils * @run testng MultiReleaseJarTest * @run testng/othervm -Djdk.util.jar.enableMultiRelease=false MultiReleaseJarTest * @summary Basic test of ModuleReader with a modular JAR that is also a * multi-release JAR */ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.lang.module.ModuleDescriptor; import java.lang.module.ModuleFinder; import java.lang.module.ModuleReader; import java.lang.module.ModuleReference; import java.net.URI; import java.net.URLConnection; import java.nio.ByteBuffer; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.util.Optional; import java.util.Set; import java.util.jar.Attributes; import java.util.jar.Manifest; import java.util.stream.Collectors; import jdk.internal.module.ModuleInfoWriter; import org.testng.annotations.Test; import static org.testng.Assert.*; /** * Exercises ModuleReader with a modular JAR containing the following files: * *
{@code * module-info.class * META-INF/versions/* * The module-info.class in the top-level directory is the binary form of: */module.class * }
{@code * module jdk.test { * requires java.base; * } * }* * The module-info.class in the versioned section is the binary form of: *
{@code * module jdk.test { * requires java.base; * requires jdk.unsupported; * } * }*/ @Test public class MultiReleaseJarTest { // Java SE/JDK major release private static final int RELEASE = Runtime.version().major(); // the name of the test module private static final String MODULE_NAME = "jdk.test"; private static final String MODULE_INFO_CLASS = "module-info.class"; /** * Uses the ModuleFinder API to locate the module packaged as a modular * and mutli-release JAR and then creates a ModuleReader to access the * contents of the module. */ public void testMultiReleaseJar() throws IOException { // are multi-release JARs enabled? String s = System.getProperty("jdk.util.jar.enableMultiRelease"); boolean multiRelease = (s == null || Boolean.parseBoolean(s)); // create the multi-release modular JAR Path jarfile = createJarFile(); // find the module ModuleFinder finder = ModuleFinder.of(jarfile); Optional