1 /* 2 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 /* 25 * @test 26 * @summary Test ResourceFilter class 27 * @modules jdk.jlink/jdk.tools.jlink.internal.plugins 28 * @run main ResourceFilterTest 29 */ 30 31 import java.io.File; 32 import java.nio.file.Files; 33 import java.util.Arrays; 34 import jdk.tools.jlink.internal.plugins.ResourceFilter; 35 36 public class ResourceFilterTest { 37 main(String[] args)38 public static void main(String[] args) throws Exception { 39 new ResourceFilterTest().test(); 40 } 41 test()42 public void test() throws Exception { 43 String[] samples = {"toto.jcov", "/module/META-INF/services/MyProvider"}; 44 String[] patterns = {"*.jcov", "**/META-INF/**", 45 "glob:*.jcov", "glob:**/META-INF/**", 46 "regex:.*\\.jcov", "regex:.*/META-INF/.*"}; 47 ResourceFilter rf = ResourceFilter.includeFilter(Arrays.asList(patterns)); 48 for (String s : samples) { 49 if (!rf.test(s)) { 50 throw new Exception("Sample " + s + "not accepted"); 51 } 52 } 53 ResourceFilter rf2 = ResourceFilter.excludeFilter(Arrays.asList(patterns)); 54 for (String s : samples) { 55 if (rf2.test(s)) { 56 throw new Exception("Sample " + s + " accepted"); 57 } 58 } 59 60 // Excluded resource list in a file 61 File resources = new File("resources.exc"); 62 resources.createNewFile(); 63 StringBuilder builder = new StringBuilder(); 64 for (String p : patterns) { 65 builder.append(p).append("\n"); 66 } 67 Files.write(resources.toPath(), builder.toString().getBytes()); 68 69 String[] input = {"@" + resources.getAbsolutePath()}; 70 ResourceFilter rf3 = ResourceFilter.includeFilter(Arrays.asList(input)); 71 for (String s : samples) { 72 if (!rf3.test(s)) { 73 throw new Exception("Sample " + s + "not accepted"); 74 } 75 } 76 ResourceFilter rf4 = ResourceFilter.excludeFilter(Arrays.asList(input)); 77 for (String s : samples) { 78 if (rf4.test(s)) { 79 throw new Exception("Sample " + s + " accepted"); 80 } 81 } 82 } 83 } 84