Path: blob/master/test/jdk/tools/jlink/plugins/ExcludeFilesPluginTest.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 files 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 ExcludeFilesPluginTest31*/3233import java.io.ByteArrayInputStream;34import java.io.File;35import java.nio.file.Files;36import java.util.HashMap;37import java.util.Map;38import jdk.tools.jlink.internal.ResourcePoolManager;3940import jdk.tools.jlink.internal.plugins.ExcludeFilesPlugin;41import jdk.tools.jlink.plugin.ResourcePool;42import jdk.tools.jlink.plugin.ResourcePoolEntry;4344public class ExcludeFilesPluginTest {45public static void main(String[] args) throws Exception {46new ExcludeFilesPluginTest().test();47}4849public void test() throws Exception {50checkFiles("**.jcov", "num/toto.jcov", "", true);51checkFiles("**.jcov", "/toto.jcov", "", true);52checkFiles("**.jcov", "toto.jcov/tutu/tata", "", false);53checkFiles("/java.base/*.jcov", "toto.jcov", "java.base", true);54checkFiles("/java.base/toto.jcov", "iti.jcov", "t/java.base", false);55checkFiles("/java.base/*/toto.jcov", "toto.jcov", "java.base", false);56checkFiles("/java.base/*/toto.jcov", "tutu/toto.jcov", "java.base", true);57checkFiles("**/java.base/*/toto.jcov", "java.base/tutu/toto.jcov", "/tutu", true);5859checkFiles("/**$*.properties", "tutu/Toto$Titi.properties", "java.base", true);60checkFiles("**$*.properties", "tutu/Toto$Titi.properties", "java.base", true);6162// Excluded files list in a file63File order = new File("files.exc");64order.createNewFile();65Files.write(order.toPath(), "**.jcov".getBytes());66checkFiles("@" + order.getAbsolutePath(), "/num/toto.jcov", "", true);67}6869public void checkFiles(String s, String sample, String module, boolean exclude) throws Exception {70Map<String, String> prop = new HashMap<>();71ExcludeFilesPlugin fplug = new ExcludeFilesPlugin();72prop.put(fplug.getName(), s);73fplug.configure(prop);74ResourcePoolManager files = new ResourcePoolManager();75ResourcePoolManager fresult = new ResourcePoolManager();76ResourcePoolEntry f = ResourcePoolEntry.create("/" + module + "/" + sample,77ResourcePoolEntry.Type.CONFIG, new byte[0]);78files.add(f);7980ResourcePool resPool = fplug.transform(files.resourcePool(), fresult.resourcePoolBuilder());8182if (exclude) {83if (resPool.contains(f)) {84throw new Exception(sample + " should be excluded by " + s);85}86} else {87if (!resPool.contains(f)) {88throw new Exception(sample + " shouldn't be excluded by " + s);89}90}91}92}939495