Use "JOpt Simple" from 
[jdk.internal.joptsimple](https://github.com/openjdk/jdk/tree/master/src/jdk.internal.opt/share/classes/jdk/internal/joptsimple)
 package to parse jpackage command line.

All command-line parsing code is placed in a new "jdk.jpackage.internal.cli" 
package with 92% unit test coverage.

### Error reporting improved

1. In case of multiple command-line errors, all are reported, unlike 
previously, only the first one was reported.

Command line (Windows): 

jpackage --linux-shortcut --mac-package-name foo -p m1 --linux-menu-group grp 
-p m2 --app-image dir

Old error output:

Error: Option [--linux-shortcut] is not valid on this platform


New error output:

Error: Option [--linux-shortcut] is not valid on this platform
Error: Option [--mac-package-name] is not valid on this platform
Error: Option [-p] is not valid with type [exe]
Error: Option [--linux-menu-group] is not valid on this platform


 2. Fix misleading error messages.

Command line (Windows): 

jpackage --input no --main-jar no.jar

Old error output:

jdk.jpackage.internal.model.ConfigException: The configured main jar does not 
exist no.jar in the input directory


New error output:

The value "no" provided for parameter --input is not a directory




### Help output fixed

Options in the original help output were out of order. On macOS, options were 
placed in wrong sections. There were trailing whitespaces. 

The old help output is captured in the cd7bca2bb665556f314170c81129ef53de91f135 
commit.

The reordered and filtered old help output is captured in the 
10dc3792e6896cfa4bbe8693ee33e4c5df45d952 commit.

Help output in this PR is captured in the 
58c2d944e2e14b1cf35786162ad2a5f9a8ccfee6 commit. Use it to see the diff between 
the new and old filtered and reordered help output.

### Functional changes

Old tool provider implementation 
[jdk.jpackage.internal.JPackageToolProvider](https://github.com/openjdk/jdk/blob/5fccabff15ae8bcc3d03156fa331bbc0fefb0cbe/src/jdk.jpackage/share/classes/jdk/jpackage/internal/JPackageToolProvider.java#L48)
 had lousy thread-safety protection that didn't work when multiple instances of 
jpackage tool provider are created and invoked asynchronously. This patch fixes 
this issue. It is safe to invoke the same jpackage tool provider instance 
asynchronously, and also safe to invoke multiple instances of jpackage tool 
provider.

Like other JDK tools, jpackage will print help output if the `-?` option is 
specified on the command line.

In addition to `--option-name <value>` variant to set option value, supports 
`--option-name=<value>`, `-option-name=<value>`, `-option-name <value>` 
variants - courtesy of 
[jdk.internal.joptsimple](https://github.com/openjdk/jdk/tree/master/src/jdk.internal.opt/share/classes/jdk/internal/joptsimple)
 package.

### Misc

All "params"-specific code removed.

The format of the `.jpackage.xml` file has changed: 
- The name of the main launcher is stored as the `@name` attribute of the 
`/jpackage-state/main-launcher` element.
- Child elements of the `/jpackage-state` element with the values of the main 
launcher properties are stored as child elements of the 
`/jpackage-state/main-launcher` element.
- "launcher-as-service" property of an additional launcher is stored as a text 
value of the `/jpackage-state/add-launcher/service` element instead of the 
value of the `/jpackage-state/add-launcher/@service` attribute.

Changes to the format of the `.jpackage.xml` file are to simplify handling of 
properties of additional and the main launcher.

[Autogenerated summary of all recognized options 
(jdk/test/jdk/tools/jpackage/junit/share/jdk.jpackage/jdk/jpackage/internal/cli/jpackage-options.md)](https://github.com/alexeysemenyukoracle/jdk/blob/JDK-8333727/test/jdk/tools/jpackage/junit/share/jdk.jpackage/jdk/jpackage/internal/cli/jpackage-options.md).

### Testing

The same testing as in the https://github.com/openjdk/jdk/pull/19668 PR. 
Additionally, verified no unexpected diffs in the test logs after running all 
jpackage tests.

-------------

Commit messages:
 - Rework ExternalApplication and AppImageFile
 - the cli: after params removed
 - Add test to run multiple instances of jpackage tool provider asynchronously
 - MainResources.properties, MacResources.properties: remove obsolete IDs
 - Remove redundant copy of ObjectMapper.java
 - ErrorTest: follow up for changes in jpackage because of the cli; 
MainResources.properties: remove unused IDs
 - JPackageToolProvider.java: remove
 - Make jtreg tests work with the cli
 - main/Main.java: make it a proxy for the cli's Main
 - *Resources.properties: remove obsolete IDs
 - ... and 30 more: https://git.openjdk.org/jdk/compare/c8f5fd6f...2d975def

Changes: https://git.openjdk.org/jdk/pull/28163/files
  Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=28163&range=00
  Issue: https://bugs.openjdk.org/browse/JDK-8333727
  Stats: 24858 lines in 169 files changed: 18015 ins; 6339 del; 504 mod
  Patch: https://git.openjdk.org/jdk/pull/28163.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/28163/head:pull/28163

PR: https://git.openjdk.org/jdk/pull/28163

Reply via email to