mirror of
https://github.com/JetBrains/JetBrainsRuntime.git
synced 2025-12-06 01:19:28 +01:00
8321139: jlink's compression plugin doesn't handle -c option correctly
Reviewed-by: jpai, alanb
This commit is contained in:
committed by
Jaikiran Pai
parent
16699a394d
commit
df0165bd69
@@ -362,10 +362,13 @@ public final class TaskHelper {
|
|||||||
|
|
||||||
if (plugin instanceof DefaultCompressPlugin) {
|
if (plugin instanceof DefaultCompressPlugin) {
|
||||||
plugOption
|
plugOption
|
||||||
= new PluginOption(false,
|
= new PluginOption(true,
|
||||||
(task, opt, arg) -> {
|
(task, opt, arg) -> {
|
||||||
Map<String, String> m = addArgumentMap(plugin);
|
Map<String, String> m = addArgumentMap(plugin);
|
||||||
m.put(plugin.getName(), DefaultCompressPlugin.LEVEL_2);
|
String level = (arg != null && !arg.isEmpty())
|
||||||
|
? arg
|
||||||
|
:"zip-6";
|
||||||
|
m.put(plugin.getName(), level);
|
||||||
}, false, "--compress", "-c");
|
}, false, "--compress", "-c");
|
||||||
mainOptions.add(plugOption);
|
mainOptions.add(plugOption);
|
||||||
} else if (plugin instanceof DefaultStripDebugPlugin) {
|
} else if (plugin instanceof DefaultStripDebugPlugin) {
|
||||||
|
|||||||
@@ -61,14 +61,14 @@ Class optimization: convert Class.forName calls to constant loads.
|
|||||||
class-for-name.usage=\
|
class-for-name.usage=\
|
||||||
\ --class-for-name Class optimization: convert Class.forName calls to constant loads.
|
\ --class-for-name Class optimization: convert Class.forName calls to constant loads.
|
||||||
|
|
||||||
compress.argument=<zip-[0-9]>[:filter=<pattern-list>]
|
compress.argument=<zip-'{0-9}'>[:filter=<pattern-list>]
|
||||||
|
|
||||||
compress.description= Compression to use in compressing resources.
|
compress.description= Compression to use in compressing resources.
|
||||||
|
|
||||||
compress.usage=\
|
compress.usage=\
|
||||||
\ --compress <compress> Compression to use in compressing resources:\n\
|
\ --compress <compress> Compression to use in compressing resources:\n\
|
||||||
\ Accepted values are:\n\
|
\ Accepted values are:\n\
|
||||||
\ zip-[0-9], where zip-0 provides no compression,\n\
|
\ zip-'{0-9}', where zip-0 provides no compression,\n\
|
||||||
\ and zip-9 provides the best compression.\n\
|
\ and zip-9 provides the best compression.\n\
|
||||||
\ Default is zip-6.
|
\ Default is zip-6.
|
||||||
|
|
||||||
@@ -307,15 +307,15 @@ plugin.opt.disable-plugin=\
|
|||||||
\ --disable-plugin <pluginname> Disable the plugin mentioned
|
\ --disable-plugin <pluginname> Disable the plugin mentioned
|
||||||
|
|
||||||
plugin.opt.compress=\
|
plugin.opt.compress=\
|
||||||
\ --compress <compress> Compression to use in compressing resources:\n\
|
\ --compress <compress> Compress all resources in the output image:\n\
|
||||||
\ Accepted values are:\n\
|
\ Accepted values are:\n\
|
||||||
\ zip-[0-9], where zip-0 provides no compression,\n\
|
\ zip-'{0-9}', where zip-0 provides no compression,\n\
|
||||||
\ and zip-9 provides the best compression.\n\
|
\ and zip-9 provides the best compression.\n\
|
||||||
\ Default is zip-6.\n\
|
\ Default is zip-6.\n\
|
||||||
\ Deprecated values to be removed in a future release:\n\
|
\ Deprecated values to be removed in a future release:\n\
|
||||||
\ 0: No compression. Equivalent to zip-0.\n\
|
\ 0: No compression. Use zip-0 instead.\n\
|
||||||
\ 1: Constant String Sharing\n\
|
\ 1: Constant String Sharing\n\
|
||||||
\ 2: Equivalent to zip-6.
|
\ 2: ZIP. Use zip-6 instead.
|
||||||
|
|
||||||
plugin.opt.strip-debug=\
|
plugin.opt.strip-debug=\
|
||||||
\ -G, --strip-debug Strip debug information
|
\ -G, --strip-debug Strip debug information
|
||||||
|
|||||||
@@ -64,12 +64,15 @@ Developers are responsible for updating their custom runtime images.
|
|||||||
`--bind-services`
|
`--bind-services`
|
||||||
: Link service provider modules and their dependencies.
|
: Link service provider modules and their dependencies.
|
||||||
|
|
||||||
`-c ={0|1|2}` or `--compress={0|1|2}`
|
`-c zip-{0-9}` or `--compress=zip-{0-9}`
|
||||||
: Enable compression of resources:
|
: Enable compression of resources. The accepted values are:
|
||||||
|
zip-{0-9}, where zip-0 provides no compression,
|
||||||
|
and zip-9 provides the best compression. Default is zip-6.
|
||||||
|
|
||||||
- `0`: No compression
|
: Deprecated values to be removed in a future release:
|
||||||
|
- `0`: No compression. Use zip-0 instead.
|
||||||
- `1`: Constant string sharing
|
- `1`: Constant string sharing
|
||||||
- `2`: ZIP
|
- `2`: ZIP. Use zip-6 instead.
|
||||||
|
|
||||||
`--disable-plugin` *pluginname*
|
`--disable-plugin` *pluginname*
|
||||||
: Disables the specified plug-in. See [jlink Plug-ins] for the list of
|
: Disables the specified plug-in. See [jlink Plug-ins] for the list of
|
||||||
@@ -170,14 +173,18 @@ For a complete list of all available plug-ins, run the command
|
|||||||
### Plugin `compress`
|
### Plugin `compress`
|
||||||
|
|
||||||
Options
|
Options
|
||||||
: `--compress=`{`0`\|`1`\|`2`}\[`:filter=`*pattern-list*\]
|
: `--compress=zip-`{`0`-`9`}\[`:filter=`*pattern-list*\]
|
||||||
|
|
||||||
Description
|
Description
|
||||||
: Compresses all resources in the output image.
|
: Compresses all resources in the output image.
|
||||||
|
Accepted values are:
|
||||||
|
zip-{0-9}, where zip-0 provides no compression,
|
||||||
|
and zip-9 provides the best compression. Default is zip-6.
|
||||||
|
|
||||||
- Level 0: No compression
|
: Deprecated values to be removed in a future release:
|
||||||
|
- Level 0: No compression. Use zip-0 instead.
|
||||||
- Level 1: Constant string sharing
|
- Level 1: Constant string sharing
|
||||||
- Level 2: ZIP
|
- Level 2: ZIP. Use zip-6 instead.
|
||||||
|
|
||||||
An optional *pattern-list* filter can be specified to list the pattern of
|
An optional *pattern-list* filter can be specified to list the pattern of
|
||||||
files to include.
|
files to include.
|
||||||
|
|||||||
@@ -42,10 +42,7 @@ import tests.JImageGenerator;
|
|||||||
/*
|
/*
|
||||||
* @test
|
* @test
|
||||||
* @summary Test image creation
|
* @summary Test image creation
|
||||||
* @bug 8189777
|
* @bug 8189777 8194922 8206962 8240349 8163382 8165735 8166810 8173717 8321139
|
||||||
* @bug 8194922
|
|
||||||
* @bug 8206962
|
|
||||||
* @bug 8240349
|
|
||||||
* @author Jean-Francois Denise
|
* @author Jean-Francois Denise
|
||||||
* @requires (vm.compMode != "Xcomp" & os.maxMemory >= 2g)
|
* @requires (vm.compMode != "Xcomp" & os.maxMemory >= 2g)
|
||||||
* @library ../lib
|
* @library ../lib
|
||||||
@@ -358,6 +355,39 @@ public class JLinkTest {
|
|||||||
helper.generateDefaultImage(userOptions, moduleName).assertFailure("Error: Invalid compression level invalid");
|
helper.generateDefaultImage(userOptions, moduleName).assertFailure("Error: Invalid compression level invalid");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// short command without argument
|
||||||
|
{
|
||||||
|
String[] userOptions = {"-c"};
|
||||||
|
String moduleName = "invalidCompressLevelEmpty";
|
||||||
|
helper.generateDefaultJModule(moduleName, "composite2");
|
||||||
|
helper.generateDefaultImage(userOptions, moduleName).assertFailure("Error: no value given for -c");
|
||||||
|
}
|
||||||
|
|
||||||
|
// invalid short command
|
||||||
|
{
|
||||||
|
String[] userOptions = {"-c", "3", "--output", "image"};
|
||||||
|
String moduleName = "invalidCompressLevel3";
|
||||||
|
helper.generateDefaultJModule(moduleName, "composite2");
|
||||||
|
helper.generateDefaultImage(userOptions, moduleName).assertFailure("Error: Invalid compression level 3");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// invalid argument value
|
||||||
|
{
|
||||||
|
String[] userOptions = {"--compress", "42", "--output", "image"};
|
||||||
|
String moduleName = "invalidCompressLevel42";
|
||||||
|
helper.generateDefaultJModule(moduleName, "composite2");
|
||||||
|
helper.generateDefaultImage(userOptions, moduleName).assertFailure("Error: Invalid compression level 42");
|
||||||
|
}
|
||||||
|
|
||||||
|
// invalid argument value
|
||||||
|
{
|
||||||
|
String[] userOptions = {"--compress", "zip-", "--output", "image"};
|
||||||
|
String moduleName = "invalidCompressLevelZip";
|
||||||
|
helper.generateDefaultJModule(moduleName, "composite2");
|
||||||
|
helper.generateDefaultImage(userOptions, moduleName).assertFailure("Error: Invalid compression level zip-");
|
||||||
|
}
|
||||||
|
|
||||||
// orphan argument - JDK-8166810
|
// orphan argument - JDK-8166810
|
||||||
{
|
{
|
||||||
String[] userOptions = {"--compress", "2", "foo" };
|
String[] userOptions = {"--compress", "2", "foo" };
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ import jdk.tools.jlink.internal.TaskHelper.BadArgs;
|
|||||||
/*
|
/*
|
||||||
* @test
|
* @test
|
||||||
* @summary Test TaskHelper option parsing
|
* @summary Test TaskHelper option parsing
|
||||||
* @bug 8303884
|
* @bug 8303884 8321139
|
||||||
* @modules jdk.jlink/jdk.tools.jlink.internal
|
* @modules jdk.jlink/jdk.tools.jlink.internal
|
||||||
* jdk.jlink/jdk.tools.jlink.plugin
|
* jdk.jlink/jdk.tools.jlink.plugin
|
||||||
* @run junit TaskHelperTest
|
* @run junit TaskHelperTest
|
||||||
@@ -59,19 +59,22 @@ public class TaskHelperTest {
|
|||||||
|
|
||||||
private static final List<Option<TaskHelperTest>> OPTIONS = List.of(
|
private static final List<Option<TaskHelperTest>> OPTIONS = List.of(
|
||||||
new Option<>(true, (task, opt, arg) -> {
|
new Option<>(true, (task, opt, arg) -> {
|
||||||
System.out.println(arg);
|
|
||||||
mainArgValue = arg;
|
mainArgValue = arg;
|
||||||
}, true, "--main-expecting"),
|
}, true, "--main-expecting"),
|
||||||
new Option<>(false, (task, opt, arg) -> {
|
new Option<>(false, (task, opt, arg) -> {
|
||||||
mainFlag = true;
|
mainFlag = true;
|
||||||
}, true, "--main-no-arg")
|
}, true, "--main-no-arg"),
|
||||||
|
new Option<>(true, (task, opt, arg) -> {
|
||||||
|
compressArgValue = (arg != null && !arg.isEmpty()) ? arg : "zip-6";
|
||||||
|
}, "--compress", "-c")
|
||||||
);
|
);
|
||||||
|
|
||||||
private static String argValue;
|
private static String argValue;
|
||||||
private static String mainArgValue;
|
private static String mainArgValue;
|
||||||
private static boolean mainFlag = false;
|
private static boolean mainFlag = false;
|
||||||
|
private static String compressArgValue;
|
||||||
|
|
||||||
public record ArgTestCase(String cmdLine, String[] tokens, String pluginArgValue, String mainArgValue, boolean mainFlagSet) {};
|
public record ArgTestCase(String cmdLine, String[] tokens, String pluginArgValue, String mainArgValue, boolean mainFlagSet) {}
|
||||||
|
|
||||||
public static class TestPluginWithRawOption implements Plugin {
|
public static class TestPluginWithRawOption implements Plugin {
|
||||||
@Override
|
@Override
|
||||||
@@ -118,6 +121,7 @@ public class TaskHelperTest {
|
|||||||
argValue = null;
|
argValue = null;
|
||||||
mainArgValue = null;
|
mainArgValue = null;
|
||||||
mainFlag = false;
|
mainFlag = false;
|
||||||
|
compressArgValue= null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Stream<ArgTestCase> gnuStyleUsages() {
|
public static Stream<ArgTestCase> gnuStyleUsages() {
|
||||||
@@ -217,4 +221,41 @@ public class TaskHelperTest {
|
|||||||
var remaining = optionsHelper.handleOptions(this, args);
|
var remaining = optionsHelper.handleOptions(this, args);
|
||||||
assertEquals(2, remaining.size());
|
assertEquals(2, remaining.size());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
record CompressTestCase(String[] tokens, String expectedCompressValue) {}
|
||||||
|
|
||||||
|
public static Stream<CompressTestCase> compressUsages() {
|
||||||
|
return Stream.of(
|
||||||
|
|
||||||
|
new CompressTestCase(new String[] {"-c", "0"}, "0"),
|
||||||
|
new CompressTestCase(new String[] {"--compress=zip-0"}, "zip-0"),
|
||||||
|
|
||||||
|
new CompressTestCase(new String[] {"-c", "1"}, "1"),
|
||||||
|
new CompressTestCase(new String[] {"--compress=zip-1"}, "zip-1"),
|
||||||
|
|
||||||
|
new CompressTestCase(new String[] {"-c", "2"}, "2"),
|
||||||
|
new CompressTestCase(new String[] {"--compress=zip-2"}, "zip-2"),
|
||||||
|
|
||||||
|
new CompressTestCase(new String[] {"--compress=zip-3"}, "zip-3"),
|
||||||
|
new CompressTestCase(new String[] {"--compress=zip-4"}, "zip-4"),
|
||||||
|
new CompressTestCase(new String[] {"--compress=zip-5"}, "zip-5"),
|
||||||
|
new CompressTestCase(new String[] {"--compress=zip-6"}, "zip-6"),
|
||||||
|
new CompressTestCase(new String[] {"--compress=zip-7"}, "zip-7"),
|
||||||
|
new CompressTestCase(new String[] {"--compress=zip-8"}, "zip-8"),
|
||||||
|
new CompressTestCase(new String[] {"--compress=zip-9"}, "zip-9")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@ParameterizedTest
|
||||||
|
@MethodSource("compressUsages")
|
||||||
|
public void testCompressOptionArg(CompressTestCase testCase) throws TaskHelper.BadArgs, IOException {
|
||||||
|
var remaining = optionsHelper.handleOptions(this, testCase.tokens);
|
||||||
|
|
||||||
|
// trigger Plugin::configure
|
||||||
|
taskHelper.getPluginsConfig(null, null, null);
|
||||||
|
|
||||||
|
assertTrue(remaining.isEmpty());
|
||||||
|
assertEquals(testCase.expectedCompressValue, compressArgValue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -137,7 +137,7 @@ public class TestSetupAOT {
|
|||||||
String jlinkOutput = tmpDir + File.separator + "jlinkOutput";
|
String jlinkOutput = tmpDir + File.separator + "jlinkOutput";
|
||||||
|
|
||||||
execTool("jlink", "--help")
|
execTool("jlink", "--help")
|
||||||
.shouldContain("Compression to use in compressing resources");
|
.shouldContain("Compress all resources in the output image");
|
||||||
execTool("jlink", "--list-plugins")
|
execTool("jlink", "--list-plugins")
|
||||||
.shouldContain("List of available plugins",
|
.shouldContain("List of available plugins",
|
||||||
"--generate-cds-archive ");
|
"--generate-cds-archive ");
|
||||||
|
|||||||
Reference in New Issue
Block a user