author | herrick |
Wed, 16 Oct 2019 10:32:08 -0400 | |
branch | JDK-8200758-branch |
changeset 58648 | 3bf53ffa9ae7 |
parent 58416 | f09bf58c1f17 |
child 58761 | 88e2753a2334 |
permissions | -rw-r--r-- |
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
1 |
/* |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
2 |
* Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved. |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
4 |
* |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
8 |
* |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
13 |
* accompanied this code). |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
14 |
* |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
18 |
* |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
21 |
* questions. |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
22 |
*/ |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
23 |
|
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
24 |
import java.nio.file.Path; |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
25 |
import java.util.HashMap; |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
26 |
import java.util.Map; |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
27 |
import java.util.List; |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
28 |
import java.util.Optional; |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
29 |
import java.lang.invoke.MethodHandles; |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
30 |
import jdk.jpackage.test.HelloApp; |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
31 |
import jdk.jpackage.test.PackageTest; |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
32 |
import jdk.jpackage.test.PackageType; |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
33 |
import jdk.jpackage.test.FileAssociations; |
58648 | 34 |
import jdk.jpackage.test.Annotations.Test; |
58416 | 35 |
import jdk.jpackage.test.TKit; |
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
36 |
|
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
37 |
/** |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
38 |
* Test --add-launcher parameter. Output of the test should be |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
39 |
* additionallauncherstest*.* installer. The output installer should provide the |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
40 |
* same functionality as the default installer (see description of the default |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
41 |
* installer in SimplePackageTest.java) plus install three extra application |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
42 |
* launchers. |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
43 |
*/ |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
44 |
|
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
45 |
/* |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
46 |
* @test |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
47 |
* @summary jpackage with --add-launcher |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
48 |
* @library ../helpers |
58416 | 49 |
* @build jdk.jpackage.test.* |
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
50 |
* @modules jdk.jpackage/jdk.jpackage.internal |
58648 | 51 |
* @compile AdditionalLaunchersTest.java |
52 |
* @run main/othervm/timeout=360 -Xmx512m jdk.jpackage.test.Main |
|
53 |
* --jpt-run=AdditionalLaunchersTest |
|
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
54 |
*/ |
58648 | 55 |
|
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
56 |
public class AdditionalLaunchersTest { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
57 |
|
58648 | 58 |
@Test |
59 |
public void test() { |
|
60 |
FileAssociations fa = new FileAssociations( |
|
61 |
MethodHandles.lookup().lookupClass().getSimpleName()); |
|
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
62 |
|
58648 | 63 |
// Configure a bunch of additional launchers and also setup |
64 |
// file association to make sure it will be linked only to the main |
|
65 |
// launcher. |
|
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
66 |
|
58648 | 67 |
PackageTest packageTest = new PackageTest().configureHelloApp() |
68 |
.addInitializer(cmd -> { |
|
69 |
fa.createFile(); |
|
70 |
cmd.addArguments("--file-associations", fa.getPropertiesFile()); |
|
71 |
cmd.addArguments("--arguments", "Duke", "--arguments", "is", |
|
72 |
"--arguments", "the", "--arguments", "King"); |
|
73 |
}); |
|
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
74 |
|
58648 | 75 |
packageTest.addHelloAppFileAssociationsVerifier(fa); |
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
76 |
|
58648 | 77 |
new AdditionalLauncher("Baz2").setArguments().applyTo(packageTest); |
78 |
new AdditionalLauncher("foo").setArguments("yep!").applyTo(packageTest); |
|
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
79 |
|
58648 | 80 |
AdditionalLauncher barLauncher = new AdditionalLauncher("Bar").setArguments( |
81 |
"one", "two", "three"); |
|
82 |
if (TKit.isLinux()) { |
|
83 |
barLauncher.setIcon(TKit.TEST_SRC_ROOT.resolve("apps/dukeplug.png")); |
|
84 |
} |
|
85 |
barLauncher.applyTo(packageTest); |
|
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
86 |
|
58648 | 87 |
packageTest.run(); |
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
88 |
} |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
89 |
|
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
90 |
private static Path replaceFileName(Path path, String newFileName) { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
91 |
String fname = path.getFileName().toString(); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
92 |
int lastDotIndex = fname.lastIndexOf("."); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
93 |
if (lastDotIndex != -1) { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
94 |
fname = newFileName + fname.substring(lastDotIndex); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
95 |
} |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
96 |
return path.getParent().resolve(fname); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
97 |
} |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
98 |
|
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
99 |
static class AdditionalLauncher { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
100 |
|
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
101 |
AdditionalLauncher(String name) { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
102 |
this.name = name; |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
103 |
} |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
104 |
|
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
105 |
AdditionalLauncher setArguments(String... args) { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
106 |
arguments = List.of(args); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
107 |
return this; |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
108 |
} |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
109 |
|
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
110 |
AdditionalLauncher setIcon(Path iconPath) { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
111 |
icon = iconPath; |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
112 |
return this; |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
113 |
} |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
114 |
|
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
115 |
void applyTo(PackageTest test) { |
58416 | 116 |
final Path propsFile = TKit.workDir().resolve(name + ".properties"); |
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
117 |
|
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
118 |
test.addInitializer(cmd -> { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
119 |
cmd.addArguments("--add-launcher", String.format("%s=%s", name, |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
120 |
propsFile)); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
121 |
|
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
122 |
Map<String, String> properties = new HashMap<>(); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
123 |
if (arguments != null) { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
124 |
properties.put("arguments", String.join(" ", |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
125 |
arguments.toArray(String[]::new))); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
126 |
} |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
127 |
|
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
128 |
if (icon != null) { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
129 |
properties.put("icon", icon.toAbsolutePath().toString()); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
130 |
} |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
131 |
|
58416 | 132 |
TKit.createPropertiesFile(propsFile, properties); |
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
133 |
}); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
134 |
test.addInstallVerifier(cmd -> { |
58648 | 135 |
Path launcherPath = replaceFileName(cmd.appLauncherPath(), name); |
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
136 |
|
58416 | 137 |
TKit.assertExecutableFileExists(launcherPath); |
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
138 |
|
58648 | 139 |
if (cmd.isFakeRuntime(String.format( |
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
140 |
"Not running %s launcher", launcherPath))) { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
141 |
return; |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
142 |
} |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
143 |
HelloApp.executeAndVerifyOutput(launcherPath, |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
144 |
Optional.ofNullable(arguments).orElse(List.of()).toArray( |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
145 |
String[]::new)); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
146 |
}); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
147 |
test.addUninstallVerifier(cmd -> { |
58648 | 148 |
Path launcherPath = replaceFileName(cmd.appLauncherPath(), name); |
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
149 |
|
58416 | 150 |
TKit.assertPathExists(launcherPath, false); |
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
151 |
}); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
152 |
} |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
153 |
|
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
154 |
private List<String> arguments; |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
155 |
private Path icon; |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
156 |
private final String name; |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
157 |
} |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff
changeset
|
158 |
} |