|
| 1 | +/* |
| 2 | + * Copyright (c) 2019, 2021, Oracle and/or its affiliates. All rights reserved. |
| 3 | + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 4 | + * |
| 5 | + * This code is free software; you can redistribute it and/or modify it |
| 6 | + * under the terms of the GNU General Public License version 2 only, as |
| 7 | + * published by the Free Software Foundation. |
| 8 | + * |
| 9 | + * This code is distributed in the hope that it will be useful, but WITHOUT |
| 10 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 11 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 12 | + * version 2 for more details (a copy is included in the LICENSE file that |
| 13 | + * accompanied this code). |
| 14 | + * |
| 15 | + * You should have received a copy of the GNU General Public License version |
| 16 | + * 2 along with this work; if not, write to the Free Software Foundation, |
| 17 | + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
| 18 | + * |
| 19 | + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
| 20 | + * or visit www.oracle.com if you need additional information or have any |
| 21 | + * questions. |
| 22 | + */ |
| 23 | + |
| 24 | +import java.nio.file.Path; |
| 25 | +import jdk.jpackage.test.JPackageCommand; |
| 26 | +import jdk.jpackage.test.PackageTest; |
| 27 | +import jdk.jpackage.test.PackageType; |
| 28 | +import jdk.jpackage.test.MacHelper; |
| 29 | +import jdk.jpackage.test.TKit; |
| 30 | + |
| 31 | +import jdk.jpackage.test.Annotations.Parameter; |
| 32 | +import jdk.jpackage.test.Annotations.Parameters; |
| 33 | +import jdk.jpackage.test.Annotations.Test; |
| 34 | + |
| 35 | +import java.util.Collection; |
| 36 | +import java.util.Arrays; |
| 37 | +import java.util.ArrayList; |
| 38 | +import java.util.List; |
| 39 | + |
| 40 | +/* |
| 41 | + * @test |
| 42 | + * @summary jpackage with --type dmg --mac-dmg-content |
| 43 | + * @library ../helpers |
| 44 | + * @library /test/lib |
| 45 | + * @library base |
| 46 | + * @key jpackagePlatformPackage |
| 47 | + * @build jdk.jpackage.test.* |
| 48 | + * @build DmgContentTest |
| 49 | + * @modules jdk.jpackage/jdk.jpackage.internal |
| 50 | + * @requires (os.family == "mac") |
| 51 | + * @run main/othervm/timeout=360 -Xmx512m jdk.jpackage.test.Main |
| 52 | + * --jpt-run=DmgContentTest |
| 53 | + */ |
| 54 | +public class DmgContentTest { |
| 55 | + |
| 56 | + private static final String TEST_JAVA = TKit.TEST_SRC_ROOT.resolve( |
| 57 | + "apps/PrintEnv.java").toString(); |
| 58 | + private static final String TEST_DUKE = TKit.TEST_SRC_ROOT.resolve( |
| 59 | + "apps/dukeplug.png").toString(); |
| 60 | + private static final String TEST_DIR = TKit.TEST_SRC_ROOT.resolve( |
| 61 | + "apps").toString(); |
| 62 | + private static final String TEST_BAD = TKit.TEST_SRC_ROOT.resolve( |
| 63 | + "non-existant").toString(); |
| 64 | + |
| 65 | + @Parameters |
| 66 | + public static Collection input() { |
| 67 | + List<Object[]> data = new ArrayList<>(); |
| 68 | + data.addAll(List.of(new Object[][] { |
| 69 | + {"0", PackageType.MAC_DMG, new String[] {TEST_JAVA, TEST_DUKE}}, |
| 70 | + {"1", PackageType.MAC_PKG, new String[] {TEST_JAVA, TEST_DUKE}}, |
| 71 | + {"1", PackageType.MAC_DMG, new String[] {TEST_JAVA, TEST_BAD}}, |
| 72 | + {"0", PackageType.MAC_DMG, |
| 73 | + new String[] {TEST_JAVA + "," + TEST_DUKE, TEST_DIR}}})); |
| 74 | + return data; |
| 75 | + } |
| 76 | + |
| 77 | + public DmgContentTest(String expected, PackageType type, String[] content) { |
| 78 | + this.expected = Integer.parseInt(expected); |
| 79 | + this.type = type; |
| 80 | + this.content = content; |
| 81 | + } |
| 82 | + |
| 83 | + @Test |
| 84 | + public void test() { |
| 85 | + new PackageTest() |
| 86 | + .forTypes(type) |
| 87 | + .configureHelloApp() |
| 88 | + .addInitializer(cmd -> { |
| 89 | + for (String arg : content) { |
| 90 | + cmd.addArguments("--mac-dmg-content", arg); |
| 91 | + } |
| 92 | + }) |
| 93 | + .addInstallVerifier(DmgContentTest::verifyDMG) |
| 94 | + .setExpectedExitCode(expected) |
| 95 | + .run(PackageTest.Action.CREATE_AND_UNPACK); |
| 96 | + } |
| 97 | + |
| 98 | + private static void verifyDMG(JPackageCommand cmd) { |
| 99 | + if (cmd.isPackageUnpacked()) { |
| 100 | + Path installDir = cmd.appInstallationDirectory(); |
| 101 | + Path dmgRoot = cmd.pathToUnpackedPackageFile(installDir) |
| 102 | + .toAbsolutePath().getParent(); |
| 103 | + TKit.assertFileExists(dmgRoot.resolve("PrintEnv.java")); |
| 104 | + } |
| 105 | + } |
| 106 | + |
| 107 | + private final int expected; |
| 108 | + private final PackageType type; |
| 109 | + private final String[] content; |
| 110 | + |
| 111 | +} |
0 commit comments