JDK-8294485 : jlink plugin to save the argument files as input to jlink in the output image
  • Type: CSR
  • Component: tools
  • Sub-Component: jlink
  • Priority: P4
  • Status: Closed
  • Resolution: Approved
  • Fix Versions: 20
  • Submitted: 2022-09-27
  • Updated: 2022-10-02
  • Resolved: 2022-10-02
Related Reports
CSR :  
Description
Summary
-------

Add `--save-jlink-argfiles` option to jlink.
 
Problem
-------

The jlink tool can already be used to create a custom run-time image and jlink options such as those added by [JDK-8232080][2] allow for branding the image (e.g. `--vendor-version=AcmeVM 23.4`) and baking in VM options (e.g., `--add-options=-Dacme.version=23.4`).

If the custom run-time image itself includes the `jdk.jlink` module, it can be desirable for such customization to be sticky. That is, it is automatically propagated into images created by the initial custom run-image.

Solution
--------

Define a plugin to implement the desired jlink option persistence.

Specification
-------------

The new jlink plugin will implement the following option:

`--save-jlink-argfiles=<filenames>` saves the contents of `<filenames>` and prepends it as arguments to the execution of jlink in the output image. `<filenames>` is a `:` (`;` on Windows) separated path of [command-line argument files][1].

```
$ jlink --list-plugins
  ...
  --save-jlink-argfiles <filenames>
                            Save the specified argument files that contain
                            the arguments to be prepended to the execution of
                            jlink in the output image. <filenames> is a
                            : (; on Windows) separated list of command-line argument files.
```
Example usage:

```
$ echo "--add-modules jdk.internal.vm.ci --add-options=-Dfoo=xyzzy --vendor-version=\"XyzzyVM 3.14.15\" --vendor-bug-url=https://bugs.xyzzy.com/" > /tmp/jre.argfile
$ export ALL_MODULES=$(java --list-modules | sed 's:@.*::g' | tr '\n' ',')
$ jlink --keep-packaged-modules=/tmp/jre/jmods --add-modules $ALL_MODULES --output=/tmp/jre --save-jlink-argfiles /tmp/jre.argfile @/tmp/jre.argfile
$ /tmp/jre/bin/java -XshowSettings:properties --version 2>&1 | grep yzzy
    foo = xyzzy
    java.vendor.url.bug = https://bugs.xyzzy.com/
    java.vendor.version = XyzzyVM 3.14.15
OpenJDK Runtime Environment XyzzyVM 3.14.15 (build 20-internal-2022-09-22-0951036)
OpenJDK 64-Bit Server VM XyzzyVM 3.14.15 (build 20-internal-2022-09-22-0951036, mixed mode)
$ /tmp/jre/bin/java -d jdk.internal.vm.ci | head -1
jdk.internal.vm.ci@20-internal
$ /tmp/jre/bin/jlink --add-modules=java.base --output=/tmp/jre2 --save-jlink-argfiles /tmp/jre.argfile
Error: --save-jlink-argfiles requires jdk.jlink to be in the output image
$ /tmp/jre/bin/jlink --add-modules=java.base --output=/tmp/jre2
$ /tmp/jre2/bin/java -XshowSettings:properties --version 2>&1 | grep yzzy
    foo = xyzzy
    java.vendor.url.bug = https://bugs.xyzzy.com/
    java.vendor.version = XyzzyVM 3.14.15
OpenJDK Runtime Environment XyzzyVM 3.14.15 (build 20-internal-2022-09-22-0951036.dnsimon...)
OpenJDK 64-Bit Server VM XyzzyVM 3.14.15 (build 20-internal-2022-09-22-0951036.dnsimon..., mixed mode)
$ /tmp/jre2/bin/java -d jdk.internal.vm.ci | head -1
jdk.internal.vm.ci@20-internal
```


  [1]: https://docs.oracle.com/en/java/javase/17/docs/specs/man/java.html#java-command-line-argument-files
  [2]: https://bugs.openjdk.org/browse/JDK-8232080
Comments
Moving to Approved.
02-10-2022

Done and done.
27-09-2022

Can you include the output of `jlink --list-plugins` for this new option in the specification section. Also this plugin should fail if `jdk.jlink` is not linked in the resulting image.
27-09-2022