Skip to content

Conversation

sashamatveev
Copy link
Member

@sashamatveev sashamatveev commented Sep 26, 2025

  • Added test for custom info plist to cover app image including embedded runtime and runtime installer.
  • Fixed bug in writePList. It was missing writeStartDocument()/writeEndDocument() and DOCTYPE should be full xml string.

Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue

Issue

  • JDK-8362598: [macos] Add tests for custom info plist files (Enhancement - P4)

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/27509/head:pull/27509
$ git checkout pull/27509

Update a local copy of the PR:
$ git checkout pull/27509
$ git pull https://git.openjdk.org/jdk.git pull/27509/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 27509

View PR using the GUI difftool:
$ git pr show -t 27509

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/27509.diff

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Sep 26, 2025

👋 Welcome back almatvee! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@sashamatveev
Copy link
Member Author

@alexeysemenyukoracle Please review.

@openjdk
Copy link

openjdk bot commented Sep 26, 2025

❗ This change is not yet ready to be integrated.
See the Progress checklist in the description for automated requirements.

@openjdk openjdk bot added the core-libs core-libs-dev@openjdk.org label Sep 26, 2025
@openjdk
Copy link

openjdk bot commented Sep 26, 2025

@sashamatveev The following label will be automatically applied to this pull request:

  • core-libs

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command.

@openjdk openjdk bot added the rfr Pull request is ready for review label Sep 26, 2025
@mlbridge
Copy link

mlbridge bot commented Sep 26, 2025

Webrevs

public static void writePList(XMLStreamWriter xml, XmlConsumer content)
throws XMLStreamException, IOException {
xml.writeDTD("plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"https://www.apple.com/DTDs/PropertyList-1.0.dtd\"");
xml.writeStartDocument();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need writeStartDocument()/writeEndDocument() calls?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To write XML declaration to Info.plist file. Without it reading PList file fails.

return (cmd.hasArgument("--mac-signing-key-user-name") || cmd.hasArgument("--mac-app-image-sign-identity"));
}

public static Path createInputRuntimeImage() throws IOException {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not mac-specific helper function. You'd rather move it to JPackageCommand class.

BTW, there is a bunch of createInputRuntimeImage() functions already:

Instead of adding another one, let's consolidate them in one.

private static final String BUNDLE_NAME_RUNTIME = "CustomRuntimeName";

// We do not need full Info.plist for testing
private static String getInfoPListXML(String bundleName) {
Copy link
Member

@alexeysemenyukoracle alexeysemenyukoracle Sep 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use jdk.jpackage.internal.util.XmlUtils.createXml() helper to create xml file. It will format the output xml and will also eliminate the need for the patch in PListWriter class.

Copy link
Member Author

@sashamatveev sashamatveev Sep 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think using PListWriter is more convenient then jdk.jpackage.internal.util.XmlUtils.createXml(). I will prefer to use PListWriter.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not suggesting replacing PListWriter with XmlUtils.createXml(). I'm suggesting replacing XMLOutputFactory.newInstance().createXMLStreamWriter(buf) with XmlUtils.createXml():

private static void savePList(String bundleName, Path plistFile) throws XMLStreamException, IOException {
    XmlUtils.createXml(plistFile, xml -> { 
        writePList(xml, toXmlConsumer(() -> {
            writeDict(xml, toXmlConsumer(() -> {
                writeString(xml, "CFBundleName", bundleName);
                writeString(xml, "CFBundleIdentifier", "CustomInfoPListTest");
                writeString(xml, "CFBundleVersion", "1.0");
            }));
        }));
    });
}

cmd.execute();

MacHelper.withExplodedDmg(cmd, dmgImage -> {
if (dmgImage.endsWith(cmd.name() + ".jdk")) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this test redundant?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. This function is called for all files in DMG such as /Volumes/foo/.background.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, ok. I see this sort of check in 5 locations.

I guess if you replace dmgImage.endsWith(cmd.name() + ".jdk") with dmgImage.endsWith(cmd.appInstallationDirectory().getFileName()) it will become self-explanatory.

@alexeysemenyukoracle
Copy link
Member

In the case of an app bundle, there is a single test case that replaces both the main and the runtime plist files. We need three test cases for better coverage:

  • custom main plist file
  • custom runtime plist file
  • custom main and runtime plist files

The tests don't cover pattern matching in custom plist files. E.g., jpackage will replace DEPLOY_LAUNCHER_NAME pattern in the main plist file with the main launcher name; jpackage will replace CF_BUNDLE_VERSION pattern in the runtime plist file with the app version. We need to test that jpackage replaces these patterns in custom plist files in the same way it does for the default plist files.

@sashamatveev
Copy link
Member Author

8362598: [macos] Add tests for custom info plist files [v3]

  • Test updated to address all comments above.

import java.util.function.Predicate;
import java.util.stream.Stream;

import base.SigningBase;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should result in the following error:

open\test\jdk\tools\jpackage\macosx\SigningRuntimeImagePackageTest.java:29: error: package base does not exist
import base.SigningBase;
           ^
1 error

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed. Not sure why it was added.

@sashamatveev
Copy link
Member Author

8362598: [macos] Add tests for custom info plist files [v5]

  • Test updated after latest merge. It started failing since plistFile.queryValue did not able to find keys stored as value of CustomInfoPListFA. FA extension is xml stored as value of CustomInfoPListFA.

@alexeysemenyukoracle
Copy link
Member

I took the liberty of using your patch as a baseline to improve testing of plist properties, including file associations. Here - #27658. Would you consider pulling it into your PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core-libs core-libs-dev@openjdk.org rfr Pull request is ready for review
Development

Successfully merging this pull request may close these issues.

2 participants