19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
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 |
20 * or visit www.oracle.com if you need additional information or have any |
21 * questions. |
21 * questions. |
22 */ |
22 */ |
23 |
23 |
|
24 import java.io.IOException; |
|
25 import java.nio.file.Files; |
24 import java.nio.file.Path; |
26 import java.nio.file.Path; |
|
27 import java.util.HashSet; |
25 import java.util.Optional; |
28 import java.util.Optional; |
26 import jdk.jpackage.test.TKit; |
29 import java.util.Set; |
27 import jdk.jpackage.test.PackageTest; |
30 import java.util.stream.Collectors; |
28 import jdk.jpackage.test.JPackageCommand; |
31 import jdk.jpackage.test.*; |
|
32 import jdk.jpackage.test.Annotations.Test; |
29 |
33 |
30 /** |
34 /** |
31 * Test --runtime-image parameter. |
35 * Test --runtime-image parameter. |
32 * Output of the test should be RuntimePackageTest*.* installer. |
36 * Output of the test should be RuntimePackageTest*.* installer. |
33 * The installer should install Java Runtime without an application. |
37 * The installer should install Java Runtime without an application. |
47 * @key jpackagePlatformPackage |
51 * @key jpackagePlatformPackage |
48 * @build jdk.jpackage.test.* |
52 * @build jdk.jpackage.test.* |
49 * @comment Temporary disable for Linux and OSX until functionality implemented |
53 * @comment Temporary disable for Linux and OSX until functionality implemented |
50 * @requires (os.family != "mac") |
54 * @requires (os.family != "mac") |
51 * @modules jdk.jpackage/jdk.jpackage.internal |
55 * @modules jdk.jpackage/jdk.jpackage.internal |
52 * @run main/othervm/timeout=720 -Xmx512m RuntimePackageTest |
56 * @compile RuntimePackageTest.java |
|
57 * @run main/othervm/timeout=720 -Xmx512m jdk.jpackage.test.Main |
|
58 * --jpt-run=RuntimePackageTest |
53 */ |
59 */ |
54 public class RuntimePackageTest { |
60 public class RuntimePackageTest { |
55 |
61 |
56 public static void main(String[] args) { |
62 @Test |
57 TKit.run(args, () -> { |
63 public static void test() { |
58 new PackageTest() |
64 new PackageTest() |
59 .addInitializer(cmd -> { |
65 .addInitializer(cmd -> { |
60 cmd.addArguments("--runtime-image", Optional.ofNullable( |
66 cmd.addArguments("--runtime-image", Optional.ofNullable( |
61 JPackageCommand.DEFAULT_RUNTIME_IMAGE).orElse(Path.of( |
67 JPackageCommand.DEFAULT_RUNTIME_IMAGE).orElse(Path.of( |
62 System.getProperty("java.home")))); |
68 System.getProperty("java.home")))); |
63 // Remove --input parameter from jpackage command line as we don't |
69 // Remove --input parameter from jpackage command line as we don't |
64 // create input directory in the test and jpackage fails |
70 // create input directory in the test and jpackage fails |
65 // if --input references non existant directory. |
71 // if --input references non existant directory. |
66 cmd.removeArgumentWithValue("--input"); |
72 cmd.removeArgumentWithValue("--input"); |
67 }) |
73 }) |
68 .run(); |
74 .addInstallVerifier(cmd -> { |
|
75 Set<Path> srcRuntime = listFiles(Path.of(cmd.getArgumentValue("--runtime-image"))); |
|
76 Set<Path> dstRuntime = listFiles(cmd.appRuntimeDirectory()); |
|
77 |
|
78 Set<Path> intersection = new HashSet<>(srcRuntime); |
|
79 intersection.retainAll(dstRuntime); |
|
80 |
|
81 srcRuntime.removeAll(intersection); |
|
82 dstRuntime.removeAll(intersection); |
|
83 |
|
84 assertFileListEmpty(srcRuntime, "Missing"); |
|
85 assertFileListEmpty(dstRuntime, "Unexpected"); |
|
86 }) |
|
87 .run(); |
|
88 } |
|
89 |
|
90 private static Set<Path> listFiles(Path root) throws IOException { |
|
91 try (var files = Files.walk(root)) { |
|
92 return files.map(root::relativize).collect(Collectors.toSet()); |
|
93 } |
|
94 } |
|
95 |
|
96 private static void assertFileListEmpty(Set<Path> paths, String msg) { |
|
97 TKit.assertTrue(paths.isEmpty(), String.format( |
|
98 "Check there are no %s files in installed image", |
|
99 msg.toLowerCase()), () -> { |
|
100 String msg2 = String.format("%s %d files", msg, paths.size()); |
|
101 TKit.trace(msg2 + ":"); |
|
102 paths.stream().map(Path::toString).sorted().forEachOrdered( |
|
103 TKit::trace); |
|
104 TKit.trace("Done"); |
69 }); |
105 }); |
70 } |
106 } |
71 } |
107 } |