changeset 14222:7c5cfe773b7c

Ability to hide/expose plugin provider. Ability to express functional state. Some tiny fixes. Reviewed-by: jlaskey
author jfdenise
date Thu, 15 Oct 2015 18:40:37 +0200
parents d79e9bf2bd4e
children 4ee3a4b785ef
files src/jdk.jlink/share/classes/jdk/tools/jlink/TaskHelper.java src/jdk.jlink/share/classes/jdk/tools/jlink/internal/ImagePluginConfiguration.java src/jdk.jlink/share/classes/jdk/tools/jlink/internal/ProcessingManagerImpl.java src/jdk.jlink/share/classes/jdk/tools/jlink/plugins/ImageBuilderProvider.java src/jdk.jlink/share/classes/jdk/tools/jlink/plugins/PluginProvider.java src/jdk.jlink/share/classes/jdk/tools/jlink/resources/plugins.properties test/jdk/jigsaw/tools/jlink/CustomImageBuilderTest.java test/jdk/jigsaw/tools/jlink/JLinkTest.java
diffstat 8 files changed, 114 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.jlink/share/classes/jdk/tools/jlink/TaskHelper.java	Thu Oct 15 08:27:31 2015 +0100
+++ b/src/jdk.jlink/share/classes/jdk/tools/jlink/TaskHelper.java	Thu Oct 15 18:40:37 2015 +0200
@@ -241,6 +241,10 @@
                         PluginOption option
                                 = new PluginOption(provider.getToolArgument() != null,
                                         (task, opt, arg) -> {
+                                            if (!prov.isFunctional()) {
+                                                throw newBadArgs("err.provider.not.functional",
+                                                        prov.getName());
+                                            }
                                             Map<String, String> m = plugins.get(prov);
                                             if (m == null) {
                                                 m = new HashMap<>();
@@ -275,14 +279,8 @@
                         // On/Off enabled by default plugin
                         // Command line option can override it
                         boolean edefault = false;
-                        if (provider instanceof OnOffResourcePluginProvider) {
-                            edefault = ((OnOffResourcePluginProvider) provider).isEnabledByDefault();
-                        } else {
-                            if (provider instanceof OnOffImageFilePluginProvider) {
-                                edefault = ((OnOffImageFilePluginProvider) provider).isEnabledByDefault();
-                            } else if (provider instanceof OnOffImageFilePluginProvider) {
-                                edefault = ((OnOffPostProcessingPluginProvider) provider).isEnabledByDefault();
-                            }
+                        if (provider instanceof OnOffPluginProvider) {
+                            edefault = prov.isFunctional() && ((OnOffPluginProvider) provider).isEnabledByDefault();
                         }
                         if (edefault) {
                             Map<String, String> m = new HashMap<>();
@@ -617,7 +615,8 @@
                             param = args[++i];
                         }
                         if (param == null || param.isEmpty()
-                                || param.charAt(0) == '-') {
+                                || (param.length() >= 2 && param.charAt(0) == '-'
+                                && param.charAt(1) == '-')) {
                             throw new BadArgs("err.missing.arg", name).
                                     showUsage(true);
                         }
@@ -677,6 +676,8 @@
                             line.append(" ").append(provider.getToolArgument());
                         }
                         line.append("\n ").append(prov.getDescription());
+                        line.append("\n").append(bundleHelper.getMessage("main.plugin.state")).
+                                append(": ").append(prov.getFunctionalStateDescription(prov.isFunctional()));
                         if (provider.getAdditionalOptions() != null) {
                             line.append("\n").append(bundleHelper.
                                     getMessage("main.plugin.additional.options")).
@@ -694,9 +695,13 @@
                 log.println(bundleHelper.getMessage("main.image.builders"));
                 for (ImageBuilderProvider prov
                         : ImagePluginProviderRepository.getImageBuilderProviders(getPluginsLayer())) {
-                    log.println("\n" + bundleHelper.getMessage("main.image.builder.name")
-                            + ": " + prov.getName());
-                    logBuilderOptions(prov.getOptions());
+                    if (prov.isExposed()) {
+                        log.println("\n" + bundleHelper.getMessage("main.image.builder.name")
+                                + ": " + prov.getName());
+                        log.println(bundleHelper.getMessage("main.plugin.state")
+                                + ": " + prov.getFunctionalStateDescription(prov.isFunctional()));
+                        logBuilderOptions(prov.getOptions());
+                    }
                 }
             }
         }
@@ -721,6 +726,8 @@
                             + ": " + (fact.getToolArgument() == null
                                     ? bundleHelper.getMessage("main.plugin.no.value")
                                     : fact.getToolArgument()));
+                    log.println(bundleHelper.getMessage("main.plugin.state")
+                            + ": " + prov.getFunctionalStateDescription(prov.isFunctional()));
                     String additionalOptions = bundleHelper.getMessage("main.plugin.no.value");
                     if (fact.getAdditionalOptions() != null) {
                         StringBuilder builder = new StringBuilder();
@@ -742,11 +749,15 @@
             if (showsImageBuilder) {
                 for (ImageBuilderProvider prov
                         : ImagePluginProviderRepository.getImageBuilderProviders(getPluginsLayer())) {
-                    log.println("\n" + bundleHelper.getMessage("main.image.builder.name")
-                            + ": " + prov.getName());
-                    log.println(bundleHelper.getMessage("main.image.builder.description")
-                            + ": " + prov.getDescription());
-                    logBuilderOptions(prov.getOptions());
+                    if (prov.isExposed()) {
+                        log.println("\n" + bundleHelper.getMessage("main.image.builder.name")
+                                + ": " + prov.getName());
+                        log.println(bundleHelper.getMessage("main.image.builder.description")
+                                + ": " + prov.getDescription());
+                        log.println(bundleHelper.getMessage("main.plugin.state")
+                                + ": " + prov.getFunctionalStateDescription(prov.isFunctional()));
+                        logBuilderOptions(prov.getOptions());
+                    }
                 }
             }
         }
@@ -894,7 +905,7 @@
 
     // Display all plugins or resource only.
     private static boolean showsPlugin(PluginProvider prov, boolean showsImageBuilder) {
-        return (prov instanceof CmdPluginProvider && showsImageBuilder)
-                || (prov instanceof CmdResourcePluginProvider);
+        return prov.isExposed() && ((prov instanceof CmdPluginProvider && showsImageBuilder)
+                || (prov instanceof CmdResourcePluginProvider));
     }
 }
