author | herrick |
Fri, 18 Oct 2019 14:14:37 -0400 | |
branch | JDK-8200758-branch |
changeset 58696 | 61c44899b4eb |
parent 58648 | 3bf53ffa9ae7 |
child 58762 | 0fe62353385b |
permissions | -rw-r--r-- |
58113 | 1 |
/* |
2 |
* Copyright (c) 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 |
package jdk.jpackage.test; |
|
24 |
||
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
25 |
import java.awt.Desktop; |
58113 | 26 |
import java.io.File; |
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
27 |
import java.nio.file.Files; |
58113 | 28 |
import java.nio.file.Path; |
58416 | 29 |
import java.util.*; |
58113 | 30 |
import java.util.function.BiConsumer; |
31 |
import java.util.function.Consumer; |
|
32 |
import java.util.function.Supplier; |
|
33 |
import java.util.stream.Collectors; |
|
34 |
import java.util.stream.Stream; |
|
58304 | 35 |
import jdk.jpackage.test.Functional.ThrowingConsumer; |
58696
61c44899b4eb
8223325: Improve wix sources generated by jpackage
herrick
parents:
58648
diff
changeset
|
36 |
import jdk.jpackage.internal.AppImageFile; |
58416 | 37 |
import static jdk.jpackage.test.PackageType.*; |
58113 | 38 |
|
39 |
/** |
|
40 |
* Instance of PackageTest is for configuring and running a single jpackage |
|
41 |
* command to produce platform specific package bundle. |
|
42 |
* |
|
58304 | 43 |
* Provides methods to hook up custom configuration of jpackage command and |
58113 | 44 |
* verification of the output bundle. |
45 |
*/ |
|
46 |
public final class PackageTest { |
|
47 |
||
48 |
/** |
|
49 |
* Default test configuration for jpackage command. Default jpackage command |
|
50 |
* initialization includes: |
|
58147
45a9084fe981
8230521: rename --output/-o option and add default value (".")
herrick
parents:
58113
diff
changeset
|
51 |
* <li>Set --input and --dest parameters. |
58113 | 52 |
* <li>Set --name parameter. Value of the parameter is the name of the first |
53 |
* class with main function found in the callers stack. Defaults can be |
|
54 |
* overridden with custom initializers set with subsequent addInitializer() |
|
55 |
* function calls. |
|
56 |
*/ |
|
57 |
public PackageTest() { |
|
58 |
action = DEFAULT_ACTION; |
|
59 |
forTypes(); |
|
58434
b00cbf427368
8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents:
58417
diff
changeset
|
60 |
setExpectedExitCode(0); |
58113 | 61 |
handlers = new HashMap<>(); |
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
62 |
namedInitializers = new HashSet<>(); |
58113 | 63 |
currentTypes.forEach(v -> handlers.put(v, new Handler(v))); |
64 |
} |
|
65 |
||
66 |
public PackageTest forTypes(PackageType... types) { |
|
67 |
Collection<PackageType> newTypes; |
|
68 |
if (types == null || types.length == 0) { |
|
69 |
newTypes = PackageType.NATIVE; |
|
70 |
} else { |
|
71 |
newTypes = Set.of(types); |
|
72 |
} |
|
73 |
currentTypes = newTypes.stream().filter(type -> type.isSupported()).collect( |
|
74 |
Collectors.toUnmodifiableSet()); |
|
75 |
return this; |
|
76 |
} |
|
77 |
||
78 |
public PackageTest forTypes(Collection<PackageType> types) { |
|
79 |
return forTypes(types.toArray(PackageType[]::new)); |
|
80 |
} |
|
81 |
||
58434
b00cbf427368
8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents:
58417
diff
changeset
|
82 |
public PackageTest setExpectedExitCode(int v) { |
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
83 |
expectedJPackageExitCode = v; |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
84 |
return this; |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
85 |
} |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
86 |
|
58696
61c44899b4eb
8223325: Improve wix sources generated by jpackage
herrick
parents:
58648
diff
changeset
|
87 |
private PackageTest addInitializer(ThrowingConsumer<JPackageCommand> v, |
61c44899b4eb
8223325: Improve wix sources generated by jpackage
herrick
parents:
58648
diff
changeset
|
88 |
String id) { |
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
89 |
if (id != null) { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
90 |
if (namedInitializers.contains(id)) { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
91 |
return this; |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
92 |
} |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
93 |
|
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
94 |
namedInitializers.add(id); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
95 |
} |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
96 |
currentTypes.stream().forEach(type -> handlers.get(type).addInitializer( |
58304 | 97 |
ThrowingConsumer.toConsumer(v))); |
58113 | 98 |
return this; |
99 |
} |
|
100 |
||
58304 | 101 |
public PackageTest addInitializer(ThrowingConsumer<JPackageCommand> v) { |
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
102 |
return addInitializer(v, null); |
58113 | 103 |
} |
104 |
||
105 |
public PackageTest addBundleVerifier( |
|
106 |
BiConsumer<JPackageCommand, Executor.Result> v) { |
|
107 |
currentTypes.stream().forEach( |
|
108 |
type -> handlers.get(type).addBundleVerifier(v)); |
|
109 |
return this; |
|
110 |
} |
|
111 |
||
58304 | 112 |
public PackageTest addBundleVerifier(ThrowingConsumer<JPackageCommand> v) { |
113 |
return addBundleVerifier( |
|
114 |
(cmd, unused) -> ThrowingConsumer.toConsumer(v).accept(cmd)); |
|
58113 | 115 |
} |
116 |
||
117 |
public PackageTest addBundlePropertyVerifier(String propertyName, |
|
118 |
BiConsumer<String, String> pred) { |
|
119 |
return addBundleVerifier(cmd -> { |
|
58416 | 120 |
pred.accept(propertyName, |
121 |
LinuxHelper.getBundleProperty(cmd, propertyName)); |
|
58113 | 122 |
}); |
123 |
} |
|
124 |
||
125 |
public PackageTest addBundlePropertyVerifier(String propertyName, |
|
126 |
String expectedPropertyValue) { |
|
127 |
return addBundlePropertyVerifier(propertyName, (unused, v) -> { |
|
58416 | 128 |
TKit.assertEquals(expectedPropertyValue, v, String.format( |
58113 | 129 |
"Check value of %s property is [%s]", propertyName, v)); |
130 |
}); |
|
131 |
} |
|
132 |
||
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
133 |
public PackageTest addBundleDesktopIntegrationVerifier(boolean integrated) { |
58417
67ffaf3a2b75
8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents:
58416
diff
changeset
|
134 |
forTypes(LINUX, () -> { |
67ffaf3a2b75
8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents:
58416
diff
changeset
|
135 |
LinuxHelper.addBundleDesktopIntegrationVerifier(this, integrated); |
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
136 |
}); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
137 |
return this; |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
138 |
} |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
139 |
|
58304 | 140 |
public PackageTest addInstallVerifier(ThrowingConsumer<JPackageCommand> v) { |
58113 | 141 |
currentTypes.stream().forEach( |
58304 | 142 |
type -> handlers.get(type).addInstallVerifier( |
143 |
ThrowingConsumer.toConsumer(v))); |
|
58113 | 144 |
return this; |
145 |
} |
|
146 |
||
58304 | 147 |
public PackageTest addUninstallVerifier(ThrowingConsumer<JPackageCommand> v) { |
58113 | 148 |
currentTypes.stream().forEach( |
58304 | 149 |
type -> handlers.get(type).addUninstallVerifier( |
150 |
ThrowingConsumer.toConsumer(v))); |
|
58113 | 151 |
return this; |
152 |
} |
|
153 |
||
58696
61c44899b4eb
8223325: Improve wix sources generated by jpackage
herrick
parents:
58648
diff
changeset
|
154 |
static void withTestFileAssociationsFile(FileAssociations fa, |
61c44899b4eb
8223325: Improve wix sources generated by jpackage
herrick
parents:
58648
diff
changeset
|
155 |
ThrowingConsumer<Path> consumer) { |
61c44899b4eb
8223325: Improve wix sources generated by jpackage
herrick
parents:
58648
diff
changeset
|
156 |
final String testFileDefaultName = String.join(".", "test", |
61c44899b4eb
8223325: Improve wix sources generated by jpackage
herrick
parents:
58648
diff
changeset
|
157 |
fa.getSuffix()); |
58416 | 158 |
TKit.withTempFile(testFileDefaultName, fa.getSuffix(), testFile -> { |
159 |
if (TKit.isLinux()) { |
|
160 |
LinuxHelper.initFileAssociationsTestFile(testFile); |
|
161 |
} |
|
162 |
consumer.accept(testFile); |
|
163 |
}); |
|
164 |
} |
|
165 |
||
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
166 |
public PackageTest addHelloAppFileAssociationsVerifier(FileAssociations fa, |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
167 |
String... faLauncherDefaultArgs) { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
168 |
|
58648 | 169 |
addInitializer(cmd -> new HelloApp(null).addTo(cmd), "HelloApp"); |
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
170 |
addInstallVerifier(cmd -> { |
58648 | 171 |
if (cmd.isFakeRuntime("Not running file associations test")) { |
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
172 |
return; |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
173 |
} |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
174 |
|
58416 | 175 |
withTestFileAssociationsFile(fa, testFile -> { |
58304 | 176 |
testFile = testFile.toAbsolutePath().normalize(); |
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
177 |
|
58304 | 178 |
final Path appOutput = Path.of(HelloApp.OUTPUT_FILENAME); |
179 |
Files.deleteIfExists(appOutput); |
|
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
180 |
|
58416 | 181 |
TKit.trace(String.format("Use desktop to open [%s] file", |
58304 | 182 |
testFile)); |
183 |
Desktop.getDesktop().open(testFile.toFile()); |
|
58416 | 184 |
TKit.waitForFileCreated(appOutput, 7); |
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
185 |
|
58304 | 186 |
List<String> expectedArgs = new ArrayList<>(List.of( |
187 |
faLauncherDefaultArgs)); |
|
188 |
expectedArgs.add(testFile.toString()); |
|
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
189 |
|
58304 | 190 |
// Wait a little bit after file has been created to |
191 |
// make sure there are no pending writes into it. |
|
192 |
Thread.sleep(3000); |
|
58416 | 193 |
HelloApp.verifyOutputFile(appOutput, expectedArgs); |
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
194 |
}); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
195 |
}); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
196 |
|
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
197 |
forTypes(PackageType.LINUX, () -> { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
198 |
LinuxHelper.addFileAssociationsVerifier(this, fa); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
199 |
}); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
200 |
|
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
201 |
return this; |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
202 |
} |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
203 |
|
58416 | 204 |
PackageTest forTypes(Collection<PackageType> types, Runnable action) { |
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
205 |
Set<PackageType> oldTypes = Set.of(currentTypes.toArray( |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
206 |
PackageType[]::new)); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
207 |
try { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
208 |
forTypes(types); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
209 |
action.run(); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
210 |
} finally { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
211 |
forTypes(oldTypes); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
212 |
} |
58416 | 213 |
return this; |
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
214 |
} |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
215 |
|
58416 | 216 |
PackageTest forTypes(PackageType type, Runnable action) { |
217 |
return forTypes(List.of(type), action); |
|
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
218 |
} |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
219 |
|
58113 | 220 |
public PackageTest configureHelloApp() { |
58416 | 221 |
return configureHelloApp(null); |
222 |
} |
|
223 |
||
224 |
public PackageTest configureHelloApp(String encodedName) { |
|
58648 | 225 |
addInitializer( |
226 |
cmd -> new HelloApp(JavaAppDesc.parse(encodedName)).addTo(cmd)); |
|
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
227 |
addInstallVerifier(HelloApp::executeLauncherAndVerifyOutput); |
58113 | 228 |
return this; |
229 |
} |
|
230 |
||
231 |
public void run() { |
|
232 |
List<Handler> supportedHandlers = handlers.values().stream() |
|
233 |
.filter(entry -> !entry.isVoid()) |
|
234 |
.collect(Collectors.toList()); |
|
235 |
||
236 |
if (supportedHandlers.isEmpty()) { |
|
237 |
// No handlers with initializers found. Nothing to do. |
|
238 |
return; |
|
239 |
} |
|
240 |
||
241 |
Supplier<JPackageCommand> initializer = new Supplier<>() { |
|
242 |
@Override |
|
243 |
public JPackageCommand get() { |
|
244 |
JPackageCommand cmd = new JPackageCommand().setDefaultInputOutput(); |
|
245 |
if (bundleOutputDir != null) { |
|
58147
45a9084fe981
8230521: rename --output/-o option and add default value (".")
herrick
parents:
58113
diff
changeset
|
246 |
cmd.setArgumentValue("--dest", bundleOutputDir.toString()); |
58113 | 247 |
} |
248 |
cmd.setDefaultAppName(); |
|
249 |
return cmd; |
|
250 |
} |
|
251 |
}; |
|
252 |
||
253 |
supportedHandlers.forEach(handler -> handler.accept(initializer.get())); |
|
254 |
} |
|
255 |
||
256 |
public PackageTest setAction(Action value) { |
|
257 |
action = value; |
|
258 |
return this; |
|
259 |
} |
|
260 |
||
261 |
public Action getAction() { |
|
262 |
return action; |
|
263 |
} |
|
264 |
||
265 |
private class Handler implements Consumer<JPackageCommand> { |
|
266 |
||
267 |
Handler(PackageType type) { |
|
268 |
if (!PackageType.NATIVE.contains(type)) { |
|
269 |
throw new IllegalArgumentException( |
|
270 |
"Attempt to configure a test for image packaging"); |
|
271 |
} |
|
272 |
this.type = type; |
|
273 |
initializers = new ArrayList<>(); |
|
274 |
bundleVerifiers = new ArrayList<>(); |
|
275 |
installVerifiers = new ArrayList<>(); |
|
276 |
uninstallVerifiers = new ArrayList<>(); |
|
277 |
} |
|
278 |
||
279 |
boolean isVoid() { |
|
280 |
return initializers.isEmpty(); |
|
281 |
} |
|
282 |
||
283 |
void addInitializer(Consumer<JPackageCommand> v) { |
|
284 |
initializers.add(v); |
|
285 |
} |
|
286 |
||
287 |
void addBundleVerifier(BiConsumer<JPackageCommand, Executor.Result> v) { |
|
288 |
bundleVerifiers.add(v); |
|
289 |
} |
|
290 |
||
291 |
void addInstallVerifier(Consumer<JPackageCommand> v) { |
|
292 |
installVerifiers.add(v); |
|
293 |
} |
|
294 |
||
295 |
void addUninstallVerifier(Consumer<JPackageCommand> v) { |
|
296 |
uninstallVerifiers.add(v); |
|
297 |
} |
|
298 |
||
299 |
@Override |
|
300 |
public void accept(JPackageCommand cmd) { |
|
301 |
type.applyTo(cmd); |
|
302 |
||
303 |
initializers.stream().forEach(v -> v.accept(cmd)); |
|
58648 | 304 |
cmd.executePrerequisiteActions(); |
305 |
||
58113 | 306 |
switch (action) { |
307 |
case CREATE: |
|
308 |
Executor.Result result = cmd.execute(); |
|
309 |
result.assertExitCodeIs(expectedJPackageExitCode); |
|
58416 | 310 |
if (expectedJPackageExitCode == 0) { |
311 |
TKit.assertFileExists(cmd.outputBundle()); |
|
312 |
} else { |
|
313 |
TKit.assertPathExists(cmd.outputBundle(), false); |
|
314 |
} |
|
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
315 |
verifyPackageBundle(cmd.createImmutableCopy(), result); |
58113 | 316 |
break; |
317 |
||
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
318 |
case VERIFY_INSTALL: |
58434
b00cbf427368
8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents:
58417
diff
changeset
|
319 |
if (expectedJPackageExitCode == 0) { |
b00cbf427368
8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents:
58417
diff
changeset
|
320 |
verifyPackageInstalled(cmd.createImmutableCopy()); |
b00cbf427368
8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents:
58417
diff
changeset
|
321 |
} |
58113 | 322 |
break; |
323 |
||
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
324 |
case VERIFY_UNINSTALL: |
58434
b00cbf427368
8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents:
58417
diff
changeset
|
325 |
if (expectedJPackageExitCode == 0) { |
b00cbf427368
8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents:
58417
diff
changeset
|
326 |
verifyPackageUninstalled(cmd.createImmutableCopy()); |
b00cbf427368
8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents:
58417
diff
changeset
|
327 |
} |
58113 | 328 |
break; |
329 |
} |
|
330 |
} |
|
331 |
||
332 |
private void verifyPackageBundle(JPackageCommand cmd, |
|
333 |
Executor.Result result) { |
|
58434
b00cbf427368
8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents:
58417
diff
changeset
|
334 |
if (expectedJPackageExitCode == 0) { |
b00cbf427368
8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents:
58417
diff
changeset
|
335 |
if (PackageType.LINUX.contains(cmd.packageType())) { |
b00cbf427368
8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents:
58417
diff
changeset
|
336 |
LinuxHelper.verifyPackageBundleEssential(cmd); |
b00cbf427368
8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents:
58417
diff
changeset
|
337 |
} |
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
338 |
} |
58113 | 339 |
bundleVerifiers.stream().forEach(v -> v.accept(cmd, result)); |
340 |
} |
|
341 |
||
342 |
private void verifyPackageInstalled(JPackageCommand cmd) { |
|
58416 | 343 |
TKit.trace(String.format("Verify installed: %s", |
58113 | 344 |
cmd.getPrintableCommandLine())); |
58648 | 345 |
TKit.assertDirectoryExists(cmd.appRuntimeDirectory()); |
346 |
if (!cmd.isRuntime()) { |
|
347 |
TKit.assertExecutableFileExists(cmd.appLauncherPath()); |
|
58113 | 348 |
|
58648 | 349 |
if (PackageType.WINDOWS.contains(cmd.packageType())) { |
350 |
new WindowsHelper.AppVerifier(cmd); |
|
351 |
} |
|
58113 | 352 |
} |
353 |
||
58696
61c44899b4eb
8223325: Improve wix sources generated by jpackage
herrick
parents:
58648
diff
changeset
|
354 |
TKit.assertPathExists(cmd.appInstallationDirectory().resolve( |
61c44899b4eb
8223325: Improve wix sources generated by jpackage
herrick
parents:
58648
diff
changeset
|
355 |
AppImageFile.FILENAME), false); |
61c44899b4eb
8223325: Improve wix sources generated by jpackage
herrick
parents:
58648
diff
changeset
|
356 |
|
58113 | 357 |
installVerifiers.stream().forEach(v -> v.accept(cmd)); |
358 |
} |
|
359 |
||
360 |
private void verifyPackageUninstalled(JPackageCommand cmd) { |
|
58416 | 361 |
TKit.trace(String.format("Verify uninstalled: %s", |
58113 | 362 |
cmd.getPrintableCommandLine())); |
363 |
if (!cmd.isRuntime()) { |
|
58648 | 364 |
TKit.assertPathExists(cmd.appLauncherPath(), false); |
365 |
||
366 |
if (PackageType.WINDOWS.contains(cmd.packageType())) { |
|
367 |
new WindowsHelper.AppVerifier(cmd); |
|
368 |
} |
|
58113 | 369 |
} |
370 |
||
58648 | 371 |
TKit.assertPathExists(cmd.appInstallationDirectory(), false); |
58113 | 372 |
|
373 |
uninstallVerifiers.stream().forEach(v -> v.accept(cmd)); |
|
374 |
} |
|
375 |
||
376 |
private final PackageType type; |
|
377 |
private final List<Consumer<JPackageCommand>> initializers; |
|
378 |
private final List<BiConsumer<JPackageCommand, Executor.Result>> bundleVerifiers; |
|
379 |
private final List<Consumer<JPackageCommand>> installVerifiers; |
|
380 |
private final List<Consumer<JPackageCommand>> uninstallVerifiers; |
|
381 |
} |
|
382 |
||
383 |
private Collection<PackageType> currentTypes; |
|
384 |
private int expectedJPackageExitCode; |
|
385 |
private Map<PackageType, Handler> handlers; |
|
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
386 |
private Set<String> namedInitializers; |
58113 | 387 |
private Action action; |
388 |
||
389 |
/** |
|
390 |
* Test action. |
|
391 |
*/ |
|
392 |
static public enum Action { |
|
393 |
/** |
|
394 |
* Create bundle. |
|
395 |
*/ |
|
396 |
CREATE, |
|
397 |
/** |
|
398 |
* Verify bundle installed. |
|
399 |
*/ |
|
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
400 |
VERIFY_INSTALL, |
58113 | 401 |
/** |
402 |
* Verify bundle uninstalled. |
|
403 |
*/ |
|
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
404 |
VERIFY_UNINSTALL; |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
405 |
|
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
406 |
@Override |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
407 |
public String toString() { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
408 |
return name().toLowerCase().replace('_', '-'); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
409 |
} |
58113 | 410 |
}; |
411 |
private final static Action DEFAULT_ACTION; |
|
412 |
private final static File bundleOutputDir; |
|
413 |
||
414 |
static { |
|
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
415 |
final String propertyName = "output"; |
58416 | 416 |
String val = TKit.getConfigProperty(propertyName); |
58113 | 417 |
if (val == null) { |
418 |
bundleOutputDir = null; |
|
419 |
} else { |
|
420 |
bundleOutputDir = new File(val).getAbsoluteFile(); |
|
421 |
||
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
422 |
if (!bundleOutputDir.isDirectory()) { |
58696
61c44899b4eb
8223325: Improve wix sources generated by jpackage
herrick
parents:
58648
diff
changeset
|
423 |
throw new IllegalArgumentException(String.format( |
61c44899b4eb
8223325: Improve wix sources generated by jpackage
herrick
parents:
58648
diff
changeset
|
424 |
"Invalid value of %s sytem property: [%s]. Should be existing directory", |
58416 | 425 |
TKit.getConfigPropertyName(propertyName), |
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
426 |
bundleOutputDir)); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
427 |
} |
58113 | 428 |
} |
429 |
} |
|
430 |
||
431 |
static { |
|
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
432 |
final String propertyName = "action"; |
58416 | 433 |
String action = Optional.ofNullable(TKit.getConfigProperty(propertyName)).orElse( |
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
434 |
Action.CREATE.toString()).toLowerCase(); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58147
diff
changeset
|
435 |
DEFAULT_ACTION = Stream.of(Action.values()).filter( |
58696
61c44899b4eb
8223325: Improve wix sources generated by jpackage
herrick
parents:
58648
diff
changeset
|
436 |
a -> a.toString().equals(action)).findFirst().orElseThrow( |
61c44899b4eb
8223325: Improve wix sources generated by jpackage
herrick
parents:
58648
diff
changeset
|
437 |
() -> new IllegalArgumentException(String.format( |
61c44899b4eb
8223325: Improve wix sources generated by jpackage
herrick
parents:
58648
diff
changeset
|
438 |
"Unrecognized value of %s property: [%s]", |
58416 | 439 |
TKit.getConfigPropertyName(propertyName), action))); |
58113 | 440 |
} |
441 |
} |