29 import java.lang.invoke.MethodHandles; |
29 import java.lang.invoke.MethodHandles; |
30 import jdk.jpackage.test.HelloApp; |
30 import jdk.jpackage.test.HelloApp; |
31 import jdk.jpackage.test.PackageTest; |
31 import jdk.jpackage.test.PackageTest; |
32 import jdk.jpackage.test.PackageType; |
32 import jdk.jpackage.test.PackageType; |
33 import jdk.jpackage.test.FileAssociations; |
33 import jdk.jpackage.test.FileAssociations; |
|
34 import jdk.jpackage.test.Annotations.Test; |
34 import jdk.jpackage.test.TKit; |
35 import jdk.jpackage.test.TKit; |
35 |
36 |
36 /** |
37 /** |
37 * Test --add-launcher parameter. Output of the test should be |
38 * Test --add-launcher parameter. Output of the test should be |
38 * additionallauncherstest*.* installer. The output installer should provide the |
39 * additionallauncherstest*.* installer. The output installer should provide the |
45 * @test |
46 * @test |
46 * @summary jpackage with --add-launcher |
47 * @summary jpackage with --add-launcher |
47 * @library ../helpers |
48 * @library ../helpers |
48 * @build jdk.jpackage.test.* |
49 * @build jdk.jpackage.test.* |
49 * @modules jdk.jpackage/jdk.jpackage.internal |
50 * @modules jdk.jpackage/jdk.jpackage.internal |
50 * @run main/othervm/timeout=360 -Xmx512m AdditionalLaunchersTest |
51 * @compile AdditionalLaunchersTest.java |
|
52 * @run main/othervm/timeout=360 -Xmx512m jdk.jpackage.test.Main |
|
53 * --jpt-run=AdditionalLaunchersTest |
51 */ |
54 */ |
|
55 |
52 public class AdditionalLaunchersTest { |
56 public class AdditionalLaunchersTest { |
53 |
57 |
54 public static void main(String[] args) { |
58 @Test |
55 TKit.run(args, () -> { |
59 public void test() { |
56 FileAssociations fa = new FileAssociations( |
60 FileAssociations fa = new FileAssociations( |
57 MethodHandles.lookup().lookupClass().getSimpleName()); |
61 MethodHandles.lookup().lookupClass().getSimpleName()); |
58 |
62 |
59 // Configure a bunch of additional launchers and also setup |
63 // Configure a bunch of additional launchers and also setup |
60 // file association to make sure it will be linked only to the main |
64 // file association to make sure it will be linked only to the main |
61 // launcher. |
65 // launcher. |
62 |
66 |
63 PackageTest packageTest = new PackageTest().configureHelloApp() |
67 PackageTest packageTest = new PackageTest().configureHelloApp() |
64 .addInitializer(cmd -> { |
68 .addInitializer(cmd -> { |
65 fa.createFile(); |
69 fa.createFile(); |
66 cmd.addArguments("--file-associations", fa.getPropertiesFile()); |
70 cmd.addArguments("--file-associations", fa.getPropertiesFile()); |
67 cmd.addArguments("--arguments", "Duke", "--arguments", "is", |
71 cmd.addArguments("--arguments", "Duke", "--arguments", "is", |
68 "--arguments", "the", "--arguments", "King"); |
72 "--arguments", "the", "--arguments", "King"); |
69 }); |
73 }); |
70 |
74 |
71 packageTest.addHelloAppFileAssociationsVerifier(fa); |
75 packageTest.addHelloAppFileAssociationsVerifier(fa); |
72 |
76 |
73 new AdditionalLauncher("Baz2").setArguments().applyTo(packageTest); |
77 new AdditionalLauncher("Baz2").setArguments().applyTo(packageTest); |
74 new AdditionalLauncher("foo").setArguments("yep!").applyTo(packageTest); |
78 new AdditionalLauncher("foo").setArguments("yep!").applyTo(packageTest); |
75 |
79 |
76 AdditionalLauncher barLauncher = new AdditionalLauncher("Bar").setArguments( |
80 AdditionalLauncher barLauncher = new AdditionalLauncher("Bar").setArguments( |
77 "one", "two", "three"); |
81 "one", "two", "three"); |
78 packageTest.forTypes(PackageType.LINUX).addInitializer(cmd -> { |
82 if (TKit.isLinux()) { |
79 barLauncher.setIcon(TKit.TEST_SRC_ROOT.resolve("apps/dukeplug.png")); |
83 barLauncher.setIcon(TKit.TEST_SRC_ROOT.resolve("apps/dukeplug.png")); |
80 }); |
84 } |
81 barLauncher.applyTo(packageTest); |
85 barLauncher.applyTo(packageTest); |
82 |
86 |
83 packageTest.run(); |
87 packageTest.run(); |
84 }); |
|
85 } |
88 } |
86 |
89 |
87 private static Path replaceFileName(Path path, String newFileName) { |
90 private static Path replaceFileName(Path path, String newFileName) { |
88 String fname = path.getFileName().toString(); |
91 String fname = path.getFileName().toString(); |
89 int lastDotIndex = fname.lastIndexOf("."); |
92 int lastDotIndex = fname.lastIndexOf("."); |
127 } |
130 } |
128 |
131 |
129 TKit.createPropertiesFile(propsFile, properties); |
132 TKit.createPropertiesFile(propsFile, properties); |
130 }); |
133 }); |
131 test.addInstallVerifier(cmd -> { |
134 test.addInstallVerifier(cmd -> { |
132 Path launcherPath = replaceFileName( |
135 Path launcherPath = replaceFileName(cmd.appLauncherPath(), name); |
133 cmd.launcherInstallationPath(), name); |
|
134 |
136 |
135 TKit.assertExecutableFileExists(launcherPath); |
137 TKit.assertExecutableFileExists(launcherPath); |
136 |
138 |
137 if (cmd.isFakeRuntimeInstalled(String.format( |
139 if (cmd.isFakeRuntime(String.format( |
138 "Not running %s launcher", launcherPath))) { |
140 "Not running %s launcher", launcherPath))) { |
139 return; |
141 return; |
140 } |
142 } |
141 HelloApp.executeAndVerifyOutput(launcherPath, |
143 HelloApp.executeAndVerifyOutput(launcherPath, |
142 Optional.ofNullable(arguments).orElse(List.of()).toArray( |
144 Optional.ofNullable(arguments).orElse(List.of()).toArray( |
143 String[]::new)); |
145 String[]::new)); |
144 }); |
146 }); |
145 test.addUninstallVerifier(cmd -> { |
147 test.addUninstallVerifier(cmd -> { |
146 Path launcherPath = replaceFileName( |
148 Path launcherPath = replaceFileName(cmd.appLauncherPath(), name); |
147 cmd.launcherInstallationPath(), name); |
|
148 |
149 |
149 TKit.assertPathExists(launcherPath, false); |
150 TKit.assertPathExists(launcherPath, false); |
150 }); |
151 }); |
151 } |
152 } |
152 |
153 |