--- a/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/ImagePluginConfiguration.java	Thu Oct 15 08:27:31 2015 +0100
+++ b/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/ImagePluginConfiguration.java	Thu Oct 15 18:40:37 2015 +0200
@@ -244,6 +244,9 @@
         List<String> seen = new ArrayList<>();
         for (StackedPluginConfiguration prop : allPlugins) {
             PluginProvider prov = providers.get(prop.getName());
+            if (!prov.isFunctional()) {
+                throw new Exception("Provider " + prov.getName() + " is not functional");
+            }
             if (seen.contains(prov.getName())) {
                 throw new Exception("Plugin " + prov.getName()
                         + " added more than once to stack ");
--- a/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/ProcessingManagerImpl.java	Thu Oct 15 08:27:31 2015 +0100
+++ b/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/ProcessingManagerImpl.java	Thu Oct 15 18:40:37 2015 +0200
@@ -222,7 +222,7 @@
         String id = name.replaceAll(" ", "_") + System.currentTimeMillis();
         Path dirPath = tmp.resolve(id);
         Files.createDirectory(dirPath);
-        return new ProcessingSessionImpl(name, tmp);
+        return new ProcessingSessionImpl(name, dirPath);
     }
 
     @Override
--- a/src/jdk.jlink/share/classes/jdk/tools/jlink/plugins/ImageBuilderProvider.java	Thu Oct 15 08:27:31 2015 +0100
+++ b/src/jdk.jlink/share/classes/jdk/tools/jlink/plugins/ImageBuilderProvider.java	Thu Oct 15 18:40:37 2015 +0200
@@ -28,6 +28,7 @@
 import java.nio.file.Path;
 import java.util.List;
 import java.util.Map;
+import jdk.tools.jlink.internal.plugins.PluginsResourceBundle;
 
 /**
  * Implement this interface and make your class available to the ServiceLoader
@@ -83,7 +84,7 @@
      *
      * @return The option name / description mapping
      */
-    public abstract Map<String, String> getOptions();
+    public Map<String, String> getOptions();
 
     /**
      * Check if an option expects an argument.
@@ -91,5 +92,35 @@
      * @param option
      * @return true if an argument is expected. False otherwise.
      */
-    public abstract boolean hasArgument(String option);
+    public boolean hasArgument(String option);
+
+    /**
+     * An exposed provider wants to be advertised (e.g.: displayed in help).
+     *
+     * @return True, the provider is exposed, false the provider is hidden.
+     */
+    public default boolean isExposed() {
+        return true;
+    }
+
+    /**
+     * Check if the provider can properly operate in the current context.
+     *
+     * @return true, the provider can operate
+     */
+    public default boolean isFunctional() {
+        return true;
+    }
+
+    /**
+     * Return a message indicating the status of the provider.
+     *
+     * @param functional
+     * @return A status description.
+     */
+    public default String getFunctionalStateDescription(boolean functional) {
+        return functional
+                ? PluginsResourceBundle.getMessage("main.status.ok")
+                : PluginsResourceBundle.getMessage("main.status.not.ok");
+    }
 }
