JDK-8342544 : [macos] jpackage test helper should check for both "--app-image" and "--mac-sign" for signing predefined app image case
  • Type: Bug
  • Component: tools
  • Sub-Component: jpackage
  • Affected Version: 20
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2024-10-17
  • Updated: 2024-11-11
  • Resolved: 2024-10-31
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 24
24 b23Fixed
Related Reports
Relates :  
Description
The fragment of JPackageCommand.outputBundle() function at https://github.com/openjdk/jdk/blame/236c71cad9fa269518456c11edcfb353bbfc084d/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/JPackageCommand.java#L402 is as follows:

/**
     * Returns path to output bundle of configured jpackage command.
     *
     * If this is build image command, returns path to application image directory.
     *
     * Special case for masOS. If this is sign app image command, returns value
     * of "--app-image".
     */
    public Path outputBundle() {
        final String bundleName;
        if (isImagePackageType()) {
            if (TKit.isOSX() && hasArgument("--app-image")) {
                return Path.of(getArgumentValue("--app-image", () -> null));
            }
            ...

The javadoc states that if jpackage signs an app image on OSX, the function should return the value of the "--app-image" parameter.

However, the code does not check for the presence of the "--mac-sign" parameter. Instead, it tests for the "--app-image" parameter. Is this a typo?

The changes to JPackageCommand.outputBundle() function were introduced in JDK-8293462 patch.

Should it be like this:
---
if (TKit.isOSX() && hasArgument("--mac-sign")) {
  return getArgumentValue("--app-image", () -> null, Path::of);
}
---
?
Comments
Changeset: 34655c67 Branch: master Author: Alexander Matveev <almatvee@openjdk.org> Date: 2024-10-31 22:18:26 +0000 URL: https://git.openjdk.org/jdk/commit/34655c67a8efe1b8eb83d51a1e0efca10c6603ca
31-10-2024

> In places where our code decides which app image to get (one we just generated or one unpacked from installer package or one we sign in place) JPackageCommand.outputBundle() returns the path to the output bundle. In the case of signing an external app image the output bundle is the external app image referenced in `--app-image`. I don't see why we need an alternative to JPackageCommand.outputBundle(). There is JPackageCommand.unpackedPackageDirectory() to get the path to the directory with the unpacked bundle. Adding additional tests for `--main-jar` and `--module` parameters suggested in my previous comment is excessive because they are mutually exclusive with `--app-image`. It can be as simple as this in JPackageCommand.outputBundle(): --- if (isImagePackageType()) { String dirName; if (!TKit.isOSX()) { dirName = name(); } else if (hasArgument("--app-image") && hasArgument("--mac-sign")) { // Request to sign external app image, not to build a new one dirName = Path.of(getArgumentValue("--app-image")); } else { dirName = dirName + ".app"; } bundleName = dirName; } --- And no need for the new function.
30-10-2024

A pull request was submitted for review. Branch: master URL: https://git.openjdk.org/jdk/pull/21776 Date: 2024-10-29 23:13:21 +0000
29-10-2024

Looks like the jpackage command line resulted in this error was a request to sign an app image specified in `--app-image`. The command line requesting the signing of an existing image should not have `--main-jar` and `--module` parameters. That said the correct branching should be something like this: --- if (isImagePackageType()) { String dirName; if (!TKit.isOSX()) { dirName = name(); } else if (!hasArgument("--main-jar") && !hasArgument("--module") && hasArgument("--app-image") && hasArgument("--mac-sign")) { // Request to sign external app image, not to build a new one dirName = Path.of(getArgumentValue("--app-image")); } else { dirName = dirName + ".app"; } bundleName = dirName; } ---
29-10-2024

SigningAppImageTwoStepsTest and SigningPackageFromTwoStepAppImageTest fails without this workround. java.nio.file.NoSuchFileException: ./SigningAppImageTwoStepsTest.app at java.base/sun.nio.fs.UnixException.translateToIOException(UnixException.java:92) at java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:106) at java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:111) at java.base/sun.nio.fs.UnixFileAttributeViews$Basic.readAttributes(UnixFileAttributeViews.java:56) at java.base/sun.nio.fs.UnixFileSystemProvider.readAttributes(UnixFileSystemProvider.java:163) at java.base/java.nio.file.Files.readAttributes(Files.java:1865) at java.base/java.nio.file.FileTreeWalker.getAttributes(FileTreeWalker.java:220) at java.base/java.nio.file.FileTreeWalker.visit(FileTreeWalker.java:277) at java.base/java.nio.file.FileTreeWalker.walk(FileTreeWalker.java:323) at java.base/java.nio.file.FileTreeIterator.<init>(FileTreeIterator.java:71) at java.base/java.nio.file.Files.walk(Files.java:3923) at java.base/java.nio.file.Files.walk(Files.java:3979) at jdk.jpackage.test.JPackageCommand.lambda$assertFileInAppImage$0(JPackageCommand.java:906) at jdk.jpackage.test.Functional$ThrowingSupplier.lambda$toSupplier$0(Functional.java:71) at jdk.jpackage.test.JPackageCommand.assertFileInAppImage(JPackageCommand.java:908) at jdk.jpackage.test.JPackageCommand.assertFileInAppImage(JPackageCommand.java:893) at jdk.jpackage.test.JPackageCommand.assertAppImageFile(JPackageCommand.java:847) at jdk.jpackage.test.JPackageCommand.assertAppLayout(JPackageCommand.java:817) at jdk.jpackage.test.JPackageCommand.assertImageCreated(JPackageCommand.java:812) at jdk.jpackage.test.JPackageCommand.executeAndAssertImageCreated(JPackageCommand.java:806) at SigningAppImageTwoStepsTest.test(SigningAppImageTwoStepsTest.java:121) java.nio.file.NoSuchFileException: ./SigningPackageFromTwoStepAppImageTest.app at java.base/sun.nio.fs.UnixException.translateToIOException(UnixException.java:92) at java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:106) at java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:111) at java.base/sun.nio.fs.UnixFileAttributeViews$Basic.readAttributes(UnixFileAttributeViews.java:56) at java.base/sun.nio.fs.UnixFileSystemProvider.readAttributes(UnixFileSystemProvider.java:163) at java.base/java.nio.file.Files.readAttributes(Files.java:1865) at java.base/java.nio.file.FileTreeWalker.getAttributes(FileTreeWalker.java:220) at java.base/java.nio.file.FileTreeWalker.visit(FileTreeWalker.java:277) at java.base/java.nio.file.FileTreeWalker.walk(FileTreeWalker.java:323) at java.base/java.nio.file.FileTreeIterator.<init>(FileTreeIterator.java:71) at java.base/java.nio.file.Files.walk(Files.java:3923) at java.base/java.nio.file.Files.walk(Files.java:3979) at jdk.jpackage.test.JPackageCommand.lambda$assertFileInAppImage$0(JPackageCommand.java:906) at jdk.jpackage.test.Functional$ThrowingSupplier.lambda$toSupplier$0(Functional.java:71) at jdk.jpackage.test.JPackageCommand.assertFileInAppImage(JPackageCommand.java:908) at jdk.jpackage.test.JPackageCommand.assertFileInAppImage(JPackageCommand.java:893) at jdk.jpackage.test.JPackageCommand.assertAppImageFile(JPackageCommand.java:847) at jdk.jpackage.test.JPackageCommand.assertAppLayout(JPackageCommand.java:817) at jdk.jpackage.test.JPackageCommand.assertImageCreated(JPackageCommand.java:812) at jdk.jpackage.test.JPackageCommand.executeAndAssertImageCreated(JPackageCommand.java:806) at SigningPackageFromTwoStepAppImageTest.test(SigningPackageFromTwoStepAppImageTest.java:151)
29-10-2024

> We should check for both "--app-image" and "--mac-sign" Great. But right now we don't check for "--mac-sign" at all. I also don't quite understand why on OSX outputBundle() should return a path to the source app image instead of the output app image. What tests would be broken if the implementation was this: --- if (isImagePackageType()) { String dirName = name(); if (TKit.isOSX()) { dirName = dirName + ".app"; } bundleName = dirName; } --- ?
26-10-2024

We should check for both "--app-image" and "--mac-sign" for signing predefined app image case. If checking just for "--mac-signing" we will return "null" for cases when we sign generated app image. So best way to check for both.
26-10-2024