88 public String getName() { 89 return NAME; 90 } 91 92 @Override 93 public Category getType() { 94 return Category.PROCESSOR; 95 } 96 97 @Override 98 public void configure(Map<String, String> config) { 99 throw new UnsupportedOperationException("Shouldn't be called"); 100 } 101 102 @Override 103 public void visit(ModulePool in, ModulePool out) { 104 in.transformAndCopy(Function.identity(), out); 105 } 106 } 107 108 public static class MyPlugin1 implements Plugin { 109 110 Integer index; 111 Set<String> after; 112 Set<String> before; 113 114 private MyPlugin1(Integer index, Set<String> after, Set<String> before) { 115 this.index = index; 116 this.after = after; 117 this.before = before; 118 } 119 120 @Override 121 public Set<String> isAfter() { 122 return after; 123 } 124 125 @Override 126 public Set<String> isBefore() { 127 return before; 128 } 129 130 @Override 131 public String getName() { 132 return NAME + index; 133 } 134 135 @Override 136 public void visit(ModulePool in, ModulePool out) { 137 System.err.println(NAME + index); 138 ordered.add(index); 139 in.transformAndCopy((file) -> { 140 return file; 141 }, out); 142 } 143 144 @Override 145 public String getDescription() { 146 return null; 147 } 148 149 @Override 150 public String getOption() { 151 return null; 152 } 153 static final String NAME = "myprovider"; 154 static final String INDEX = "INDEX"; 155 156 @Override 157 public void configure(Map<String, String> config) { 158 throw new UnsupportedOperationException("Shouldn't be called"); 159 } 160 } 161 162 public static void main(String[] args) throws Exception { 163 164 Helper helper = Helper.newHelper(); 165 if (helper == null) { 166 System.err.println("Test not run"); 167 return; 168 } 169 apitest(); 170 test(); 171 testOrder(); 172 testCycleOrder(); 173 } 174 175 private static void apitest() throws Exception { 176 boolean failed = false; 177 Jlink jl = new Jlink(); 178 179 try { 180 jl.build(null); 181 failed = true; 182 } catch (Exception ex) { 183 // XXX OK 184 } 185 if (failed) { 186 throw new Exception("Should have failed"); 187 } 188 System.out.println(jl); 189 190 JlinkConfiguration config 191 = new JlinkConfiguration(null, null, null, null); 192 244 = new Jlink.PluginsConfiguration(lst, builder, null); 245 246 jlink.build(config, plugins); 247 248 if (!Files.exists(output)) { 249 throw new AssertionError("Directory not created"); 250 } 251 File jimage = new File(output.toString(), "lib" + File.separator + "modules"); 252 if (!jimage.exists()) { 253 throw new AssertionError("jimage not generated"); 254 } 255 File release = new File(output.toString(), "release"); 256 if (!release.exists()) { 257 throw new AssertionError("release not generated"); 258 } 259 260 if (!Files.exists(output.resolve("toto.txt"))) { 261 throw new AssertionError("Post processing not called"); 262 } 263 264 } 265 266 private static void testOrder() throws Exception { 267 Jlink jlink = new Jlink(); 268 Path output = Paths.get("integrationout2"); 269 List<Path> modulePaths = new ArrayList<>(); 270 File jmods 271 = JImageGenerator.getJModsDir(new File(System.getProperty("test.jdk"))); 272 modulePaths.add(jmods.toPath()); 273 Set<String> mods = new HashSet<>(); 274 mods.add("java.management"); 275 Set<String> limits = new HashSet<>(); 276 limits.add("java.management"); 277 JlinkConfiguration config = new Jlink.JlinkConfiguration(output, 278 modulePaths, mods, limits, null); 279 280 List<Plugin> lst = new ArrayList<>(); 281 282 // Order is Plug1>Plug2>Plug3 283 // Plug1 284 285 286 // TRANSFORMER 3, must be after 2. 287 { 288 Set<String> after = new HashSet<>(); 289 after.add(MyPlugin1.NAME+"2"); 290 lst.add(new MyPlugin1(3, after, Collections.emptySet())); 291 } 292 293 // TRANSFORMER 2, must be after 1. 294 { 295 Set<String> after = new HashSet<>(); 296 after.add(MyPlugin1.NAME+"1"); 297 lst.add(new MyPlugin1(2, after, Collections.emptySet())); 298 } 299 300 // TRANSFORMER 1 301 { 302 Set<String> before = new HashSet<>(); 303 before.add(MyPlugin1.NAME+"2"); 304 lst.add(new MyPlugin1(1, Collections.emptySet(), before)); 305 } 306 307 // Image builder 308 DefaultImageBuilder builder = new DefaultImageBuilder(output); 309 PluginsConfiguration plugins 310 = new Jlink.PluginsConfiguration(lst, builder, null); 311 312 jlink.build(config, plugins); 313 314 if (ordered.isEmpty()) { 315 throw new AssertionError("Plugins not called"); 316 } 317 List<Integer> clone = new ArrayList<>(); 318 clone.addAll(ordered); 319 Collections.sort(clone); 320 if (!clone.equals(ordered)) { 321 throw new AssertionError("Ordered is not properly sorted" + ordered); 322 } 323 } 324 325 private static void testCycleOrder() throws Exception { 326 Jlink jlink = new Jlink(); 327 Path output = Paths.get("integrationout3"); 328 List<Path> modulePaths = new ArrayList<>(); 329 File jmods 330 = JImageGenerator.getJModsDir(new File(System.getProperty("test.jdk"))); 331 modulePaths.add(jmods.toPath()); 332 Set<String> mods = new HashSet<>(); 333 mods.add("java.management"); 334 Set<String> limits = new HashSet<>(); 335 limits.add("java.management"); 336 JlinkConfiguration config = new Jlink.JlinkConfiguration(output, 337 modulePaths, mods, limits, null); 338 339 List<Plugin> lst = new ArrayList<>(); 340 341 // packager 1 342 { 343 Set<String> before = new HashSet<>(); 344 before.add(MyPlugin1.NAME+"2"); 345 lst.add(new MyPlugin1(1, Collections.emptySet(), before)); 346 } 347 348 // packager 2 349 { 350 Set<String> before = new HashSet<>(); 351 before.add(MyPlugin1.NAME+"1"); 352 lst.add(new MyPlugin1(2, Collections.emptySet(), before)); 353 } 354 355 // Image builder 356 DefaultImageBuilder builder = new DefaultImageBuilder(output); 357 PluginsConfiguration plugins 358 = new Jlink.PluginsConfiguration(lst, builder, null); 359 boolean failed = false; 360 try { 361 jlink.build(config, plugins); 362 failed = true; 363 } catch (Exception ex) { 364 // XXX OK 365 } 366 if (failed) { 367 throw new AssertionError("Should have failed"); 368 } 369 } 370 } | 88 public String getName() { 89 return NAME; 90 } 91 92 @Override 93 public Category getType() { 94 return Category.PROCESSOR; 95 } 96 97 @Override 98 public void configure(Map<String, String> config) { 99 throw new UnsupportedOperationException("Shouldn't be called"); 100 } 101 102 @Override 103 public void visit(ModulePool in, ModulePool out) { 104 in.transformAndCopy(Function.identity(), out); 105 } 106 } 107 108 public static void main(String[] args) throws Exception { 109 110 Helper helper = Helper.newHelper(); 111 if (helper == null) { 112 System.err.println("Test not run"); 113 return; 114 } 115 apitest(); 116 test(); 117 } 118 119 private static void apitest() throws Exception { 120 boolean failed = false; 121 Jlink jl = new Jlink(); 122 123 try { 124 jl.build(null); 125 failed = true; 126 } catch (Exception ex) { 127 // XXX OK 128 } 129 if (failed) { 130 throw new Exception("Should have failed"); 131 } 132 System.out.println(jl); 133 134 JlinkConfiguration config 135 = new JlinkConfiguration(null, null, null, null); 136 188 = new Jlink.PluginsConfiguration(lst, builder, null); 189 190 jlink.build(config, plugins); 191 192 if (!Files.exists(output)) { 193 throw new AssertionError("Directory not created"); 194 } 195 File jimage = new File(output.toString(), "lib" + File.separator + "modules"); 196 if (!jimage.exists()) { 197 throw new AssertionError("jimage not generated"); 198 } 199 File release = new File(output.toString(), "release"); 200 if (!release.exists()) { 201 throw new AssertionError("release not generated"); 202 } 203 204 if (!Files.exists(output.resolve("toto.txt"))) { 205 throw new AssertionError("Post processing not called"); 206 } 207 208 } 209 } |