|
1 /* |
|
2 * Copyright (c) 2018, 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 import java.io.File; |
|
25 import java.nio.file.Files; |
|
26 |
|
27 /* |
|
28 * @test |
|
29 * @summary jpackage create image to verify --icon |
|
30 * @library ../helpers |
|
31 * @build JPackageHelper |
|
32 * @build JPackagePath |
|
33 * @requires ((os.family == "windows") | (os.family == "mac")) |
|
34 * @modules jdk.jpackage |
|
35 * @run main/othervm -Xmx512m JPackageCreateAppImageResourceTest |
|
36 */ |
|
37 public class JPackageCreateAppImageResourceTest { |
|
38 private static final String OUTPUT = "output"; |
|
39 private static final String app = JPackagePath.getApp("icon"); |
|
40 private static final String appOutput = JPackagePath.getAppOutputFile(); |
|
41 private static final String appWorkingDir = |
|
42 JPackagePath.getAppWorkingDir("icon"); |
|
43 private static final String resourceDir = |
|
44 JPackagePath.getTestSrcRoot() + File.separator + "resources"; |
|
45 |
|
46 private static final String[] CMD = { |
|
47 "create-app-image", |
|
48 "--input", "input", |
|
49 "--name", "icon", |
|
50 "--main-jar", "hello.jar", |
|
51 "--main-class", "Hello", |
|
52 "--resource-dir", resourceDir, |
|
53 "--output", OUTPUT}; |
|
54 |
|
55 private static void validateResult(String[] result) throws Exception { |
|
56 if (result.length != 2) { |
|
57 throw new AssertionError( |
|
58 "Unexpected number of lines: " + result.length); |
|
59 } |
|
60 |
|
61 if (!result[0].trim().equals("jpackage test application")) { |
|
62 throw new AssertionError("Unexpected result[0]: " + result[0]); |
|
63 } |
|
64 |
|
65 if (!result[1].trim().equals("args.length: 0")) { |
|
66 throw new AssertionError("Unexpected result[1]: " + result[1]); |
|
67 } |
|
68 } |
|
69 |
|
70 private static void validate() throws Exception { |
|
71 int retVal = JPackageHelper.execute(null, app); |
|
72 if (retVal != 0) { |
|
73 throw new AssertionError( |
|
74 "Test application exited with error: " + retVal); |
|
75 } |
|
76 |
|
77 File outfile = new File(appWorkingDir + File.separator + appOutput); |
|
78 if (!outfile.exists()) { |
|
79 throw new AssertionError(appOutput + " was not created"); |
|
80 } |
|
81 |
|
82 String output = Files.readString(outfile.toPath()); |
|
83 String[] result = output.split("\n"); |
|
84 validateResult(result); |
|
85 } |
|
86 |
|
87 private static void validateIcon() throws Exception { |
|
88 File origIcon = new File(getIconPath()); |
|
89 File icon = new File(JPackagePath.getAppIcon("icon")); |
|
90 if (origIcon.length() != icon.length()) { |
|
91 System.err.println("file: " + origIcon + " - origIcon.length(): " |
|
92 + origIcon.length()); |
|
93 System.err.println("file: " + icon + " - icon.length(): " |
|
94 + icon.length()); |
|
95 throw new AssertionError("Icons size does not match"); |
|
96 } |
|
97 } |
|
98 |
|
99 private static void testIcon() throws Exception { |
|
100 JPackageHelper.executeCLI(true, CMD); |
|
101 validate(); |
|
102 validateIcon(); |
|
103 } |
|
104 |
|
105 private static void testIconToolProvider() throws Exception { |
|
106 JPackageHelper.deleteOutputFolder(OUTPUT); |
|
107 JPackageHelper.executeToolProvider(true, CMD); |
|
108 validate(); |
|
109 validateIcon(); |
|
110 } |
|
111 |
|
112 private static String getResourcenPath() { |
|
113 return JPackagePath.getTestSrcRoot() + File.separator + "resources"; |
|
114 } |
|
115 |
|
116 private static String getIconPath() { |
|
117 String ext = ".ico"; |
|
118 if (JPackageHelper.isOSX()) { |
|
119 ext = ".icns"; |
|
120 } else if (JPackageHelper.isLinux()) { |
|
121 ext = ".png"; |
|
122 } |
|
123 return resourceDir + File.separator + "icon" + ext; |
|
124 } |
|
125 |
|
126 public static void main(String[] args) throws Exception { |
|
127 JPackageHelper.createHelloImageJar(); |
|
128 testIcon(); |
|
129 testIconToolProvider(); |
|
130 } |
|
131 } |