Path: blob/master/test/jdk/tools/jlink/JLink2Test.java
41144 views
/*1* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @summary Test image creation26* @author Jean-Francois Denise27* @library ../lib28* @modules java.base/jdk.internal.jimage29* jdk.jdeps/com.sun.tools.classfile30* jdk.jlink/jdk.tools.jlink.internal31* jdk.jlink/jdk.tools.jlink.plugin32* jdk.jlink/jdk.tools.jmod33* jdk.jlink/jdk.tools.jimage34* jdk.compiler35* @build tests.*36* @run main/othervm -verbose:gc -Xmx1g JLink2Test37*/38import java.io.File;39import java.io.FileOutputStream;40import java.io.IOException;41import java.nio.file.Files;42import java.nio.file.Path;43import java.util.ArrayList;44import java.util.Arrays;45import java.util.Collections;46import java.util.List;47import java.util.jar.JarEntry;48import java.util.jar.JarOutputStream;49import jdk.tools.jlink.internal.PluginRepository;50import jdk.tools.jlink.plugin.Plugin;5152import tests.Helper;53import tests.JImageGenerator;54import tests.JImageValidator;5556public class JLink2Test {5758public static void main(String[] args) throws Exception {59Helper helper = Helper.newHelper();60if (helper == null) {61System.err.println("Test not run");62return;63}64helper.generateDefaultModules();6566// This test case must be first one, the JlinkTask is clean67// and reveals possible bug related to plugin options in defaults68testSameNames(helper);69testOptions();70}7172private static void testSameNames(Helper helper) throws Exception {73// Multiple modules with the same name in modulepath, take the first one in the path.74// First jmods then jars. So jmods are found, jars are hidden.75String[] jarClasses = {"amodule.jar.Main"};76String[] jmodsClasses = {"amodule.jmods.Main"};77helper.generateDefaultJarModule("amodule", Arrays.asList(jarClasses));78helper.generateDefaultJModule("amodule", Arrays.asList(jmodsClasses));79List<String> okLocations = new ArrayList<>();80okLocations.addAll(Helper.toLocation("amodule", Arrays.asList(jmodsClasses)));81Path image = helper.generateDefaultImage(new String[0], "amodule").assertSuccess();82JImageValidator validator = new JImageValidator("amodule", okLocations,83image.toFile(), Collections.emptyList(), Collections.emptyList());84validator.validate();85}8687private static void testOptions() throws Exception {88List<Plugin> builtInPlugins = new ArrayList<>();89builtInPlugins.addAll(PluginRepository.getPlugins(ModuleLayer.boot()));90if(builtInPlugins.isEmpty()) {91throw new Exception("No builtin plugins");92}93List<String> options = new ArrayList<>();94for (Plugin p : builtInPlugins) {95if (p.getOption() == null) {96throw new Exception("Null option for " + p.getName());97}98if (options.contains(p.getName())) {99throw new Exception("Option " + p.getOption() + " used more than once");100}101options.add(p.getName());102}103}104}105106107