386 }, false, "--no-header-files"); 387 mainOptions.add(plugOption); 388 } 389 } 390 } 391 392 private PluginOption getOption(String name) throws BadArgs { 393 for (PluginOption o : pluginsOptions) { 394 if (o.matches(name)) { 395 return o; 396 } 397 } 398 for (PluginOption o : mainOptions) { 399 if (o.matches(name)) { 400 return o; 401 } 402 } 403 return null; 404 } 405 406 private PluginsConfiguration getPluginsConfig(Path output 407 ) throws IOException, BadArgs { 408 if (output != null) { 409 if (Files.exists(output)) { 410 throw new PluginException(PluginsResourceBundle. 411 getMessage("err.dir.already.exits", output)); 412 } 413 } 414 415 List<Plugin> pluginsList = new ArrayList<>(); 416 for (Entry<Plugin, List<Map<String, String>>> entry : pluginToMaps.entrySet()) { 417 Plugin plugin = entry.getKey(); 418 List<Map<String, String>> argsMaps = entry.getValue(); 419 420 // same plugin option may be used multiple times in command line. 421 // we call configure once for each occurrence. It is upto the plugin 422 // to 'merge' and/or 'override' arguments. 423 for (Map<String, String> map : argsMaps) { 424 try { 425 plugin.configure(Collections.unmodifiableMap(map)); 426 } catch (IllegalArgumentException e) { 427 if (JlinkTask.DEBUG) { 428 System.err.println("Plugin " + plugin.getName() + " threw exception with config: " + map); 429 e.printStackTrace(); 430 } 431 throw e; 432 } 433 } 434 435 if (!Utils.isDisabled(plugin)) { 436 pluginsList.add(plugin); 437 } 438 } 439 440 // recreate or postprocessing don't require an output directory. 441 ImageBuilder builder = null; 442 if (output != null) { 443 builder = new DefaultImageBuilder(output); 444 445 } 446 return new Jlink.PluginsConfiguration(pluginsList, 447 builder, lastSorter); 448 } 449 } 450 451 private static final class ResourceBundleHelper { 452 453 private final ResourceBundle bundle; 454 private final ResourceBundle pluginBundle; 455 456 ResourceBundleHelper(String path) { 457 Locale locale = Locale.getDefault(); 458 try { 459 bundle = ResourceBundle.getBundle(path, locale); 460 pluginBundle = ResourceBundle.getBundle("jdk.tools.jlink.resources.plugins", locale); 461 } catch (MissingResourceException e) { 462 throw new InternalError("Cannot find jlink resource bundle for locale " + locale); 463 } 464 } 465 728 } 729 730 public void setLog(PrintWriter log) { 731 this.log = log; 732 } 733 734 public void reportError(String key, Object... args) { 735 log.println(bundleHelper.getMessage("error.prefix") + " " 736 + bundleHelper.getMessage(key, args)); 737 } 738 739 public void reportUnknownError(String message) { 740 log.println(bundleHelper.getMessage("error.prefix") + " " + message); 741 } 742 743 public void warning(String key, Object... args) { 744 log.println(bundleHelper.getMessage("warn.prefix") + " " 745 + bundleHelper.getMessage(key, args)); 746 } 747 748 public PluginsConfiguration getPluginsConfig(Path output) 749 throws IOException, BadArgs { 750 return pluginOptions.getPluginsConfig(output); 751 } 752 753 public Path getExistingImage() { 754 return pluginOptions.existingImage; 755 } 756 757 public void showVersion(boolean full) { 758 log.println(version(full ? "full" : "release")); 759 } 760 761 public String version(String key) { 762 return System.getProperty("java.version"); 763 } 764 765 static Layer createPluginsLayer(List<Path> paths) { 766 767 Path[] dirs = paths.toArray(new Path[0]); 768 ModuleFinder finder = new ModulePath(Runtime.version(), true, dirs); 769 Configuration bootConfiguration = Layer.boot().configuration(); 770 try { | 386 }, false, "--no-header-files"); 387 mainOptions.add(plugOption); 388 } 389 } 390 } 391 392 private PluginOption getOption(String name) throws BadArgs { 393 for (PluginOption o : pluginsOptions) { 394 if (o.matches(name)) { 395 return o; 396 } 397 } 398 for (PluginOption o : mainOptions) { 399 if (o.matches(name)) { 400 return o; 401 } 402 } 403 return null; 404 } 405 406 private PluginsConfiguration getPluginsConfig(Path output, Map<String, String> launchers 407 ) throws IOException, BadArgs { 408 if (output != null) { 409 if (Files.exists(output)) { 410 throw new PluginException(PluginsResourceBundle. 411 getMessage("err.dir.already.exits", output)); 412 } 413 } 414 415 List<Plugin> pluginsList = new ArrayList<>(); 416 for (Entry<Plugin, List<Map<String, String>>> entry : pluginToMaps.entrySet()) { 417 Plugin plugin = entry.getKey(); 418 List<Map<String, String>> argsMaps = entry.getValue(); 419 420 // same plugin option may be used multiple times in command line. 421 // we call configure once for each occurrence. It is upto the plugin 422 // to 'merge' and/or 'override' arguments. 423 for (Map<String, String> map : argsMaps) { 424 try { 425 plugin.configure(Collections.unmodifiableMap(map)); 426 } catch (IllegalArgumentException e) { 427 if (JlinkTask.DEBUG) { 428 System.err.println("Plugin " + plugin.getName() + " threw exception with config: " + map); 429 e.printStackTrace(); 430 } 431 throw e; 432 } 433 } 434 435 if (!Utils.isDisabled(plugin)) { 436 pluginsList.add(plugin); 437 } 438 } 439 440 // recreate or postprocessing don't require an output directory. 441 ImageBuilder builder = null; 442 if (output != null) { 443 builder = new DefaultImageBuilder(output, launchers); 444 } 445 446 return new Jlink.PluginsConfiguration(pluginsList, 447 builder, lastSorter); 448 } 449 } 450 451 private static final class ResourceBundleHelper { 452 453 private final ResourceBundle bundle; 454 private final ResourceBundle pluginBundle; 455 456 ResourceBundleHelper(String path) { 457 Locale locale = Locale.getDefault(); 458 try { 459 bundle = ResourceBundle.getBundle(path, locale); 460 pluginBundle = ResourceBundle.getBundle("jdk.tools.jlink.resources.plugins", locale); 461 } catch (MissingResourceException e) { 462 throw new InternalError("Cannot find jlink resource bundle for locale " + locale); 463 } 464 } 465 728 } 729 730 public void setLog(PrintWriter log) { 731 this.log = log; 732 } 733 734 public void reportError(String key, Object... args) { 735 log.println(bundleHelper.getMessage("error.prefix") + " " 736 + bundleHelper.getMessage(key, args)); 737 } 738 739 public void reportUnknownError(String message) { 740 log.println(bundleHelper.getMessage("error.prefix") + " " + message); 741 } 742 743 public void warning(String key, Object... args) { 744 log.println(bundleHelper.getMessage("warn.prefix") + " " 745 + bundleHelper.getMessage(key, args)); 746 } 747 748 public PluginsConfiguration getPluginsConfig(Path output, Map<String, String> launchers) 749 throws IOException, BadArgs { 750 return pluginOptions.getPluginsConfig(output, launchers); 751 } 752 753 public Path getExistingImage() { 754 return pluginOptions.existingImage; 755 } 756 757 public void showVersion(boolean full) { 758 log.println(version(full ? "full" : "release")); 759 } 760 761 public String version(String key) { 762 return System.getProperty("java.version"); 763 } 764 765 static Layer createPluginsLayer(List<Path> paths) { 766 767 Path[] dirs = paths.toArray(new Path[0]); 768 ModuleFinder finder = new ModulePath(Runtime.version(), true, dirs); 769 Configuration bootConfiguration = Layer.boot().configuration(); 770 try { |