author | herrick |
Tue, 01 Oct 2019 18:22:34 -0400 | |
branch | JDK-8200758-branch |
changeset 58434 | b00cbf427368 |
parent 58416 | f09bf58c1f17 |
child 58464 | d82489644b15 |
permissions | -rw-r--r-- |
58113 | 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; |
|
58416 | 28 |
import jdk.jpackage.test.TKit; |
58113 | 29 |
import jdk.jpackage.test.PackageTest; |
30 |
import jdk.jpackage.test.PackageType; |
|
58416 | 31 |
import jdk.jpackage.test.Functional; |
58434
b00cbf427368
8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents:
58416
diff
changeset
|
32 |
import jdk.jpackage.test.JPackageCommand; |
b00cbf427368
8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents:
58416
diff
changeset
|
33 |
import jdk.jpackage.test.Annotations.Parameter; |
58113 | 34 |
|
35 |
/** |
|
36 |
* Test --install-dir parameter. Output of the test should be installdirtest*.* |
|
37 |
* package bundle. The output package should provide the same functionality as |
|
38 |
* the default package but install test application in specified directory. |
|
39 |
* |
|
40 |
* Linux: |
|
41 |
* |
|
42 |
* Application should be installed in /opt/jpackage/installdirtest folder. |
|
43 |
* |
|
44 |
* Mac: |
|
45 |
* |
|
46 |
* Application should be installed in /Applications/jpackage/installdirtest.app |
|
47 |
* folder. |
|
48 |
* |
|
49 |
* Windows: |
|
50 |
* |
|
51 |
* Application should be installed in %ProgramFiles%/TestVendor/InstallDirTest1234 |
|
52 |
* folder. |
|
53 |
*/ |
|
54 |
||
55 |
/* |
|
56 |
* @test |
|
57 |
* @summary jpackage with --install-dir |
|
58 |
* @library ../helpers |
|
58416 | 59 |
* @build jdk.jpackage.test.* |
58434
b00cbf427368
8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents:
58416
diff
changeset
|
60 |
* @compile InstallDirTest.java |
58113 | 61 |
* @modules jdk.jpackage/jdk.jpackage.internal |
58434
b00cbf427368
8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents:
58416
diff
changeset
|
62 |
* @run main/othervm/timeout=360 -Xmx512m jdk.jpackage.test.Main |
b00cbf427368
8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents:
58416
diff
changeset
|
63 |
* --jpt-run=InstallDirTest.testCommon |
b00cbf427368
8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents:
58416
diff
changeset
|
64 |
*/ |
b00cbf427368
8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents:
58416
diff
changeset
|
65 |
|
b00cbf427368
8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents:
58416
diff
changeset
|
66 |
/* |
b00cbf427368
8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents:
58416
diff
changeset
|
67 |
* @test |
b00cbf427368
8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents:
58416
diff
changeset
|
68 |
* @summary jpackage with --install-dir |
b00cbf427368
8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents:
58416
diff
changeset
|
69 |
* @library ../helpers |
b00cbf427368
8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents:
58416
diff
changeset
|
70 |
* @build jdk.jpackage.test.* |
b00cbf427368
8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents:
58416
diff
changeset
|
71 |
* @compile InstallDirTest.java |
b00cbf427368
8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents:
58416
diff
changeset
|
72 |
* @modules jdk.jpackage/jdk.jpackage.internal |
b00cbf427368
8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents:
58416
diff
changeset
|
73 |
* @requires (os.family == "linux") |
b00cbf427368
8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents:
58416
diff
changeset
|
74 |
* @run main/othervm/timeout=360 -Xmx512m jdk.jpackage.test.Main |
b00cbf427368
8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents:
58416
diff
changeset
|
75 |
* --jpt-run=InstallDirTest.testLinuxInvalid,testLinuxUnsupported |
58113 | 76 |
*/ |
77 |
public class InstallDirTest { |
|
78 |
||
58434
b00cbf427368
8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents:
58416
diff
changeset
|
79 |
public static void testCommon() { |
58416 | 80 |
final Map<PackageType, Path> INSTALL_DIRS = Functional.identity(() -> { |
81 |
Map<PackageType, Path> reply = new HashMap<>(); |
|
82 |
reply.put(PackageType.WIN_MSI, Path.of("TestVendor\\InstallDirTest1234")); |
|
83 |
reply.put(PackageType.WIN_EXE, reply.get(PackageType.WIN_MSI)); |
|
84 |
||
85 |
reply.put(PackageType.LINUX_DEB, Path.of("/opt/jpackage")); |
|
86 |
reply.put(PackageType.LINUX_RPM, reply.get(PackageType.LINUX_DEB)); |
|
58113 | 87 |
|
58416 | 88 |
reply.put(PackageType.MAC_PKG, Path.of("/Application/jpackage")); |
89 |
reply.put(PackageType.MAC_DMG, reply.get(PackageType.MAC_PKG)); |
|
58113 | 90 |
|
58416 | 91 |
return reply; |
92 |
}).get(); |
|
58113 | 93 |
|
58434
b00cbf427368
8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents:
58416
diff
changeset
|
94 |
new PackageTest().configureHelloApp() |
b00cbf427368
8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents:
58416
diff
changeset
|
95 |
.addInitializer(cmd -> { |
b00cbf427368
8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents:
58416
diff
changeset
|
96 |
cmd.addArguments("--install-dir", INSTALL_DIRS.get( |
b00cbf427368
8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents:
58416
diff
changeset
|
97 |
cmd.packageType())); |
b00cbf427368
8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents:
58416
diff
changeset
|
98 |
}).run(); |
b00cbf427368
8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents:
58416
diff
changeset
|
99 |
} |
b00cbf427368
8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents:
58416
diff
changeset
|
100 |
|
b00cbf427368
8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents:
58416
diff
changeset
|
101 |
@Parameter("/") |
b00cbf427368
8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents:
58416
diff
changeset
|
102 |
@Parameter(".") |
b00cbf427368
8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents:
58416
diff
changeset
|
103 |
@Parameter("foo") |
b00cbf427368
8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents:
58416
diff
changeset
|
104 |
@Parameter("/opt/foo/.././.") |
b00cbf427368
8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents:
58416
diff
changeset
|
105 |
public static void testLinuxInvalid(String installDir) { |
b00cbf427368
8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents:
58416
diff
changeset
|
106 |
testLinuxBad(installDir, "Invalid installation directory"); |
b00cbf427368
8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents:
58416
diff
changeset
|
107 |
} |
b00cbf427368
8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents:
58416
diff
changeset
|
108 |
|
b00cbf427368
8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents:
58416
diff
changeset
|
109 |
@Parameter("/usr") |
b00cbf427368
8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents:
58416
diff
changeset
|
110 |
@Parameter("/usr/local") |
b00cbf427368
8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents:
58416
diff
changeset
|
111 |
@Parameter("/usr/foo") |
b00cbf427368
8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents:
58416
diff
changeset
|
112 |
public static void testLinuxUnsupported(String installDir) { |
b00cbf427368
8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents:
58416
diff
changeset
|
113 |
testLinuxBad(installDir, "currently unsupported"); |
b00cbf427368
8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents:
58416
diff
changeset
|
114 |
} |
b00cbf427368
8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents:
58416
diff
changeset
|
115 |
|
b00cbf427368
8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents:
58416
diff
changeset
|
116 |
private static void testLinuxBad(String installDir, |
b00cbf427368
8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents:
58416
diff
changeset
|
117 |
String errorMessageSubstring) { |
b00cbf427368
8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents:
58416
diff
changeset
|
118 |
new PackageTest().configureHelloApp() |
b00cbf427368
8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents:
58416
diff
changeset
|
119 |
.setExpectedExitCode(1) |
b00cbf427368
8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents:
58416
diff
changeset
|
120 |
.forTypes(PackageType.LINUX) |
b00cbf427368
8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents:
58416
diff
changeset
|
121 |
.addInitializer(cmd -> { |
b00cbf427368
8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents:
58416
diff
changeset
|
122 |
cmd.addArguments("--install-dir", installDir); |
b00cbf427368
8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents:
58416
diff
changeset
|
123 |
cmd.saveConsoleOutput(true); |
b00cbf427368
8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents:
58416
diff
changeset
|
124 |
}) |
b00cbf427368
8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents:
58416
diff
changeset
|
125 |
.addBundleVerifier((cmd, result) -> { |
b00cbf427368
8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents:
58416
diff
changeset
|
126 |
String errorMessage = JPackageCommand.filterOutput(result. |
b00cbf427368
8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents:
58416
diff
changeset
|
127 |
getOutput().stream()).filter(line -> line.contains( |
b00cbf427368
8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents:
58416
diff
changeset
|
128 |
errorMessageSubstring)).findFirst().orElse(null); |
b00cbf427368
8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents:
58416
diff
changeset
|
129 |
TKit.assertNotNull(errorMessage, String.format( |
b00cbf427368
8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents:
58416
diff
changeset
|
130 |
"Check output contains [%s] substring", |
b00cbf427368
8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents:
58416
diff
changeset
|
131 |
errorMessageSubstring)); |
b00cbf427368
8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents:
58416
diff
changeset
|
132 |
}) |
b00cbf427368
8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents:
58416
diff
changeset
|
133 |
.run(); |
58113 | 134 |
} |
135 |
} |