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