author | herrick |
Thu, 17 Oct 2019 08:00:37 -0400 | |
branch | JDK-8200758-branch |
changeset 58671 | 3b578a5976df |
parent 58648 | 3bf53ffa9ae7 |
child 58762 | 0fe62353385b |
permissions | -rw-r--r-- |
58416 | 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 |
||
24 |
package jdk.jpackage.tests; |
|
25 |
||
26 |
import java.io.IOException; |
|
27 |
import java.nio.file.Files; |
|
28 |
import java.nio.file.Path; |
|
29 |
import java.util.List; |
|
30 |
import java.util.ArrayList; |
|
58648 | 31 |
import java.util.function.Function; |
32 |
import java.util.function.Predicate; |
|
58463 | 33 |
import java.util.regex.Pattern; |
58416 | 34 |
import java.util.stream.Collectors; |
58648 | 35 |
import java.util.stream.Stream; |
36 |
import jdk.jpackage.test.*; |
|
58671
3b578a5976df
8232387 : tools/jpackage/share/jdk/jpackage/tests/BasicTest.java fails
herrick
parents:
58648
diff
changeset
|
37 |
import jdk.jpackage.test.Functional.ThrowingConsumer; |
58416 | 38 |
import jdk.jpackage.test.Annotations.*; |
39 |
||
40 |
/* |
|
41 |
* @test |
|
42 |
* @summary jpackage basic testing |
|
43 |
* @library ../../../../helpers |
|
44 |
* @build jdk.jpackage.test.* |
|
58648 | 45 |
* @modules jdk.jpackage/jdk.jpackage.internal |
58416 | 46 |
* @compile BasicTest.java |
47 |
* @run main/othervm/timeout=360 -Xmx512m jdk.jpackage.test.Main |
|
48 |
* --jpt-run=jdk.jpackage.tests.BasicTest |
|
49 |
*/ |
|
50 |
||
58648 | 51 |
public final class BasicTest { |
58416 | 52 |
@Test |
53 |
public void testNoArgs() { |
|
54 |
List<String> output = JPackageCommand.filterOutput( |
|
58463 | 55 |
getJPackageToolProvider().executeAndGetOutput()); |
58416 | 56 |
TKit.assertStringListEquals(List.of("Usage: jpackage <mode> <options>", |
57 |
"Use jpackage --help (or -h) for a list of possible options"), |
|
58 |
output, "Check jpackage output"); |
|
59 |
} |
|
60 |
||
61 |
@Test |
|
62 |
public void testVersion() { |
|
63 |
List<String> output = JPackageCommand.filterOutput( |
|
58463 | 64 |
getJPackageToolProvider() |
58416 | 65 |
.addArgument("--version") |
66 |
.executeAndGetOutput()); |
|
67 |
TKit.assertStringListEquals(List.of(System.getProperty("java.version")), |
|
68 |
output, "Check jpackage output"); |
|
69 |
} |
|
70 |
||
71 |
@Test |
|
58648 | 72 |
public void testHelp() { |
73 |
List<String> hOutput = getJPackageToolProvider() |
|
74 |
.addArgument("-h").executeAndGetOutput(); |
|
75 |
List<String> helpOutput = getJPackageToolProvider() |
|
76 |
.addArgument("--help").executeAndGetOutput(); |
|
77 |
||
78 |
TKit.assertStringListEquals(hOutput, helpOutput, |
|
79 |
"Check -h and --help parameters produce the same output"); |
|
80 |
||
81 |
final String windowsPrefix = "--win-"; |
|
82 |
final String linuxPrefix = "--linux-"; |
|
83 |
final String osxPrefix = "--mac-"; |
|
84 |
||
85 |
final String expectedPrefix; |
|
86 |
final List<String> unexpectedPrefixes; |
|
87 |
||
88 |
if (TKit.isWindows()) { |
|
89 |
expectedPrefix = windowsPrefix; |
|
90 |
unexpectedPrefixes = List.of(osxPrefix, linuxPrefix); |
|
91 |
} else if (TKit.isLinux()) { |
|
92 |
expectedPrefix = linuxPrefix; |
|
93 |
unexpectedPrefixes = List.of(windowsPrefix, osxPrefix); |
|
94 |
} else if (TKit.isOSX()) { |
|
95 |
expectedPrefix = osxPrefix; |
|
96 |
unexpectedPrefixes = List.of(linuxPrefix, windowsPrefix); |
|
97 |
} else { |
|
98 |
throw TKit.throwUnknownPlatformError(); |
|
99 |
} |
|
100 |
||
101 |
Function<String, Predicate<String>> createPattern = (prefix) -> { |
|
102 |
return Pattern.compile("^ " + prefix).asPredicate(); |
|
103 |
}; |
|
104 |
||
105 |
Function<List<String>, Long> countStrings = (prefixes) -> { |
|
106 |
return hOutput.stream().filter( |
|
107 |
prefixes.stream().map(createPattern).reduce(x -> false, |
|
108 |
Predicate::or)).peek(TKit::trace).count(); |
|
109 |
}; |
|
110 |
||
111 |
TKit.trace("Check parameters in help text"); |
|
112 |
TKit.assertNotEquals(0, countStrings.apply(List.of(expectedPrefix)), |
|
113 |
"Check help text contains plaform specific parameters"); |
|
114 |
TKit.assertEquals(0, countStrings.apply(unexpectedPrefixes), |
|
115 |
"Check help text doesn't contain unexpected parameters"); |
|
116 |
} |
|
117 |
||
118 |
@Test |
|
119 |
public void testVerbose() { |
|
120 |
JPackageCommand cmd = JPackageCommand.helloAppImage() |
|
121 |
.setFakeRuntime().executePrerequisiteActions(); |
|
122 |
||
123 |
List<String> expectedVerboseOutputStrings = new ArrayList<>(); |
|
124 |
expectedVerboseOutputStrings.add("Creating app package:"); |
|
125 |
if (TKit.isWindows()) { |
|
126 |
expectedVerboseOutputStrings.add("Result application bundle:"); |
|
127 |
expectedVerboseOutputStrings.add( |
|
128 |
"Succeeded in building Windows Application Image package"); |
|
129 |
} else if (TKit.isLinux()) { |
|
130 |
expectedVerboseOutputStrings.add( |
|
131 |
"Succeeded in building Linux Application Image package"); |
|
132 |
} else if (TKit.isOSX()) { |
|
133 |
expectedVerboseOutputStrings.add("Preparing Info.plist:"); |
|
134 |
expectedVerboseOutputStrings.add( |
|
135 |
"Succeeded in building Mac Application Image package"); |
|
136 |
} else { |
|
137 |
TKit.throwUnknownPlatformError(); |
|
138 |
} |
|
139 |
||
140 |
TKit.deleteDirectoryContentsRecursive(cmd.outputDir()); |
|
141 |
List<String> nonVerboseOutput = cmd.createExecutor().executeAndGetOutput(); |
|
142 |
||
143 |
TKit.deleteDirectoryContentsRecursive(cmd.outputDir()); |
|
144 |
List<String> verboseOutput = cmd.createExecutor().addArgument( |
|
145 |
"--verbose").executeAndGetOutput(); |
|
146 |
||
147 |
TKit.assertTrue(nonVerboseOutput.size() < verboseOutput.size(), |
|
148 |
"Check verbose output is longer than regular"); |
|
149 |
||
150 |
expectedVerboseOutputStrings.forEach(str -> { |
|
151 |
TKit.assertTextStream(str).label("regular output") |
|
152 |
.predicate(String::contains).negate() |
|
153 |
.apply(nonVerboseOutput.stream()); |
|
154 |
}); |
|
155 |
||
156 |
expectedVerboseOutputStrings.forEach(str -> { |
|
157 |
TKit.assertTextStream(str).label("verbose output") |
|
158 |
.apply(verboseOutput.stream()); |
|
159 |
}); |
|
160 |
} |
|
161 |
||
162 |
@Test |
|
58416 | 163 |
public void testNoName() { |
164 |
final String mainClassName = "Greetings"; |
|
165 |
||
58648 | 166 |
JPackageCommand cmd = JPackageCommand.helloAppImage(mainClassName) |
58416 | 167 |
.removeArgumentWithValue("--name"); |
168 |
||
169 |
Path expectedImageDir = cmd.outputDir().resolve(mainClassName); |
|
170 |
if (TKit.isOSX()) { |
|
171 |
expectedImageDir = expectedImageDir.getParent().resolve( |
|
172 |
expectedImageDir.getFileName().toString() + ".app"); |
|
173 |
} |
|
174 |
||
175 |
cmd.executeAndAssertHelloAppImageCreated(); |
|
176 |
TKit.assertEquals(expectedImageDir.toAbsolutePath().normalize().toString(), |
|
58648 | 177 |
cmd.outputBundle().toAbsolutePath().normalize().toString(), |
58416 | 178 |
String.format( |
179 |
"Check [%s] directory is filled with application image data", |
|
180 |
expectedImageDir)); |
|
181 |
} |
|
182 |
||
183 |
@Test |
|
58648 | 184 |
// Regular app |
185 |
@Parameter("Hello") |
|
186 |
// Modular app |
|
187 |
@Parameter("com.other/com.other.Hello") |
|
188 |
public void testApp(String javaAppDesc) { |
|
189 |
JPackageCommand.helloAppImage(javaAppDesc) |
|
58416 | 190 |
.executeAndAssertHelloAppImageCreated(); |
191 |
} |
|
192 |
||
193 |
@Test |
|
58648 | 194 |
public void testWhitespaceInPaths() { |
195 |
JPackageCommand.helloAppImage("a/b c.jar:Hello") |
|
196 |
.setArgumentValue("--input", TKit.workDir().resolve("The quick brown fox")) |
|
197 |
.setArgumentValue("--dest", TKit.workDir().resolve("jumps over the lazy dog")) |
|
58416 | 198 |
.executeAndAssertHelloAppImageCreated(); |
199 |
} |
|
200 |
||
201 |
@Test |
|
58466
47f0d21c7e8d
8231882: --add-modules ALL-MODULE-PATH is not handled properly
herrick
parents:
58463
diff
changeset
|
202 |
@Parameter("ALL-MODULE-PATH") |
58416 | 203 |
@Parameter("ALL-DEFAULT") |
58648 | 204 |
@Parameter("java.desktop") |
205 |
@Parameter("java.desktop,jdk.jartool") |
|
206 |
@Parameter({ "java.desktop", "jdk.jartool" }) |
|
207 |
public void testAddModules(String... addModulesArg) { |
|
208 |
JPackageCommand cmd = JPackageCommand |
|
209 |
.helloAppImage("goodbye.jar:com.other/com.other.Hello"); |
|
210 |
Stream.of(addModulesArg).map(v -> Stream.of("--add-modules", v)).flatMap( |
|
211 |
s -> s).forEachOrdered(cmd::addArgument); |
|
58416 | 212 |
cmd.executeAndAssertHelloAppImageCreated(); |
213 |
} |
|
214 |
||
215 |
/** |
|
216 |
* Test --temp option. Doesn't make much sense for app image as temporary |
|
58648 | 217 |
* directory is used only on Windows. Test it in packaging mode. |
58416 | 218 |
* @throws IOException |
219 |
*/ |
|
58648 | 220 |
@Test |
58416 | 221 |
public void testTemp() throws IOException { |
58671
3b578a5976df
8232387 : tools/jpackage/share/jdk/jpackage/tests/BasicTest.java fails
herrick
parents:
58648
diff
changeset
|
222 |
TKit.withTempDirectory("temp-root", tempRoot -> { |
3b578a5976df
8232387 : tools/jpackage/share/jdk/jpackage/tests/BasicTest.java fails
herrick
parents:
58648
diff
changeset
|
223 |
Function<JPackageCommand, Path> getTempDir = cmd -> { |
3b578a5976df
8232387 : tools/jpackage/share/jdk/jpackage/tests/BasicTest.java fails
herrick
parents:
58648
diff
changeset
|
224 |
return tempRoot.resolve(cmd.outputBundle().getFileName()); |
3b578a5976df
8232387 : tools/jpackage/share/jdk/jpackage/tests/BasicTest.java fails
herrick
parents:
58648
diff
changeset
|
225 |
}; |
58648 | 226 |
|
58671
3b578a5976df
8232387 : tools/jpackage/share/jdk/jpackage/tests/BasicTest.java fails
herrick
parents:
58648
diff
changeset
|
227 |
ThrowingConsumer<JPackageCommand> addTempDir = cmd -> { |
3b578a5976df
8232387 : tools/jpackage/share/jdk/jpackage/tests/BasicTest.java fails
herrick
parents:
58648
diff
changeset
|
228 |
Path tempDir = getTempDir.apply(cmd); |
3b578a5976df
8232387 : tools/jpackage/share/jdk/jpackage/tests/BasicTest.java fails
herrick
parents:
58648
diff
changeset
|
229 |
Files.createDirectories(tempDir); |
3b578a5976df
8232387 : tools/jpackage/share/jdk/jpackage/tests/BasicTest.java fails
herrick
parents:
58648
diff
changeset
|
230 |
cmd.addArguments("--temp", tempDir); |
3b578a5976df
8232387 : tools/jpackage/share/jdk/jpackage/tests/BasicTest.java fails
herrick
parents:
58648
diff
changeset
|
231 |
}; |
58416 | 232 |
|
58671
3b578a5976df
8232387 : tools/jpackage/share/jdk/jpackage/tests/BasicTest.java fails
herrick
parents:
58648
diff
changeset
|
233 |
new PackageTest().configureHelloApp().addInitializer(addTempDir) |
3b578a5976df
8232387 : tools/jpackage/share/jdk/jpackage/tests/BasicTest.java fails
herrick
parents:
58648
diff
changeset
|
234 |
.addBundleVerifier(cmd -> { |
3b578a5976df
8232387 : tools/jpackage/share/jdk/jpackage/tests/BasicTest.java fails
herrick
parents:
58648
diff
changeset
|
235 |
// Check jpackage actually used the supplied directory. |
3b578a5976df
8232387 : tools/jpackage/share/jdk/jpackage/tests/BasicTest.java fails
herrick
parents:
58648
diff
changeset
|
236 |
Path tempDir = getTempDir.apply(cmd); |
3b578a5976df
8232387 : tools/jpackage/share/jdk/jpackage/tests/BasicTest.java fails
herrick
parents:
58648
diff
changeset
|
237 |
TKit.assertNotEquals(0, tempDir.toFile().list().length, |
3b578a5976df
8232387 : tools/jpackage/share/jdk/jpackage/tests/BasicTest.java fails
herrick
parents:
58648
diff
changeset
|
238 |
String.format( |
3b578a5976df
8232387 : tools/jpackage/share/jdk/jpackage/tests/BasicTest.java fails
herrick
parents:
58648
diff
changeset
|
239 |
"Check jpackage wrote some data in the supplied temporary directory [%s]", |
3b578a5976df
8232387 : tools/jpackage/share/jdk/jpackage/tests/BasicTest.java fails
herrick
parents:
58648
diff
changeset
|
240 |
tempDir)); |
3b578a5976df
8232387 : tools/jpackage/share/jdk/jpackage/tests/BasicTest.java fails
herrick
parents:
58648
diff
changeset
|
241 |
}) |
3b578a5976df
8232387 : tools/jpackage/share/jdk/jpackage/tests/BasicTest.java fails
herrick
parents:
58648
diff
changeset
|
242 |
.run(); |
58416 | 243 |
|
58671
3b578a5976df
8232387 : tools/jpackage/share/jdk/jpackage/tests/BasicTest.java fails
herrick
parents:
58648
diff
changeset
|
244 |
new PackageTest().configureHelloApp().addInitializer(addTempDir) |
3b578a5976df
8232387 : tools/jpackage/share/jdk/jpackage/tests/BasicTest.java fails
herrick
parents:
58648
diff
changeset
|
245 |
.addInitializer(cmd -> { |
3b578a5976df
8232387 : tools/jpackage/share/jdk/jpackage/tests/BasicTest.java fails
herrick
parents:
58648
diff
changeset
|
246 |
// Clean output from the previus jpackage run. |
3b578a5976df
8232387 : tools/jpackage/share/jdk/jpackage/tests/BasicTest.java fails
herrick
parents:
58648
diff
changeset
|
247 |
Files.delete(cmd.outputBundle()); |
3b578a5976df
8232387 : tools/jpackage/share/jdk/jpackage/tests/BasicTest.java fails
herrick
parents:
58648
diff
changeset
|
248 |
}) |
58416 | 249 |
// Temporary directory should not be empty, |
250 |
// jpackage should exit with error. |
|
58671
3b578a5976df
8232387 : tools/jpackage/share/jdk/jpackage/tests/BasicTest.java fails
herrick
parents:
58648
diff
changeset
|
251 |
.setExpectedExitCode(1) |
3b578a5976df
8232387 : tools/jpackage/share/jdk/jpackage/tests/BasicTest.java fails
herrick
parents:
58648
diff
changeset
|
252 |
.run(); |
58416 | 253 |
}); |
254 |
} |
|
255 |
||
256 |
@Test |
|
257 |
public void testAtFile() throws IOException { |
|
58648 | 258 |
JPackageCommand cmd = JPackageCommand.helloAppImage(); |
58416 | 259 |
|
260 |
// Init options file with the list of options configured |
|
261 |
// for JPackageCommand instance. |
|
262 |
final Path optionsFile = TKit.workDir().resolve("options"); |
|
263 |
Files.write(optionsFile, |
|
264 |
List.of(String.join(" ", cmd.getAllArguments()))); |
|
265 |
||
266 |
// Build app jar file. |
|
267 |
cmd.executePrerequisiteActions(); |
|
268 |
||
269 |
// Make sure output directory is empty. Normally JPackageCommand would |
|
270 |
// do this automatically. |
|
271 |
TKit.deleteDirectoryContentsRecursive(cmd.outputDir()); |
|
272 |
||
273 |
// Instead of running jpackage command through configured |
|
274 |
// JPackageCommand instance, run vanilla jpackage command with @ file. |
|
58463 | 275 |
getJPackageToolProvider() |
58416 | 276 |
.addArgument(String.format("@%s", optionsFile)) |
277 |
.execute().assertExitCodeIsZero(); |
|
278 |
||
279 |
// Verify output of jpackage command. |
|
280 |
cmd.assertImageCreated(); |
|
281 |
HelloApp.executeLauncherAndVerifyOutput(cmd); |
|
282 |
} |
|
283 |
||
284 |
@Parameter("Hello") |
|
285 |
@Parameter("com.foo/com.foo.main.Aloha") |
|
286 |
@Test |
|
287 |
public void testJLinkRuntime(String javaAppDesc) { |
|
58463 | 288 |
JPackageCommand cmd = JPackageCommand.helloAppImage(javaAppDesc); |
58416 | 289 |
|
290 |
// If `--module` parameter was set on jpackage command line, get its |
|
291 |
// value and extract module name. |
|
292 |
// E.g.: foo.bar2/foo.bar.Buz -> foo.bar2 |
|
293 |
// Note: HelloApp class manages `--module` parameter on jpackage command line |
|
294 |
final String moduleName = cmd.getArgumentValue("--module", () -> null, |
|
295 |
(v) -> v.split("/", 2)[0]); |
|
296 |
||
297 |
if (moduleName != null) { |
|
298 |
// Build module jar. |
|
299 |
cmd.executePrerequisiteActions(); |
|
300 |
} |
|
301 |
||
302 |
TKit.withTempDirectory("runtime", runtimeDir -> { |
|
303 |
TKit.deleteDirectoryRecursive(runtimeDir, String.format( |
|
304 |
"Delete [%s] output directory for jlink command", runtimeDir)); |
|
58463 | 305 |
Executor jlink = getToolProvider(JavaTool.JLINK) |
58416 | 306 |
.saveOutput(false) |
307 |
.addArguments( |
|
308 |
"--add-modules", "java.base", |
|
309 |
"--output", runtimeDir.toString(), |
|
310 |
"--strip-debug", |
|
311 |
"--no-header-files", |
|
312 |
"--no-man-pages"); |
|
313 |
||
314 |
if (moduleName != null) { |
|
315 |
jlink.addArguments("--add-modules", moduleName, "--module-path", |
|
316 |
Path.of(cmd.getArgumentValue("--module-path")).resolve( |
|
317 |
"hello.jar").toString()); |
|
318 |
} |
|
319 |
||
320 |
jlink.execute().assertExitCodeIsZero(); |
|
321 |
||
322 |
cmd.addArguments("--runtime-image", runtimeDir); |
|
323 |
cmd.executeAndAssertHelloAppImageCreated(); |
|
324 |
||
58648 | 325 |
final Path appImageRuntimePath = cmd.appRuntimeDirectory(); |
58416 | 326 |
|
58463 | 327 |
// |
58416 | 328 |
// This is an overkill to list modules in jlink output as we have |
329 |
// already verified that Java app is functional and thus app's runtime |
|
330 |
// is likely to be OK, but let's double check. |
|
58463 | 331 |
// |
332 |
// Filter out all first strings with whitespace. They are java |
|
333 |
// launcher output like `Picked up ...` unrelated to module names. |
|
334 |
// |
|
335 |
Pattern whitespaceChar = Pattern.compile("\\s"); |
|
58416 | 336 |
List<String> moduleList = new Executor().dumpOutput().setExecutable( |
337 |
appImageRuntimePath.resolve( |
|
338 |
JPackageCommand.relativePathInRuntime(JavaTool.JAVA))).addArguments( |
|
58463 | 339 |
"--list-modules").executeAndGetOutput().stream().dropWhile( |
340 |
s -> whitespaceChar.matcher(s).find()).sorted().collect( |
|
341 |
Collectors.toList()); |
|
58416 | 342 |
|
343 |
List<String> expectedModules = new ArrayList<>(); |
|
344 |
expectedModules.add(String.format("java.base@%s", |
|
345 |
System.getProperty("java.version"))); |
|
346 |
if (moduleName != null) { |
|
347 |
expectedModules.add(moduleName); |
|
348 |
} |
|
349 |
expectedModules = expectedModules.stream().sorted().collect( |
|
350 |
Collectors.toList()); |
|
351 |
||
352 |
TKit.assertStringListEquals(expectedModules, moduleList, |
|
353 |
String.format( |
|
354 |
"Check modules in application image runtime directory at [%s]", |
|
355 |
appImageRuntimePath)); |
|
356 |
}); |
|
357 |
} |
|
358 |
||
58463 | 359 |
private static Executor getJPackageToolProvider() { |
360 |
return getToolProvider(JavaTool.JPACKAGE); |
|
58416 | 361 |
} |
362 |
||
58463 | 363 |
private static Executor getToolProvider(JavaTool tool) { |
58648 | 364 |
return new Executor().dumpOutput().saveOutput().setToolProvider(tool); |
58416 | 365 |
} |
366 |
} |