Skip to content
Permalink
Browse files
8218685: jlink --list-plugins needs to be readable and tidy
Reviewed-by: mchung, alanb
  • Loading branch information
Ian Graves authored and Mandy Chung committed Sep 29, 2020
1 parent 2fe0a5d commit 8df3e72cea9217a7a10e2ac4bf4d1501a7fad43c
Showing with 412 additions and 420 deletions.
  1. +18 −43 src/jdk.jlink/linux/classes/jdk/tools/jlink/internal/plugins/StripNativeDebugSymbolsPlugin.java
  2. +18 −0 src/jdk.jlink/linux/classes/jdk/tools/jlink/resources/strip_native_debug_symbols_plugin.properties
  3. +52 −42 src/jdk.jlink/share/classes/jdk/tools/jlink/internal/TaskHelper.java
  4. +87 −0 src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/AbstractPlugin.java
  5. +4 −20 src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/AddResourcePlugin.java
  6. +4 −17 src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/DefaultCompressPlugin.java
  7. +2 −12 src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/DefaultStripDebugPlugin.java
  8. +5 −17 src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/ExcludeFilesPlugin.java
  9. +4 −16 src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/ExcludeJmodSectionPlugin.java
  10. +6 −17 src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/ExcludePlugin.java
  11. +4 −17 src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/ExcludeVMPlugin.java
  12. +3 −21 src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/GenerateJLIClassesPlugin.java
  13. +8 −21 src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/IncludeLocalesPlugin.java
  14. +5 −18 src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/LegalNoticeFilePlugin.java
  15. +3 −19 src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/OrderResourcesPlugin.java
  16. +5 −0 src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/PluginsResourceBundle.java
  17. +7 −20 src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/ReleaseInfoPlugin.java
  18. +3 −20 src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/StringSharingPlugin.java
  19. +2 −13 src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/StripJavaDebugAttributesPlugin.java
  20. +3 −12 src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/StripNativeCommandsPlugin.java
  21. +5 −23 src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/SystemModulesPlugin.java
  22. +3 −20 src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/VersionPropsPlugin.java
  23. +4 −20 src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/ZipPlugin.java
  24. +8 −0 src/jdk.jlink/share/classes/jdk/tools/jlink/plugin/Plugin.java
  25. +122 −0 src/jdk.jlink/share/classes/jdk/tools/jlink/resources/plugins.properties
  26. +7 −3 test/jdk/tools/jlink/IntegrationTest.java
  27. +14 −3 test/jdk/tools/jlink/JLinkTest.java
  28. +1 −1 test/jdk/tools/jlink/plugins/ExcludeFilesPluginTest.java
  29. +1 −1 test/jdk/tools/jlink/plugins/ExcludeModuleInfoTest.java
  30. +1 −1 test/jdk/tools/jlink/plugins/ExcludePluginTest.java
  31. +1 −1 test/jdk/tools/jlink/plugins/ExcludeVMPluginTest.java
  32. +2 −2 test/jdk/tools/jlink/plugins/OrderResourcesPluginTest.java
@@ -45,7 +45,6 @@
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 @@
* 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 StripNativeDebugSymbolsPlugin() {
}

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 ResourcePool transform(ResourcePool in, ResourcePoolBuilder out) {
}

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 Category getType() {
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 void doConfigure(boolean withChecks, Map<String, String> orig) {
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 void doConfigure(boolean withChecks, Map<String, String> orig) {
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 void doConfigure(boolean withChecks, Map<String, String> orig) {
// 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 @@ private void validateStripArg(String stripArg) throws IllegalArgumentException {
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()));
}
}

@@ -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}''
@@ -30,20 +30,22 @@
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.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.HashMap;
import java.util.Map.Entry;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
import java.util.Set;
import java.util.HashSet;
import java.util.List;
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 @@ private void addOrderedPluginOptions(Plugin plugin,
= 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 @@ private void addOrderedPluginOptions(Plugin plugin,
} 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 @@ private PluginsConfiguration getPluginsConfig(Path output, Map<String, String> l
// 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 void listPlugins() {
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());

// 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());
}
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());
}

String option = plugin.getOption();
if (option != null) {
log.println(bundleHelper.getMessage("main.plugin.option")
+ ": --" + plugin.getOption()
+ (plugin.hasArguments()? ("=" + plugin.getArgumentsDescription()) : ""));
}

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());
}

// 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 String version(String key) {

// 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()));
}
}

1 comment on commit 8df3e72

@bridgekeeper

This comment has been minimized.

Copy link

@bridgekeeper bridgekeeper bot commented on 8df3e72 Sep 29, 2020

Please sign in to comment.