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