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