author | sundar |
Tue, 21 Jun 2016 19:05:34 +0530 | |
changeset 39129 | 4b2086305b68 |
parent 38320 | e24c7029e8ba |
child 39321 | c60f34e8c057 |
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 order of plugins |
|
27 |
* @author Jean-Francois Denise |
|
28 |
* @library ../../lib |
|
29 |
* @modules java.base/jdk.internal.jimage |
|
30 |
* jdk.jdeps/com.sun.tools.classfile |
|
31 |
* jdk.jlink/jdk.tools.jlink.internal |
|
32 |
* jdk.jlink/jdk.tools.jmod |
|
33 |
* jdk.jlink/jdk.tools.jimage |
|
34 |
* jdk.compiler |
|
35 |
* @build tests.* |
|
36 |
* @run main/othervm PluginOrderTest |
|
37 |
*/ |
|
38 |
import java.util.ArrayList; |
|
39 |
import java.util.Collections; |
|
40 |
import java.util.HashSet; |
|
41 |
import java.util.List; |
|
42 |
import java.util.Map; |
|
43 |
import java.util.Set; |
|
44 |
||
45 |
import jdk.tools.jlink.internal.PluginOrderingGraph; |
|
46 |
import jdk.tools.jlink.plugin.Plugin; |
|
38320 | 47 |
import jdk.tools.jlink.plugin.Plugin.Category; |
48 |
import jdk.tools.jlink.plugin.ModulePool; |
|
36511 | 49 |
import jdk.tools.jlink.plugin.TransformerPlugin; |
50 |
||
51 |
public class PluginOrderTest { |
|
52 |
||
53 |
public static void main(String[] args) throws Exception { |
|
54 |
||
55 |
validGraph0(); |
|
56 |
validGraph1(); |
|
57 |
||
58 |
boolean failed = false; |
|
59 |
||
60 |
try { |
|
61 |
withCycles0(); |
|
62 |
failed = true; |
|
63 |
} catch (Exception ex) { |
|
64 |
//ok |
|
65 |
System.err.println(ex.getMessage()); |
|
66 |
} |
|
67 |
if (failed) { |
|
68 |
throw new Exception("Should have failed"); |
|
69 |
} |
|
70 |
||
71 |
try { |
|
72 |
withCycles1(); |
|
73 |
failed = true; |
|
74 |
} catch (Exception ex) { |
|
75 |
//ok |
|
76 |
System.err.println(ex.getMessage()); |
|
77 |
} |
|
78 |
if (failed) { |
|
79 |
throw new Exception("Should have failed"); |
|
80 |
} |
|
81 |
||
82 |
try { |
|
83 |
withCycles2(); |
|
84 |
failed = true; |
|
85 |
} catch (Exception ex) { |
|
86 |
//ok |
|
87 |
System.err.println(ex.getMessage()); |
|
88 |
} |
|
89 |
if (failed) { |
|
90 |
throw new Exception("Should have failed"); |
|
91 |
} |
|
92 |
} |
|
93 |
||
94 |
private static void validGraph0() throws Exception { |
|
95 |
Set<String> set = new HashSet<>(); |
|
96 |
set.add("plug2"); |
|
97 |
List<Plugin> plugins = new ArrayList<>(); |
|
98 |
plugins.add(new Plug("plug2", Collections.emptySet(), Collections.emptySet(), |
|
38320 | 99 |
Category.TRANSFORMER)); |
100 |
plugins.add(new Plug("plug1", set, Collections.emptySet(), Category.TRANSFORMER)); |
|
36511 | 101 |
List<Plugin> ordered = PluginOrderingGraph.sort(plugins); |
102 |
if (ordered.get(0) != plugins.get(1) || ordered.get(1) != plugins.get(0)) { |
|
103 |
throw new Exception("Invalid sorting"); |
|
104 |
} |
|
105 |
} |
|
106 |
||
107 |
private static void validGraph1() { |
|
108 |
Set<String> lst1 = new HashSet<>(); |
|
109 |
lst1.add("plug2"); |
|
110 |
lst1.add("plug3"); |
|
38320 | 111 |
Plugin p1 = new Plug("plug1", lst1, Collections.emptySet(), Category.TRANSFORMER); |
36511 | 112 |
|
38320 | 113 |
Plugin p2 = new Plug("plug2", Collections.emptySet(), Collections.emptySet(), Category.TRANSFORMER); |
36511 | 114 |
|
115 |
Set<String> lst3 = new HashSet<>(); |
|
116 |
lst3.add("plug4"); |
|
117 |
lst3.add("plug6"); |
|
38320 | 118 |
Plugin p3 = new Plug("plug3", lst3, Collections.emptySet(), Category.TRANSFORMER); |
36511 | 119 |
|
38320 | 120 |
Plugin p4 = new Plug("plug4", Collections.emptySet(), Collections.emptySet(), Category.TRANSFORMER); |
36511 | 121 |
|
122 |
Set<String> lst5 = new HashSet<>(); |
|
123 |
lst5.add("plug3"); |
|
124 |
lst5.add("plug1"); |
|
125 |
lst5.add("plug2"); |
|
126 |
lst5.add("plug6"); |
|
38320 | 127 |
Plugin p5 = new Plug("plug5", lst5, Collections.emptySet(), Category.TRANSFORMER); |
36511 | 128 |
|
129 |
Set<String> lst6 = new HashSet<>(); |
|
130 |
lst6.add("plug4"); |
|
131 |
lst6.add("plug2"); |
|
38320 | 132 |
Plugin p6 = new Plug("plug6", lst6, Collections.emptySet(), Category.TRANSFORMER); |
36511 | 133 |
|
38320 | 134 |
Plugin p7 = new Plug("plug7", Collections.emptySet(), Collections.emptySet(), Category.TRANSFORMER); |
36511 | 135 |
|
38320 | 136 |
Plugin p8 = new Plug("plug8", Collections.emptySet(), Collections.emptySet(), Category.TRANSFORMER); |
36511 | 137 |
|
138 |
List<Plugin> plugins = new ArrayList<>(); |
|
139 |
plugins.add(p1); |
|
140 |
plugins.add(p2); |
|
141 |
plugins.add(p3); |
|
142 |
plugins.add(p4); |
|
143 |
plugins.add(p5); |
|
144 |
plugins.add(p6); |
|
145 |
plugins.add(p7); |
|
146 |
plugins.add(p8); |
|
147 |
||
148 |
PluginOrderingGraph.sort(plugins); |
|
149 |
} |
|
150 |
||
151 |
private static void withCycles0() throws Exception { |
|
152 |
Set<String> set2 = new HashSet<>(); |
|
153 |
set2.add("plug1"); |
|
154 |
List<Plugin> plugins = new ArrayList<>(); |
|
155 |
plugins.add(new Plug("plug2", set2, Collections.emptySet(), |
|
38320 | 156 |
Category.TRANSFORMER)); |
36511 | 157 |
|
158 |
Set<String> set1 = new HashSet<>(); |
|
159 |
set1.add("plug2"); |
|
38320 | 160 |
plugins.add(new Plug("plug1", set1, Collections.emptySet(), Category.TRANSFORMER)); |
36511 | 161 |
PluginOrderingGraph.sort(plugins); |
162 |
||
163 |
} |
|
164 |
||
165 |
private static void withCycles2() { |
|
166 |
Set<String> lst1 = new HashSet<>(); |
|
167 |
lst1.add("plug2"); |
|
168 |
lst1.add("plug3"); |
|
38320 | 169 |
Plugin p1 = new Plug("plug1", lst1, Collections.emptySet(), Category.TRANSFORMER); |
36511 | 170 |
|
38320 | 171 |
Plugin p2 = new Plug("plug2", Collections.emptySet(), Collections.emptySet(), Category.TRANSFORMER); |
36511 | 172 |
|
173 |
Set<String> lst3 = new HashSet<>(); |
|
174 |
lst3.add("plug4"); |
|
175 |
lst3.add("plug6"); |
|
38320 | 176 |
Plugin p3 = new Plug("plug3", lst3, Collections.emptySet(), Category.TRANSFORMER); |
36511 | 177 |
|
38320 | 178 |
Plugin p4 = new Plug("plug4", Collections.emptySet(), Collections.emptySet(), Category.TRANSFORMER); |
36511 | 179 |
|
180 |
Set<String> lst5 = new HashSet<>(); |
|
181 |
lst5.add("plug3"); |
|
182 |
lst5.add("plug1"); |
|
183 |
lst5.add("plug2"); |
|
38320 | 184 |
Plugin p5 = new Plug("plug5", lst5, Collections.emptySet(), Category.TRANSFORMER); |
36511 | 185 |
|
186 |
Set<String> lst6 = new HashSet<>(); |
|
187 |
lst6.add("plug4"); |
|
188 |
lst6.add("plug1"); |
|
38320 | 189 |
Plugin p6 = new Plug("plug6", lst6, Collections.emptySet(), Category.TRANSFORMER); |
36511 | 190 |
|
38320 | 191 |
Plugin p7 = new Plug("plug7", Collections.emptySet(), Collections.emptySet(), Category.TRANSFORMER); |
36511 | 192 |
|
38320 | 193 |
Plugin p8 = new Plug("plug8", Collections.emptySet(), Collections.emptySet(), Category.TRANSFORMER); |
36511 | 194 |
|
195 |
List<Plugin> plugins = new ArrayList<>(); |
|
196 |
plugins.add(p1); |
|
197 |
plugins.add(p2); |
|
198 |
plugins.add(p3); |
|
199 |
plugins.add(p4); |
|
200 |
plugins.add(p5); |
|
201 |
plugins.add(p6); |
|
202 |
plugins.add(p7); |
|
203 |
plugins.add(p8); |
|
204 |
PluginOrderingGraph.sort(plugins); |
|
205 |
} |
|
206 |
||
207 |
private static void withCycles1() { |
|
208 |
Set<String> lst1 = new HashSet<>(); |
|
209 |
lst1.add("plug2"); |
|
210 |
lst1.add("plug3"); |
|
38320 | 211 |
Plugin p = new Plug("plug1", lst1, Collections.emptySet(), Category.TRANSFORMER); |
212 |
Plugin p2 = new Plug("plug2", Collections.emptySet(), Collections.emptySet(), Category.TRANSFORMER); |
|
36511 | 213 |
|
214 |
Set<String> lst3 = new HashSet<>(); |
|
215 |
lst3.add("plug2"); |
|
216 |
||
217 |
Set<String> lst4 = new HashSet<>(); |
|
218 |
lst4.add("plug1"); |
|
219 |
||
38320 | 220 |
Plugin p3 = new Plug("plug3", lst4, lst3, Category.TRANSFORMER); |
36511 | 221 |
List<Plugin> plugins = new ArrayList<>(); |
222 |
plugins.add(p); |
|
223 |
plugins.add(p2); |
|
224 |
plugins.add(p3); |
|
225 |
PluginOrderingGraph.sort(plugins); |
|
226 |
} |
|
227 |
||
228 |
private static class Plug implements TransformerPlugin { |
|
229 |
||
230 |
private final Set<String> isBefore; |
|
231 |
private final Set<String> isAfter; |
|
38320 | 232 |
private final Category category; |
36511 | 233 |
private final String name; |
234 |
||
38320 | 235 |
private Plug(String name, Set<String> isBefore, Set<String> isAfter, Category category) { |
36511 | 236 |
this.name = name; |
237 |
this.isBefore = isBefore; |
|
238 |
this.isAfter = isAfter; |
|
239 |
this.category = category; |
|
240 |
} |
|
241 |
||
242 |
@Override |
|
243 |
public Set<String> isAfter() { |
|
244 |
return isAfter; |
|
245 |
} |
|
246 |
||
247 |
@Override |
|
248 |
public Set<String> isBefore() { |
|
249 |
return isBefore; |
|
250 |
} |
|
251 |
||
252 |
@Override |
|
253 |
public String toString() { |
|
254 |
return name; |
|
255 |
} |
|
256 |
||
257 |
@Override |
|
38320 | 258 |
public void visit(ModulePool in, ModulePool out) { |
36511 | 259 |
|
260 |
} |
|
261 |
||
262 |
@Override |
|
39129
4b2086305b68
8159593: Plugin Set<Category> getType() should return a Category
sundar
parents:
38320
diff
changeset
|
263 |
public Category getType() { |
4b2086305b68
8159593: Plugin Set<Category> getType() should return a Category
sundar
parents:
38320
diff
changeset
|
264 |
return category; |
36511 | 265 |
} |
266 |
||
267 |
@Override |
|
268 |
public String getName() { |
|
269 |
return name; |
|
270 |
} |
|
271 |
} |
|
272 |
} |