1 /* 2 * Copyright (c) 2018, 2019, 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 java.util.HashMap; 26 import java.util.Map; 27 import java.util.function.Supplier; 28 import jdk.jpackage.test.TKit; 29 import jdk.jpackage.test.PackageTest; 30 import jdk.jpackage.test.PackageType; 31 import jdk.jpackage.test.Functional; 32 import jdk.jpackage.test.JPackageCommand; 33 import jdk.jpackage.test.Annotations.Parameter; 34 35 /** 36 * Test --install-dir parameter. Output of the test should be 37 * commoninstalldirtest*.* package bundle. The output package should provide the 38 * same functionality as the default package but install test application in 39 * specified directory. 40 * 41 * Linux: 42 * 43 * Application should be installed in /opt/jpackage/commoninstalldirtest folder. 44 * 45 * Mac: 46 * 47 * Application should be installed in /Applications/jpackage/commoninstalldirtest.app 48 * folder. 49 * 50 * Windows: 51 * 52 * Application should be installed in %ProgramFiles%/TestVendor/InstallDirTest1234 53 * folder. 54 */ 55 56 /* 57 * @test 58 * @summary jpackage with --install-dir 59 * @library ../helpers 60 * @key jpackagePlatformPackage 61 * @build jdk.jpackage.test.* 62 * @compile InstallDirTest.java 63 * @modules jdk.incubator.jpackage/jdk.incubator.jpackage.internal 64 * @run main/othervm/timeout=540 -Xmx512m jdk.jpackage.test.Main 65 * --jpt-run=InstallDirTest.testCommon 66 */ 67 68 /* 69 * @test 70 * @summary jpackage with --install-dir 71 * @library ../helpers 72 * @key jpackagePlatformPackage 73 * @build jdk.jpackage.test.* 74 * @compile InstallDirTest.java 75 * @modules jdk.incubator.jpackage/jdk.incubator.jpackage.internal 76 * @requires (os.family == "linux") 77 * @requires (jpackage.test.SQETest == null) 78 * @run main/othervm/timeout=360 -Xmx512m jdk.jpackage.test.Main 79 * --jpt-run=InstallDirTest.testLinuxInvalid,testLinuxUnsupported 80 */ 81 public class InstallDirTest { 82 83 public static void testCommon() { 84 final Map<PackageType, Path> INSTALL_DIRS = Functional.identity(() -> { 85 Map<PackageType, Path> reply = new HashMap<>(); 86 reply.put(PackageType.WIN_MSI, Path.of("TestVendor\\InstallDirTest1234")); 87 reply.put(PackageType.WIN_EXE, reply.get(PackageType.WIN_MSI)); 88 89 reply.put(PackageType.LINUX_DEB, Path.of("/opt/jpackage")); 90 reply.put(PackageType.LINUX_RPM, reply.get(PackageType.LINUX_DEB)); 91 92 reply.put(PackageType.MAC_PKG, Path.of("/Applications/jpackage")); 93 94 return reply; 95 }).get(); 96 97 new PackageTest().excludeTypes(PackageType.MAC_DMG).configureHelloApp() 98 .addInitializer(cmd -> { 99 cmd.addArguments("--install-dir", INSTALL_DIRS.get( 100 cmd.packageType())); 101 }).run(); 102 } 103 104 @Parameter("/") 105 @Parameter(".") 106 @Parameter("foo") 107 @Parameter("/opt/foo/.././.") 108 public static void testLinuxInvalid(String installDir) { 109 testLinuxBad(installDir, "Invalid installation directory"); 110 } 111 112 @Parameter("/usr") 113 @Parameter("/usr/local") 114 @Parameter("/usr/foo") 115 public static void testLinuxUnsupported(String installDir) { 116 testLinuxBad(installDir, "currently unsupported"); 117 } 118 119 private static void testLinuxBad(String installDir, 120 String errorMessageSubstring) { 121 new PackageTest().configureHelloApp() 122 .setExpectedExitCode(1) 123 .forTypes(PackageType.LINUX) 124 .addInitializer(cmd -> { 125 cmd.addArguments("--install-dir", installDir); 126 cmd.saveConsoleOutput(true); 127 }) 128 .addBundleVerifier((cmd, result) -> { 129 TKit.assertTextStream(errorMessageSubstring).apply( 130 result.getOutput().stream()); 131 }) 132 .run(); 133 } 134 }