author | chegar |
Wed, 18 Jan 2017 09:36:24 +0000 | |
changeset 43185 | d75d9ff8d4e7 |
parent 41559 | 5b33f33df1fb |
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 last sorter property |
|
27 |
* @author Jean-Francois Denise |
|
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 LastSorterTest |
32 |
*/ |
|
33 |
||
34 |
import java.util.ArrayList; |
|
35 |
import java.util.Collections; |
|
36 |
import java.util.HashMap; |
|
37 |
import java.util.List; |
|
38 |
import java.util.Map; |
|
39 |
||
40 |
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
|
41 |
import jdk.tools.jlink.internal.ImagePluginStack; |
5b33f33df1fb
8168091: jlink should check security permission early when programmatic access is used
sundar
parents:
39834
diff
changeset
|
42 |
import jdk.tools.jlink.internal.Jlink; |
5b33f33df1fb
8168091: jlink should check security permission early when programmatic access is used
sundar
parents:
39834
diff
changeset
|
43 |
import jdk.tools.jlink.internal.Jlink.PluginsConfiguration; |
36511 | 44 |
import jdk.tools.jlink.internal.PluginRepository; |
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.internal.ResourcePoolManager; |
36511 | 46 |
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
|
47 |
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
|
48 |
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
|
49 |
import jdk.tools.jlink.plugin.ResourcePoolEntry; |
36511 | 50 |
|
51 |
public class LastSorterTest { |
|
52 |
||
53 |
public LastSorterTest() { |
|
54 |
for (int i = 1; i <= 6; i++) { |
|
55 |
PluginRepository.registerPlugin(new SorterPlugin("sorterplugin" + i)); |
|
56 |
} |
|
57 |
} |
|
58 |
||
59 |
public static void main(String[] args) throws Exception { |
|
60 |
new LastSorterTest().test(); |
|
61 |
} |
|
62 |
||
63 |
public void test() throws Exception { |
|
64 |
checkUnknownPlugin(); |
|
65 |
||
66 |
checkOrderAfterLastSorter(); |
|
67 |
||
68 |
checkPositiveCase(); |
|
69 |
||
70 |
checkTwoLastSorters(); |
|
71 |
} |
|
72 |
||
73 |
private void checkTwoLastSorters() throws Exception { |
|
74 |
List<Plugin> plugins = new ArrayList<>(); |
|
75 |
plugins.add(createPlugin("sorterplugin5", "/a")); |
|
76 |
plugins.add(createPlugin("sorterplugin6", "/a")); |
|
77 |
PluginsConfiguration config = new Jlink.PluginsConfiguration(plugins, |
|
78 |
null, "sorterplugin5"); |
|
79 |
||
80 |
ImagePluginStack stack = ImagePluginConfiguration.parseConfiguration(config); |
|
81 |
||
82 |
// check order |
|
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
|
83 |
ResourcePoolManager res = fillOutResourceResourcePool(); |
36511 | 84 |
|
85 |
try { |
|
86 |
stack.visitResources(res); |
|
87 |
throw new AssertionError("Exception expected: Order of resources is already frozen." + |
|
88 |
"Plugin sorterplugin6 is badly located"); |
|
89 |
} catch (Exception e) { |
|
90 |
// expected |
|
91 |
} |
|
92 |
} |
|
93 |
||
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
|
94 |
private ResourcePoolManager fillOutResourceResourcePool() throws Exception { |
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
|
95 |
ResourcePoolManager res = 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
|
96 |
res.add(ResourcePoolEntry.create("/eee/bbb/res1.class", new byte[90])); |
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
|
97 |
res.add(ResourcePoolEntry.create("/aaaa/bbb/res2.class", new byte[90])); |
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
|
98 |
res.add(ResourcePoolEntry.create("/bbb/aa/res1.class", new byte[90])); |
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 |
res.add(ResourcePoolEntry.create("/aaaa/bbb/res3.class", new byte[90])); |
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 |
res.add(ResourcePoolEntry.create("/bbb/aa/res2.class", new byte[90])); |
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
|
101 |
res.add(ResourcePoolEntry.create("/fff/bbb/res1.class", new byte[90])); |
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
|
102 |
res.add(ResourcePoolEntry.create("/aaaa/bbb/res1.class", new byte[90])); |
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
|
103 |
res.add(ResourcePoolEntry.create("/bbb/aa/res3.class", new byte[90])); |
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
|
104 |
res.add(ResourcePoolEntry.create("/ccc/bbb/res1.class", new byte[90])); |
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
|
105 |
res.add(ResourcePoolEntry.create("/ddd/bbb/res1.class", new byte[90])); |
36511 | 106 |
return res; |
107 |
} |
|
108 |
||
109 |
private static Plugin createPlugin(String name, String arg) { |
|
110 |
Map<String, String> conf = new HashMap<>(); |
|
111 |
conf.put(name, arg); |
|
112 |
return Jlink.newPlugin(name, conf, null); |
|
113 |
} |
|
114 |
||
115 |
private void checkPositiveCase() throws Exception { |
|
116 |
List<Plugin> plugins = new ArrayList<>(); |
|
117 |
plugins.add(createPlugin("sorterplugin1", "/c")); |
|
118 |
plugins.add(createPlugin("sorterplugin2", "/b")); |
|
119 |
plugins.add(createPlugin("sorterplugin3", "/a")); |
|
120 |
||
121 |
PluginsConfiguration config = new Jlink.PluginsConfiguration(plugins, |
|
122 |
null, "sorterplugin3"); |
|
123 |
||
124 |
ImagePluginStack stack = ImagePluginConfiguration.parseConfiguration(config); |
|
125 |
||
126 |
// check order |
|
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
|
127 |
ResourcePoolManager res = fillOutResourceResourcePool(); |
36511 | 128 |
|
129 |
stack.visitResources(res); |
|
130 |
} |
|
131 |
||
132 |
private void checkUnknownPlugin() { |
|
133 |
List<Plugin> plugins = new ArrayList<>(); |
|
134 |
plugins.add(createPlugin("sorterplugin1", "/1")); |
|
135 |
plugins.add(createPlugin("sorterplugin2", "/1")); |
|
136 |
plugins.add(createPlugin("sorterplugin3", "/1")); |
|
137 |
plugins.add(createPlugin("sorterplugin4", "/1")); |
|
138 |
||
139 |
PluginsConfiguration config = new Jlink.PluginsConfiguration(plugins, |
|
140 |
null, "sorterplugin5"); |
|
141 |
try { |
|
142 |
ImagePluginConfiguration.parseConfiguration(config); |
|
143 |
throw new AssertionError("Unknown plugin should have failed."); |
|
144 |
} catch (Exception ex) { |
|
145 |
// XXX OK expected |
|
146 |
} |
|
147 |
} |
|
148 |
||
149 |
private void checkOrderAfterLastSorter() throws Exception { |
|
150 |
List<Plugin> plugins = new ArrayList<>(); |
|
151 |
plugins.add(createPlugin("sorterplugin1", "/c")); |
|
152 |
plugins.add(createPlugin("sorterplugin2", "/b")); |
|
153 |
plugins.add(createPlugin("sorterplugin3", "/a")); |
|
154 |
plugins.add(createPlugin("sorterplugin4", "/d")); |
|
155 |
||
156 |
PluginsConfiguration config = new Jlink.PluginsConfiguration(plugins, |
|
157 |
null, "sorterplugin3"); |
|
158 |
||
159 |
ImagePluginStack stack = ImagePluginConfiguration.parseConfiguration(config); |
|
160 |
||
161 |
// check order |
|
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
|
162 |
ResourcePoolManager res = fillOutResourceResourcePool(); |
36511 | 163 |
try { |
164 |
stack.visitResources(res); |
|
165 |
throw new AssertionError("Order was changed after the last sorter, but no exception occurred"); |
|
166 |
} catch (Exception ex) { |
|
167 |
// XXX OK expected |
|
168 |
} |
|
169 |
} |
|
170 |
||
39321
c60f34e8c057
8160641: PostProcessingPlugin and ExecutableImage should not be part of plugin API
sundar
parents:
39129
diff
changeset
|
171 |
public static class SorterPlugin implements Plugin { |
36511 | 172 |
|
173 |
private final String name; |
|
174 |
private String starts; |
|
175 |
||
176 |
private SorterPlugin(String name) { |
|
177 |
this.name = name; |
|
178 |
} |
|
179 |
||
180 |
@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
|
181 |
public ResourcePool transform(ResourcePool resources, ResourcePoolBuilder output) { |
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
|
182 |
List<ResourcePoolEntry> paths = new ArrayList<>(); |
38320 | 183 |
resources.entries().forEach(res -> { |
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
|
184 |
if (res.path().startsWith(starts)) { |
36511 | 185 |
paths.add(0, res); |
186 |
} else { |
|
187 |
paths.add(res); |
|
188 |
} |
|
38320 | 189 |
}); |
36511 | 190 |
|
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
|
191 |
for (ResourcePoolEntry r : paths) { |
36511 | 192 |
output.add(r); |
193 |
} |
|
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
|
194 |
|
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
|
195 |
return output.build(); |
36511 | 196 |
} |
197 |
||
198 |
@Override |
|
199 |
public String getName() { |
|
200 |
return name; |
|
201 |
} |
|
202 |
||
203 |
@Override |
|
204 |
public void configure(Map<String, String> config) { |
|
205 |
String arguments = config.get(name); |
|
206 |
this.starts = arguments; |
|
207 |
} |
|
208 |
} |
|
209 |
} |