RFR: 8279995: jpackage --add-launcher option should allow overriding description [v2]
Alexey Semenyuk
asemenyuk at openjdk.java.net
Fri Feb 11 22:17:09 UTC 2022
On Fri, 11 Feb 2022 21:22:44 GMT, Alexander Matveev <almatvee at openjdk.org> wrote:
>> Added ability to override description for additional launchers via "description" property.
>
> Alexander Matveev has updated the pull request incrementally with one additional commit since the last revision:
>
> 8279995: jpackage --add-launcher option should allow overriding description [v2]
test/jdk/tools/jpackage/helpers/jdk/jpackage/test/AdditionalLauncher.java line 90:
> 88: .findFirst().orElse(null);
> 89:
> 90: return entry == null ? null : entry.getValue();
This can be simply
`rawProperties.stream().findAny(item -> item.getKey().equals(key)).map(e -> e.getValue()).orElse(null);`
Or slightly better:
public String getRawPropertyValue(String key, Supplier<String> getDefault) {
return rawProperties.stream().findAny(item -> item.getKey().equals(key)).map(e -> e.getValue()).orElseGet(getDefault);
}
Then we can create a function that will return the expected description of an additional launcher:
private String getDesciption(JPackageCommand cmd) {
return getRawPropertyValue("description", () -> cmd.getArgumentValue("--description", unused -> "Unknown"));
}
This will let you avoid `if (expectedDescription != null)` checks and **always** verify launcher description.
test/jdk/tools/jpackage/helpers/jdk/jpackage/test/AdditionalLauncher.java line 275:
> 273: expectedDescription.equals(lines.get(i).trim());
> 274: }
> 275: }
This piece of code can be placed in `WindowsHelper.getExecutableDesciption(Path pathToExeFile)` function to make it reusable in other tests if needed. This way it can be used to verify the description of the main launcher.
test/jdk/tools/jpackage/helpers/jdk/jpackage/test/AdditionalLauncher.java line 277:
> 275: }
> 276: }
> 277: TKit.assertTrue(descriptionIsValid, "Invalid file description");
I'd use `TKit.assertEquals()` to compare the expected description with the actual one. This will produce a meaningful error message in log output in case they don't match.
-------------
PR: https://git.openjdk.java.net/jdk/pull/7399
More information about the core-libs-dev
mailing list