--- a/src/jdk.jlink/share/classes/jdk/tools/jlink/plugins/PluginProvider.java	Thu Oct 15 08:27:31 2015 +0100
+++ b/src/jdk.jlink/share/classes/jdk/tools/jlink/plugins/PluginProvider.java	Thu Oct 15 18:40:37 2015 +0200
@@ -27,6 +27,7 @@
 import java.io.IOException;
 import java.util.Map;
 import java.util.Objects;
+import jdk.tools.jlink.internal.plugins.PluginsResourceBundle;
 
 /**
  * An abstract plugin provider class. A provider has a name, a description and
@@ -101,6 +102,36 @@
     }
 
     /**
+     * An exposed provider wants to be advertised (e.g.: displayed in help).
+     *
+     * @return True, the provider is exposed, false the provider is hidden.
+     */
+    public boolean isExposed() {
+        return true;
+    }
+
+    /**
+     * Check if the provider can properly operate in the current context.
+     *
+     * @return true, the provider can operate
+     */
+    public boolean isFunctional() {
+        return true;
+    }
+
+    /**
+     * Return a message indicating the status of the provider.
+     *
+     * @param functional
+     * @return A status description.
+     */
+    public String getFunctionalStateDescription(boolean functional) {
+        return functional
+                ? PluginsResourceBundle.getMessage("main.status.ok")
+                : PluginsResourceBundle.getMessage("main.status.not.ok");
+    }
+
+    /**
      * Create plugins based on passed configuration.
      *
      * @param config The plugins configuration.
--- a/src/jdk.jlink/share/classes/jdk/tools/jlink/resources/plugins.properties	Thu Oct 15 08:27:31 2015 +0100
+++ b/src/jdk.jlink/share/classes/jdk/tools/jlink/resources/plugins.properties	Thu Oct 15 18:40:37 2015 +0200
@@ -64,6 +64,10 @@
 
 zip.description=ZIP Compression
 
+main.status.ok=Functional.
+
+main.status.not.ok= Not functional.
+
 main.opt.list-plugins=\
 \  --list-plugins                       Available plugins information
 
@@ -112,6 +116,11 @@
 main.image.builders=\
 Options bound to the image builder in use.
 
+main.plugin.state=\
+Functional state
+
+err.provider.not.functional=The provider {0} is not functional.
+
 err.plugin.mutiple.options=More than one plugin enabled by {0} option
 
 err.no.plugins.path=No plugins path argument.
--- a/test/jdk/jigsaw/tools/jlink/CustomImageBuilderTest.java	Thu Oct 15 08:27:31 2015 +0100
+++ b/test/jdk/jigsaw/tools/jlink/CustomImageBuilderTest.java	Thu Oct 15 18:40:37 2015 +0200
@@ -103,8 +103,9 @@
                 .call();
         result.assertSuccess();
         String message = result.getMessage();
-        if (!message.contains("Image Builder Name: custom-image-builder\n" +
-                " --custom-image-option-1 custom-image-option-description")) {
+        if (!message.contains("Image Builder Name: custom-image-builder\n"
+                + "Functional state: Functional.\n"
+                + " --custom-image-option-1 custom-image-option-description")) {
             System.err.println(result.getMessage());
             throw new AssertionError("Custom image builder not found");
         }
--- a/test/jdk/jigsaw/tools/jlink/JLinkTest.java	Thu Oct 15 08:27:31 2015 +0100
+++ b/test/jdk/jigsaw/tools/jlink/JLinkTest.java	Thu Oct 15 18:40:37 2015 +0200
@@ -68,6 +68,10 @@
         {
             // number of built-in plugins
             List<PluginProvider> builtInPluginsProviders = ImagePluginProviderRepository.getPluginProviders(Layer.boot());
+            for (PluginProvider p : builtInPluginsProviders) {
+                p.isExposed();
+                p.isFunctional();
+            }
             if (builtInPluginsProviders.size() != numPlugins) {
                 throw new AssertionError("Plugins not found: " + builtInPluginsProviders.size());
             }