8218685: jlink --list-plugins needs to be readable and tidy

Reviewed-by: mchung, alanb
This commit is contained in:
Ian Graves 2020-09-29 21:16:35 +00:00 committed by Mandy Chung
parent 2fe0a5d75e
commit 8df3e72cea
32 changed files with 412 additions and 420 deletions

View File

@ -45,7 +45,6 @@ import java.util.Objects;
import java.util.Optional;
import java.util.ResourceBundle;
import jdk.tools.jlink.plugin.Plugin;
import jdk.tools.jlink.plugin.PluginException;
import jdk.tools.jlink.plugin.ResourcePool;
import jdk.tools.jlink.plugin.ResourcePoolBuilder;
@ -56,7 +55,7 @@ import jdk.tools.jlink.plugin.ResourcePoolEntry;
* libraries and binaries.
*
*/
public final class StripNativeDebugSymbolsPlugin implements Plugin {
public final class StripNativeDebugSymbolsPlugin extends AbstractPlugin {
public static final String NAME = "strip-native-debug-symbols";
private static final boolean DEBUG = Boolean.getBoolean("jlink.debug");
@ -92,14 +91,10 @@ public final class StripNativeDebugSymbolsPlugin implements Plugin {
}
public StripNativeDebugSymbolsPlugin(ObjCopyCmdBuilder cmdBuilder) {
super(NAME, resourceBundle);
this.cmdBuilder = cmdBuilder;
}
@Override
public String getName() {
return NAME;
}
@Override
public ResourcePool transform(ResourcePool in, ResourcePoolBuilder out) {
StrippedDebugInfoBinaryBuilder builder = new StrippedDebugInfoBinaryBuilder(
@ -137,10 +132,9 @@ public final class StripNativeDebugSymbolsPlugin implements Plugin {
}
private void logError(ResourcePoolEntry resource, String msgKey) {
String msg = PluginsResourceBundle.getMessage(resourceBundle,
msgKey,
NAME,
resource.path());
String msg = getMessage(msgKey,
NAME,
resource.path());
System.err.println(msg);
}
@ -149,23 +143,11 @@ public final class StripNativeDebugSymbolsPlugin implements Plugin {
return Category.TRANSFORMER;
}
@Override
public String getDescription() {
String key = NAME + ".description";
return PluginsResourceBundle.getMessage(resourceBundle, key);
}
@Override
public boolean hasArguments() {
return true;
}
@Override
public String getArgumentsDescription() {
String key = NAME + ".argument";
return PluginsResourceBundle.getMessage(resourceBundle, key);
}
@Override
public void configure(Map<String, String> config) {
doConfigure(true, config);
@ -196,8 +178,7 @@ public final class StripNativeDebugSymbolsPlugin implements Plugin {
String[] tokens = arg.split("=");
if (tokens.length != 2 || !KEEP_DEBUG_INFO_ARG.equals(tokens[0])) {
throw new IllegalArgumentException(
PluginsResourceBundle.getMessage(resourceBundle,
NAME + ".iae", NAME, arg));
getMessage(NAME + ".iae", NAME, arg));
}
hasKeepDebugInfo = true;
debuginfoExt = tokens[1];
@ -211,8 +192,7 @@ public final class StripNativeDebugSymbolsPlugin implements Plugin {
String[] tokens = arg.split("=");
if (tokens.length != 2 || !STRIP_CMD_ARG.equals(tokens[0])) {
throw new IllegalArgumentException(
PluginsResourceBundle.getMessage(resourceBundle,
NAME + ".iae", NAME, arg));
getMessage(NAME + ".iae", NAME, arg));
}
if (withChecks) {
validateStripArg(tokens[1]);
@ -246,26 +226,23 @@ public final class StripNativeDebugSymbolsPlugin implements Plugin {
// on the same plugin instance multiple times. Plugin option can
// repeat.
throw new IllegalArgumentException(
PluginsResourceBundle.getMessage(resourceBundle,
NAME + ".iae.conflict",
NAME,
EXCLUDE_DEBUG_INFO_ARG,
KEEP_DEBUG_INFO_ARG));
getMessage(NAME + ".iae.conflict",
NAME,
EXCLUDE_DEBUG_INFO_ARG,
KEEP_DEBUG_INFO_ARG));
}
if (!arg.startsWith(STRIP_CMD_ARG) &&
!arg.startsWith(KEEP_DEBUG_INFO_ARG) &&
!arg.startsWith(EXCLUDE_DEBUG_INFO_ARG)) {
// unknown arg value; case --strip-native-debug-symbols foobar
throw new IllegalArgumentException(
PluginsResourceBundle.getMessage(resourceBundle,
NAME + ".iae", NAME, arg));
getMessage(NAME + ".iae", NAME, arg));
}
if (!config.isEmpty()) {
// extraneous values; --strip-native-debug-symbols keep-debuginfo-files:foo=bar
throw new IllegalArgumentException(
PluginsResourceBundle.getMessage(resourceBundle,
NAME + ".iae", NAME,
config.toString()));
getMessage(NAME + ".iae", NAME,
config.toString()));
}
includeDebugSymbols = hasKeepDebugInfo;
}
@ -275,15 +252,13 @@ public final class StripNativeDebugSymbolsPlugin implements Plugin {
Path strip = Paths.get(stripArg); // verify it's a resonable path
if (!Files.isExecutable(strip)) {
throw new IllegalArgumentException(
PluginsResourceBundle.getMessage(resourceBundle,
NAME + ".invalidstrip",
stripArg));
getMessage(NAME + ".invalidstrip",
stripArg));
}
} catch (InvalidPathException e) {
throw new IllegalArgumentException(
PluginsResourceBundle.getMessage(resourceBundle,
NAME + ".invalidstrip",
e.getInput()));
getMessage(NAME + ".invalidstrip",
e.getInput()));
}
}

View File

@ -35,6 +35,24 @@ Strip debug symbols from native libraries (if any). \n\
strip-native-debug-symbols.argument=\
<exclude-debuginfo-files|keep-debuginfo-files|objcopy=/path/to/objcopy>
strip-native-debug-symbols.usage=\
\ --strip-native-debug-symbols \
\ <exclude-debuginfo-files|keep-debuginfo-files|objcopy=PATH_TO_OBJ>\n\
\ Strip debug symbols from native libraries (if any). \n\
\ This plugin requires at least one option:\n\
\ objcopy: The path to the 'objcopy' binary.\n\
\ Defaults to 'objcopy' in PATH.\n\
\ exclude-debuginfo-files: Exclude debug info \n\
\ files. Defaults to true.\n\
\ keep-debuginfo-files[=<ext>]: Keep debug info\n\
\ files in <file>.<ext>.\n\
\ Defaults to <file>.debuginfo \n\
\ Examples: --strip-native-debug-symbols \n\
\ keep-debuginfo-files:objcopy=OBJPATH\n\
\ --strip-native-debug-symbols\n\
\ exclude-debuginfo-files
strip-native-debug-symbols.invalidstrip=Invalid objcopy command: {0}
strip-native-debug-symbols.iae={0}: Unrecognized argument ''{1}''

View File

