22 */ |
22 */ |
23 |
23 |
24 /* |
24 /* |
25 * @test |
25 * @test |
26 * @summary Test ResourceFilter class |
26 * @summary Test ResourceFilter class |
27 * @author Jean-Francois Denise |
|
28 * @modules jdk.jlink/jdk.tools.jlink.internal.plugins |
27 * @modules jdk.jlink/jdk.tools.jlink.internal.plugins |
29 * @run main ResourceFilterTest |
28 * @run main ResourceFilterTest |
30 */ |
29 */ |
31 |
30 |
32 import java.io.File; |
31 import java.io.File; |
33 import java.nio.file.Files; |
32 import java.nio.file.Files; |
|
33 import java.util.Arrays; |
34 import jdk.tools.jlink.internal.plugins.ResourceFilter; |
34 import jdk.tools.jlink.internal.plugins.ResourceFilter; |
35 |
35 |
36 public class ResourceFilterTest { |
36 public class ResourceFilterTest { |
37 |
37 |
38 public static void main(String[] args) throws Exception { |
38 public static void main(String[] args) throws Exception { |
39 new ResourceFilterTest().test(); |
39 new ResourceFilterTest().test(); |
40 } |
40 } |
41 |
41 |
42 public void test() throws Exception { |
42 public void test() throws Exception { |
43 String[] samples = {"toto.jcov", "/module/META-INF/services/MyProvider"}; |
43 String[] samples = {"toto.jcov", "/module/META-INF/services/MyProvider"}; |
44 String[] patterns = {"*.jcov", "*/META-INF/*"}; |
44 String[] patterns = {"*.jcov", "**/META-INF/**", |
45 ResourceFilter rf = new ResourceFilter(patterns); |
45 "glob:*.jcov", "glob:**/META-INF/**", |
|
46 "regex:.*\\.jcov", "regex:.*/META-INF/.*"}; |
|
47 ResourceFilter rf = ResourceFilter.includeFilter(Arrays.asList(patterns)); |
46 for (String s : samples) { |
48 for (String s : samples) { |
47 if (!rf.test(s)) { |
49 if (!rf.test(s)) { |
48 throw new Exception("Sample " + s + "not accepted"); |
50 throw new Exception("Sample " + s + "not accepted"); |
49 } |
51 } |
50 } |
52 } |
51 ResourceFilter rf2 = new ResourceFilter(patterns, true); |
53 ResourceFilter rf2 = ResourceFilter.excludeFilter(Arrays.asList(patterns)); |
52 for (String s : samples) { |
54 for (String s : samples) { |
53 if (rf2.test(s)) { |
55 if (rf2.test(s)) { |
54 throw new Exception("Sample " + s + " accepted"); |
56 throw new Exception("Sample " + s + " accepted"); |
55 } |
57 } |
56 } |
58 } |
62 for (String p : patterns) { |
64 for (String p : patterns) { |
63 builder.append(p).append("\n"); |
65 builder.append(p).append("\n"); |
64 } |
66 } |
65 Files.write(resources.toPath(), builder.toString().getBytes()); |
67 Files.write(resources.toPath(), builder.toString().getBytes()); |
66 |
68 |
67 String[] input = {resources.getAbsolutePath()}; |
69 String[] input = {"@" + resources.getAbsolutePath()}; |
68 ResourceFilter rf3 = new ResourceFilter(input); |
70 ResourceFilter rf3 = ResourceFilter.includeFilter(Arrays.asList(input)); |
69 for (String s : samples) { |
71 for (String s : samples) { |
70 if (!rf3.test(s)) { |
72 if (!rf3.test(s)) { |
71 throw new Exception("Sample " + s + "not accepted"); |
73 throw new Exception("Sample " + s + "not accepted"); |
72 } |
74 } |
73 } |
75 } |
74 ResourceFilter rf4 = new ResourceFilter(input, true); |
76 ResourceFilter rf4 = ResourceFilter.excludeFilter(Arrays.asList(input)); |
75 for (String s : samples) { |
77 for (String s : samples) { |
76 if (rf4.test(s)) { |
78 if (rf4.test(s)) { |
77 throw new Exception("Sample " + s + " accepted"); |
79 throw new Exception("Sample " + s + " accepted"); |
78 } |
80 } |
79 } |
81 } |