Path: blob/master/test/jdk/tools/jlink/plugins/ExcludePluginTest.java
41149 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 exclude plugin26* @author Jean-Francois Denise27* @modules jdk.jlink/jdk.tools.jlink.internal28* jdk.jlink/jdk.tools.jlink.internal.plugins29* jdk.jlink/jdk.tools.jlink.plugin30* @run main ExcludePluginTest31*/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.ResourcePool;41import jdk.tools.jlink.plugin.ResourcePoolBuilder;42import jdk.tools.jlink.plugin.ResourcePoolEntry;4344public class ExcludePluginTest {4546public static void main(String[] args) throws Exception {47new ExcludePluginTest().test();48}4950public void test() throws Exception {51check("**.jcov", "/num/toto.jcov", true);52check("**.jcov", "/toto.jcov/", true);53check("**.jcov", "/toto.jcov/tutu/tata", false);54check("/java.base/*.jcov", "/java.base/toto.jcov", true);55check("/java.base/toto.jcov", "/tjava.base/iti.jcov", false);56check("/java.base/*/toto.jcov", "/java.base/toto.jcov", false);57check("/java.base/*/toto.jcov", "/java.base/tutu/toto.jcov", true);58check("**/java.base/*/toto.jcov", "/tutu/java.base/tutu/toto.jcov", true);59check("/META-INF/**", "/META-INF/services/ MyProvider ", true);60check("/META-INF/**", "/META-INF/services/MyProvider", true);61check("**/META-INF", "/ META-INF/services/MyProvider", false);62check("**/META-INF/**", "/java.base//META-INF/services/MyProvider", true);63check("/java.base/*/Toto$Titi.class", "/java.base/tutu/Toto$Titi.class", true);64check("/**$**.class", "/java.base/tutu/Toto$Titi.class", true);65check("**$**.class", "/java.base/tutu/Toto$Titi.class", true);6667// Excluded resource list in a file68File order = new File("resources.exc");69order.createNewFile();70Files.write(order.toPath(), "**.jcov".getBytes());71check("@" + order.getAbsolutePath(), "/num/toto.jcov", true);72}7374public void check(String s, String sample, boolean exclude) throws Exception {75Map<String, String> prop = new HashMap<>();76ExcludePlugin excludePlugin = new ExcludePlugin();77prop.put(excludePlugin.getName(), s);78excludePlugin.configure(prop);79ResourcePoolManager resourcesMgr = new ResourcePoolManager();80ResourcePoolEntry resource = ResourcePoolEntry.create(sample, new byte[0]);81resourcesMgr.add(resource);82ResourcePoolManager resultMgr = new ResourcePoolManager();83ResourcePool resPool = excludePlugin.transform(resourcesMgr.resourcePool(),84resultMgr.resourcePoolBuilder());85if (exclude) {86if (resPool.contains(resource)) {87throw new AssertionError(sample + " should be excluded by " + s);88}89} else {90if (!resPool.contains(resource)) {91throw new AssertionError(sample + " shouldn't be excluded by " + s);92}93}94}95}969798