@ -30,20 +30,22 @@ import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Map;
import java.util.HashMap;
import java.util.Map.Entry;
import java.util.Set;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Map.Entry;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
import java.util.Set;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import java.util.Collections;
import java.util.Locale;
import java.util.ResourceBundle;
import java.util.MissingResourceException;
import java.util.Comparator;
import jdk.tools.jlink.builder.DefaultImageBuilder;
import jdk.tools.jlink.builder.ImageBuilder;
@ -373,7 +375,7 @@ public final class TaskHelper {
= new PluginOption(false,
(task, opt, arg) -> {
Map<String, String> m = addArgumentMap(plugin);
m.put(DefaultCompressPlugin.NAME, DefaultCompressPlugin.LEVEL_2);
m.put(plugin.getName(), DefaultCompressPlugin.LEVEL_2);
}, false, "--compress", "-c");
mainOptions.add(plugOption);
} else if (plugin instanceof DefaultStripDebugPlugin) {
@ -386,14 +388,14 @@ public final class TaskHelper {
} else if (plugin instanceof ExcludeJmodSectionPlugin) {
plugOption = new PluginOption(false, (task, opt, arg) -> {
Map<String, String> m = addArgumentMap(plugin);
m.put(ExcludeJmodSectionPlugin.NAME,
m.put(plugin.getName(),
ExcludeJmodSectionPlugin.MAN_PAGES);
}, false, "--no-man-pages");
mainOptions.add(plugOption);
plugOption = new PluginOption(false, (task, opt, arg) -> {
Map<String, String> m = addArgumentMap(plugin);
m.put(ExcludeJmodSectionPlugin.NAME,
m.put(plugin.getName(),
ExcludeJmodSectionPlugin.INCLUDE_HEADER_FILES);
}, false, "--no-header-files");
mainOptions.add(plugOption);
@ -450,8 +452,8 @@ public final class TaskHelper {
// aren't being used at the same time. --strip-debug invokes --strip-native-debug-symbols on
// platforms that support it, so it makes little sense to allow both at the same time.
if ((plugin instanceof DefaultStripDebugPlugin && seenPlugins.contains(STRIP_NATIVE_DEBUG_SYMBOLS_NAME)) ||
(STRIP_NATIVE_DEBUG_SYMBOLS_NAME.equals(plugin.getName()) && seenPlugins.contains(DefaultStripDebugPlugin.NAME))) {
throw new BadArgs("err.plugin.conflicts", "--" + DefaultStripDebugPlugin.NAME,
(STRIP_NATIVE_DEBUG_SYMBOLS_NAME.equals(plugin.getName()) && seenPlugins.contains(plugin.getName()))) {
throw new BadArgs("err.plugin.conflicts", "--" + plugin.getName(),
"-G",
"--" + STRIP_NATIVE_DEBUG_SYMBOLS_NAME);
}
@ -606,42 +608,50 @@ public final class TaskHelper {
List<Plugin> pluginList = PluginRepository.
getPlugins(pluginOptions.pluginsLayer);
for (Plugin plugin : Utils.getSortedPlugins(pluginList)) {
showPlugin(plugin, log);
}
pluginList.stream()
.sorted(Comparator.comparing((Plugin plugin) -> plugin.getUsage().isEmpty(),
(Boolean res1, Boolean res2) -> Boolean.compare(res2,res1))
.thenComparing(Plugin::getName)
)
.forEach((plugin) -> showPlugin(plugin, log));
log.println("\n" + bundleHelper.getMessage("main.extended.help.footer"));
}
private void showPlugin(Plugin plugin, PrintWriter log) {
if (showsPlugin(plugin)) {
log.println("\n" + bundleHelper.getMessage("main.plugin.name")
+ ": " + plugin.getName());
if(!plugin.getUsage().isEmpty()) {
log.println(plugin.getUsage());
} else {
log.println("\n" + bundleHelper.getMessage("main.plugin.name")
+ ": " + plugin.getName());
// print verbose details for non-builtin plugins
if (!Utils.isBuiltin(plugin)) {
log.println(bundleHelper.getMessage("main.plugin.class")
+ ": " + plugin.getClass().getName());
log.println(bundleHelper.getMessage("main.plugin.module")
+ ": " + plugin.getClass().getModule().getName());
Category category = plugin.getType();
log.println(bundleHelper.getMessage("main.plugin.category")
+ ": " + category.getName());
log.println(bundleHelper.getMessage("main.plugin.state")
+ ": " + plugin.getStateDescription());
// print verbose details for non-builtin plugins
if (!Utils.isBuiltin(plugin)) {
log.println(bundleHelper.getMessage("main.plugin.class")
+ ": " + plugin.getClass().getName());
log.println(bundleHelper.getMessage("main.plugin.module")
+ ": " + plugin.getClass().getModule().getName());
Category category = plugin.getType();
log.println(bundleHelper.getMessage("main.plugin.category")
+ ": " + category.getName());
log.println(bundleHelper.getMessage("main.plugin.state")
+ ": " + plugin.getStateDescription());
}
String option = plugin.getOption();
if (option != null) {
log.println(bundleHelper.getMessage("main.plugin.option")
+ ": --" + plugin.getOption()
+ (plugin.hasArguments()? ("=" + plugin.getArgumentsDescription()) : ""));
}
// description can be long spanning more than one line and so
// print a newline after description label.
log.println(bundleHelper.getMessage("main.plugin.description")
+ ": " + plugin.getDescription());
}
String option = plugin.getOption();
if (option != null) {
log.println(bundleHelper.getMessage("main.plugin.option")
+ ": --" + plugin.getOption()
+ (plugin.hasArguments()? ("=" + plugin.getArgumentsDescription()) : ""));
}
// description can be long spanning more than one line and so
// print a newline after description label.
log.println(bundleHelper.getMessage("main.plugin.description")
+ ": " + plugin.getDescription());
}
}
@ -725,6 +735,6 @@ public final class TaskHelper {
// Display all plugins
private static boolean showsPlugin(Plugin plugin) {
return (!Utils.isDisabled(plugin) && plugin.getOption() != null);
return (!Utils.isDisabled(plugin) && (plugin.getOption() != null) || !(plugin.getUsage().isEmpty()));
}
}

View File

@ -0,0 +1,87 @@
/*
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package jdk.tools.jlink.internal.plugins;
import jdk.tools.jlink.plugin.Plugin;
import java.util.Locale;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
public abstract class AbstractPlugin implements Plugin {
static final String DESCRIPTION = "description";
static final String USAGE = "usage";
private static final ResourceBundle standardPluginsBundle;
static {
Locale locale = Locale.getDefault();
try {
standardPluginsBundle = ResourceBundle.getBundle("jdk.tools.jlink."
+ "resources.plugins", locale);
} catch (MissingResourceException e) {
throw new InternalError("Cannot find jlink resource bundle for "
+ "locale " + locale);
}
}
private final ResourceBundle pluginsBundle;
private final String name;
protected AbstractPlugin(String name) {
this.name = name;
this.pluginsBundle = standardPluginsBundle;
}
protected AbstractPlugin(String name, ResourceBundle bundle) {
this.name = name;
this.pluginsBundle = bundle;
}
@Override
public String getName() {
return name;
}
@Override
public String getDescription() {
return getMessage(getName() + "." + DESCRIPTION, getName());
}
@Override
public String getUsage() {
return getMessage(getName() + "." + USAGE, getName());
}
@Override
public String getArgumentsDescription() {
return PluginsResourceBundle.getArgument(getName());
}
protected String getMessage(String key, Object...args) {
return PluginsResourceBundle.getMessage(this.pluginsBundle, key, args);
}
}

View File

@ -29,7 +29,6 @@ import java.nio.charset.StandardCharsets;
import java.util.Map;
import java.util.function.Function;
import jdk.tools.jlink.plugin.Plugin;
import jdk.tools.jlink.plugin.ResourcePool;
import jdk.tools.jlink.plugin.ResourcePoolBuilder;
import jdk.tools.jlink.plugin.ResourcePoolEntry;
@ -37,27 +36,16 @@ import jdk.tools.jlink.plugin.ResourcePoolEntry;
/**
* Base plugin to add a resource
*/
abstract class AddResourcePlugin implements Plugin {
abstract class AddResourcePlugin extends AbstractPlugin {
private final String name;
private final String path;
private String value;
protected AddResourcePlugin(String n, String p) {
name = n;
protected AddResourcePlugin(String name, String p) {
super(name);
path = p;
}
@Override
public String getName() {
return name;
}
@Override
public String getDescription() {
return PluginsResourceBundle.getDescription(name);
}
@Override
public Category getType() {
return Category.ADDER;
@ -73,14 +61,10 @@ abstract class AddResourcePlugin implements Plugin {
return true;
}
@Override
public String getArgumentsDescription() {
return PluginsResourceBundle.getArgument(name);
}
@Override
public void configure(Map<String, String> config) {
var v = config.get(name);
var v = config.get(getName());
if (v == null)
throw new AssertionError();
value = v;

View File

@ -30,7 +30,6 @@ import java.util.function.Function;
import jdk.tools.jlink.internal.ResourcePoolManager.ResourcePoolImpl;
import jdk.tools.jlink.plugin.ResourcePool;
import jdk.tools.jlink.plugin.ResourcePoolBuilder;
import jdk.tools.jlink.plugin.Plugin;
import jdk.tools.jlink.internal.ImagePluginStack;
import jdk.tools.jlink.internal.ResourcePoolManager;
import jdk.tools.jlink.internal.ResourcePrevisitor;
@ -40,8 +39,7 @@ import jdk.tools.jlink.internal.StringTable;
*
* ZIP and String Sharing compression plugin
*/
public final class DefaultCompressPlugin implements Plugin, ResourcePrevisitor {
public static final String NAME = "compress";
public final class DefaultCompressPlugin extends AbstractPlugin implements ResourcePrevisitor {
public static final String FILTER = "filter";
public static final String LEVEL_0 = "0";
public static final String LEVEL_1 = "1";
@ -50,9 +48,8 @@ public final class DefaultCompressPlugin implements Plugin, ResourcePrevisitor {
private StringSharingPlugin ss;
private ZipPlugin zip;
@Override
public String getName() {
return NAME;
public DefaultCompressPlugin() {
super("compress");
}
@Override
@ -83,25 +80,15 @@ public final class DefaultCompressPlugin implements Plugin, ResourcePrevisitor {
return Category.COMPRESSOR;
}
@Override
public String getDescription() {
return PluginsResourceBundle.getDescription(NAME);
}
@Override
public boolean hasArguments() {
return true;
}
@Override
public String getArgumentsDescription() {
return PluginsResourceBundle.getArgument(NAME);
}
@Override
public void configure(Map<String, String> config) {
ResourceFilter resFilter = ResourceFilter.includeFilter(config.get(FILTER));
String level = config.get(NAME);
String level = config.get(getName());
if (level != null) {
switch (level) {
case LEVEL_0:

View File

@ -39,9 +39,8 @@ import jdk.tools.jlink.plugin.ResourcePoolBuilder;
* symbols.
*
*/
public final class DefaultStripDebugPlugin implements Plugin {
public final class DefaultStripDebugPlugin extends AbstractPlugin {
public static final String NAME = "strip-debug";
private static final String STRIP_NATIVE_DEBUG_PLUGIN = "strip-native-debug-symbols";
private static final String EXCLUDE_DEBUGINFO = "exclude-debuginfo-files";
@ -55,20 +54,11 @@ public final class DefaultStripDebugPlugin implements Plugin {
public DefaultStripDebugPlugin(Plugin javaStripPlugin,
NativePluginFactory nativeStripPluginFact) {
super("strip-debug");
this.javaStripPlugin = javaStripPlugin;
this.stripNativePluginFactory = nativeStripPluginFact;
}
@Override
public String getName() {
return NAME;
}
@Override
public String getDescription() {
return PluginsResourceBundle.getDescription(NAME);
}
@Override
public ResourcePool transform(ResourcePool in, ResourcePoolBuilder out) {
Plugin stripNativePlugin = stripNativePluginFactory.create();

View File

@ -26,7 +26,7 @@ package jdk.tools.jlink.internal.plugins;
import java.util.Map;
import java.util.function.Predicate;
import jdk.tools.jlink.plugin.Plugin;
import jdk.tools.jlink.plugin.ResourcePool;
import jdk.tools.jlink.plugin.ResourcePoolBuilder;
import jdk.tools.jlink.plugin.ResourcePoolEntry;
@ -35,14 +35,12 @@ import jdk.tools.jlink.plugin.ResourcePoolEntry;
*
* Exclude files plugin
*/
public final class ExcludeFilesPlugin implements Plugin {
public final class ExcludeFilesPlugin extends AbstractPlugin {
public static final String NAME = "exclude-files";
private Predicate<String> predicate;
@Override
public String getName() {
return NAME;
public ExcludeFilesPlugin () {
super("exclude-files");
}
@Override
@ -61,23 +59,13 @@ public final class ExcludeFilesPlugin implements Plugin {
return Category.FILTER;
}
@Override
public String getDescription() {
return PluginsResourceBundle.getDescription(NAME);
}
@Override
public boolean hasArguments() {
return true;
}
@Override
public String getArgumentsDescription() {
return PluginsResourceBundle.getArgument(NAME);
}
@Override
public void configure(Map<String, String> config) {
predicate = ResourceFilter.excludeFilter(config.get(NAME));
predicate = ResourceFilter.excludeFilter(config.get(getName()));
}
}

View File

@ -28,7 +28,6 @@ import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import jdk.tools.jlink.plugin.Plugin;
import jdk.tools.jlink.plugin.ResourcePool;
import jdk.tools.jlink.plugin.ResourcePoolBuilder;
import jdk.tools.jlink.plugin.ResourcePoolEntry.Type;
@ -37,22 +36,20 @@ import jdk.tools.jlink.plugin.ResourcePoolEntry.Type;
*
* A plugin to exclude a JMOD section such as man pages or header files
*/
public final class ExcludeJmodSectionPlugin implements Plugin {
public final class ExcludeJmodSectionPlugin extends AbstractPlugin {
public static final String NAME = "exclude-jmod-section";
public static final String MAN_PAGES = "man";
public static final String INCLUDE_HEADER_FILES = "headers";
private final Set<Type> filters = new HashSet<>();
@Override
public String getName() {
return NAME;
public ExcludeJmodSectionPlugin() {
super("exclude-jmod-section");
}
@Override
public void configure(Map<String, String> config) {
String arg = config.get(NAME);
String arg = config.get(getName());
if (arg.isEmpty()) {
throw new IllegalArgumentException("Section name must be specified");
}
@ -86,18 +83,9 @@ public final class ExcludeJmodSectionPlugin implements Plugin {
return Category.FILTER;
}
@Override
public String getDescription() {
return PluginsResourceBundle.getDescription(NAME);
}
@Override
public boolean hasArguments() {
return true;
}
@Override
public String getArgumentsDescription() {
return PluginsResourceBundle.getArgument(NAME);
}
}

View File

@ -26,7 +26,7 @@ package jdk.tools.jlink.internal.plugins;
import java.util.Map;
import java.util.function.Predicate;
import jdk.tools.jlink.plugin.Plugin;
import jdk.tools.jlink.plugin.PluginException;
import jdk.tools.jlink.plugin.ResourcePool;
import jdk.tools.jlink.plugin.ResourcePoolBuilder;
@ -36,14 +36,13 @@ import jdk.tools.jlink.plugin.ResourcePoolEntry;
*
* Exclude resources plugin
*/
public final class ExcludePlugin implements Plugin {
public final class ExcludePlugin extends AbstractPlugin {
public static final String NAME = "exclude-resources";
private Predicate<String> predicate;
@Override
public String getName() {
return NAME;
public ExcludePlugin() {
super("exclude-resources");
}
@Override
@ -63,21 +62,11 @@ public final class ExcludePlugin implements Plugin {
return out.build();
}
@Override
public String getDescription() {
return PluginsResourceBundle.getDescription(NAME);
}
@Override
public boolean hasArguments() {
return true;
}
@Override
public String getArgumentsDescription() {
return PluginsResourceBundle.getArgument(NAME);
}
@Override
public Category getType() {
return Category.FILTER;
@ -85,6 +74,6 @@ public final class ExcludePlugin implements Plugin {
@Override
public void configure(Map<String, String> config) {
predicate = ResourceFilter.excludeFilter(config.get(NAME));
predicate = ResourceFilter.excludeFilter(config.get(getName()));
}
}

View File

@ -37,7 +37,6 @@ import java.util.function.Predicate;
import java.util.stream.Collectors;
import jdk.tools.jlink.internal.Platform;
import jdk.tools.jlink.plugin.Plugin;
import jdk.tools.jlink.plugin.PluginException;
import jdk.tools.jlink.plugin.ResourcePool;
import jdk.tools.jlink.plugin.ResourcePoolBuilder;
@ -48,7 +47,7 @@ import jdk.tools.jlink.plugin.ResourcePoolModule;
*
* Exclude VM plugin
*/
public final class ExcludeVMPlugin implements Plugin {
public final class ExcludeVMPlugin extends AbstractPlugin {
private static final class JvmComparator implements Comparator<Jvm> {
@ -80,7 +79,6 @@ public final class ExcludeVMPlugin implements Plugin {
private static final String JVM_CFG = "jvm.cfg";
public static final String NAME = "vm";
private static final String ALL = "all";
private static final String CLIENT = "client";
private static final String SERVER = "server";
@ -90,9 +88,8 @@ public final class ExcludeVMPlugin implements Plugin {
private Jvm target;
private boolean keepAll;
@Override
public String getName() {
return NAME;
public ExcludeVMPlugin() {
super("vm");
}
/**
@ -172,24 +169,14 @@ public final class ExcludeVMPlugin implements Plugin {
return Category.FILTER;
}
@Override
public String getDescription() {
return PluginsResourceBundle.getDescription(NAME);
}
@Override
public boolean hasArguments() {
return true;
}
@Override
public String getArgumentsDescription() {
return PluginsResourceBundle.getArgument(NAME);
}
@Override
public void configure(Map<String, String> config) {
String value = config.get(NAME);
String value = config.get(getName());
String exclude = "";
switch (value) {
case ALL: {

View File

@ -37,7 +37,6 @@ import java.util.stream.Stream;
import jdk.internal.access.JavaLangInvokeAccess;
import jdk.internal.access.SharedSecrets;
import jdk.tools.jlink.plugin.Plugin;
import jdk.tools.jlink.plugin.PluginException;
import jdk.tools.jlink.plugin.ResourcePool;
import jdk.tools.jlink.plugin.ResourcePoolBuilder;
@ -61,11 +60,8 @@ import jdk.tools.jlink.plugin.ResourcePoolEntry;
* feeding that into jlink using {@code --generate-jli-classes=@trace_file} can
* help improve startup time.
*/
public final class GenerateJLIClassesPlugin implements Plugin {
public final class GenerateJLIClassesPlugin extends AbstractPlugin {
private static final String NAME = "generate-jli-classes";
private static final String DESCRIPTION = PluginsResourceBundle.getDescription(NAME);
private static final String DEFAULT_TRACE_FILE = "default_jli_trace.txt";
@ -76,16 +72,7 @@ public final class GenerateJLIClassesPlugin implements Plugin {
private Stream<String> traceFileStream;
public GenerateJLIClassesPlugin() {
}
@Override
public String getName() {
return NAME;
}
@Override
public String getDescription() {
return DESCRIPTION;
super("generate-jli-classes");
}
@Override
@ -98,14 +85,9 @@ public final class GenerateJLIClassesPlugin implements Plugin {
return true;
}
@Override
public String getArgumentsDescription() {
return PluginsResourceBundle.getArgument(NAME);
}
@Override
public void configure(Map<String, String> config) {
mainArgument = config.get(NAME);
mainArgument = config.get(getName());
}
public void initialize(ResourcePool in) {

View File

@ -48,7 +48,6 @@ import jdk.tools.jlink.plugin.PluginException;
import jdk.tools.jlink.plugin.ResourcePool;
import jdk.tools.jlink.plugin.ResourcePoolBuilder;
import jdk.tools.jlink.plugin.ResourcePoolEntry;
import jdk.tools.jlink.plugin.Plugin;
import sun.util.cldr.CLDRBaseLocaleDataMetaInfo;
import sun.util.locale.provider.LocaleProviderAdapter;
import sun.util.locale.provider.LocaleProviderAdapter.Type;
@ -76,9 +75,8 @@ import sun.util.locale.provider.ResourceBundleBasedAdapter;
* start with at least one white space character, e.g., " ar ar-EG ..."
* ^
*/
public final class IncludeLocalesPlugin implements Plugin, ResourcePrevisitor {
public final class IncludeLocalesPlugin extends AbstractPlugin implements ResourcePrevisitor {
public static final String NAME = "include-locales";
private static final String MODULENAME = "jdk.localedata";
private static final Set<String> LOCALEDATA_PACKAGES = Set.of(
"sun.text.resources.cldr.ext",
@ -147,9 +145,8 @@ public final class IncludeLocalesPlugin implements Plugin, ResourcePrevisitor {
private static final Locale noNONY = new Locale("no", "NO", "NY");
private static final Locale thTHTH = new Locale("th", "TH", "TH");
@Override
public String getName() {
return NAME;
public IncludeLocalesPlugin() {
super("include-locales");
}
@Override
@ -180,30 +177,20 @@ public final class IncludeLocalesPlugin implements Plugin, ResourcePrevisitor {
return Category.FILTER;
}
@Override
public String getDescription() {
return PluginsResourceBundle.getDescription(NAME);
}
@Override
public boolean hasArguments() {
return true;
}
@Override
public String getArgumentsDescription() {
return PluginsResourceBundle.getArgument(NAME);
}
@Override
public void configure(Map<String, String> config) {
userParam = config.get(NAME);
userParam = config.get(getName());
try {
priorityList = Locale.LanguageRange.parse(userParam, EQUIV_MAP);
} catch (IllegalArgumentException iae) {
throw new IllegalArgumentException(String.format(
PluginsResourceBundle.getMessage(NAME + ".invalidtag"),
PluginsResourceBundle.getMessage(getName() + ".invalidtag"),
iae.getMessage().replaceFirst("^range=", "")));
}
}
@ -218,7 +205,7 @@ public final class IncludeLocalesPlugin implements Plugin, ResourcePrevisitor {
ResourcePoolModule module = optMod.get();
Set<String> packages = module.packages();
if (!packages.containsAll(LOCALEDATA_PACKAGES)) {
throw new PluginException(PluginsResourceBundle.getMessage(NAME + ".missingpackages") +
throw new PluginException(PluginsResourceBundle.getMessage(getName()+ ".missingpackages") +
LOCALEDATA_PACKAGES.stream()
.filter(pn -> !packages.contains(pn))
.collect(Collectors.joining(",\n\t")));
@ -235,14 +222,14 @@ public final class IncludeLocalesPlugin implements Plugin, ResourcePrevisitor {
.collect(Collectors.toList());
} else {
// jdk.localedata is not added.
throw new PluginException(PluginsResourceBundle.getMessage(NAME + ".localedatanotfound"));
throw new PluginException(PluginsResourceBundle.getMessage(getName() + ".localedatanotfound"));
}
filtered = filterLocales(available);
if (filtered.isEmpty()) {
throw new PluginException(
String.format(PluginsResourceBundle.getMessage(NAME + ".nomatchinglocales"), userParam));
String.format(PluginsResourceBundle.getMessage(getName() + ".nomatchinglocales"), userParam));
}
List<String> value = Stream.concat(

View File

@ -36,7 +36,6 @@ import java.util.Set;
import jdk.tools.jlink.internal.ModuleSorter;
import jdk.tools.jlink.internal.Utils;
import jdk.tools.jlink.plugin.Plugin;
import jdk.tools.jlink.plugin.PluginException;
import jdk.tools.jlink.plugin.ResourcePool;
import jdk.tools.jlink.plugin.ResourcePoolBuilder;
@ -52,18 +51,16 @@ import jdk.tools.jlink.plugin.ResourcePoolModule;
* On platform that does not support symbolic links, a file
* will be created to contain the path to the linked target.
*/
public final class LegalNoticeFilePlugin implements Plugin {
public final class LegalNoticeFilePlugin extends AbstractPlugin {
private static final String NAME = "dedup-legal-notices";
private static final String ERROR_IF_NOT_SAME_CONTENT = "error-if-not-same-content";
private final Map<String, List<ResourcePoolEntry>> licenseOrNotice =
new HashMap<>();
private boolean errorIfNotSameContent = false;
@Override
public String getName() {
return NAME;
public LegalNoticeFilePlugin() {
super("dedup-legal-notices");
}
@Override
@ -73,12 +70,12 @@ public final class LegalNoticeFilePlugin implements Plugin {
@Override
public void configure(Map<String, String> config) {
String arg = config.get(NAME);
String arg = config.get(getName());
if (arg != null) {
if (arg.equals(ERROR_IF_NOT_SAME_CONTENT)) {
errorIfNotSameContent = true;
} else {
throw new IllegalArgumentException(NAME + ": " + arg);
throw new IllegalArgumentException(getName() + ": " + arg);
}
}
}
@ -140,18 +137,8 @@ public final class LegalNoticeFilePlugin implements Plugin {
return Category.TRANSFORMER;
}
@Override
public String getDescription() {
return PluginsResourceBundle.getDescription(NAME);
}
@Override
public boolean hasArguments() {
return true;
}
@Override
public String getArgumentsDescription() {
return PluginsResourceBundle.getArgument(NAME);
}
}

View File

@ -37,7 +37,6 @@ import java.util.Map;
import java.util.function.ToIntFunction;
import jdk.tools.jlink.internal.Utils;
import jdk.tools.jlink.plugin.Plugin;
import jdk.tools.jlink.plugin.ResourcePool;
import jdk.tools.jlink.plugin.ResourcePoolBuilder;
import jdk.tools.jlink.plugin.ResourcePoolEntry;
@ -46,23 +45,18 @@ import jdk.tools.jlink.plugin.ResourcePoolEntry;
*
* Order Resources plugin
*/
public final class OrderResourcesPlugin implements Plugin {
public static final String NAME = "order-resources";
public final class OrderResourcesPlugin extends AbstractPlugin {
private static final FileSystem JRT_FILE_SYSTEM = Utils.jrtFileSystem();
private final List<ToIntFunction<String>> filters;
private final Map<String, Integer> orderedPaths;
public OrderResourcesPlugin() {
super("order-resources");
this.filters = new ArrayList<>();
this.orderedPaths = new HashMap<>();
}
@Override
public String getName() {
return NAME;
}
static class SortWrapper {
private final ResourcePoolEntry resource;
private final int ordinal;
@ -148,24 +142,14 @@ public final class OrderResourcesPlugin implements Plugin {
return Category.SORTER;
}
@Override
public String getDescription() {
return PluginsResourceBundle.getDescription(NAME);
}
@Override
public boolean hasArguments() {
return true;
}
@Override
public String getArgumentsDescription() {
return PluginsResourceBundle.getArgument(NAME);
}
@Override
public void configure(Map<String, String> config) {
List<String> patterns = Utils.parseList(config.get(NAME));
List<String> patterns = Utils.parseList(config.get(getName()));
int ordinal = 0;
for (String pattern : patterns) {

View File

@ -33,6 +33,7 @@ public final class PluginsResourceBundle {
static final String DESCRIPTION = "description";
static final String ARGUMENT = "argument";
static final String USAGE = "usage";
private static final ResourceBundle pluginsBundle;
static {
@ -57,6 +58,10 @@ public final class PluginsResourceBundle {
return getMessage(name + "." + DESCRIPTION, name);
}
public static String getUsage(String name) {
return getMessage(name + "." + USAGE, name);
}
public static String getOption(String name, String option) {
return getMessage(name + "." + option);
}

View File

@ -44,32 +44,24 @@ import jdk.tools.jlink.plugin.ResourcePool;
import jdk.tools.jlink.plugin.ResourcePoolBuilder;
import jdk.tools.jlink.plugin.ResourcePoolEntry;
import jdk.tools.jlink.plugin.ResourcePoolModule;
import jdk.tools.jlink.plugin.Plugin;
/**
* This plugin adds/deletes information for 'release' file.
*/
public final class ReleaseInfoPlugin implements Plugin {
public final class ReleaseInfoPlugin extends AbstractPlugin {
// option name
public static final String NAME = "release-info";
public static final String KEYS = "keys";
private final Map<String, String> release = new HashMap<>();
public ReleaseInfoPlugin() {
super("release-info");
}
@Override
public Category getType() {
return Category.METAINFO_ADDER;
}
@Override
public String getName() {
return NAME;
}
@Override
public String getDescription() {
return PluginsResourceBundle.getDescription(NAME);
}
@Override
public Set<State> getState() {
return EnumSet.of(State.AUTO_ENABLED, State.FUNCTIONAL);
@ -80,14 +72,9 @@ public final class ReleaseInfoPlugin implements Plugin {
return true;
}
@Override
public String getArgumentsDescription() {
return PluginsResourceBundle.getArgument(NAME);
}
@Override
public void configure(Map<String, String> config) {
String operation = config.get(NAME);
String operation = config.get(getName());
if (operation == null) {
return;
}
@ -101,7 +88,7 @@ public final class ReleaseInfoPlugin implements Plugin {
// and put whatever value that was passed in command line.
config.keySet().stream()
.filter(s -> !NAME.equals(s))
.filter(s -> !getName().equals(s))
.forEach(s -> release.put(s, config.get(s)));
}
break;

View File

@ -56,7 +56,6 @@ import jdk.internal.jimage.decompressor.CompressIndexes;
import jdk.internal.jimage.decompressor.SignatureParser;
import jdk.internal.jimage.decompressor.StringSharingDecompressor;
import jdk.tools.jlink.internal.ResourcePoolManager.ResourcePoolImpl;
import jdk.tools.jlink.plugin.Plugin;
import jdk.tools.jlink.plugin.PluginException;
import jdk.tools.jlink.plugin.ResourcePool;
import jdk.tools.jlink.plugin.ResourcePoolBuilder;
@ -70,9 +69,7 @@ import jdk.tools.jlink.internal.StringTable;
* A Plugin that stores the image classes constant pool UTF_8 entries into the
* Image StringsTable.
*/
public class StringSharingPlugin implements Plugin, ResourcePrevisitor {
public static final String NAME = "compact-cp";
public class StringSharingPlugin extends AbstractPlugin implements ResourcePrevisitor {
private static final int[] SIZES;
@ -340,6 +337,7 @@ public class StringSharingPlugin implements Plugin, ResourcePrevisitor {
}
StringSharingPlugin(Predicate<String> predicate) {
super("compact-cp");
this.predicate = predicate;
}
@ -370,29 +368,14 @@ public class StringSharingPlugin implements Plugin, ResourcePrevisitor {
return result.build();
}
@Override
public String getName() {
return NAME;
}
@Override
public String getDescription() {
return PluginsResourceBundle.getDescription(NAME);
}
@Override
public boolean hasArguments() {
return true;
}
@Override
public String getArgumentsDescription() {
return PluginsResourceBundle.getArgument(NAME);
}
@Override
public void configure(Map<String, String> config) {
predicate = ResourceFilter.includeFilter(config.get(NAME));
predicate = ResourceFilter.includeFilter(config.get(getName()));
}
@Override

View File

@ -28,7 +28,6 @@ import java.util.function.Predicate;
import jdk.internal.org.objectweb.asm.ClassReader;
import jdk.internal.org.objectweb.asm.ClassWriter;
import jdk.tools.jlink.plugin.Plugin;
import jdk.tools.jlink.plugin.ResourcePool;
import jdk.tools.jlink.plugin.ResourcePoolBuilder;
import jdk.tools.jlink.plugin.ResourcePoolEntry;
@ -37,8 +36,7 @@ import jdk.tools.jlink.plugin.ResourcePoolEntry;
*
* Strip java debug attributes plugin
*/
public final class StripJavaDebugAttributesPlugin implements Plugin {
public static final String NAME = "strip-java-debug-attributes";
public final class StripJavaDebugAttributesPlugin extends AbstractPlugin {
private final Predicate<String> predicate;
public StripJavaDebugAttributesPlugin() {
@ -46,19 +44,10 @@ public final class StripJavaDebugAttributesPlugin implements Plugin {
}
StripJavaDebugAttributesPlugin(Predicate<String> predicate) {
super("strip-java-debug-attributes");
this.predicate = predicate;
}
@Override
public String getName() {
return NAME;
}
@Override
public String getDescription() {
return PluginsResourceBundle.getDescription(NAME);
}
@Override
public ResourcePool transform(ResourcePool in, ResourcePoolBuilder out) {
//remove *.diz files as well as debug attributes.

View File

@ -27,19 +27,15 @@ package jdk.tools.jlink.internal.plugins;
import jdk.tools.jlink.plugin.ResourcePool;
import jdk.tools.jlink.plugin.ResourcePoolBuilder;
import jdk.tools.jlink.plugin.ResourcePoolEntry;
import jdk.tools.jlink.plugin.Plugin;
/**
*
* Strip Native Commands plugin
*/
public final class StripNativeCommandsPlugin implements Plugin {
public final class StripNativeCommandsPlugin extends AbstractPlugin {
public static final String NAME = "strip-native-commands";
@Override
public String getName() {
return NAME;
public StripNativeCommandsPlugin() {
super("strip-native-commands");
}
@Override
@ -55,9 +51,4 @@ public final class StripNativeCommandsPlugin implements Plugin {
return out.build();
}
@Override
public String getDescription() {
return PluginsResourceBundle.getDescription(NAME);
}
}

View File

@ -78,7 +78,6 @@ import jdk.internal.org.objectweb.asm.Opcodes;
import static jdk.internal.org.objectweb.asm.Opcodes.*;
import jdk.tools.jlink.internal.ModuleSorter;
import jdk.tools.jlink.plugin.Plugin;
import jdk.tools.jlink.plugin.PluginException;
import jdk.tools.jlink.plugin.ResourcePool;
import jdk.tools.jlink.plugin.ResourcePoolBuilder;
@ -97,10 +96,7 @@ import jdk.tools.jlink.plugin.ResourcePoolEntry;
* @see jdk.internal.module.SystemModules
*/
public final class SystemModulesPlugin implements Plugin {
private static final String NAME = "system-modules";
private static final String DESCRIPTION =
PluginsResourceBundle.getDescription(NAME);
public final class SystemModulesPlugin extends AbstractPlugin {
private static final String SYSTEM_MODULES_MAP_CLASS =
"jdk/internal/module/SystemModulesMap";
private static final String SYSTEM_MODULES_CLASS_PREFIX =
@ -113,19 +109,10 @@ public final class SystemModulesPlugin implements Plugin {
private boolean enabled;
public SystemModulesPlugin() {
super("system-modules");
this.enabled = true;
}
@Override
public String getName() {
return NAME;
}
@Override
public String getDescription() {
return DESCRIPTION;
}
@Override
public Set<State> getState() {
return enabled ? EnumSet.of(State.AUTO_ENABLED, State.FUNCTIONAL)
@ -137,23 +124,18 @@ public final class SystemModulesPlugin implements Plugin {
return true;
}
@Override
public String getArgumentsDescription() {
return PluginsResourceBundle.getArgument(NAME);
}
@Override
public void configure(Map<String, String> config) {
String arg = config.get(NAME);
String arg = config.get(getName());
if (arg != null) {
throw new IllegalArgumentException(NAME + ": " + arg);
throw new IllegalArgumentException(getName() + ": " + arg);
}
}
@Override
public ResourcePool transform(ResourcePool in, ResourcePoolBuilder out) {
if (!enabled) {
throw new PluginException(NAME + " was set");
throw new PluginException(getName() + " was set");
}
// validate, transform (if needed), and add the module-info.class files

View File

@ -32,7 +32,6 @@ import jdk.internal.org.objectweb.asm.ClassVisitor;
import jdk.internal.org.objectweb.asm.ClassWriter;
import jdk.internal.org.objectweb.asm.MethodVisitor;
import jdk.internal.org.objectweb.asm.Opcodes;
import jdk.tools.jlink.plugin.Plugin;
import jdk.tools.jlink.plugin.ResourcePool;
import jdk.tools.jlink.plugin.ResourcePoolBuilder;
import jdk.tools.jlink.plugin.ResourcePoolEntry;
@ -45,12 +44,11 @@ import jdk.tools.jlink.plugin.ResourcePoolEntry;
* We assume that the initialization code only has ldcs, method calls and
* field instructions.
*/
abstract class VersionPropsPlugin implements Plugin {
abstract class VersionPropsPlugin extends AbstractPlugin {
private static final String VERSION_PROPS_CLASS
= "/java.base/java/lang/VersionProps.class";
private final String name;
private final String field;
private String value;
@ -59,8 +57,8 @@ abstract class VersionPropsPlugin implements Plugin {
* @param option The option name
*/
protected VersionPropsPlugin(String field, String option) {
super(option);
this.field = field;
this.name = option;
}
/**
@ -73,16 +71,6 @@ abstract class VersionPropsPlugin implements Plugin {
this(field, field.toLowerCase().replace('_', '-'));
}
@Override
public String getName() {
return name;
}
@Override
public String getDescription() {
return PluginsResourceBundle.getDescription(name);
}
@Override
public Category getType() {
return Category.TRANSFORMER;
@ -98,14 +86,9 @@ abstract class VersionPropsPlugin implements Plugin {
return true;
}
@Override
public String getArgumentsDescription() {
return PluginsResourceBundle.getArgument(name);
}
@Override
public void configure(Map<String, String> config) {
var v = config.get(name);
var v = config.get(getName());
if (v == null)
throw new AssertionError();
value = v;

View File

@ -36,19 +36,17 @@ import jdk.tools.jlink.internal.ResourcePoolManager.ResourcePoolImpl;
import jdk.tools.jlink.plugin.ResourcePool;
import jdk.tools.jlink.plugin.ResourcePoolBuilder;
import jdk.tools.jlink.plugin.ResourcePoolEntry;
import jdk.tools.jlink.plugin.Plugin;
/**
*
* ZIP Compression plugin
*/
public final class ZipPlugin implements Plugin {
public final class ZipPlugin extends AbstractPlugin {
public static final String NAME = "zip";
private Predicate<String> predicate;
public ZipPlugin() {
this((Predicate<String>) null);
}
ZipPlugin(String[] patterns) {
@ -56,37 +54,23 @@ public final class ZipPlugin implements Plugin {
}
ZipPlugin(Predicate<String> predicate) {
super("zip");
this.predicate = predicate;
}
@Override
public String getName() {
return NAME;
}
@Override
public Category getType() {
return Category.COMPRESSOR;
}
@Override
public String getDescription() {
return PluginsResourceBundle.getDescription(NAME);
}
@Override
public boolean hasArguments() {
return false;
}
@Override
public String getArgumentsDescription() {
return PluginsResourceBundle.getArgument(NAME);
}
@Override
public void configure(Map<String, String> config) {
predicate = ResourceFilter.includeFilter(config.get(NAME));
predicate = ResourceFilter.includeFilter(config.get(getName()));
}
static byte[] compress(byte[] bytesIn) {

View File

@ -124,6 +124,14 @@ public interface Plugin {
return "";
}
/**
* The plugin usage for printing to console.
* @return The usage.
*/
public default String getUsage() {
return "";
}
/**
* The option that identifies this plugin. This may be null.
* "--" is prefixed to the String (when non-null) when invoking

View File

@ -30,6 +30,11 @@ Prepend the specified <options> string, which may include\n\
whitespace, before any other options when invoking the virtual machine\n\
in the resulting image.
add-options.usage=\
\ --add-options <options> Prepend the specified <options> string, which may\n\
\ include whitespace, before any other options when\n\
\ invoking the virtual machine in the resulting image.
release-info.argument=<file>|add:<key1>=<value1>:<key2>=<value2>:...|del:<key list>
release-info.description=\
@ -38,11 +43,22 @@ add: is to add properties to the 'release' file.\n\
Any number of <key>=<value> pairs can be passed.\n\
del: is to delete the list of keys in release file.
release-info.usage=\
\ --release-info <file>|add:<key1>=<value1>:<key2>=<value2>:...|del:<key list>\n\
\ <file> option is to load release properties from\n\
\ the supplied file.\n\
\ add: is to add properties to the 'release' file.\n\
\ Any number of <key>=<value> pairs can be passed.\n\
\ del: is to delete the list of keys in release file.
class-for-name.argument=
class-for-name.description=\
Class optimization: convert Class.forName calls to constant loads.
class-for-name.usage=\
\ --class-for-name Class optimization: convert Class.forName calls to constant loads.
compress.argument=<0|1|2>[:filter=<pattern-list>]
compress.description=\
@ -53,12 +69,29 @@ Level 2: ZIP.\n\
An optional <pattern-list> filter can be specified to list the pattern of\n\
files to be included.
compress.usage=\
\ --compress <0|1|2>[:filter=<pattern-list>]\n\
\ Compress all resources in the output image.\n\
\ Level 0: No compression\n\
\ Level 1: Constant string sharing\n\
\ Level 2: ZIP.\n\
\ An optional <pattern-list> filter can be\n\
\ specified to list the pattern of \n\
\ files to be included.
compact-cp.argument=<resource paths>
compact-cp.description=Constant Pool strings sharing.\n\
By default, all resources are compressed. You can express the set \n\
of resources to compress or not compress (use ^ for negation).
compact-cp.usage=\
\ --compact-cp <resource paths>\n\
\ Constant Pool strings sharing.\n\
\ By default, all resources are compressed.\n\
\ You can express the set of resources to\n\
\ compress or not compress (use ^ for negation).
dedup-legal-notices.argument=[error-if-not-same-content]
dedup-legal-notices.description=\
@ -66,22 +99,44 @@ De-duplicate all legal notices. If error-if-not-same-content is\n\
specified then it will be an error if two files of the same filename\n\
are different.
dedup-legal-notices.usage=\
\ --dedup-legal-notices [error-if-not-same-content]\n\
\ De-duplicate all legal notices.\n\
\ If error-if-not-same-content is specified then\n\
\ it will be an error if two files of the same\n\
\ filename are different.
exclude-files.argument=<pattern-list> of files to exclude
exclude-files.description=\
Specify files to exclude. e.g.: **.java,glob:/java.base/lib/client/**
exclude-files.usage=\
\ --exclude-files <pattern-list>\n\
\ Specify files to exclude.\n\
\ e.g.: **.java,glob:/java.base/lib/client/**
exclude-resources.argument=<pattern-list> resources to exclude
exclude-resources.description=\
Specify resources to exclude. e.g.: **.jcov,glob:**/META-INF/**
exclude-resources.usage=\
\ --exclude-resources <pattern-list>\n\
\ Specify resources to exclude.\n\
\ e.g.: **.jcov,glob:**/META-INF/**
exclude-jmod-section.argument=<section-name>\n\
where <section-name> is \"man\" or \"headers".
exclude-jmod-section.description=\
Specify a JMOD section to exclude
exclude-jmod-section.usage=\
\ --exclude-jmod-section <section-name>\n\
\ Specify a JMOD section to exclude.\n\
\ Where <section-name> is \"man\" or \"headers\".
generate-jli-classes.argument=@filename
generate-jli-classes.description=\
@ -91,10 +146,25 @@ If this plugin runs on a different runtime version than the image being \n\
created then code generation will be disabled by default to guarantee \n\
correctness - add ignore-version=true to override this.
generate-jli-classes.usage=\
\ --generate-jli-classes @filename\n\
\ Specify a file listing the java.lang.invoke\n\
\ classes to pre-generate. By default, this plugin\n\
\ may use a builtin list of classes to pre-generate.\n\
\ If this plugin runs on a different runtime version\n\
\ than the image being created then code generation\n\
\ will be disabled by default to guarantee \n\
\ correctness add ignore-version=true\n\
\ to override this.
system-modules.argument=retainModuleTarget
system-modules.description=Fast loading of module descriptors (always enabled)
system-modules.usage=\
\ --system-modules retainModuleTarget\n\
\ Fast loading of module descriptors (always enabled)
onoff.argument=<on|off>
order-resources.argument=<pattern-list> of paths in priority order. If a @file\n\
@ -103,42 +173,87 @@ is specified, then each line should be an exact match for the path to be ordered
order-resources.description=\
Order resources. e.g.: **/module-info.class,@classlist,/java.base/java/lang/**
order-resources.usage=\
\ --order-resources <pattern-list>\n\
\ Order resources. \n\
\ e.g.: **/module-info.class,@classlist,\n\
\ /java.base/java/lang/**
strip-debug.description=\
Strip debug information from the output image
strip-debug.usage=\
\ --strip-debug Strip debug information from the output image
strip-java-debug-attributes.description=\
Strip Java debug attributes from classes in the output image
strip-java-debug-attributes.usage=\
\ --strip-java-debug-attributes \n\
\ Strip Java debug attributes from\n\
\ classes in the output image
strip-native-commands.description=\
Exclude native commands (such as java/java.exe) from the image
strip-native-commands.usage=\
\ --strip-native-commands Exclude native commands (such as java/java.exe)\n\
\ from the image.
vendor-version.argument=<vendor-version>
vendor-version.description=\
Override the vendor version string baked into the build, if any.\n\
The value of the system property "java.vendor.version" will be <vendor-version>.
vendor-version.usage=\
\ --vendor-version <vendor-version>\n\
\ Override the vendor version string baked into the\n\
\ build,if any. The value of the system property\n\
\ "java.vendor.version" will be <vendor-version>.
vendor-bug-url.argument=<vendor-bug-url>
vendor-bug-url.description=\
Override the vendor bug URL baked into the build. The value\n\
of the system property "java.vendor.url.bug" will be <vendor-url-bug>.
vendor-bug-url.usage=\
\ --vendor-bug-url <vendor-bug-url>\n\
\ Override the vendor bug URL baked into the build.\n\
\ The value of the system property\n\
\ "java.vendor.url.bug" will be <vendor-url-bug>.
vendor-vm-bug-url.argument=<vendor-vm-bug-url>
vendor-vm-bug-url.description=\
Override the vendor VM bug URL baked into the build. The URL\n\
displayed in VM error logs will be <vendor-vm-bug-url>.
vendor-vm-bug-url.usage=\
\ --vendor-vm-bug-url <vendor-vm-bug-url>\n\
\ Override the vendor VM bug URL baked \n\
\ into the build. The URL displayed in VM error\n\
\ logs will be <vendor-vm-bug-url>.
vm.argument=<client|server|minimal|all>
vm.description=\
Select the HotSpot VM in the output image. Default is all
vm.usage=\
\ --vm <client|server|minimal|all>\n\
\ Select the HotSpot VM in the output image.\n\
\ Default is all
zip.argument=[comma separated list of resource paths]
zip.description=ZIP Compression
zip.usage=\
\ --zip [comma separated list of resource paths]\n\
\ ZIP Compression
include-locales.argument=\
<langtag>[,<langtag>]*
@ -146,6 +261,13 @@ include-locales.description=\
BCP 47 language tags separated by a comma, allowing locale matching\n\
defined in RFC 4647. e.g.: en,ja,*-IN
include-locales.usage=\
\ --include-locales <langtag>[,<langtag>]*\n\
\ BCP 47 language tags separated by a comma,\n\
\ allowing\n\
\ locale matching defined in RFC 4647.\n\
\ e.g.: en,ja,*-IN
include-locales.missingpackages=\
Missing locale data packages in jdk.localedata:\n\t

View File

@ -168,16 +168,20 @@ public class IntegrationTest {
//Strip debug
{
Map<String, String> config1 = new HashMap<>();
config1.put(DefaultStripDebugPlugin.NAME, "");
Plugin strip = Jlink.newPlugin("strip-debug", config1, null);
config1.put(strip.getName(), "");
lst.add(strip);
}
// compress
{
Map<String, String> config1 = new HashMap<>();
config1.put(DefaultCompressPlugin.NAME, "2");
String pluginName = "compress";
config1.put(pluginName, "2");
Plugin compress
= Jlink.newPlugin("compress", config1, null);
= Jlink.newPlugin(pluginName, config1, null);
if(!pluginName.equals(compress.getName())) {
throw new AssertionError("compress plugin name doesn't match test constant");
}
lst.add(compress);
}
// Post processor

View File

@ -32,6 +32,8 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.spi.ToolProvider;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.Stream;
import jdk.tools.jlink.plugin.Plugin;
@ -243,13 +245,22 @@ public class JLinkTest {
JLINK_TOOL.run(pw, pw, "--list-plugins");
String output = writer.toString();
long number = Stream.of(output.split("\\R"))
.filter((s) -> s.matches("Plugin Name:.*"))
.count();
List<String> commands = Stream.of(output.split("\\R"))
.filter((s) -> s.matches(" --.*"))
.collect(Collectors.toList());
int number = commands.size();
if (number != totalPlugins) {
System.err.println(output);
throw new AssertionError("Found: " + number + " expected " + totalPlugins);
}
boolean isSorted = IntStream.range(1, number)
.allMatch((int index) -> commands.get(index).compareTo(commands.get(index - 1)) >= 0);
if(!isSorted) {
throw new AssertionError("--list-plugins not presented in alphabetical order");
}
}
// filter out files and resources + Skip debug + compress

View File

@ -69,8 +69,8 @@ public class ExcludeFilesPluginTest {
public void checkFiles(String s, String sample, String module, boolean exclude) throws Exception {
Map<String, String> prop = new HashMap<>();
prop.put(ExcludeFilesPlugin.NAME, s);
ExcludeFilesPlugin fplug = new ExcludeFilesPlugin();
prop.put(fplug.getName(), s);
fplug.configure(prop);
ResourcePoolManager files = new ResourcePoolManager();
ResourcePoolManager fresult = new ResourcePoolManager();

View File

@ -56,8 +56,8 @@ public class ExcludeModuleInfoTest {
public void check(String s, String sample) throws Exception {
Map<String, String> prop = new HashMap<>();
prop.put(ExcludePlugin.NAME, s);
ExcludePlugin excludePlugin = new ExcludePlugin();
prop.put(excludePlugin.getName(), s);
excludePlugin.configure(prop);
ResourcePoolManager resourcesMgr = new ResourcePoolManager();
ResourcePoolEntry resource = ResourcePoolEntry.create(sample, new byte[0]);

View File

@ -74,8 +74,8 @@ public class ExcludePluginTest {
public void check(String s, String sample, boolean exclude) throws Exception {
Map<String, String> prop = new HashMap<>();
prop.put(ExcludePlugin.NAME, s);
ExcludePlugin excludePlugin = new ExcludePlugin();
prop.put(excludePlugin.getName(), s);
excludePlugin.configure(prop);
ResourcePoolManager resourcesMgr = new ResourcePoolManager();
ResourcePoolEntry resource = ResourcePoolEntry.create(sample, new byte[0]);

View File

@ -187,7 +187,7 @@ public class ExcludeVMPluginTest {
Plugin p = new ExcludeVMPlugin();
Map<String, String> config = new HashMap<>();
if (vm != null) {
config.put(ExcludeVMPlugin.NAME, vm);
config.put(p.getName(), vm);
}
p.configure(config);
ResourcePool out = p.transform(poolMgr.resourcePool(), outMgr.resourcePoolBuilder());

View File

@ -93,7 +93,7 @@ public class OrderResourcesPluginTest {
{
ResourcePoolManager out = new ResourcePoolManager();
Map<String, String> config = new HashMap<>();
config.put(OrderResourcesPlugin.NAME, "/zazou/**,**/module-info.class");
config.put("order-resources", "/zazou/**,**/module-info.class");
Plugin p = new OrderResourcesPlugin();
p.configure(config);
ResourcePool resPool = p.transform(resources.resourcePool(), out.resourcePoolBuilder());
@ -116,7 +116,7 @@ public class OrderResourcesPluginTest {
ResourcePoolManager out = new ResourcePoolManager();
Map<String, String> config = new HashMap<>();
config.put(OrderResourcesPlugin.NAME, "@" + order.getAbsolutePath());
config.put("order-resources", "@" + order.getAbsolutePath());
Plugin p = new OrderResourcesPlugin();
p.configure(config);
ResourcePool resPool = p.transform(resources.resourcePool(), out.resourcePoolBuilder());