|
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 exclude plugin |
|
27 * @author Jean-Francois Denise |
|
28 * @modules jdk.jlink/jdk.tools.jlink.internal |
|
29 * jdk.jlink/jdk.tools.jlink.internal.plugins |
|
30 * @run main ExcludePluginTest |
|
31 */ |
|
32 |
|
33 import java.io.File; |
|
34 import java.nio.file.Files; |
|
35 import java.util.HashMap; |
|
36 import java.util.Map; |
|
37 import jdk.tools.jlink.internal.PoolImpl; |
|
38 |
|
39 import jdk.tools.jlink.internal.plugins.ExcludePlugin; |
|
40 import jdk.tools.jlink.plugin.Pool; |
|
41 import jdk.tools.jlink.plugin.Pool.ModuleData; |
|
42 |
|
43 public class ExcludePluginTest { |
|
44 |
|
45 public static void main(String[] args) throws Exception { |
|
46 new ExcludePluginTest().test(); |
|
47 } |
|
48 |
|
49 public void test() throws Exception { |
|
50 check("*.jcov", "/num/toto.jcov", true); |
|
51 check("*.jcov", "//toto.jcov", true); |
|
52 check("*.jcov", "/toto.jcov/tutu/tata", false); |
|
53 check("/java.base/*.jcov", "/java.base/toto.jcov", true); |
|
54 check("/java.base/toto.jcov", "t/java.base/iti.jcov", false); |
|
55 check("/java.base/*/toto.jcov", "/java.base/toto.jcov", false); |
|
56 check("/java.base/*/toto.jcov", "/java.base/tutu/toto.jcov", true); |
|
57 check("*/java.base/*/toto.jcov", "/tutu/java.base/tutu/toto.jcov", true); |
|
58 check("*/META-INF/*", "/META-INF/services/ MyProvider ", false); |
|
59 check("*/META-INF/*", "/META-INF/services/MyProvider", false); |
|
60 check("*/META-INF", " /META-INF/services/MyProvider", false); |
|
61 check("*/META-INF/*", "/java.base//META-INF/services/MyProvider", true); |
|
62 check("/java.base/*/Toto$Titi.class", "/java.base/tutu/Toto$Titi.class", true); |
|
63 check("/*$*.class", "/java.base/tutu/Toto$Titi.class", true); |
|
64 check("*$*.class", "/java.base/tutu/Toto$Titi.class", true); |
|
65 |
|
66 // Excluded resource list in a file |
|
67 File order = new File("resources.exc"); |
|
68 order.createNewFile(); |
|
69 Files.write(order.toPath(), "*.jcov".getBytes()); |
|
70 check(order.getAbsolutePath(), "/num/toto.jcov", true); |
|
71 } |
|
72 |
|
73 public void check(String s, String sample, boolean exclude) throws Exception { |
|
74 Map<String, String> prop = new HashMap<>(); |
|
75 prop.put(ExcludePlugin.NAME, s); |
|
76 ExcludePlugin excludePlugin = new ExcludePlugin(); |
|
77 excludePlugin.configure(prop); |
|
78 Pool resources = new PoolImpl(); |
|
79 ModuleData resource = Pool.newResource(sample, new byte[0]); |
|
80 resources.add(resource); |
|
81 Pool result = new PoolImpl(); |
|
82 excludePlugin.visit(resources, result); |
|
83 if (exclude) { |
|
84 if (result.getContent().contains(resource)) { |
|
85 throw new AssertionError(sample + " should be excluded by " + s); |
|
86 } |
|
87 } else { |
|
88 if (!result.getContent().contains(resource)) { |
|
89 throw new AssertionError(sample + " shouldn't be excluded by " + s); |
|
90 } |
|
91 } |
|
92 } |
|
93 } |