Path: blob/master/test/jdk/tools/jlink/plugins/ExcludeModuleInfoTest.java
41149 views
/*1* Copyright (c) 2018, 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* @bug 819492226* @summary jlink --exclude-resources should never exclude module-info.class27* @modules jdk.jlink/jdk.tools.jlink.internal28* jdk.jlink/jdk.tools.jlink.internal.plugins29* jdk.jlink/jdk.tools.jlink.plugin30* @run main ExcludeModuleInfoTest31*/3233import java.io.File;34import java.nio.file.Files;35import java.util.HashMap;36import java.util.Map;37import jdk.tools.jlink.internal.ResourcePoolManager;3839import jdk.tools.jlink.internal.plugins.ExcludePlugin;40import jdk.tools.jlink.plugin.PluginException;41import jdk.tools.jlink.plugin.ResourcePool;42import jdk.tools.jlink.plugin.ResourcePoolBuilder;43import jdk.tools.jlink.plugin.ResourcePoolEntry;4445public class ExcludeModuleInfoTest {4647public static void main(String[] args) throws Exception {48new ExcludeModuleInfoTest().test();49}5051public void test() throws Exception {52check("**.class", "/mymodule/module-info.class");53check("/java.base/module-info.class", "/java.base/module-info.class");54}5556public void check(String s, String sample) throws Exception {57Map<String, String> prop = new HashMap<>();58ExcludePlugin excludePlugin = new ExcludePlugin();59prop.put(excludePlugin.getName(), s);60excludePlugin.configure(prop);61ResourcePoolManager resourcesMgr = new ResourcePoolManager();62ResourcePoolEntry resource = ResourcePoolEntry.create(sample, new byte[0]);63resourcesMgr.add(resource);64ResourcePoolManager resultMgr = new ResourcePoolManager();65try {66excludePlugin.transform(resourcesMgr.resourcePool(),67resultMgr.resourcePoolBuilder());68throw new AssertionError(sample + " exclusion should have resulted in exception");69} catch (PluginException pe) {70System.err.println("Got exception as expected: " + pe);71pe.printStackTrace();72}73}74}757677