Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,13 @@

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\"");
try {
xml.writeDTD("<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"https://www.apple.com/DTDs/PropertyList-1.0.dtd\">");
} catch (UnsupportedOperationException ex) {
// Silently ignore.
// This would normally be thrown by com.sun.xml.internal.stream.writers.XMLDOMWriterImpl.writeDTD()

Check failure on line 97 in src/jdk.jpackage/share/classes/jdk/jpackage/internal/util/PListWriter.java

View check run for this annotation

openjdk / jcheck-openjdk/jdk-27658

Whitespace error

Column 111: trailing whitespace
// or (presumably) any other DOM tree-backed XML stream writer implementation.

Check failure on line 98 in src/jdk.jpackage/share/classes/jdk/jpackage/internal/util/PListWriter.java

View check run for this annotation

openjdk / jcheck-openjdk/jdk-27658

Whitespace error

Column 90: trailing whitespace
}
xml.writeStartElement("plist");
xml.writeAttribute("version", "1.0");
content.accept(xml);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
*/
package jdk.jpackage.internal.util;

import static jdk.jpackage.internal.util.function.ExceptionBox.rethrowUnchecked;

import java.io.IOException;
import java.io.Writer;
import java.lang.reflect.Proxy;
Expand All @@ -43,6 +45,7 @@
import javax.xml.transform.Source;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMResult;
import javax.xml.transform.stax.StAXResult;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
Expand All @@ -63,8 +66,7 @@ public static XmlConsumer toXmlConsumer(XmlConsumerNoArg xmlConsumer) {
return xml -> xmlConsumer.accept();
}

public static void createXml(Path dstFile, XmlConsumer xmlConsumer) throws
IOException {
public static void createXml(Path dstFile, XmlConsumer xmlConsumer) throws IOException {
XMLOutputFactory xmlFactory = XMLOutputFactory.newInstance();
Files.createDirectories(dstFile.getParent());
try (Writer w = Files.newBufferedWriter(dstFile)) {
Expand All @@ -78,9 +80,28 @@ public static void createXml(Path dstFile, XmlConsumer xmlConsumer) throws
xml.flush();
xml.close();
} catch (XMLStreamException ex) {
throw new IOException(ex);
} catch (IOException ex) {
throw ex;
throw rethrowUnchecked(ex);
}
}

public static void createXml(Node root, XmlConsumer xmlConsumer) throws IOException {
createXml(new DOMResult(root), xmlConsumer);
}

public static DOMResult createXml(XmlConsumer xmlConsumer) throws IOException {
var dom = new DOMResult(initDocumentBuilder().newDocument());
createXml(dom, xmlConsumer);
return dom;
}

public static void createXml(DOMResult dom, XmlConsumer xmlConsumer) throws IOException {
try {
var xml = XMLOutputFactory.newInstance().createXMLStreamWriter(dom);
xmlConsumer.accept(xml);
xml.flush();
xml.close();
} catch (XMLStreamException ex) {
throw rethrowUnchecked(ex);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
/*
* Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package jdk.jpackage.test;

import static java.util.Map.entry;
import static org.junit.jupiter.api.Assertions.assertEquals;

import java.io.IOException;
import java.io.StringReader;
import java.io.UncheckedIOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import jdk.jpackage.internal.util.PListReader;
import jdk.jpackage.internal.util.XmlUtils;
import org.junit.jupiter.api.Test;
import org.w3c.dom.Node;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;

public class MacHelperTest {

@Test
public void test_flatMapPList() {
var props = MacHelper.flatMapPList(new PListReader(createXml(
"<key>AppName</key>",
"<string>Hello</string>",
"<key>AppVersion</key>",
"<real>1.0</real>",
"<key>UserData</key>",
"<dict>",
" <key>Foo</key>",
" <array>",
" <string>Str</string>",
" <array>",
" <string>Another Str</string>",
" <true/>",
" <false/>",
" </array>",
" </array>",
"</dict>",
"<key>Checksum</key>",
"<data>7841ff0076cdde93bdca02cfd332748c40620ce4</data>",
"<key>Plugins</key>",
"<array>",
" <dict>",
" <key>PluginName</key>",
" <string>Foo</string>",
" <key>Priority</key>",
" <integer>13</integer>",
" <key>History</key>",
" <array>",
" <string>New File</string>",
" <string>Another New File</string>",
" </array>",
" </dict>",
" <dict>",
" <key>PluginName</key>",
" <string>Bar</string>",
" <key>Priority</key>",
" <real>23</real>",
" <key>History</key>",
" <array/>",
" </dict>",
" <dict/>",
"</array>"
)));

assertEquals(Map.ofEntries(
entry("/AppName", "Hello"),
entry("/AppVersion", "1.0"),
entry("/UserData/Foo[0]", "Str"),
entry("/UserData/Foo[1][0]", "Another Str"),
entry("/UserData/Foo[1][1]", "true"),
entry("/UserData/Foo[1][2]", "false"),
entry("/Checksum", "7841ff0076cdde93bdca02cfd332748c40620ce4"),
entry("/Plugins[0]/PluginName", "Foo"),
entry("/Plugins[0]/Priority", "13"),
entry("/Plugins[0]/History[0]", "New File"),
entry("/Plugins[0]/History[1]", "Another New File"),
entry("/Plugins[1]/PluginName", "Bar"),
entry("/Plugins[1]/Priority", "23"),
entry("/Plugins[1]/History[]", ""),
entry("/Plugins[2]{}", "")
), props);
}

private static String createPListXml(String ...xml) {
final List<String> content = new ArrayList<>();
content.add("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
content.add("<plist version=\"1.0\">");
content.add("<dict>");
content.addAll(List.of(xml));
content.add("</dict>");
content.add("</plist>");
return String.join("", content.toArray(String[]::new));
}

private static Node createXml(String ...xml) {
try {
return XmlUtils.initDocumentBuilder().parse(new InputSource(new StringReader(createPListXml(xml))));
} catch (IOException ex) {
throw new UncheckedIOException(ex);
} catch (SAXException ex) {
throw new RuntimeException(ex);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ public JPackageCommand setFakeRuntime() {
// an error by PackageTest.
createBulkFile.accept(fakeRuntimeDir.resolve(Path.of("bin", "bulk")));

cmd.addArguments("--runtime-image", fakeRuntimeDir);
cmd.setArgumentValue("--runtime-image", fakeRuntimeDir);
});

return this;
Expand Down Expand Up @@ -363,6 +363,29 @@ public static JPackageCommand helloAppImage(JavaAppDesc javaAppDesc) {
return cmd;
}

public static Path createInputRuntimeImage() throws IOException {

final Path runtimeImageDir;

if (JPackageCommand.DEFAULT_RUNTIME_IMAGE != null) {
runtimeImageDir = JPackageCommand.DEFAULT_RUNTIME_IMAGE;
} else {
runtimeImageDir = TKit.createTempDirectory("runtime-image").resolve("data");

new Executor().setToolProvider(JavaTool.JLINK)
.dumpOutput()
.addArguments(
"--output", runtimeImageDir.toString(),
"--add-modules", "java.desktop",
"--strip-debug",
"--no-header-files",
"--no-man-pages")
.execute();
}

return runtimeImageDir;
}

public JPackageCommand setPackageType(PackageType type) {
verifyMutable();
type.applyTo(this);
Expand Down
Loading