< prev index next >

src/jdk.jlink/share/classes/jdk/tools/jlink/internal/TaskHelper.java

Print this page




 320                             }, "-G");
 321                     mainOptions.add(plugOption);
 322                 }
 323             }
 324         }
 325 
 326         private PlugOption getOption(String name) throws BadArgs {
 327             for (PlugOption o : pluginsOptions) {
 328                 if (o.matches(name)) {
 329                     return o;
 330                 }
 331             }
 332             for (PlugOption o : mainOptions) {
 333                 if (o.matches(name)) {
 334                     return o;
 335                 }
 336             }
 337             return null;
 338         }
 339 
 340         private PluginsConfiguration getPluginsConfig(Path output,
 341                 boolean genbom) throws IOException, BadArgs {
 342             if (output != null) {
 343                 if (Files.exists(output)) {
 344                     throw new PluginException(PluginsResourceBundle.
 345                             getMessage("err.dir.already.exits", output));
 346                 }
 347             }
 348 
 349             PluginContextImpl pluginContext = new PluginContextImpl();
 350             List<Plugin> pluginsList = new ArrayList<>();
 351             for (Entry<Plugin, List<Map<String, String>>> entry : pluginToMaps.entrySet()) {
 352                 Plugin plugin = entry.getKey();
 353                 List<Map<String, String>> argsMaps = entry.getValue();
 354 
 355                 // same plugin option may be used multiple times in command line.
 356                 // we call configure once for each occurrence. It is upto the plugin
 357                 // to 'merge' and/or 'override' arguments.
 358                 for (Map<String, String> map : argsMaps) {
 359                     plugin.configure(Collections.unmodifiableMap(map), pluginContext);
 360                 }
 361 
 362                 if (!Utils.isDisabled(plugin)) {
 363                     pluginsList.add(plugin);
 364                 }
 365             }
 366 
 367             // recreate or postprocessing don't require an output directory.
 368             ImageBuilder builder = null;
 369             if (output != null) {
 370                 builder = new DefaultImageBuilder(genbom, output);
 371 
 372             }
 373             return new Jlink.PluginsConfiguration(pluginsList,
 374                     builder, lastSorter, pluginContext);
 375         }
 376     }
 377 
 378     private static final class ResourceBundleHelper {
 379 
 380         private final ResourceBundle bundle;
 381         private final ResourceBundle pluginBundle;
 382 
 383         ResourceBundleHelper(String path) {
 384             Locale locale = Locale.getDefault();
 385             try {
 386                 bundle = ResourceBundle.getBundle(path, locale);
 387                 pluginBundle = ResourceBundle.getBundle("jdk.tools.jlink.resources.plugins", locale);
 388             } catch (MissingResourceException e) {
 389                 throw new InternalError("Cannot find jlink resource bundle for locale " + locale);
 390             }


 659     }
 660 
 661     public void setLog(PrintWriter log) {
 662         this.log = log;
 663     }
 664 
 665     public void reportError(String key, Object... args) {
 666         log.println(bundleHelper.getMessage("error.prefix") + " "
 667                 + bundleHelper.getMessage(key, args));
 668     }
 669 
 670     public void reportUnknownError(String message) {
 671         log.println(bundleHelper.getMessage("error.prefix") + " " + message);
 672     }
 673 
 674     public void warning(String key, Object... args) {
 675         log.println(bundleHelper.getMessage("warn.prefix") + " "
 676                 + bundleHelper.getMessage(key, args));
 677     }
 678 
 679     public PluginsConfiguration getPluginsConfig(Path output, boolean genbom)
 680             throws IOException, BadArgs {
 681         return pluginOptions.getPluginsConfig(output, genbom);
 682     }
 683 
 684     public Path getExistingImage() {
 685         return pluginOptions.existingImage;
 686     }
 687 
 688     public void showVersion(boolean full) {
 689         log.println(version(full ? "full" : "release"));
 690     }
 691 
 692     public String version(String key) {
 693         return System.getProperty("java.version");
 694     }
 695 
 696     static Layer createPluginsLayer(List<Path> paths) {
 697         Path[] arr = new Path[paths.size()];
 698         paths.toArray(arr);
 699         ModuleFinder finder = ModuleFinder.of(arr);
 700 
 701         // jmods are located at link-time




 320                             }, "-G");
 321                     mainOptions.add(plugOption);
 322                 }
 323             }
 324         }
 325 
 326         private PlugOption getOption(String name) throws BadArgs {
 327             for (PlugOption o : pluginsOptions) {
 328                 if (o.matches(name)) {
 329                     return o;
 330                 }
 331             }
 332             for (PlugOption o : mainOptions) {
 333                 if (o.matches(name)) {
 334                     return o;
 335                 }
 336             }
 337             return null;
 338         }
 339 
 340         private PluginsConfiguration getPluginsConfig(Path output
 341                     ) throws IOException, BadArgs {
 342             if (output != null) {
 343                 if (Files.exists(output)) {
 344                     throw new PluginException(PluginsResourceBundle.
 345                             getMessage("err.dir.already.exits", output));
 346                 }
 347             }
 348 
 349             PluginContextImpl pluginContext = new PluginContextImpl();
 350             List<Plugin> pluginsList = new ArrayList<>();
 351             for (Entry<Plugin, List<Map<String, String>>> entry : pluginToMaps.entrySet()) {
 352                 Plugin plugin = entry.getKey();
 353                 List<Map<String, String>> argsMaps = entry.getValue();
 354 
 355                 // same plugin option may be used multiple times in command line.
 356                 // we call configure once for each occurrence. It is upto the plugin
 357                 // to 'merge' and/or 'override' arguments.
 358                 for (Map<String, String> map : argsMaps) {
 359                     plugin.configure(Collections.unmodifiableMap(map), pluginContext);
 360                 }
 361 
 362                 if (!Utils.isDisabled(plugin)) {
 363                     pluginsList.add(plugin);
 364                 }
 365             }
 366 
 367             // recreate or postprocessing don't require an output directory.
 368             ImageBuilder builder = null;
 369             if (output != null) {
 370                 builder = new DefaultImageBuilder(output);
 371 
 372             }
 373             return new Jlink.PluginsConfiguration(pluginsList,
 374                     builder, lastSorter, pluginContext);
 375         }
 376     }
 377 
 378     private static final class ResourceBundleHelper {
 379 
 380         private final ResourceBundle bundle;
 381         private final ResourceBundle pluginBundle;
 382 
 383         ResourceBundleHelper(String path) {
 384             Locale locale = Locale.getDefault();
 385             try {
 386                 bundle = ResourceBundle.getBundle(path, locale);
 387                 pluginBundle = ResourceBundle.getBundle("jdk.tools.jlink.resources.plugins", locale);
 388             } catch (MissingResourceException e) {
 389                 throw new InternalError("Cannot find jlink resource bundle for locale " + locale);
 390             }


 659     }
 660 
 661     public void setLog(PrintWriter log) {
 662         this.log = log;
 663     }
 664 
 665     public void reportError(String key, Object... args) {
 666         log.println(bundleHelper.getMessage("error.prefix") + " "
 667                 + bundleHelper.getMessage(key, args));
 668     }
 669 
 670     public void reportUnknownError(String message) {
 671         log.println(bundleHelper.getMessage("error.prefix") + " " + message);
 672     }
 673 
 674     public void warning(String key, Object... args) {
 675         log.println(bundleHelper.getMessage("warn.prefix") + " "
 676                 + bundleHelper.getMessage(key, args));
 677     }
 678 
 679     public PluginsConfiguration getPluginsConfig(Path output)
 680             throws IOException, BadArgs {
 681         return pluginOptions.getPluginsConfig(output);
 682     }
 683 
 684     public Path getExistingImage() {
 685         return pluginOptions.existingImage;
 686     }
 687 
 688     public void showVersion(boolean full) {
 689         log.println(version(full ? "full" : "release"));
 690     }
 691 
 692     public String version(String key) {
 693         return System.getProperty("java.version");
 694     }
 695 
 696     static Layer createPluginsLayer(List<Path> paths) {
 697         Path[] arr = new Path[paths.size()];
 698         paths.toArray(arr);
 699         ModuleFinder finder = ModuleFinder.of(arr);
 700 
 701         // jmods are located at link-time


< prev index next >