Skip to content
Permalink
Browse files
8266179: [macos] jpackage should specify architecture for produced pk…
…g files

Reviewed-by: herrick, kcr, asemenyuk
  • Loading branch information
Alexander Matveev committed May 4, 2021
1 parent d282799 commit 2c53654bf1140c7cd243598ebdbff9ca4b9c54ba
@@ -284,6 +284,8 @@ private void prepareDistributionXMLFile(Map<String, ? super Object> params)
xml.writeStartElement("options");
xml.writeAttribute("customize", "never");
xml.writeAttribute("require-scripts", "false");
xml.writeAttribute("hostArchitectures",
Platform.isArmMac() ? "arm64" : "x86_64");
xml.writeEndElement(); // </options>
xml.writeStartElement("choices-outline");
xml.writeStartElement("line");
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2021, 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
@@ -111,6 +111,10 @@ static boolean isMac() {
return getPlatform() == MAC;
}

static boolean isArmMac() {
return (isMac() && "aarch64".equals(System.getProperty("os.arch")));
}

static boolean isLinux() {
return getPlatform() == LINUX;
}
@@ -0,0 +1,94 @@
/*
* Copyright (c) 2021, 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.
*/

import java.nio.file.Files;
import java.nio.file.Path;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathFactory;
import jdk.jpackage.test.JPackageCommand;
import jdk.jpackage.test.PackageTest;
import jdk.jpackage.test.PackageType;
import jdk.jpackage.test.TKit;
import jdk.jpackage.test.Annotations.Test;

/**
* Test will generation default pkg package and will validate "hostArchitectures"
* attribute in unpacked pkg package inside Distribution file. See JDK-8266179.
*/

/*
* @test
* @summary jpackage test to validate "hostArchitectures" attribute
* @library ../helpers
* @build jdk.jpackage.test.*
* @modules jdk.jpackage/jdk.jpackage.internal
* @compile HostArchPkgTest.java
* @requires (os.family == "mac")
* @key jpackagePlatformPackage
* @run main/othervm/timeout=360 -Xmx512m jdk.jpackage.test.Main
* --jpt-run=HostArchPkgTest
*/
public class HostArchPkgTest {

private static void verifyHostArch(JPackageCommand cmd) throws Exception {
Path distributionFile = cmd.pathToUnpackedPackageFile(Path.of("/"))
.toAbsolutePath()
.getParent()
.resolve("data")
.resolve("Distribution");

DocumentBuilderFactory dbf
= DocumentBuilderFactory.newDefaultInstance();
dbf.setFeature("http://apache.org/xml/features/" +
"nonvalidating/load-external-dtd", false);
DocumentBuilder b = dbf.newDocumentBuilder();
org.w3c.dom.Document doc
= b.parse(Files.newInputStream(distributionFile));

XPath xPath = XPathFactory.newInstance().newXPath();

String v = (String) xPath.evaluate(
"/installer-gui-script/options/@hostArchitectures",
doc, XPathConstants.STRING);

if ("aarch64".equals(System.getProperty("os.arch"))) {
TKit.assertEquals(v, "arm64",
"Check value of \"hostArchitectures\" attribute");
} else {
TKit.assertEquals(v, "x86_64",
"Check value of \"hostArchitectures\" attribute");
}
}

@Test
public static void test() {
new PackageTest()
.forTypes(PackageType.MAC_PKG)
.configureHelloApp()
.addInstallVerifier(HostArchPkgTest::verifyHostArch)
.run(PackageTest.Action.CREATE_AND_UNPACK);
}
}

0 comments on commit 2c53654

Please sign in to comment.