-
Notifications
You must be signed in to change notification settings - Fork 6.2k
8321139: jlink's man page does not document the --compress option correctly #28359
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
|
👋 Welcome back ammbra! A progress list of the required criteria for merging this PR into |
|
❗ This change is not yet ready to be integrated. |
Webrevs
|
| `-c ={0|1|2}` or `--compress={0|1|2}` | ||
| : Enable compression of resources: | ||
| `-c=zip-[0-9]` or `--compress=zip-[0-9]` | ||
| : Enable compression of resources. The accepted values are: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All good for --compress. Can you double check that -c actually works?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you so much for spotting this! -c does not work and jlink --help command does not list it either. Will remove it from this part.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suspect something has got messed up in the CLI parsing. -c should be the short form of --compress. At this time, -c, with no params, is the equivalent of --compress 2 so we get a confusing warning. As we've found, providing parameters to the short form doesn't seem to work. So I think we need to dig into this more.
Also a comment on the "Deprecated values to be removed in a future release" section. It would be easy to read it that zip-0 and zip-6 are being deprecated. Instead of "Equivalent to zip-0", then maybe we should say "Use zip-0 instead".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So maybe I should investigate first what happened to -c argument and then improve the documentation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would be great, if you have the cycles.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I looked into the issue and provided a fix. Hence I modified the description of this PR and issue related to it. Please let me know if is ok to change the title of the bug and PR as well, to proper reflect the changes introduced. Thank you 🙏 .
|
|
||
| `-c ={0|1|2}` or `--compress={0|1|2}` | ||
| : Enable compression of resources: | ||
| `-c zip-[0-9]` or `--compress=zip-[0-9]` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit - the use of square brackets is usually meant to imply "optional". Here it is mandatory to specify a digit between 0 and 9 following the "zip-" text. Perhaps using angular bracket would be better?
-c zip-<0-9> or --compress=zip-<0-9>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. Thank you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit - the use of square brackets is usually meant to imply "optional". Here it is mandatory to specify a digit between 0 and 9 following the "zip-" text. Perhaps using angular bracket would be better?
Hmmm, square brackets in the shell are a regex indicating a wildcard. I think that [0-9] reads better in the shell/command line context.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No objections from me to let it stay in the current form then.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
{ } is use in some man pages pick one from the items from inside the braces. Maybe zip-{0..9} would work here as the jlink man page already uses [ ] for optional items.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The message showed when running jlink --help option mentions zip-[0-9]. In my current approach, I kept that implementation aligned with what help would show when running the jlink --help command (same approach regarding jlink --list-plugins output).
jlink --help
Possible options include:
--add-modules <mod>[,<mod>...] Root modules to resolve in addition to the
initial modules. <mod> can also be ALL-MODULE-PATH.
--bind-services Link in service provider modules and
their dependencies
--compress <compress> Compression to use in compressing resources:
Accepted values are:
zip-[0-9], where zip-0 provides no compression,
and zip-9 provides the best compression.
Default is zip-6.
Deprecated values to be removed in a future release:
0: No compression. Use zip-0 instead.
1: Constant String Sharing
2: ZIP. Use zip-6 instead.
I did not intervene over the output of jlink -- list-plugins.
jlink --list-plugins
List of available plugins:
--add-options <options> Prepend the specified <options> string, which may
include whitespace before any other options when
invoking the virtual machine in the resulting image.
--compress <compress> Compression to use in compressing resources:
Accepted values are:
zip-[0-9], where zip-0 provides no compression,
and zip-9 provides the best compression.
Default is zip-6.
Given the situations mentioned above, what do you believe to be the best way forward? 🙏
| assertEquals(2, remaining.size()); | ||
| } | ||
|
|
||
| record CompressTestCase(String[] tokens, String expectedCompressValue, boolean expectedMainFlag) {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello Ana, what is the expectedMainFlag meant for? I see that every usage of it initializes it to false.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi Jaikiran,
Thank you for spotting that! I guided myself from the previous tests done there and forgot this parameter. I actually do not need it and will remove it.
| new CompressTestCase(new String[] {"--compress=zip-6"}, "zip-6", false), | ||
| new CompressTestCase(new String[] {"--compress=zip-7"}, "zip-7", false), | ||
| new CompressTestCase(new String[] {"--compress=zip-8"}, "zip-8", false), | ||
| new CompressTestCase(new String[] {"--compress=zip-9"}, "zip-9", false) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think a few negative tests would also be useful. For example, -c 3 --compress=42, --compress=zip- should all fail.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for pointing out that part. I pushed a new commit to cover suggested values and more (I followed the previous example on testing for invalid values 😁).
|
The change overall looks reasonable to me. Given that we ended up fixing the behaviour of My knowledge of this tool is very limited, so please wait for Alan's input before doing the JBS issue change. |
| new CompressTestCase(new String[] {"--compress=zip-10"}, "zip-10") | ||
| ); | ||
|
|
||
| for (var args : invalidOptValues) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit - might be better to rename args to testCase.
| try { | ||
| var remaining = optionsHelper.handleOptions(this, args.tokens); | ||
| assertTrue(remaining.isEmpty()); | ||
| assertEquals(args.expectedCompressValue, compressArgValue); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think these 2 asserts are an oversight. Since we expect optionsHelper.handleOptions(...) to always throw a BadArgs for these invalid option values, we should replace these 2 asserts with a:
fail("processing of " + Arrays.toString(testCase.tokens) + " was expected to fail, but didn't");This will then rightly fail the test if the exception isn't thrown.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To my understanding, for compression plugin the validation of the actual value is performed in DefaultCompressPlugin (
jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/DefaultCompressPlugin.java
Line 118 in d57fc1b
| throw new IllegalArgumentException("Invalid compression level " + level); |
jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/DefaultCompressPlugin.java
Line 115 in d57fc1b
| throw new IllegalArgumentException("Invalid compression level " + level); |
At the moment, optionsHelper.handleOptions seems to set up TaskHelper's internal state and it shouldn't throw exceptions for syntactically correct options. In my opinion, this fix is not that much related to the value allowed, but to the syntax allowed for the option. I noticed that there is another test class JLinkTest that tests for actual values. When I tested locally my build of this modified jlink, for invalid values I did get that IllegalArgumentException.
However, I am very new to the testing framework and am welcoming more thoughts/ideas 🙏 .
| String level = (arg != null && !arg.isEmpty()) | ||
| ? arg | ||
| :"zip-6"; | ||
| m.put(plugin.getName(), level); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for fixing this.
This PR looks into aligning the behavior and documentation for
--compressoption and plugin ofjlink:-c {0|1|2}tojlink, then the tool should process it as when receiving--compress={0|1|2}. As these values are now deprecated, a warning should be issued to the end user.-c zip-[0-9]tojlink, then the tool should process it as when receiving--compress=zip-[0-9].jlinkcommand does not contain either-cor--compresswith a value, the default level selected iszip-6.--compressoption description reflects above behavior and warns that previous compression levels are deprecated to be removed in a future release.--pluginoption description reflects the implementation behavior and warns that previous compression levels are deprecated to be removed in a future release.Some implementation details and choices:
jlinkman page states that the tool supports-c={0|1|2}, I inspired myself on howjavacsupports the shortened options https://docs.oracle.com/en/java/javase/25/docs/specs/man/javac.html#options.-c 0and--compress=0produce the same compression level as ofzip-0, I preferred not to tie the new compression level to the old value for the option. I believe that this approach would make it easier/cleaner to remove the code for the deprecated values (when their time comes).-c 2and--compress=2produce the same compression level as ofzip-6, I preferred not to tie the new compression level to the old value for the option. I believe that this approach would make it easier/cleaner to remove the code for the deprecated values (when their time comes).Progress
Issue
Reviewing
Using
gitCheckout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/28359/head:pull/28359$ git checkout pull/28359Update a local copy of the PR:
$ git checkout pull/28359$ git pull https://git.openjdk.org/jdk.git pull/28359/headUsing Skara CLI tools
Checkout this PR locally:
$ git pr checkout 28359View PR using the GUI difftool:
$ git pr show -t 28359Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/28359.diff
Using Webrev
Link to Webrev Comment