author | herrick |
Mon, 10 Dec 2018 16:48:25 -0500 | |
branch | JDK-8200758-branch |
changeset 57067 | 9c17d779808e |
parent 57059 | 9bb2a4dc3af7 |
child 57080 | bd4ce7f9ea2c |
permissions | -rw-r--r-- |
57038 | 1 |
/* |
2 |
* Copyright (c) 2014, 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.BufferedWriter; |
|
31 |
import java.io.File; |
|
32 |
import java.io.FileWriter; |
|
33 |
import java.io.IOException; |
|
34 |
import java.io.PrintStream; |
|
35 |
import java.io.Writer; |
|
36 |
import java.net.URLEncoder; |
|
37 |
import java.text.MessageFormat; |
|
38 |
import java.util.ArrayList; |
|
39 |
import java.util.Arrays; |
|
40 |
import java.util.Collection; |
|
41 |
import java.util.HashMap; |
|
42 |
import java.util.LinkedHashSet; |
|
43 |
import java.util.List; |
|
44 |
import java.util.Map; |
|
45 |
import java.util.Optional; |
|
46 |
import java.util.ResourceBundle; |
|
47 |
||
57039 | 48 |
import static jdk.jpackage.internal.StandardBundlerParam.*; |
57067
9c17d779808e
8213425: Analyze output from Source code scanner and fix where needed.
herrick
parents:
57059
diff
changeset
|
49 |
import static jdk.jpackage.internal.MacBaseInstallerBundler.SIGNING_KEYCHAIN; |
9c17d779808e
8213425: Analyze output from Source code scanner and fix where needed.
herrick
parents:
57059
diff
changeset
|
50 |
import static jdk.jpackage.internal.MacBaseInstallerBundler.SIGNING_KEY_USER; |
57038 | 51 |
|
52 |
public class MacPkgBundler extends MacBaseInstallerBundler { |
|
53 |
||
54 |
private static final ResourceBundle I18N = ResourceBundle.getBundle( |
|
57059 | 55 |
"jdk.jpackage.internal.resources.MacResources"); |
57038 | 56 |
|
57 |
private static final String DEFAULT_BACKGROUND_IMAGE = "background_pkg.png"; |
|
58 |
||
59 |
private static final String TEMPLATE_PREINSTALL_SCRIPT = |
|
60 |
"preinstall.template"; |
|
61 |
private static final String TEMPLATE_POSTINSTALL_SCRIPT = |
|
62 |
"postinstall.template"; |
|
63 |
||
64 |
private static final BundlerParamInfo<File> PACKAGES_ROOT = |
|
65 |
new StandardBundlerParam<>( |
|
66 |
I18N.getString("param.packages-root.name"), |
|
67 |
I18N.getString("param.packages-root.description"), |
|
68 |
"mac.pkg.packagesRoot", |
|
69 |
File.class, |
|
70 |
params -> { |
|
71 |
File packagesRoot = |
|
72 |
new File(BUILD_ROOT.fetchFrom(params), "packages"); |
|
73 |
packagesRoot.mkdirs(); |
|
74 |
return packagesRoot; |
|
75 |
}, |
|
76 |
(s, p) -> new File(s)); |
|
77 |
||
78 |
||
79 |
protected final BundlerParamInfo<File> SCRIPTS_DIR = |
|
80 |
new StandardBundlerParam<>( |
|
81 |
I18N.getString("param.scripts-dir.name"), |
|
82 |
I18N.getString("param.scripts-dir.description"), |
|
83 |
"mac.pkg.scriptsDir", |
|
84 |
File.class, |
|
85 |
params -> { |
|
86 |
File scriptsDir = |
|
87 |
new File(CONFIG_ROOT.fetchFrom(params), "scripts"); |
|
88 |
scriptsDir.mkdirs(); |
|
89 |
return scriptsDir; |
|
90 |
}, |
|
91 |
(s, p) -> new File(s)); |
|
92 |
||
93 |
public static final |
|
94 |
BundlerParamInfo<String> DEVELOPER_ID_INSTALLER_SIGNING_KEY = |
|
95 |
new StandardBundlerParam<>( |
|
96 |
I18N.getString("param.signing-key-developer-id-installer.name"), |
|
97 |
I18N.getString( |
|
98 |
"param.signing-key-developer-id-installer.description"), |
|
99 |
"mac.signing-key-developer-id-installer", |
|
100 |
String.class, |
|
101 |
params -> { |
|
102 |
String result = MacBaseInstallerBundler.findKey( |
|
103 |
"Developer ID Installer: " |
|
104 |
+ SIGNING_KEY_USER.fetchFrom(params), |
|
105 |
SIGNING_KEYCHAIN.fetchFrom(params), |
|
106 |
VERBOSE.fetchFrom(params)); |
|
107 |
if (result != null) { |
|
108 |
MacCertificate certificate = new MacCertificate( |
|
109 |
result, VERBOSE.fetchFrom(params)); |
|
110 |
||
111 |
if (!certificate.isValid()) { |
|
112 |
Log.error(MessageFormat.format( |
|
113 |
I18N.getString("error.certificate.expired"), |
|
114 |
result)); |
|
115 |
} |
|
116 |
} |
|
117 |
||
118 |
return result; |
|
119 |
}, |
|
120 |
(s, p) -> s); |
|
121 |
||
122 |
public static final BundlerParamInfo<String> MAC_INSTALL_DIR = |
|
123 |
new StandardBundlerParam<>( |
|
124 |
I18N.getString("param.mac-install-dir.name"), |
|
125 |
I18N.getString("param.mac-install-dir.description"), |
|
126 |
"mac-install-dir", |
|
127 |
String.class, |
|
128 |
params -> { |
|
129 |
String dir = INSTALL_DIR.fetchFrom(params); |
|
130 |
return (dir != null) ? dir : "/Applications"; |
|
131 |
}, |
|
132 |
(s, p) -> s |
|
133 |
); |
|
134 |
||
135 |
public static final BundlerParamInfo<String> INSTALLER_SUFFIX = |
|
136 |
new StandardBundlerParam<> ( |
|
137 |
I18N.getString("param.installer-suffix.name"), |
|
138 |
I18N.getString("param.installer-suffix.description"), |
|
139 |
"mac.pkg.installerName.suffix", |
|
140 |
String.class, |
|
141 |
params -> "", |
|
142 |
(s, p) -> s); |
|
143 |
||
144 |
public MacPkgBundler() { |
|
145 |
super(); |
|
146 |
baseResourceLoader = MacResources.class; |
|
147 |
} |
|
148 |
||
149 |
public File bundle(Map<String, ? super Object> params, File outdir) { |
|
150 |
Log.verbose(MessageFormat.format(I18N.getString("message.building-pkg"), |
|
151 |
APP_NAME.fetchFrom(params))); |
|
152 |
if (!outdir.isDirectory() && !outdir.mkdirs()) { |
|
153 |
throw new RuntimeException(MessageFormat.format( |
|
154 |
I18N.getString("error.cannot-create-output-dir"), |
|
155 |
outdir.getAbsolutePath())); |
|
156 |
} |
|
157 |
if (!outdir.canWrite()) { |
|
158 |
throw new RuntimeException(MessageFormat.format( |
|
159 |
I18N.getString("error.cannot-write-to-output-dir"), |
|
160 |
outdir.getAbsolutePath())); |
|
161 |
} |
|
162 |
||
163 |
File appImageDir = null; |
|
164 |
try { |
|
165 |
appImageDir = prepareAppBundle(params, false); |
|
166 |
||
167 |
if (appImageDir != null && prepareConfigFiles(params)) { |
|
168 |
||
169 |
File configScript = getConfig_Script(params); |
|
170 |
if (configScript.exists()) { |
|
171 |
Log.verbose(MessageFormat.format(I18N.getString( |
|
172 |
"message.running-script"), |
|
173 |
configScript.getAbsolutePath())); |
|
174 |
IOUtils.run("bash", configScript, false); |
|
175 |
} |
|
176 |
||
177 |
return createPKG(params, outdir, appImageDir); |
|
178 |
} |
|
179 |
return null; |
|
180 |
} catch (IOException ex) { |
|
181 |
Log.verbose(ex); |
|
182 |
return null; |
|
183 |
} finally { |
|
184 |
try { |
|
185 |
if (appImageDir != null && |
|
186 |
PREDEFINED_APP_IMAGE.fetchFrom(params) == null && |
|
187 |
(PREDEFINED_RUNTIME_IMAGE.fetchFrom(params) == null || |
|
188 |
!Arguments.CREATE_JRE_INSTALLER.fetchFrom(params)) && |
|
189 |
!Log.isDebug() && |
|
190 |
!Log.isVerbose()) { |
|
191 |
IOUtils.deleteRecursive(appImageDir); |
|
192 |
} else if (appImageDir != null) { |
|
193 |
Log.verbose(MessageFormat.format(I18N.getString( |
|
194 |
"message.intermediate-image-location"), |
|
195 |
appImageDir.getAbsolutePath())); |
|
196 |
} |
|
197 |
||
198 |
// cleanup |
|
199 |
cleanupConfigFiles(params); |
|
200 |
} catch (IOException ex) { |
|
201 |
Log.debug(ex); |
|
202 |
// noinspection ReturnInsideFinallyBlock |
|
203 |
return null; |
|
204 |
} |
|
205 |
} |
|
206 |
} |
|
207 |
||
208 |
private File getPackages_AppPackage(Map<String, ? super Object> params) { |
|
209 |
return new File(PACKAGES_ROOT.fetchFrom(params), |
|
210 |
APP_FS_NAME.fetchFrom(params) + "-app.pkg"); |
|
211 |
} |
|
212 |
||
213 |
private File getPackages_DaemonPackage(Map<String, ? super Object> params) { |
|
214 |
return new File(PACKAGES_ROOT.fetchFrom(params), |
|
215 |
APP_FS_NAME.fetchFrom(params) + "-daemon.pkg"); |
|
216 |
} |
|
217 |
||
218 |
private void cleanupPackagesFiles(Map<String, ? super Object> params) { |
|
219 |
if (Log.isDebug() || Log.isVerbose()) { |
|
220 |
return; |
|
221 |
} |
|
222 |
||
223 |
if (getPackages_AppPackage(params) != null) { |
|
224 |
getPackages_AppPackage(params).delete(); |
|
225 |
} |
|
226 |
if (getPackages_DaemonPackage(params) != null) { |
|
227 |
getPackages_DaemonPackage(params).delete(); |
|
228 |
} |
|
229 |
} |
|
230 |
||
231 |
private File getConfig_DistributionXMLFile( |
|
232 |
Map<String, ? super Object> params) { |
|
233 |
return new File(CONFIG_ROOT.fetchFrom(params), "distribution.dist"); |
|
234 |
} |
|
235 |
||
236 |
private File getConfig_BackgroundImage(Map<String, ? super Object> params) { |
|
237 |
return new File(CONFIG_ROOT.fetchFrom(params), |
|
238 |
APP_NAME.fetchFrom(params) + "-background.png"); |
|
239 |
} |
|
240 |
||
241 |
private File getScripts_PreinstallFile(Map<String, ? super Object> params) { |
|
242 |
return new File(SCRIPTS_DIR.fetchFrom(params), "preinstall"); |
|
243 |
} |
|
244 |
||
245 |
private File getScripts_PostinstallFile( |
|
246 |
Map<String, ? super Object> params) { |
|
247 |
return new File(SCRIPTS_DIR.fetchFrom(params), "postinstall"); |
|
248 |
} |
|
249 |
||
250 |
private void cleanupConfigFiles(Map<String, ? super Object> params) { |
|
251 |
if (Log.isDebug() || Log.isVerbose()) { |
|
252 |
return; |
|
253 |
} |
|
254 |
||
255 |
if (getConfig_DistributionXMLFile(params) != null) { |
|
256 |
getConfig_DistributionXMLFile(params).delete(); |
|
257 |
} |
|
258 |
if (getConfig_BackgroundImage(params) != null) { |
|
259 |
getConfig_BackgroundImage(params).delete(); |
|
260 |
} |
|
261 |
} |
|
262 |
||
263 |
private String getAppIdentifier(Map<String, ? super Object> params) { |
|
264 |
return IDENTIFIER.fetchFrom(params); |
|
265 |
} |
|
266 |
||
267 |
private String getDaemonIdentifier(Map<String, ? super Object> params) { |
|
268 |
return IDENTIFIER.fetchFrom(params) + ".daemon"; |
|
269 |
} |
|
270 |
||
271 |
private void preparePackageScripts(Map<String, ? super Object> params) |
|
272 |
throws IOException { |
|
273 |
Log.verbose(I18N.getString("message.preparing-scripts")); |
|
274 |
||
275 |
Map<String, String> data = new HashMap<>(); |
|
276 |
||
277 |
data.put("DEPLOY_DAEMON_IDENTIFIER", getDaemonIdentifier(params)); |
|
278 |
data.put("DEPLOY_LAUNCHD_PLIST_FILE", |
|
279 |
IDENTIFIER.fetchFrom(params).toLowerCase() + ".launchd.plist"); |
|
280 |
||
281 |
Writer w = new BufferedWriter( |
|
282 |
new FileWriter(getScripts_PreinstallFile(params))); |
|
283 |
String content = preprocessTextResource(MacAppBundler.BUNDLER_PREFIX |
|
284 |
+ getScripts_PreinstallFile(params).getName(), |
|
285 |
I18N.getString("resource.pkg-preinstall-script"), |
|
286 |
TEMPLATE_PREINSTALL_SCRIPT, |
|
287 |
data, |
|
288 |
VERBOSE.fetchFrom(params), |
|
289 |
DROP_IN_RESOURCES_ROOT.fetchFrom(params)); |
|
290 |
w.write(content); |
|
291 |
w.close(); |
|
292 |
getScripts_PreinstallFile(params).setExecutable(true, false); |
|
293 |
||
294 |
w = new BufferedWriter( |
|
295 |
new FileWriter(getScripts_PostinstallFile(params))); |
|
296 |
content = preprocessTextResource(MacAppBundler.BUNDLER_PREFIX |
|
297 |
+ getScripts_PostinstallFile(params).getName(), |
|
298 |
I18N.getString("resource.pkg-postinstall-script"), |
|
299 |
TEMPLATE_POSTINSTALL_SCRIPT, |
|
300 |
data, |
|
301 |
VERBOSE.fetchFrom(params), |
|
302 |
DROP_IN_RESOURCES_ROOT.fetchFrom(params)); |
|
303 |
w.write(content); |
|
304 |
w.close(); |
|
305 |
getScripts_PostinstallFile(params).setExecutable(true, false); |
|
306 |
} |
|
307 |
||
308 |
private void prepareDistributionXMLFile(Map<String, ? super Object> params) |
|
309 |
throws IOException { |
|
310 |
File f = getConfig_DistributionXMLFile(params); |
|
311 |
||
312 |
Log.verbose(MessageFormat.format(I18N.getString( |
|
313 |
"message.preparing-distribution-dist"), f.getAbsolutePath())); |
|
314 |
||
315 |
PrintStream out = new PrintStream(f); |
|
316 |
||
317 |
out.println( |
|
318 |
"<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>"); |
|
319 |
out.println("<installer-gui-script minSpecVersion=\"1\">"); |
|
320 |
||
321 |
out.println("<title>" + APP_NAME.fetchFrom(params) + "</title>"); |
|
322 |
out.println("<background" + " file=\"" |
|
323 |
+ getConfig_BackgroundImage(params).getName() |
|
324 |
+ "\"" |
|
325 |
+ " mime-type=\"image/png\"" |
|
326 |
+ " alignment=\"bottomleft\" " |
|
327 |
+ " scaling=\"none\"" |
|
328 |
+ "/>"); |
|
329 |
||
330 |
if (!LICENSE_FILE.fetchFrom(params).isEmpty()) { |
|
331 |
File licFile = null; |
|
332 |
||
333 |
List<String> licFiles = LICENSE_FILE.fetchFrom(params); |
|
334 |
if (licFiles.isEmpty()) { |
|
335 |
return; |
|
336 |
} |
|
337 |
String licFileStr = licFiles.get(0); |
|
338 |
||
339 |
for (RelativeFileSet rfs : APP_RESOURCES_LIST.fetchFrom(params)) { |
|
340 |
if (rfs.contains(licFileStr)) { |
|
341 |
licFile = new File(rfs.getBaseDirectory(), licFileStr); |
|
342 |
break; |
|
343 |
} |
|
344 |
} |
|
345 |
||
346 |
// this is NPE protection, validate should have caught it's absence |
|
347 |
// so we don't complain or throw an error |
|
348 |
if (licFile != null) { |
|
349 |
out.println("<license" |
|
350 |
+ " file=\"" + licFile.getAbsolutePath() + "\"" |
|
351 |
+ " mime-type=\"text/rtf\"" |
|
352 |
+ "/>"); |
|
353 |
} |
|
354 |
} |
|
355 |
||
356 |
/* |
|
357 |
* Note that the content of the distribution file |
|
358 |
* below is generated by productbuild --synthesize |
|
359 |
*/ |
|
360 |
||
361 |
String appId = getAppIdentifier(params); |
|
362 |
String daemonId = getDaemonIdentifier(params); |
|
363 |
||
364 |
out.println("<pkg-ref id=\"" + appId + "\"/>"); |
|
365 |
||
366 |
out.println("<options customize=\"never\" require-scripts=\"false\"/>"); |
|
367 |
out.println("<choices-outline>"); |
|
368 |
out.println(" <line choice=\"default\">"); |
|
369 |
out.println(" <line choice=\"" + appId + "\"/>"); |
|
370 |
out.println(" </line>"); |
|
371 |
out.println("</choices-outline>"); |
|
372 |
out.println("<choice id=\"default\"/>"); |
|
373 |
out.println("<choice id=\"" + appId + "\" visible=\"false\">"); |
|
374 |
out.println(" <pkg-ref id=\"" + appId + "\"/>"); |
|
375 |
out.println("</choice>"); |
|
376 |
out.println("<pkg-ref id=\"" + appId + "\" version=\"" |
|
377 |
+ VERSION.fetchFrom(params) + "\" onConclusion=\"none\">" |
|
378 |
+ URLEncoder.encode(getPackages_AppPackage(params).getName(), |
|
379 |
"UTF-8") + "</pkg-ref>"); |
|
380 |
||
381 |
out.println("</installer-gui-script>"); |
|
382 |
||
383 |
out.close(); |
|
384 |
} |
|
385 |
||
386 |
private boolean prepareConfigFiles(Map<String, ? super Object> params) |
|
387 |
throws IOException { |
|
388 |
File imageTarget = getConfig_BackgroundImage(params); |
|
389 |
fetchResource(MacAppBundler.BUNDLER_PREFIX + imageTarget.getName(), |
|
390 |
I18N.getString("resource.pkg-background-image"), |
|
391 |
DEFAULT_BACKGROUND_IMAGE, |
|
392 |
imageTarget, |
|
393 |
VERBOSE.fetchFrom(params), |
|
394 |
DROP_IN_RESOURCES_ROOT.fetchFrom(params)); |
|
395 |
||
396 |
prepareDistributionXMLFile(params); |
|
397 |
||
398 |
fetchResource(MacAppBundler.BUNDLER_PREFIX |
|
399 |
+ getConfig_Script(params).getName(), |
|
400 |
I18N.getString("resource.post-install-script"), |
|
401 |
(String) null, |
|
402 |
getConfig_Script(params), |
|
403 |
VERBOSE.fetchFrom(params), |
|
404 |
DROP_IN_RESOURCES_ROOT.fetchFrom(params)); |
|
405 |
||
406 |
return true; |
|
407 |
} |
|
408 |
||
409 |
// name of post-image script |
|
410 |
private File getConfig_Script(Map<String, ? super Object> params) { |
|
411 |
return new File(CONFIG_ROOT.fetchFrom(params), |
|
412 |
APP_NAME.fetchFrom(params) + "-post-image.sh"); |
|
413 |
} |
|
414 |
||
415 |
private File createPKG(Map<String, ? super Object> params, |
|
416 |
File outdir, File appLocation) { |
|
417 |
// generic find attempt |
|
418 |
try { |
|
419 |
File appPKG = getPackages_AppPackage(params); |
|
420 |
||
421 |
// build application package |
|
422 |
ProcessBuilder pb = new ProcessBuilder("pkgbuild", |
|
423 |
"--component", |
|
424 |
appLocation.toString(), |
|
425 |
"--install-location", |
|
426 |
MAC_INSTALL_DIR.fetchFrom(params), |
|
427 |
appPKG.getAbsolutePath()); |
|
428 |
IOUtils.exec(pb, false); |
|
429 |
||
430 |
// build final package |
|
431 |
File finalPKG = new File(outdir, INSTALLER_NAME.fetchFrom(params) |
|
432 |
+ INSTALLER_SUFFIX.fetchFrom(params) |
|
433 |
+ ".pkg"); |
|
434 |
outdir.mkdirs(); |
|
435 |
||
436 |
List<String> commandLine = new ArrayList<>(); |
|
437 |
commandLine.add("productbuild"); |
|
438 |
||
439 |
commandLine.add("--resources"); |
|
440 |
commandLine.add(CONFIG_ROOT.fetchFrom(params).getAbsolutePath()); |
|
441 |
||
442 |
// maybe sign |
|
443 |
if (Optional.ofNullable(MacAppImageBuilder. |
|
444 |
SIGN_BUNDLE.fetchFrom(params)).orElse(Boolean.TRUE)) { |
|
445 |
if (Platform.getMajorVersion() > 10 || |
|
446 |
(Platform.getMajorVersion() == 10 && |
|
447 |
Platform.getMinorVersion() >= 12)) { |
|
448 |
// we need this for OS X 10.12+ |
|
449 |
Log.verbose(I18N.getString("message.signing.pkg")); |
|
450 |
} |
|
451 |
||
452 |
String signingIdentity = |
|
453 |
DEVELOPER_ID_INSTALLER_SIGNING_KEY.fetchFrom(params); |
|
454 |
if (signingIdentity != null) { |
|
455 |
commandLine.add("--sign"); |
|
456 |
commandLine.add(signingIdentity); |
|
457 |
} |
|
458 |
||
459 |
String keychainName = SIGNING_KEYCHAIN.fetchFrom(params); |
|
460 |
if (keychainName != null && !keychainName.isEmpty()) { |
|
461 |
commandLine.add("--keychain"); |
|
462 |
commandLine.add(keychainName); |
|
463 |
} |
|
464 |
} |
|
465 |
||
466 |
commandLine.add("--distribution"); |
|
467 |
commandLine.add( |
|
468 |
getConfig_DistributionXMLFile(params).getAbsolutePath()); |
|
469 |
commandLine.add("--package-path"); |
|
470 |
commandLine.add(PACKAGES_ROOT.fetchFrom(params).getAbsolutePath()); |
|
471 |
||
472 |
commandLine.add(finalPKG.getAbsolutePath()); |
|
473 |
||
474 |
pb = new ProcessBuilder(commandLine); |
|
475 |
IOUtils.exec(pb, false); |
|
476 |
||
477 |
return finalPKG; |
|
478 |
} catch (Exception ignored) { |
|
479 |
Log.verbose(ignored); |
|
480 |
return null; |
|
481 |
} finally { |
|
482 |
cleanupPackagesFiles(params); |
|
483 |
cleanupConfigFiles(params); |
|
484 |
} |
|
485 |
} |
|
486 |
||
487 |
////////////////////////////////////////////////////////////////////////// |
|
488 |
// Implement Bundler |
|
489 |
////////////////////////////////////////////////////////////////////////// |
|
490 |
||
491 |
@Override |
|
492 |
public String getName() { |
|
57059 | 493 |
return I18N.getString("pkg.bundler.name"); |
57038 | 494 |
} |
495 |
||
496 |
@Override |
|
497 |
public String getDescription() { |
|
57059 | 498 |
return I18N.getString("pkg.bundler.description"); |
57038 | 499 |
} |
500 |
||
501 |
@Override |
|
502 |
public String getID() { |
|
503 |
return "pkg"; |
|
504 |
} |
|
505 |
||
506 |
@Override |
|
507 |
public Collection<BundlerParamInfo<?>> getBundleParameters() { |
|
508 |
Collection<BundlerParamInfo<?>> results = new LinkedHashSet<>(); |
|
509 |
results.addAll(MacAppBundler.getAppBundleParameters()); |
|
510 |
results.addAll(getPKGBundleParameters()); |
|
511 |
return results; |
|
512 |
} |
|
513 |
||
514 |
public Collection<BundlerParamInfo<?>> getPKGBundleParameters() { |
|
515 |
Collection<BundlerParamInfo<?>> results = new LinkedHashSet<>(); |
|
516 |
||
517 |
results.addAll(MacAppBundler.getAppBundleParameters()); |
|
518 |
results.addAll(Arrays.asList( |
|
519 |
DEVELOPER_ID_INSTALLER_SIGNING_KEY, |
|
520 |
// IDENTIFIER, |
|
521 |
INSTALLER_SUFFIX, |
|
522 |
LICENSE_FILE, |
|
523 |
// SERVICE_HINT, |
|
524 |
SIGNING_KEYCHAIN)); |
|
525 |
||
526 |
return results; |
|
527 |
} |
|
528 |
||
529 |
@Override |
|
530 |
public boolean validate(Map<String, ? super Object> params) |
|
531 |
throws UnsupportedPlatformException, ConfigException { |
|
532 |
try { |
|
533 |
if (params == null) throw new ConfigException( |
|
534 |
I18N.getString("error.parameters-null"), |
|
535 |
I18N.getString("error.parameters-null.advice")); |
|
536 |
||
537 |
// run basic validation to ensure requirements are met |
|
538 |
// we are not interested in return code, only possible exception |
|
539 |
validateAppImageAndBundeler(params); |
|
540 |
||
541 |
// validate license file, if used, exists in the proper place |
|
542 |
if (params.containsKey(LICENSE_FILE.getID())) { |
|
543 |
List<RelativeFileSet> appResourcesList = |
|
544 |
APP_RESOURCES_LIST.fetchFrom(params); |
|
545 |
for (String license : LICENSE_FILE.fetchFrom(params)) { |
|
546 |
boolean found = false; |
|
547 |
for (RelativeFileSet appResources : appResourcesList) { |
|
548 |
found = found || appResources.contains(license); |
|
549 |
} |
|
550 |
if (!found) { |
|
551 |
throw new ConfigException( |
|
552 |
I18N.getString("error.license-missing"), |
|
553 |
MessageFormat.format( |
|
554 |
I18N.getString("error.license-missing.advice"), |
|
555 |
license)); |
|
556 |
} |
|
557 |
} |
|
558 |
} |
|
559 |
||
560 |
// reject explicitly set sign to true and no valid signature key |
|
561 |
if (Optional.ofNullable(MacAppImageBuilder. |
|
562 |
SIGN_BUNDLE.fetchFrom(params)).orElse(Boolean.FALSE)) { |
|
563 |
String signingIdentity = |
|
564 |
DEVELOPER_ID_INSTALLER_SIGNING_KEY.fetchFrom(params); |
|
565 |
if (signingIdentity == null) { |
|
566 |
throw new ConfigException( |
|
567 |
I18N.getString("error.explicit-sign-no-cert"), |
|
568 |
I18N.getString( |
|
569 |
"error.explicit-sign-no-cert.advice")); |
|
570 |
} |
|
571 |
} |
|
572 |
||
573 |
// hdiutil is always available so there's no need |
|
574 |
// to test for availability. |
|
575 |
||
576 |
return true; |
|
577 |
} catch (RuntimeException re) { |
|
578 |
if (re.getCause() instanceof ConfigException) { |
|
579 |
throw (ConfigException) re.getCause(); |
|
580 |
} else { |
|
581 |
throw new ConfigException(re); |
|
582 |
} |
|
583 |
} |
|
584 |
} |
|
585 |
||
586 |
@Override |
|
587 |
public File execute( |
|
588 |
Map<String, ? super Object> params, File outputParentDir) { |
|
589 |
return bundle(params, outputParentDir); |
|
590 |
} |
|
591 |
||
592 |
@Override |
|
593 |
public boolean supported() { |
|
594 |
return Platform.getPlatform() == Platform.MAC; |
|
595 |
} |
|
596 |
||
597 |
} |