author | alanb |
Fri, 07 Apr 2017 08:05:54 +0000 | |
changeset 44545 | 83b611b88ac8 |
parent 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 Negative test for ImagePluginStack. |
|
27 |
* @author Andrei Eremeev |
|
43185 | 28 |
* @modules jdk.jlink/jdk.tools.jlink |
29 |
* jdk.jlink/jdk.tools.jlink.internal |
|
30 |
* jdk.jlink/jdk.tools.jlink.plugin |
|
36511 | 31 |
* @run main/othervm PluginsNegativeTest |
32 |
*/ |
|
33 |
import java.util.ArrayList; |
|
34 |
import java.util.Collections; |
|
35 |
import java.util.List; |
|
36 |
import java.util.Map; |
|
37 |
||
38 |
import jdk.tools.jlink.internal.ImagePluginConfiguration; |
|
41559
5b33f33df1fb
8168091: jlink should check security permission early when programmatic access is used
sundar
parents:
39834
diff
changeset
|
39 |
import jdk.tools.jlink.internal.Jlink; |
5b33f33df1fb
8168091: jlink should check security permission early when programmatic access is used
sundar
parents:
39834
diff
changeset
|
40 |
import jdk.tools.jlink.internal.Jlink.PluginsConfiguration; |
36511 | 41 |
import jdk.tools.jlink.internal.PluginRepository; |
42 |
import jdk.tools.jlink.internal.ImagePluginStack; |
|
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:
39321
diff
changeset
|
43 |
import jdk.tools.jlink.internal.ResourcePoolManager; |
36511 | 44 |
import jdk.tools.jlink.plugin.Plugin; |
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:
39321
diff
changeset
|
45 |
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:
39321
diff
changeset
|
46 |
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:
39321
diff
changeset
|
47 |
import jdk.tools.jlink.plugin.ResourcePoolEntry; |
36511 | 48 |
|
49 |
public class PluginsNegativeTest { |
|
50 |
||
51 |
public static void main(String[] args) throws Exception { |
|
52 |
new PluginsNegativeTest().test(); |
|
53 |
} |
|
54 |
||
55 |
public void test() throws Exception { |
|
56 |
testDuplicateBuiltInProviders(); |
|
57 |
testUnknownProvider(); |
|
58 |
PluginRepository.registerPlugin(new CustomPlugin("plugin")); |
|
59 |
testEmptyInputResource(); |
|
60 |
testEmptyOutputResource(); |
|
61 |
} |
|
62 |
||
63 |
private void testDuplicateBuiltInProviders() { |
|
64 |
List<Plugin> javaPlugins = new ArrayList<>(); |
|
44545
83b611b88ac8
8177530: Module system implementation refresh (4/2017)
alanb
parents:
43185
diff
changeset
|
65 |
javaPlugins.addAll(PluginRepository.getPlugins(ModuleLayer.boot())); |
36511 | 66 |
for (Plugin javaPlugin : javaPlugins) { |
67 |
System.out.println("Registered plugin: " + javaPlugin.getName()); |
|
68 |
} |
|
69 |
for (Plugin javaPlugin : javaPlugins) { |
|
70 |
String pluginName = javaPlugin.getName(); |
|
71 |
try { |
|
72 |
PluginRepository.registerPlugin(new CustomPlugin(pluginName)); |
|
73 |
try { |
|
44545
83b611b88ac8
8177530: Module system implementation refresh (4/2017)
alanb
parents:
43185
diff
changeset
|
74 |
PluginRepository.getPlugin(pluginName, ModuleLayer.boot()); |
36511 | 75 |
throw new AssertionError("Exception is not thrown for duplicate plugin: " + pluginName); |
76 |
} catch (Exception ignored) { |
|
77 |
} |
|
78 |
} finally { |
|
79 |
PluginRepository.unregisterPlugin(pluginName); |
|
80 |
} |
|
81 |
} |
|
82 |
} |
|
83 |
||
84 |
private void testUnknownProvider() { |
|
44545
83b611b88ac8
8177530: Module system implementation refresh (4/2017)
alanb
parents:
43185
diff
changeset
|
85 |
if (PluginRepository.getPlugin("unknown", ModuleLayer.boot()) != null) { |
36511 | 86 |
throw new AssertionError("Exception expected for unknown plugin name"); |
87 |
} |
|
88 |
} |
|
89 |
||
90 |
private static Plugin createPlugin(String name) { |
|
91 |
return Jlink.newPlugin(name, Collections.emptyMap(), null); |
|
92 |
} |
|
93 |
||
94 |
private void testEmptyOutputResource() throws Exception { |
|
95 |
List<Plugin> plugins = new ArrayList<>(); |
|
96 |
plugins.add(createPlugin("plugin")); |
|
97 |
ImagePluginStack stack = ImagePluginConfiguration.parseConfiguration(new PluginsConfiguration(plugins, |
|
98 |
null, null)); |
|
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:
39321
diff
changeset
|
99 |
ResourcePoolManager inResources = 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:
39321
diff
changeset
|
100 |
inResources.add(ResourcePoolEntry.create("/aaa/bbb/A", new byte[10])); |
36511 | 101 |
try { |
102 |
stack.visitResources(inResources); |
|
103 |
throw new AssertionError("Exception expected when output resource is empty"); |
|
104 |
} catch (Exception ignored) { |
|
105 |
} |
|
106 |
} |
|
107 |
||
108 |
private void testEmptyInputResource() throws Exception { |
|
109 |
List<Plugin> plugins = new ArrayList<>(); |
|
110 |
plugins.add(createPlugin("plugin")); |
|
111 |
ImagePluginStack stack = ImagePluginConfiguration.parseConfiguration(new PluginsConfiguration(plugins, |
|
112 |
null, null)); |
|
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:
39321
diff
changeset
|
113 |
ResourcePoolManager inResources = 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:
39321
diff
changeset
|
114 |
ResourcePool outResources = stack.visitResources(inResources); |
36511 | 115 |
if (!outResources.isEmpty()) { |
116 |
throw new AssertionError("Output resource is not empty"); |
|
117 |
} |
|
118 |
} |
|
119 |
||
39321
c60f34e8c057
8160641: PostProcessingPlugin and ExecutableImage should not be part of plugin API
sundar
parents:
39129
diff
changeset
|
120 |
public static class CustomPlugin implements Plugin { |
36511 | 121 |
|
122 |
private final String name; |
|
123 |
||
124 |
CustomPlugin(String name) { |
|
125 |
this.name = name; |
|
126 |
} |
|
127 |
||
128 |
@Override |
|
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:
39321
diff
changeset
|
129 |
public ResourcePool transform(ResourcePool inResources, ResourcePoolBuilder outResources) { |
53a6fb443c20
8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents:
39321
diff
changeset
|
130 |
// don't add anything to the builder |
53a6fb443c20
8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents:
39321
diff
changeset
|
131 |
return outResources.build(); |
36511 | 132 |
} |
133 |
||
134 |
@Override |
|
135 |
public String getName() { |
|
136 |
return name; |
|
137 |
} |
|
138 |
||
139 |
@Override |
|
140 |
public String getDescription() { |
|
141 |
return null; |
|
142 |
} |
|
143 |
||
144 |
@Override |
|
145 |
public void configure(Map<String, String> config) { |
|
146 |
||
147 |
} |
|
148 |
} |
|
149 |
} |