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; |
24 import java.nio.file.Files; |
25 import java.nio.file.Files; |
25 import jdk.jpackage.internal.ApplicationLayout; |
|
26 import java.nio.file.Path; |
26 import java.nio.file.Path; |
|
27 import java.nio.file.StandardCopyOption; |
27 import jdk.jpackage.test.TKit; |
28 import jdk.jpackage.test.TKit; |
28 import jdk.jpackage.test.Functional; |
29 import jdk.jpackage.test.Functional; |
|
30 import jdk.jpackage.test.Annotations.*; |
29 import jdk.jpackage.test.JPackageCommand; |
31 import jdk.jpackage.test.JPackageCommand; |
30 |
32 |
31 /* |
33 /* |
32 * @test |
34 * @test |
33 * @summary jpackage create image to verify --icon |
35 * @summary jpackage create image with custom icon |
34 * @library ../helpers |
36 * @library ../helpers |
35 * @build jdk.jpackage.test.* |
37 * @build jdk.jpackage.test.* |
36 * @modules jdk.jpackage/jdk.jpackage.internal |
38 * @modules jdk.jpackage/jdk.jpackage.internal |
37 * @run main/othervm -Xmx512m IconTest |
39 * @compile IconTest.java |
|
40 * @run main/othervm/timeout=360 -Xmx512m jdk.jpackage.test.Main |
|
41 * --jpt-run=IconTest |
38 */ |
42 */ |
|
43 |
39 public class IconTest { |
44 public class IconTest { |
40 public static void main(String[] args) { |
45 @Test |
41 TKit.run(args, () -> { |
46 public static void testResourceDir() throws IOException { |
42 JPackageCommand cmd = JPackageCommand.helloAppImage().addArguments("--icon", GOLDEN_ICON); |
47 TKit.withTempDirectory("resources", tempDir -> { |
43 cmd.useToolProvider(true).executeAndAssertHelloAppImageCreated(); |
48 JPackageCommand cmd = JPackageCommand.helloAppImage() |
|
49 .addArguments("--resource-dir", tempDir); |
44 |
50 |
45 Path iconPath = ApplicationLayout.platformAppImage().resolveAt( |
51 Files.copy(GOLDEN_ICON, tempDir.resolve(appIconFileName(cmd)), |
46 cmd.appImage()).destktopIntegrationDirectory().resolve( |
52 StandardCopyOption.REPLACE_EXISTING); |
47 cmd.launcherPathInAppImage().getFileName().toString().replaceAll( |
|
48 "\\.[^.]*$", "") + ICON_SUFFIX); |
|
49 |
53 |
50 TKit.assertFileExists(iconPath); |
54 testIt(cmd); |
51 TKit.assertTrue(-1 == Files.mismatch(GOLDEN_ICON, iconPath), |
|
52 String.format( |
|
53 "Check application icon file [%s] is a copy of source icon file [%s]", |
|
54 iconPath, GOLDEN_ICON)); |
|
55 }); |
55 }); |
|
56 } |
|
57 |
|
58 @Test |
|
59 @Parameter("true") |
|
60 @Parameter("false") |
|
61 public static void testParameter(boolean relativePath) throws IOException { |
|
62 final Path iconPath; |
|
63 if (relativePath) { |
|
64 iconPath = TKit.createRelativePathCopy(GOLDEN_ICON); |
|
65 } else { |
|
66 iconPath = GOLDEN_ICON; |
|
67 } |
|
68 |
|
69 testIt(JPackageCommand.helloAppImage().addArguments("--icon", iconPath)); |
|
70 } |
|
71 |
|
72 private static String appIconFileName(JPackageCommand cmd) { |
|
73 return cmd.appLauncherPath().getFileName().toString().replaceAll( |
|
74 "\\.[^.]*$", "") + ICON_SUFFIX; |
|
75 } |
|
76 |
|
77 private static void testIt(JPackageCommand cmd) throws IOException { |
|
78 cmd.executeAndAssertHelloAppImageCreated(); |
|
79 |
|
80 Path iconPath = cmd.appLayout().destktopIntegrationDirectory().resolve( |
|
81 appIconFileName(cmd)); |
|
82 |
|
83 TKit.assertFileExists(iconPath); |
|
84 TKit.assertTrue(-1 == Files.mismatch(GOLDEN_ICON, iconPath), |
|
85 String.format( |
|
86 "Check application icon file [%s] is a copy of source icon file [%s]", |
|
87 iconPath, GOLDEN_ICON)); |
56 } |
88 } |
57 |
89 |
58 private final static String ICON_SUFFIX = Functional.identity(() -> { |
90 private final static String ICON_SUFFIX = Functional.identity(() -> { |
59 if (TKit.isOSX()) { |
91 if (TKit.isOSX()) { |
60 return ".icns"; |
92 return ".icns"; |