author | herrick |
Mon, 10 Dec 2018 16:48:25 -0500 | |
branch | JDK-8200758-branch |
changeset 57067 | 9c17d779808e |
parent 57059 | 9bb2a4dc3af7 |
child 57070 | 42783e8e73de |
permissions | -rw-r--r-- |
57038 | 1 |
/* |
2 |
* Copyright (c) 2012, 2018, 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. Oracle designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
|
10 |
* |
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
24 |
*/ |
|
25 |
||
57039 | 26 |
package jdk.jpackage.internal; |
57038 | 27 |
|
57039 | 28 |
import jdk.jpackage.internal.resources.MacResources; |
57038 | 29 |
|
30 |
import java.io.File; |
|
31 |
import java.io.IOException; |
|
32 |
import java.math.BigInteger; |
|
33 |
import java.text.MessageFormat; |
|
34 |
import java.util.Arrays; |
|
35 |
import java.util.Collection; |
|
36 |
import java.util.HashMap; |
|
37 |
import java.util.Map; |
|
38 |
import java.util.Optional; |
|
39 |
import java.util.ResourceBundle; |
|
40 |
||
57039 | 41 |
import static jdk.jpackage.internal.StandardBundlerParam.*; |
42 |
import static jdk.jpackage.internal.MacBaseInstallerBundler.*; |
|
43 |
import jdk.jpackage.internal.AbstractAppImageBuilder; |
|
57038 | 44 |
|
45 |
public class MacAppBundler extends AbstractImageBundler { |
|
46 |
||
57059 | 47 |
private static final ResourceBundle I18N = ResourceBundle.getBundle( |
48 |
"jdk.jpackage.internal.resources.MacResources"); |
|
57038 | 49 |
|
50 |
private static final String TEMPLATE_BUNDLE_ICON = "GenericApp.icns"; |
|
51 |
||
52 |
private static Map<String, String> getMacCategories() { |
|
53 |
Map<String, String> map = new HashMap<>(); |
|
54 |
map.put("Business", "public.app-category.business"); |
|
55 |
map.put("Developer Tools", "public.app-category.developer-tools"); |
|
56 |
map.put("Education", "public.app-category.education"); |
|
57 |
map.put("Entertainment", "public.app-category.entertainment"); |
|
58 |
map.put("Finance", "public.app-category.finance"); |
|
59 |
map.put("Games", "public.app-category.games"); |
|
60 |
map.put("Graphics & Design", "public.app-category.graphics-design"); |
|
61 |
map.put("Healthcare & Fitness", |
|
62 |
"public.app-category.healthcare-fitness"); |
|
63 |
map.put("Lifestyle", "public.app-category.lifestyle"); |
|
64 |
map.put("Medical", "public.app-category.medical"); |
|
65 |
map.put("Music", "public.app-category.music"); |
|
66 |
map.put("News", "public.app-category.news"); |
|
67 |
map.put("Photography", "public.app-category.photography"); |
|
68 |
map.put("Productivity", "public.app-category.productivity"); |
|
69 |
map.put("Reference", "public.app-category.reference"); |
|
70 |
map.put("Social Networking", "public.app-category.social-networking"); |
|
71 |
map.put("Sports", "public.app-category.sports"); |
|
72 |
map.put("Travel", "public.app-category.travel"); |
|
73 |
map.put("Utilities", "public.app-category.utilities"); |
|
74 |
map.put("Video", "public.app-category.video"); |
|
75 |
map.put("Weather", "public.app-category.weather"); |
|
76 |
||
77 |
map.put("Action Games", "public.app-category.action-games"); |
|
78 |
map.put("Adventure Games", "public.app-category.adventure-games"); |
|
79 |
map.put("Arcade Games", "public.app-category.arcade-games"); |
|
80 |
map.put("Board Games", "public.app-category.board-games"); |
|
81 |
map.put("Card Games", "public.app-category.card-games"); |
|
82 |
map.put("Casino Games", "public.app-category.casino-games"); |
|
83 |
map.put("Dice Games", "public.app-category.dice-games"); |
|
84 |
map.put("Educational Games", "public.app-category.educational-games"); |
|
85 |
map.put("Family Games", "public.app-category.family-games"); |
|
86 |
map.put("Kids Games", "public.app-category.kids-games"); |
|
87 |
map.put("Music Games", "public.app-category.music-games"); |
|
88 |
map.put("Puzzle Games", "public.app-category.puzzle-games"); |
|
89 |
map.put("Racing Games", "public.app-category.racing-games"); |
|
90 |
map.put("Role Playing Games", "public.app-category.role-playing-games"); |
|
91 |
map.put("Simulation Games", "public.app-category.simulation-games"); |
|
92 |
map.put("Sports Games", "public.app-category.sports-games"); |
|
93 |
map.put("Strategy Games", "public.app-category.strategy-games"); |
|
94 |
map.put("Trivia Games", "public.app-category.trivia-games"); |
|
95 |
map.put("Word Games", "public.app-category.word-games"); |
|
96 |
||
97 |
return map; |
|
98 |
} |
|
99 |
||
100 |
public static final EnumeratedBundlerParam<String> MAC_CATEGORY = |
|
101 |
new EnumeratedBundlerParam<>( |
|
102 |
I18N.getString("param.category-name"), |
|
103 |
I18N.getString("param.category-name.description"), |
|
104 |
Arguments.CLIOptions.MAC_APP_STORE_CATEGORY.getId(), |
|
105 |
String.class, |
|
106 |
params -> params.containsKey(CATEGORY.getID()) |
|
107 |
? CATEGORY.fetchFrom(params) |
|
108 |
: "Unknown", |
|
109 |
(s, p) -> s, |
|
110 |
getMacCategories(), |
|
111 |
false //strict - for MacStoreBundler this should be strict |
|
112 |
); |
|
113 |
||
114 |
public static final BundlerParamInfo<String> MAC_CF_BUNDLE_NAME = |
|
115 |
new StandardBundlerParam<>( |
|
116 |
I18N.getString("param.cfbundle-name.name"), |
|
117 |
I18N.getString("param.cfbundle-name.description"), |
|
118 |
Arguments.CLIOptions.MAC_BUNDLE_NAME.getId(), |
|
119 |
String.class, |
|
120 |
params -> null, |
|
121 |
(s, p) -> s); |
|
122 |
||
123 |
public static final BundlerParamInfo<String> MAC_CF_BUNDLE_IDENTIFIER = |
|
124 |
new StandardBundlerParam<>( |
|
125 |
I18N.getString("param.cfbundle-identifier.name"), |
|
126 |
I18N.getString("param.cfbundle-identifier.description"), |
|
127 |
Arguments.CLIOptions.MAC_BUNDLE_IDENTIFIER.getId(), |
|
128 |
String.class, |
|
129 |
IDENTIFIER::fetchFrom, |
|
130 |
(s, p) -> s); |
|
131 |
||
132 |
public static final BundlerParamInfo<String> MAC_CF_BUNDLE_VERSION = |
|
133 |
new StandardBundlerParam<>( |
|
134 |
I18N.getString("param.cfbundle-version.name"), |
|
135 |
I18N.getString("param.cfbundle-version.description"), |
|
136 |
"mac.CFBundleVersion", |
|
137 |
String.class, |
|
138 |
p -> { |
|
139 |
String s = VERSION.fetchFrom(p); |
|
140 |
if (validCFBundleVersion(s)) { |
|
141 |
return s; |
|
142 |
} else { |
|
143 |
return "100"; |
|
144 |
} |
|
145 |
}, |
|
146 |
(s, p) -> s); |
|
147 |
||
148 |
public static final BundlerParamInfo<File> CONFIG_ROOT = |
|
149 |
new StandardBundlerParam<>( |
|
150 |
I18N.getString("param.config-root.name"), |
|
151 |
I18N.getString("param.config-root.description"), |
|
152 |
"configRoot", |
|
153 |
File.class, |
|
154 |
params -> { |
|
155 |
File configRoot = |
|
156 |
new File(BUILD_ROOT.fetchFrom(params), "macosx"); |
|
157 |
configRoot.mkdirs(); |
|
158 |
return configRoot; |
|
159 |
}, |
|
160 |
(s, p) -> new File(s)); |
|
161 |
||
162 |
public static final BundlerParamInfo<String> DEFAULT_ICNS_ICON = |
|
163 |
new StandardBundlerParam<>( |
|
164 |
I18N.getString("param.default-icon-icns"), |
|
165 |
I18N.getString("param.default-icon-icns.description"), |
|
166 |
".mac.default.icns", |
|
167 |
String.class, |
|
168 |
params -> TEMPLATE_BUNDLE_ICON, |
|
169 |
(s, p) -> s); |
|
170 |
||
171 |
public static final BundlerParamInfo<String> DEVELOPER_ID_APP_SIGNING_KEY = |
|
172 |
new StandardBundlerParam<>( |
|
173 |
I18N.getString("param.signing-key-developer-id-app.name"), |
|
174 |
I18N.getString("param.signing-key-developer-id-app.description"), |
|
175 |
"mac.signing-key-developer-id-app", |
|
176 |
String.class, |
|
177 |
params -> { |
|
178 |
String result = MacBaseInstallerBundler.findKey( |
|
179 |
"Developer ID Application: " |
|
180 |
+ SIGNING_KEY_USER.fetchFrom(params), |
|
181 |
SIGNING_KEYCHAIN.fetchFrom(params), |
|
182 |
VERBOSE.fetchFrom(params)); |
|
183 |
if (result != null) { |
|
184 |
MacCertificate certificate = new MacCertificate(result, |
|
185 |
VERBOSE.fetchFrom(params)); |
|
186 |
||
187 |
if (!certificate.isValid()) { |
|
188 |
Log.error(MessageFormat.format(I18N.getString( |
|
189 |
"error.certificate.expired"), result)); |
|
190 |
} |
|
191 |
} |
|
192 |
||
193 |
return result; |
|
194 |
}, |
|
195 |
(s, p) -> s); |
|
196 |
||
197 |
public static final BundlerParamInfo<String> BUNDLE_ID_SIGNING_PREFIX = |
|
198 |
new StandardBundlerParam<>( |
|
199 |
I18N.getString("param.bundle-id-signing-prefix.name"), |
|
200 |
I18N.getString("param.bundle-id-signing-prefix.description"), |
|
201 |
Arguments.CLIOptions.MAC_BUNDLE_SIGNING_PREFIX.getId(), |
|
202 |
String.class, |
|
203 |
params -> IDENTIFIER.fetchFrom(params) + ".", |
|
204 |
(s, p) -> s); |
|
205 |
||
206 |
public static final BundlerParamInfo<File> ICON_ICNS = |
|
207 |
new StandardBundlerParam<>( |
|
208 |
I18N.getString("param.icon-icns.name"), |
|
209 |
I18N.getString("param.icon-icns.description"), |
|
210 |
"icon.icns", |
|
211 |
File.class, |
|
212 |
params -> { |
|
213 |
File f = ICON.fetchFrom(params); |
|
214 |
if (f != null && !f.getName().toLowerCase().endsWith(".icns")) { |
|
215 |
Log.error(MessageFormat.format( |
|
216 |
I18N.getString("message.icon-not-icns"), f)); |
|
217 |
return null; |
|
218 |
} |
|
219 |
return f; |
|
220 |
}, |
|
221 |
(s, p) -> new File(s)); |
|
222 |
||
223 |
public MacAppBundler() { |
|
224 |
super(); |
|
225 |
baseResourceLoader = MacResources.class; |
|
226 |
} |
|
227 |
||
228 |
public static boolean validCFBundleVersion(String v) { |
|
229 |
// CFBundleVersion (String - iOS, OS X) specifies the build version |
|
230 |
// number of the bundle, which identifies an iteration (released or |
|
231 |
// unreleased) of the bundle. The build version number should be a |
|
232 |
// string comprised of three non-negative, period-separated integers |
|
233 |
// with the first integer being greater than zero. The string should |
|
234 |
// only contain numeric (0-9) and period (.) characters. Leading zeros |
|
235 |
// are truncated from each integer and will be ignored (that is, |
|
236 |
// 1.02.3 is equivalent to 1.2.3). This key is not localizable. |
|
237 |
||
238 |
if (v == null) { |
|
239 |
return false; |
|
240 |
} |
|
241 |
||
242 |
String p[] = v.split("\\."); |
|
243 |
if (p.length > 3 || p.length < 1) { |
|
244 |
Log.verbose(I18N.getString( |
|
245 |
"message.version-string-too-many-components")); |
|
246 |
return false; |
|
247 |
} |
|
248 |
||
249 |
try { |
|
250 |
BigInteger n = new BigInteger(p[0]); |
|
251 |
if (BigInteger.ONE.compareTo(n) > 0) { |
|
252 |
Log.verbose(I18N.getString( |
|
253 |
"message.version-string-first-number-not-zero")); |
|
254 |
return false; |
|
255 |
} |
|
256 |
if (p.length > 1) { |
|
257 |
n = new BigInteger(p[1]); |
|
258 |
if (BigInteger.ZERO.compareTo(n) > 0) { |
|
259 |
Log.verbose(I18N.getString( |
|
260 |
"message.version-string-no-negative-numbers")); |
|
261 |
return false; |
|
262 |
} |
|
263 |
} |
|
264 |
if (p.length > 2) { |
|
265 |
n = new BigInteger(p[2]); |
|
266 |
if (BigInteger.ZERO.compareTo(n) > 0) { |
|
267 |
Log.verbose(I18N.getString( |
|
268 |
"message.version-string-no-negative-numbers")); |
|
269 |
return false; |
|
270 |
} |
|
271 |
} |
|
272 |
} catch (NumberFormatException ne) { |
|
273 |
Log.verbose(I18N.getString("message.version-string-numbers-only")); |
|
274 |
Log.verbose(ne); |
|
275 |
return false; |
|
276 |
} |
|
277 |
||
278 |
return true; |
|
279 |
} |
|
280 |
||
281 |
@Override |
|
282 |
public boolean validate(Map<String, ? super Object> params) |
|
283 |
throws UnsupportedPlatformException, ConfigException { |
|
284 |
try { |
|
285 |
return doValidate(params); |
|
286 |
} catch (RuntimeException re) { |
|
287 |
if (re.getCause() instanceof ConfigException) { |
|
288 |
throw (ConfigException) re.getCause(); |
|
289 |
} else { |
|
290 |
throw new ConfigException(re); |
|
291 |
} |
|
292 |
} |
|
293 |
} |
|
294 |
||
57067
9c17d779808e
8213425: Analyze output from Source code scanner and fix where needed.
herrick
parents:
57059
diff
changeset
|
295 |
private boolean doValidate(Map<String, ? super Object> p) |
57038 | 296 |
throws UnsupportedPlatformException, ConfigException { |
297 |
if (Platform.getPlatform() != Platform.MAC) { |
|
298 |
throw new UnsupportedPlatformException(); |
|
299 |
} |
|
300 |
||
301 |
imageBundleValidation(p); |
|
302 |
||
303 |
if (StandardBundlerParam.getPredefinedAppImage(p) != null) { |
|
304 |
return true; |
|
305 |
} |
|
306 |
||
307 |
// validate short version |
|
308 |
if (!validCFBundleVersion(MAC_CF_BUNDLE_VERSION.fetchFrom(p))) { |
|
309 |
throw new ConfigException( |
|
310 |
I18N.getString("error.invalid-cfbundle-version"), |
|
311 |
I18N.getString("error.invalid-cfbundle-version.advice")); |
|
312 |
} |
|
313 |
||
314 |
// reject explicitly set sign to true and no valid signature key |
|
315 |
if (Optional.ofNullable(MacAppImageBuilder. |
|
316 |
SIGN_BUNDLE.fetchFrom(p)).orElse(Boolean.FALSE)) { |
|
317 |
String signingIdentity = DEVELOPER_ID_APP_SIGNING_KEY.fetchFrom(p); |
|
318 |
if (signingIdentity == null) { |
|
319 |
throw new ConfigException( |
|
320 |
I18N.getString("error.explicit-sign-no-cert"), |
|
321 |
I18N.getString("error.explicit-sign-no-cert.advice")); |
|
322 |
} |
|
323 |
} |
|
324 |
||
325 |
return true; |
|
326 |
} |
|
327 |
||
328 |
private File getConfig_InfoPlist(Map<String, ? super Object> params) { |
|
329 |
return new File(CONFIG_ROOT.fetchFrom(params), "Info.plist"); |
|
330 |
} |
|
331 |
||
332 |
private File getConfig_Icon(Map<String, ? super Object> params) { |
|
333 |
return new File(CONFIG_ROOT.fetchFrom(params), |
|
334 |
APP_NAME.fetchFrom(params) + ".icns"); |
|
335 |
} |
|
336 |
||
337 |
File doBundle(Map<String, ? super Object> p, File outputDirectory, |
|
338 |
boolean dependentTask) { |
|
339 |
if (Arguments.CREATE_JRE_INSTALLER.fetchFrom(p)) { |
|
340 |
return doJreBundle(p, outputDirectory, dependentTask); |
|
341 |
} else { |
|
342 |
return doAppBundle(p, outputDirectory, dependentTask); |
|
343 |
} |
|
344 |
} |
|
345 |
||
346 |
File doJreBundle(Map<String, ? super Object> p, |
|
347 |
File outputDirectory, boolean dependentTask) { |
|
348 |
try { |
|
349 |
File rootDirectory = createRoot(p, outputDirectory, dependentTask, |
|
350 |
APP_NAME.fetchFrom(p), "macapp-image-builder"); |
|
351 |
AbstractAppImageBuilder appBuilder = new MacAppImageBuilder(p, |
|
352 |
APP_NAME.fetchFrom(p), outputDirectory.toPath()); |
|
353 |
File predefined = PREDEFINED_RUNTIME_IMAGE.fetchFrom(p); |
|
354 |
if (predefined == null ) { |
|
355 |
JLinkBundlerHelper.generateServerJre(p, appBuilder); |
|
356 |
} else { |
|
357 |
return predefined; |
|
358 |
} |
|
359 |
return rootDirectory; |
|
360 |
} catch (Exception ex) { |
|
361 |
Log.error("Exception: "+ex); |
|
362 |
Log.verbose(ex); |
|
363 |
return null; |
|
364 |
} |
|
365 |
} |
|
366 |
||
367 |
File doAppBundle(Map<String, ? super Object> p, File outputDirectory, |
|
368 |
boolean dependentTask) { |
|
369 |
try { |
|
370 |
File rootDirectory = createRoot(p, outputDirectory, dependentTask, |
|
371 |
APP_NAME.fetchFrom(p) + ".app", "macapp-image-builder"); |
|
372 |
AbstractAppImageBuilder appBuilder = |
|
373 |
new MacAppImageBuilder(p, outputDirectory.toPath()); |
|
374 |
if (PREDEFINED_RUNTIME_IMAGE.fetchFrom(p) == null ) { |
|
375 |
JLinkBundlerHelper.execute(p, appBuilder); |
|
376 |
} else { |
|
377 |
StandardBundlerParam.copyPredefinedRuntimeImage(p, appBuilder); |
|
378 |
} |
|
379 |
return rootDirectory; |
|
380 |
} catch (Exception ex) { |
|
381 |
Log.error("Exception: "+ex); |
|
382 |
Log.verbose(ex); |
|
383 |
return null; |
|
384 |
} |
|
385 |
} |
|
386 |
||
387 |
public void cleanupConfigFiles(Map<String, ? super Object> params) { |
|
388 |
if (Log.isDebug() || Log.isVerbose()) { |
|
389 |
return; |
|
390 |
} |
|
391 |
||
392 |
if (CONFIG_ROOT.fetchFrom(params) != null) { |
|
393 |
getConfig_Icon(params).delete(); |
|
394 |
getConfig_InfoPlist(params).delete(); |
|
395 |
} |
|
396 |
} |
|
397 |
||
398 |
///////////////////////////////////////////////////////////////////////// |
|
399 |
// Implement Bundler |
|
400 |
///////////////////////////////////////////////////////////////////////// |
|
401 |
||
402 |
@Override |
|
403 |
public String getName() { |
|
57059 | 404 |
return I18N.getString("app.bundler.name"); |
57038 | 405 |
} |
406 |
||
407 |
@Override |
|
408 |
public String getDescription() { |
|
57059 | 409 |
return I18N.getString("app.bundler.description"); |
57038 | 410 |
} |
411 |
||
412 |
@Override |
|
413 |
public String getID() { |
|
414 |
return "mac.app"; |
|
415 |
} |
|
416 |
||
417 |
@Override |
|
418 |
public String getBundleType() { |
|
419 |
return "IMAGE"; |
|
420 |
} |
|
421 |
||
422 |
@Override |
|
423 |
public Collection<BundlerParamInfo<?>> getBundleParameters() { |
|
424 |
return getAppBundleParameters(); |
|
425 |
} |
|
426 |
||
427 |
public static Collection<BundlerParamInfo<?>> getAppBundleParameters() { |
|
428 |
return Arrays.asList( |
|
429 |
APP_NAME, |
|
430 |
APP_RESOURCES, |
|
431 |
ARGUMENTS, |
|
432 |
BUNDLE_ID_SIGNING_PREFIX, |
|
433 |
CLASSPATH, |
|
434 |
DEVELOPER_ID_APP_SIGNING_KEY, |
|
435 |
ICON_ICNS, |
|
436 |
JVM_OPTIONS, |
|
437 |
MAC_CATEGORY, |
|
438 |
MAC_CF_BUNDLE_IDENTIFIER, |
|
439 |
MAC_CF_BUNDLE_NAME, |
|
440 |
MAC_CF_BUNDLE_VERSION, |
|
441 |
MAIN_CLASS, |
|
442 |
MAIN_JAR, |
|
443 |
PREFERENCES_ID, |
|
444 |
SIGNING_KEYCHAIN, |
|
445 |
VERSION, |
|
446 |
VERBOSE |
|
447 |
); |
|
448 |
} |
|
449 |
||
450 |
||
451 |
@Override |
|
452 |
public File execute(Map<String, ? super Object> params, |
|
453 |
File outputParentDir) { |
|
454 |
return doBundle(params, outputParentDir, false); |
|
455 |
} |
|
456 |
||
457 |
@Override |
|
458 |
public boolean supported() { |
|
459 |
return Platform.getPlatform() == Platform.MAC; |
|
460 |
} |
|
461 |
||
462 |
} |