author | duke |
Wed, 05 Jul 2017 22:06:37 +0200 | |
changeset 40471 | ad45133ff99e |
parent 39834 | 53a6fb443c20 |
child 43185 | d75d9ff8d4e7 |
permissions | -rw-r--r-- |
36511 | 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; |
|
39834
53a6fb443c20
8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents:
39151
diff
changeset
|
37 |
import jdk.tools.jlink.internal.ResourcePoolManager; |
36511 | 38 |
|
39 |
import jdk.tools.jlink.internal.plugins.ExcludePlugin; |
|
39834
53a6fb443c20
8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents:
39151
diff
changeset
|
40 |
import jdk.tools.jlink.plugin.ResourcePool; |
53a6fb443c20
8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents:
39151
diff
changeset
|
41 |
import jdk.tools.jlink.plugin.ResourcePoolBuilder; |
53a6fb443c20
8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents:
39151
diff
changeset
|
42 |
import jdk.tools.jlink.plugin.ResourcePoolEntry; |
36511 | 43 |
|
44 |
public class ExcludePluginTest { |
|
45 |
||
46 |
public static void main(String[] args) throws Exception { |
|
47 |
new ExcludePluginTest().test(); |
|
48 |
} |
|
49 |
||
50 |
public void test() throws Exception { |
|
39042 | 51 |
check("**.jcov", "/num/toto.jcov", true); |
39151
34455cc82f5e
8147794: Jlink's ModuleEntry.stream can't be consumed more than once and ModuleEntry content should be read only if needed
sundar
parents:
39042
diff
changeset
|
52 |
check("**.jcov", "/toto.jcov/", true); |
39042 | 53 |
check("**.jcov", "/toto.jcov/tutu/tata", false); |
36511 | 54 |
check("/java.base/*.jcov", "/java.base/toto.jcov", true); |
39151
34455cc82f5e
8147794: Jlink's ModuleEntry.stream can't be consumed more than once and ModuleEntry content should be read only if needed
sundar
parents:
39042
diff
changeset
|
55 |
check("/java.base/toto.jcov", "/tjava.base/iti.jcov", false); |
36511 | 56 |
check("/java.base/*/toto.jcov", "/java.base/toto.jcov", false); |
57 |
check("/java.base/*/toto.jcov", "/java.base/tutu/toto.jcov", true); |
|
39042 | 58 |
check("**/java.base/*/toto.jcov", "/tutu/java.base/tutu/toto.jcov", true); |
59 |
check("/META-INF/**", "/META-INF/services/ MyProvider ", true); |
|
60 |
check("/META-INF/**", "/META-INF/services/MyProvider", true); |
|
39151
34455cc82f5e
8147794: Jlink's ModuleEntry.stream can't be consumed more than once and ModuleEntry content should be read only if needed
sundar
parents:
39042
diff
changeset
|
61 |
check("**/META-INF", "/ META-INF/services/MyProvider", false); |
39042 | 62 |
check("**/META-INF/**", "/java.base//META-INF/services/MyProvider", true); |
36511 | 63 |
check("/java.base/*/Toto$Titi.class", "/java.base/tutu/Toto$Titi.class", true); |
39042 | 64 |
check("/**$**.class", "/java.base/tutu/Toto$Titi.class", true); |
65 |
check("**$**.class", "/java.base/tutu/Toto$Titi.class", true); |
|
36511 | 66 |
|
67 |
// Excluded resource list in a file |
|
68 |
File order = new File("resources.exc"); |
|
69 |
order.createNewFile(); |
|
39042 | 70 |
Files.write(order.toPath(), "**.jcov".getBytes()); |
71 |
check("@" + order.getAbsolutePath(), "/num/toto.jcov", true); |
|
36511 | 72 |
} |
73 |
||
74 |
public void check(String s, String sample, boolean exclude) throws Exception { |
|
75 |
Map<String, String> prop = new HashMap<>(); |
|
76 |
prop.put(ExcludePlugin.NAME, s); |
|
77 |
ExcludePlugin excludePlugin = new ExcludePlugin(); |
|
78 |
excludePlugin.configure(prop); |
|
39834
53a6fb443c20
8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents:
39151
diff
changeset
|
79 |
ResourcePoolManager resourcesMgr = new ResourcePoolManager(); |
53a6fb443c20
8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents:
39151
diff
changeset
|
80 |
ResourcePoolEntry resource = ResourcePoolEntry.create(sample, new byte[0]); |
53a6fb443c20
8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents:
39151
diff
changeset
|
81 |
resourcesMgr.add(resource); |
53a6fb443c20
8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents:
39151
diff
changeset
|
82 |
ResourcePoolManager resultMgr = new ResourcePoolManager(); |
53a6fb443c20
8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents:
39151
diff
changeset
|
83 |
ResourcePool resPool = excludePlugin.transform(resourcesMgr.resourcePool(), |
53a6fb443c20
8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents:
39151
diff
changeset
|
84 |
resultMgr.resourcePoolBuilder()); |
36511 | 85 |
if (exclude) { |
39834
53a6fb443c20
8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents:
39151
diff
changeset
|
86 |
if (resPool.contains(resource)) { |
36511 | 87 |
throw new AssertionError(sample + " should be excluded by " + s); |
88 |
} |
|
89 |
} else { |
|
39834
53a6fb443c20
8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents:
39151
diff
changeset
|
90 |
if (!resPool.contains(resource)) { |
36511 | 91 |
throw new AssertionError(sample + " shouldn't be excluded by " + s); |
92 |
} |
|
93 |
} |
|
94 |
} |
|
95 |
} |