8160063: Provide a means to disable a plugin via the command line

Reviewed-by: jlaskey
This commit is contained in:
Athijegannathan Sundararajan 2016-11-02 10:49:15 +05:30
parent 530da2782a
commit d9bc8cbcdb
5 changed files with 43 additions and 32 deletions

View File

@ -526,30 +526,16 @@ public class JlinkTask {
}
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() {

View File

@ -161,6 +161,7 @@ public final class TaskHelper {
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 @@ public final class TaskHelper {
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);
}
@ -197,6 +199,16 @@ public final class TaskHelper {
// to have the options parsed.
},
"--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)) {

View File

@ -159,13 +159,6 @@ public final class GenerateJLIClassesPlugin implements Plugin {
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

View File

@ -74,12 +74,11 @@ where <section-name> is \"man\" or \"headers".
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.resources-last-sorter=\
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.no.value=\
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

View File

@ -83,5 +83,21 @@ public class JLinkPluginsTest {
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");
}
}
}