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.File; |
|
25 import java.nio.file.Files; |
24 import java.nio.file.Files; |
|
25 import jdk.jpackage.internal.ApplicationLayout; |
|
26 import java.nio.file.Path; |
|
27 import jdk.jpackage.test.TKit; |
|
28 import jdk.jpackage.test.Functional; |
|
29 import jdk.jpackage.test.JPackageCommand; |
26 |
30 |
27 /* |
31 /* |
28 * @test |
32 * @test |
29 * @summary jpackage create image to verify --icon |
33 * @summary jpackage create image to verify --icon |
30 * @library ../helpers |
34 * @library ../helpers |
31 * @build JPackageHelper |
35 * @build jdk.jpackage.test.* |
32 * @build JPackagePath |
36 * @modules jdk.jpackage/jdk.jpackage.internal |
33 * @modules jdk.jpackage |
|
34 * @run main/othervm -Xmx512m IconTest |
37 * @run main/othervm -Xmx512m IconTest |
35 */ |
38 */ |
36 public class IconTest { |
39 public class IconTest { |
37 private static final String OUTPUT = "output"; |
40 public static void main(String[] args) { |
38 private static final String app = JPackagePath.getApp(); |
41 TKit.run(args, () -> { |
39 private static final String appOutput = JPackagePath.getAppOutputFile(); |
42 JPackageCommand cmd = JPackageCommand.helloAppImage().addArguments("--icon", GOLDEN_ICON); |
|
43 cmd.useToolProvider(true).executeAndAssertHelloAppImageCreated(); |
40 |
44 |
41 private static final String[] CMD = { |
45 Path iconPath = ApplicationLayout.platformAppImage().resolveAt( |
42 "--package-type", "app-image", |
46 cmd.appImage()).destktopIntegrationDirectory().resolve( |
43 "--input", "input", |
47 cmd.launcherPathInAppImage().getFileName().toString().replaceAll( |
44 "--name", "test", |
48 "\\.[^.]*$", "") + ICON_SUFFIX); |
45 "--main-jar", "hello.jar", |
|
46 "--main-class", "Hello", |
|
47 "--icon", getIconPath(), |
|
48 "--dest", OUTPUT}; |
|
49 |
49 |
50 private static void validateResult(String[] result) throws Exception { |
50 TKit.assertFileExists(iconPath); |
51 if (result.length != 2) { |
51 TKit.assertTrue(-1 == Files.mismatch(GOLDEN_ICON, iconPath), |
52 throw new AssertionError( |
52 String.format( |
53 "Unexpected number of lines: " + result.length); |
53 "Check application icon file [%s] is a copy of source icon file [%s]", |
|
54 iconPath, GOLDEN_ICON)); |
|
55 }); |
|
56 } |
|
57 |
|
58 private final static String ICON_SUFFIX = Functional.identity(() -> { |
|
59 if (TKit.isOSX()) { |
|
60 return ".icns"; |
54 } |
61 } |
55 |
62 |
56 if (!result[0].trim().equals("jpackage test application")) { |
63 if (TKit.isLinux()) { |
57 throw new AssertionError("Unexpected result[0]: " + result[0]); |
64 return ".png"; |
58 } |
65 } |
59 |
66 |
60 if (!result[1].trim().equals("args.length: 0")) { |
67 if (TKit.isWindows()) { |
61 throw new AssertionError("Unexpected result[1]: " + result[1]); |
68 return ".ico"; |
62 } |
|
63 } |
|
64 |
|
65 private static void validate() throws Exception { |
|
66 int retVal = JPackageHelper.execute(null, app); |
|
67 if (retVal != 0) { |
|
68 throw new AssertionError( |
|
69 "Test application exited with error: " + retVal); |
|
70 } |
69 } |
71 |
70 |
72 File outfile = new File(appOutput); |
71 throw TKit.throwUnknownPlatformError(); |
73 if (!outfile.exists()) { |
72 }).get(); |
74 throw new AssertionError(appOutput + " was not created"); |
|
75 } |
|
76 |
73 |
77 String output = Files.readString(outfile.toPath()); |
74 private final static Path GOLDEN_ICON = TKit.TEST_SRC_ROOT.resolve(Path.of( |
78 String[] result = output.split("\n"); |
75 "resources", "icon" + ICON_SUFFIX)); |
79 validateResult(result); |
|
80 } |
|
81 |
|
82 private static void validateIcon() throws Exception { |
|
83 File origIcon = new File(getIconPath()); |
|
84 File icon = new File(JPackagePath.getAppIcon()); |
|
85 if (origIcon.length() != icon.length()) { |
|
86 System.err.println("origIcon.length(): " + origIcon.length()); |
|
87 System.err.println("icon.length(): " + icon.length()); |
|
88 throw new AssertionError("Icons size does not match"); |
|
89 } |
|
90 } |
|
91 |
|
92 private static void testIcon() throws Exception { |
|
93 JPackageHelper.executeCLI(true, CMD); |
|
94 validate(); |
|
95 validateIcon(); |
|
96 } |
|
97 |
|
98 private static void testIconToolProvider() throws Exception { |
|
99 JPackageHelper.deleteOutputFolder(OUTPUT); |
|
100 JPackageHelper.executeToolProvider(true, CMD); |
|
101 validate(); |
|
102 validateIcon(); |
|
103 } |
|
104 |
|
105 private static String getIconPath() { |
|
106 String ext = ".ico"; |
|
107 if (JPackageHelper.isOSX()) { |
|
108 ext = ".icns"; |
|
109 } else if (JPackageHelper.isLinux()) { |
|
110 ext = ".png"; |
|
111 } |
|
112 |
|
113 String path = JPackagePath.getTestSrcRoot() + File.separator + "resources" |
|
114 + File.separator + "icon" + ext; |
|
115 |
|
116 return path; |
|
117 } |
|
118 |
|
119 public static void main(String[] args) throws Exception { |
|
120 JPackageHelper.createHelloImageJar(); |
|
121 testIcon(); |
|
122 testIconToolProvider(); |
|
123 } |
|
124 |
|
125 } |
76 } |