changeset 15996:58796fb3241f

8160063: Provide a means to disable a plugin via the command line Reviewed-by: jlaskey
author sundar
date Wed, 02 Nov 2016 10:49:15 +0530
parents 92103cb21bd6
children 79d71eeecfc8
files src/jdk.jlink/share/classes/jdk/tools/jlink/internal/JlinkTask.java src/jdk.jlink/share/classes/jdk/tools/jlink/internal/TaskHelper.java src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/GenerateJLIClassesPlugin.java src/jdk.jlink/share/classes/jdk/tools/jlink/resources/plugins.properties test/tools/jlink/JLinkPluginsTest.java
diffstat 5 files changed, 43 insertions(+), 32 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/JlinkTask.java	Tue Nov 01 17:29:49 2016 -0700
+++ b/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/JlinkTask.java	Wed Nov 02 10:49:15 2016 +0530
@@ -526,30 +526,16 @@
     }
 
     private static enum Section {
-        NATIVE_LIBS("native", nativeDir()),
-        NATIVE_CMDS("bin", "bin"),
-        CLASSES("classes", "classes"),
-        CONFIG("conf", "conf"),
-        UNKNOWN("unknown", "unknown");
-
-        private static String nativeDir() {
-            if (System.getProperty("os.name").startsWith("Windows")) {
-                return "bin";
-            } else {
-                return "lib";
-            }
-        }
+        NATIVE_LIBS("native"),
+        NATIVE_CMDS("bin"),
+        CLASSES("classes"),
+        CONFIG("conf"),
+        UNKNOWN("unknown");
 
         private final String jmodDir;
-        private final String imageDir;
 
-        Section(String jmodDir, String imageDir) {
+        Section(String jmodDir) {
             this.jmodDir = jmodDir;
-            this.imageDir = imageDir;
-        }
-
-        String imageDir() {
-            return imageDir;
         }
 
         String jmodDir() {
--- a/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/TaskHelper.java	Tue Nov 01 17:29:49 2016 -0700
+++ b/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/TaskHelper.java	Wed Nov 02 10:49:15 2016 +0530
@@ -161,6 +161,7 @@
         private static final String POST_PROCESS = "--post-process-path";
 
         private Layer pluginsLayer = Layer.boot();
+        private final List<Plugin> plugins;
         private String lastSorter;
         private boolean listPlugins;
         private Path existingImage;
@@ -184,9 +185,10 @@
                 pluginsLayer = createPluginsLayer(paths);
             }
 
+            plugins = PluginRepository.getPlugins(pluginsLayer);
+
             Set<String> optionsSeen = new HashSet<>();
-            for (Plugin plugin : PluginRepository.
-                    getPlugins(pluginsLayer)) {
+            for (Plugin plugin : plugins) {
                 if (!Utils.isDisabled(plugin)) {
                     addOrderedPluginOptions(plugin, optionsSeen);
                 }
@@ -198,6 +200,16 @@
                     },
                     "--plugin-module-path"));
             mainOptions.add(new PlugOption(true, (task, opt, arg) -> {
+                    for (Plugin plugin : plugins) {
+                        if (plugin.getName().equals(arg)) {
+                            pluginToMaps.remove(plugin);
+                            return;
+                        }
+                    }
+                    throw newBadArgs("err.no.such.plugin", arg);
+                },
+                "--disable-plugin"));
+            mainOptions.add(new PlugOption(true, (task, opt, arg) -> {
                 Path path = Paths.get(arg);
                 if (!Files.exists(path) || !Files.isDirectory(path)) {
                     throw newBadArgs("err.existing.image.must.exist");
--- a/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/GenerateJLIClassesPlugin.java	Tue Nov 01 17:29:49 2016 -0700
+++ b/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/GenerateJLIClassesPlugin.java	Wed Nov 02 10:49:15 2016 +0530
@@ -159,13 +159,6 @@
     public void configure(Map<String, String> config) {
         String mainArgument = config.get(NAME);
 
-        if ("none".equals(mainArgument)) {
-            speciesTypes = Set.of();
-            invokerTypes = Set.of();
-            dmhMethods = Map.of();
-            return;
-        }
-
         // Start with the default configuration
         Set<String> defaultBMHSpecies = defaultSpecies();
         // Expand BMH species signatures
--- a/src/jdk.jlink/share/classes/jdk/tools/jlink/resources/plugins.properties	Tue Nov 01 17:29:49 2016 -0700
+++ b/src/jdk.jlink/share/classes/jdk/tools/jlink/resources/plugins.properties	Wed Nov 02 10:49:15 2016 +0530
@@ -74,12 +74,11 @@
 exclude-jmod-section.description=\
 Specify a JMOD section to exclude
 
-generate-jli-classes.argument=<none|@filename>
+generate-jli-classes.argument=@filename
 
 generate-jli-classes.description=\
 Takes a file hinting to jlink what java.lang.invoke classes to pre-generate. If\n\
-this flag is not specified a default set of classes will be generated. To \n\
-disable pre-generation specify none as the argument
+this flag is not specified a default set of classes will be generated.
 
 installed-modules.description=Fast loading of module descriptors (always enabled)
 
@@ -144,6 +143,9 @@
 plugin.opt.plugin-module-path=\
 \  --plugin-module-path <modulepath> Custom plugin module path
 
+plugin.opt.disable-plugin=\
+\  --disable-plugin <pluginname>     Disable the plugin mentioned
+
 plugin.opt.c=\
 \  -c, --compress=<0|1|2>            Enable compression of resources\
 \n                                    More details in --list-plugins option
@@ -193,6 +195,8 @@
 main.plugin.state=\
 Functional state
 
+err.no.such.plugin=No such plugin: {0}
+
 err.provider.not.functional=The provider {0} is not functional.
 
 err.plugin.mutiple.options=More than one plugin enabled by {0} option
--- a/test/tools/jlink/JLinkPluginsTest.java	Tue Nov 01 17:29:49 2016 -0700
+++ b/test/tools/jlink/JLinkPluginsTest.java	Wed Nov 02 10:49:15 2016 +0530
@@ -83,5 +83,21 @@
             Path imageDir = helper.generateDefaultImage(userOptions, moduleName).assertSuccess();
             helper.checkImage(imageDir, moduleName, null, null);
         }
+        {
+            // disable generate jli classes - JDK-8160063
+            String[] userOptions = {"--disable-plugin", "generate-jli-classes"};
+            String moduleName = "jlidisabled";
+            helper.generateDefaultJModule(moduleName, "composite2");
+            Path imageDir = helper.generateDefaultImage(userOptions, moduleName).assertSuccess();
+            helper.checkImage(imageDir, moduleName, null, null);
+        }
+        {
+            // disable invalid plugin - JDK-8160063
+            String[] userOptions = {"--disable-plugin", "non-existent-plugin"};
+            String moduleName = "invaliddisabled";
+            helper.generateDefaultJModule(moduleName, "composite2");
+            helper.generateDefaultImage(userOptions, moduleName).
+                assertFailure("Error: No such plugin: non-existent-plugin");
+        }
     }
 }