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