author | herrick |
Thu, 25 Jul 2019 17:27:53 -0400 | |
branch | JDK-8200758-branch |
changeset 57554 | cb6733b3ed62 |
parent 57529 | e3b156ad362f |
child 57908 | 9a005146bc1c |
permissions | -rw-r--r-- |
57038 | 1 |
/* |
57106
ea870b9ce89a
8216492: Update copyright of all new jpackage fils to 2019
kcr
parents:
57096
diff
changeset
|
2 |
* Copyright (c) 2014, 2019, Oracle and/or its affiliates. All rights reserved. |
57038 | 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 |
|
28 |
import java.io.BufferedWriter; |
|
29 |
import java.io.File; |
|
30 |
import java.io.FileWriter; |
|
31 |
import java.io.IOException; |
|
32 |
import java.io.PrintStream; |
|
57217
b1291b2cedc9
8219144: Cannot find installed application on Mac
herrick
parents:
57150
diff
changeset
|
33 |
import java.io.PrintWriter; |
57038 | 34 |
import java.io.Writer; |
35 |
import java.net.URLEncoder; |
|
57217
b1291b2cedc9
8219144: Cannot find installed application on Mac
herrick
parents:
57150
diff
changeset
|
36 |
import java.nio.file.Files; |
57331
221a589c52ee
8222676: create-installer with --app-image fails on mac
herrick
parents:
57290
diff
changeset
|
37 |
import java.nio.file.Path; |
57038 | 38 |
import java.text.MessageFormat; |
39 |
import java.util.ArrayList; |
|
40 |
import java.util.Arrays; |
|
41 |
import java.util.Collection; |
|
42 |
import java.util.HashMap; |
|
43 |
import java.util.LinkedHashSet; |
|
44 |
import java.util.List; |
|
45 |
import java.util.Map; |
|
46 |
import java.util.Optional; |
|
47 |
import java.util.ResourceBundle; |
|
48 |
||
57039 | 49 |
import static jdk.jpackage.internal.StandardBundlerParam.*; |
57067
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_KEYCHAIN; |
9c17d779808e
8213425: Analyze output from Source code scanner and fix where needed.
herrick
parents:
57059
diff
changeset
|
51 |
import static jdk.jpackage.internal.MacBaseInstallerBundler.SIGNING_KEY_USER; |
57038 | 52 |
|
53 |
public class MacPkgBundler extends MacBaseInstallerBundler { |
|
54 |
||
55 |
private static final ResourceBundle I18N = ResourceBundle.getBundle( |
|
57059 | 56 |
"jdk.jpackage.internal.resources.MacResources"); |
57038 | 57 |
|
58 |
private static final String DEFAULT_BACKGROUND_IMAGE = "background_pkg.png"; |
|
59 |
||
60 |
private static final String TEMPLATE_PREINSTALL_SCRIPT = |
|
61 |
"preinstall.template"; |
|
62 |
private static final String TEMPLATE_POSTINSTALL_SCRIPT = |
|
63 |
"postinstall.template"; |
|
64 |
||
65 |
private static final BundlerParamInfo<File> PACKAGES_ROOT = |
|
66 |
new StandardBundlerParam<>( |
|
67 |
"mac.pkg.packagesRoot", |
|
68 |
File.class, |
|
69 |
params -> { |
|
70 |
File packagesRoot = |
|
57256 | 71 |
new File(TEMP_ROOT.fetchFrom(params), "packages"); |
57038 | 72 |
packagesRoot.mkdirs(); |
73 |
return packagesRoot; |
|
74 |
}, |
|
75 |
(s, p) -> new File(s)); |
|
76 |
||
77 |
||
78 |
protected final BundlerParamInfo<File> SCRIPTS_DIR = |
|
79 |
new StandardBundlerParam<>( |
|
80 |
"mac.pkg.scriptsDir", |
|
81 |
File.class, |
|
82 |
params -> { |
|
83 |
File scriptsDir = |
|
84 |
new File(CONFIG_ROOT.fetchFrom(params), "scripts"); |
|
85 |
scriptsDir.mkdirs(); |
|
86 |
return scriptsDir; |
|
87 |
}, |
|
88 |
(s, p) -> new File(s)); |
|
89 |
||
90 |
public static final |
|
91 |
BundlerParamInfo<String> DEVELOPER_ID_INSTALLER_SIGNING_KEY = |
|
92 |
new StandardBundlerParam<>( |
|
93 |
"mac.signing-key-developer-id-installer", |
|
94 |
String.class, |
|
95 |
params -> { |
|
96 |
String result = MacBaseInstallerBundler.findKey( |
|
97 |
"Developer ID Installer: " |
|
98 |
+ SIGNING_KEY_USER.fetchFrom(params), |
|
99 |
SIGNING_KEYCHAIN.fetchFrom(params), |
|
100 |
VERBOSE.fetchFrom(params)); |
|
101 |
if (result != null) { |
|
102 |
MacCertificate certificate = new MacCertificate( |
|
103 |
result, VERBOSE.fetchFrom(params)); |
|
104 |
||
105 |
if (!certificate.isValid()) { |
|
106 |
Log.error(MessageFormat.format( |
|
107 |
I18N.getString("error.certificate.expired"), |
|
108 |
result)); |
|
109 |
} |
|
110 |
} |
|
111 |
||
112 |
return result; |
|
113 |
}, |
|
114 |
(s, p) -> s); |
|
115 |
||
116 |
public static final BundlerParamInfo<String> MAC_INSTALL_DIR = |
|
117 |
new StandardBundlerParam<>( |
|
118 |
"mac-install-dir", |
|
119 |
String.class, |
|
120 |
params -> { |
|
121 |
String dir = INSTALL_DIR.fetchFrom(params); |
|
122 |
return (dir != null) ? dir : "/Applications"; |
|
123 |
}, |
|
124 |
(s, p) -> s |
|
125 |
); |
|
126 |
||
127 |
public static final BundlerParamInfo<String> INSTALLER_SUFFIX = |
|
128 |
new StandardBundlerParam<> ( |
|
129 |
"mac.pkg.installerName.suffix", |
|
130 |
String.class, |
|
131 |
params -> "", |
|
132 |
(s, p) -> s); |
|
133 |
||
57140 | 134 |
public File bundle(Map<String, ? super Object> params, |
135 |
File outdir) throws PackagerException { |
|
57038 | 136 |
Log.verbose(MessageFormat.format(I18N.getString("message.building-pkg"), |
137 |
APP_NAME.fetchFrom(params))); |
|
57407 | 138 |
|
139 |
IOUtils.writableOutputDir(outdir.toPath()); |
|
57038 | 140 |
|
141 |
try { |
|
57554 | 142 |
File appImageDir = prepareAppBundle(params); |
57038 | 143 |
|
144 |
if (appImageDir != null && prepareConfigFiles(params)) { |
|
145 |
||
146 |
File configScript = getConfig_Script(params); |
|
147 |
if (configScript.exists()) { |
|
148 |
Log.verbose(MessageFormat.format(I18N.getString( |
|
149 |
"message.running-script"), |
|
150 |
configScript.getAbsolutePath())); |
|
57391 | 151 |
IOUtils.run("bash", configScript); |
57038 | 152 |
} |
153 |
||
154 |
return createPKG(params, outdir, appImageDir); |
|
155 |
} |
|
156 |
return null; |
|
157 |
} catch (IOException ex) { |
|
158 |
Log.verbose(ex); |
|
57140 | 159 |
throw new PackagerException(ex); |
57038 | 160 |
} |
161 |
} |
|
162 |
||
163 |
private File getPackages_AppPackage(Map<String, ? super Object> params) { |
|
164 |
return new File(PACKAGES_ROOT.fetchFrom(params), |
|
57119 | 165 |
APP_NAME.fetchFrom(params) + "-app.pkg"); |
57038 | 166 |
} |
167 |
||
168 |
private File getPackages_DaemonPackage(Map<String, ? super Object> params) { |
|
169 |
return new File(PACKAGES_ROOT.fetchFrom(params), |
|
57119 | 170 |
APP_NAME.fetchFrom(params) + "-daemon.pkg"); |
57038 | 171 |
} |
172 |
||
173 |
private File getConfig_DistributionXMLFile( |
|
174 |
Map<String, ? super Object> params) { |
|
175 |
return new File(CONFIG_ROOT.fetchFrom(params), "distribution.dist"); |
|
176 |
} |
|
177 |
||
178 |
private File getConfig_BackgroundImage(Map<String, ? super Object> params) { |
|
179 |
return new File(CONFIG_ROOT.fetchFrom(params), |
|
180 |
APP_NAME.fetchFrom(params) + "-background.png"); |
|
181 |
} |
|
182 |
||
183 |
private File getScripts_PreinstallFile(Map<String, ? super Object> params) { |
|
184 |
return new File(SCRIPTS_DIR.fetchFrom(params), "preinstall"); |
|
185 |
} |
|
186 |
||
187 |
private File getScripts_PostinstallFile( |
|
188 |
Map<String, ? super Object> params) { |
|
189 |
return new File(SCRIPTS_DIR.fetchFrom(params), "postinstall"); |
|
190 |
} |
|
191 |
||
192 |
private String getAppIdentifier(Map<String, ? super Object> params) { |
|
193 |
return IDENTIFIER.fetchFrom(params); |
|
194 |
} |
|
195 |
||
196 |
private String getDaemonIdentifier(Map<String, ? super Object> params) { |
|
197 |
return IDENTIFIER.fetchFrom(params) + ".daemon"; |
|
198 |
} |
|
199 |
||
200 |
private void preparePackageScripts(Map<String, ? super Object> params) |
|
201 |
throws IOException { |
|
202 |
Log.verbose(I18N.getString("message.preparing-scripts")); |
|
203 |
||
204 |
Map<String, String> data = new HashMap<>(); |
|
205 |
||
57290
47c2aca6c306
8215241: Permissions are not set correctly on sub-folders in /Applications
ssadetsky
parents:
57256
diff
changeset
|
206 |
data.put("INSTALL_LOCATION", MAC_INSTALL_DIR.fetchFrom(params)); |
57038 | 207 |
|
57390 | 208 |
try (Writer w = Files.newBufferedWriter( |
209 |
getScripts_PreinstallFile(params).toPath())) { |
|
210 |
String content = preprocessTextResource( |
|
211 |
getScripts_PreinstallFile(params).getName(), |
|
212 |
I18N.getString("resource.pkg-preinstall-script"), |
|
213 |
TEMPLATE_PREINSTALL_SCRIPT, |
|
214 |
data, |
|
215 |
VERBOSE.fetchFrom(params), |
|
216 |
RESOURCE_DIR.fetchFrom(params)); |
|
217 |
w.write(content); |
|
218 |
} |
|
57038 | 219 |
getScripts_PreinstallFile(params).setExecutable(true, false); |
220 |
||
57390 | 221 |
try (Writer w = Files.newBufferedWriter( |
222 |
getScripts_PostinstallFile(params).toPath())) { |
|
223 |
String content = preprocessTextResource( |
|
224 |
getScripts_PostinstallFile(params).getName(), |
|
225 |
I18N.getString("resource.pkg-postinstall-script"), |
|
226 |
TEMPLATE_POSTINSTALL_SCRIPT, |
|
227 |
data, |
|
228 |
VERBOSE.fetchFrom(params), |
|
229 |
RESOURCE_DIR.fetchFrom(params)); |
|
230 |
w.write(content); |
|
231 |
} |
|
57038 | 232 |
getScripts_PostinstallFile(params).setExecutable(true, false); |
233 |
} |
|
234 |
||
235 |
private void prepareDistributionXMLFile(Map<String, ? super Object> params) |
|
236 |
throws IOException { |
|
237 |
File f = getConfig_DistributionXMLFile(params); |
|
238 |
||
239 |
Log.verbose(MessageFormat.format(I18N.getString( |
|
240 |
"message.preparing-distribution-dist"), f.getAbsolutePath())); |
|
241 |
||
57390 | 242 |
try (PrintStream out = new PrintStream(f)) { |
57038 | 243 |
|
57390 | 244 |
out.println( |
57038 | 245 |
"<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>"); |
57390 | 246 |
out.println("<installer-gui-script minSpecVersion=\"1\">"); |
57038 | 247 |
|
57390 | 248 |
out.println("<title>" + APP_NAME.fetchFrom(params) + "</title>"); |
249 |
out.println("<background" + " file=\"" |
|
250 |
+ getConfig_BackgroundImage(params).getName() |
|
251 |
+ "\"" |
|
252 |
+ " mime-type=\"image/png\"" |
|
253 |
+ " alignment=\"bottomleft\" " |
|
254 |
+ " scaling=\"none\"" |
|
255 |
+ "/>"); |
|
57038 | 256 |
|
57390 | 257 |
String licFileStr = LICENSE_FILE.fetchFrom(params); |
258 |
if (licFileStr != null) { |
|
259 |
File licFile = new File(licFileStr); |
|
260 |
out.println("<license" |
|
261 |
+ " file=\"" + licFile.getAbsolutePath() + "\"" |
|
262 |
+ " mime-type=\"text/rtf\"" |
|
263 |
+ "/>"); |
|
264 |
} |
|
57038 | 265 |
|
57390 | 266 |
/* |
267 |
* Note that the content of the distribution file |
|
268 |
* below is generated by productbuild --synthesize |
|
269 |
*/ |
|
57038 | 270 |
|
57390 | 271 |
String appId = getAppIdentifier(params); |
57038 | 272 |
|
57390 | 273 |
out.println("<pkg-ref id=\"" + appId + "\"/>"); |
274 |
out.println( |
|
275 |
"<options customize=\"never\" require-scripts=\"false\"/>"); |
|
276 |
out.println("<choices-outline>"); |
|
277 |
out.println(" <line choice=\"default\">"); |
|
278 |
out.println(" <line choice=\"" + appId + "\"/>"); |
|
279 |
out.println(" </line>"); |
|
280 |
out.println("</choices-outline>"); |
|
281 |
out.println("<choice id=\"default\"/>"); |
|
282 |
out.println("<choice id=\"" + appId + "\" visible=\"false\">"); |
|
283 |
out.println(" <pkg-ref id=\"" + appId + "\"/>"); |
|
284 |
out.println("</choice>"); |
|
285 |
out.println("<pkg-ref id=\"" + appId + "\" version=\"" |
|
286 |
+ VERSION.fetchFrom(params) + "\" onConclusion=\"none\">" |
|
287 |
+ URLEncoder.encode( |
|
288 |
getPackages_AppPackage(params).getName(), |
|
289 |
"UTF-8") + "</pkg-ref>"); |
|
57038 | 290 |
|
57390 | 291 |
out.println("</installer-gui-script>"); |
57038 | 292 |
|
57390 | 293 |
} |
57038 | 294 |
} |
295 |
||
296 |
private boolean prepareConfigFiles(Map<String, ? super Object> params) |
|
297 |
throws IOException { |
|
298 |
File imageTarget = getConfig_BackgroundImage(params); |
|
57091
06bc4bd64599
8215515: Add a command line option to override internal resources.
herrick
parents:
57080
diff
changeset
|
299 |
fetchResource(imageTarget.getName(), |
57038 | 300 |
I18N.getString("resource.pkg-background-image"), |
301 |
DEFAULT_BACKGROUND_IMAGE, |
|
302 |
imageTarget, |
|
303 |
VERBOSE.fetchFrom(params), |
|
57091
06bc4bd64599
8215515: Add a command line option to override internal resources.
herrick
parents:
57080
diff
changeset
|
304 |
RESOURCE_DIR.fetchFrom(params)); |
57038 | 305 |
|
306 |
prepareDistributionXMLFile(params); |
|
307 |
||
57091
06bc4bd64599
8215515: Add a command line option to override internal resources.
herrick
parents:
57080
diff
changeset
|
308 |
fetchResource(getConfig_Script(params).getName(), |
57038 | 309 |
I18N.getString("resource.post-install-script"), |
310 |
(String) null, |
|
311 |
getConfig_Script(params), |
|
312 |
VERBOSE.fetchFrom(params), |
|
57091
06bc4bd64599
8215515: Add a command line option to override internal resources.
herrick
parents:
57080
diff
changeset
|
313 |
RESOURCE_DIR.fetchFrom(params)); |
57038 | 314 |
|
315 |
return true; |
|
316 |
} |
|
317 |
||
318 |
// name of post-image script |
|
319 |
private File getConfig_Script(Map<String, ? super Object> params) { |
|
320 |
return new File(CONFIG_ROOT.fetchFrom(params), |
|
321 |
APP_NAME.fetchFrom(params) + "-post-image.sh"); |
|
322 |
} |
|
323 |
||
57217
b1291b2cedc9
8219144: Cannot find installed application on Mac
herrick
parents:
57150
diff
changeset
|
324 |
private void patchCPLFile(File cpl) throws IOException { |
b1291b2cedc9
8219144: Cannot find installed application on Mac
herrick
parents:
57150
diff
changeset
|
325 |
String cplData = Files.readString(cpl.toPath()); |
b1291b2cedc9
8219144: Cannot find installed application on Mac
herrick
parents:
57150
diff
changeset
|
326 |
String[] lines = cplData.split("\n"); |
57390 | 327 |
try (PrintWriter out = new PrintWriter(Files.newBufferedWriter( |
328 |
cpl.toPath()))) { |
|
57529
e3b156ad362f
8224627: Creating installer with --runtime-image on OS X fails
herrick
parents:
57438
diff
changeset
|
329 |
int skip = 0; |
e3b156ad362f
8224627: Creating installer with --runtime-image on OS X fails
herrick
parents:
57438
diff
changeset
|
330 |
// Used to skip Java.runtime bundle, since |
57217
b1291b2cedc9
8219144: Cannot find installed application on Mac
herrick
parents:
57150
diff
changeset
|
331 |
// pkgbuild with --root will find two bundles app and Java runtime. |
b1291b2cedc9
8219144: Cannot find installed application on Mac
herrick
parents:
57150
diff
changeset
|
332 |
// We cannot generate component proprty list when using |
b1291b2cedc9
8219144: Cannot find installed application on Mac
herrick
parents:
57150
diff
changeset
|
333 |
// --component argument. |
b1291b2cedc9
8219144: Cannot find installed application on Mac
herrick
parents:
57150
diff
changeset
|
334 |
for (int i = 0; i < lines.length; i++) { |
b1291b2cedc9
8219144: Cannot find installed application on Mac
herrick
parents:
57150
diff
changeset
|
335 |
if (lines[i].trim().equals("<key>BundleIsRelocatable</key>")) { |
b1291b2cedc9
8219144: Cannot find installed application on Mac
herrick
parents:
57150
diff
changeset
|
336 |
out.println(lines[i]); |
b1291b2cedc9
8219144: Cannot find installed application on Mac
herrick
parents:
57150
diff
changeset
|
337 |
out.println("<false/>"); |
b1291b2cedc9
8219144: Cannot find installed application on Mac
herrick
parents:
57150
diff
changeset
|
338 |
i++; |
b1291b2cedc9
8219144: Cannot find installed application on Mac
herrick
parents:
57150
diff
changeset
|
339 |
} else if (lines[i].trim().equals("<key>ChildBundles</key>")) { |
57529
e3b156ad362f
8224627: Creating installer with --runtime-image on OS X fails
herrick
parents:
57438
diff
changeset
|
340 |
++skip; |
e3b156ad362f
8224627: Creating installer with --runtime-image on OS X fails
herrick
parents:
57438
diff
changeset
|
341 |
} else if ((skip > 0) && lines[i].trim().equals("</array>")) { |
e3b156ad362f
8224627: Creating installer with --runtime-image on OS X fails
herrick
parents:
57438
diff
changeset
|
342 |
--skip; |
57217
b1291b2cedc9
8219144: Cannot find installed application on Mac
herrick
parents:
57150
diff
changeset
|
343 |
} else { |
57529
e3b156ad362f
8224627: Creating installer with --runtime-image on OS X fails
herrick
parents:
57438
diff
changeset
|
344 |
if (skip == 0) { |
57217
b1291b2cedc9
8219144: Cannot find installed application on Mac
herrick
parents:
57150
diff
changeset
|
345 |
out.println(lines[i]); |
b1291b2cedc9
8219144: Cannot find installed application on Mac
herrick
parents:
57150
diff
changeset
|
346 |
} |
b1291b2cedc9
8219144: Cannot find installed application on Mac
herrick
parents:
57150
diff
changeset
|
347 |
} |
b1291b2cedc9
8219144: Cannot find installed application on Mac
herrick
parents:
57150
diff
changeset
|
348 |
} |
b1291b2cedc9
8219144: Cannot find installed application on Mac
herrick
parents:
57150
diff
changeset
|
349 |
} |
b1291b2cedc9
8219144: Cannot find installed application on Mac
herrick
parents:
57150
diff
changeset
|
350 |
} |
b1291b2cedc9
8219144: Cannot find installed application on Mac
herrick
parents:
57150
diff
changeset
|
351 |
|
57331
221a589c52ee
8222676: create-installer with --app-image fails on mac
herrick
parents:
57290
diff
changeset
|
352 |
// pkgbuild includes all components from "--root" and subfolders, |
221a589c52ee
8222676: create-installer with --app-image fails on mac
herrick
parents:
57290
diff
changeset
|
353 |
// so if we have app image in folder which contains other images, then they |
221a589c52ee
8222676: create-installer with --app-image fails on mac
herrick
parents:
57290
diff
changeset
|
354 |
// will be included as well. It does have "--filter" option which use regex |
221a589c52ee
8222676: create-installer with --app-image fails on mac
herrick
parents:
57290
diff
changeset
|
355 |
// to exclude files/folder, but it will overwrite default one which excludes |
221a589c52ee
8222676: create-installer with --app-image fails on mac
herrick
parents:
57290
diff
changeset
|
356 |
// based on doc "any .svn or CVS directories, and any .DS_Store files". |
221a589c52ee
8222676: create-installer with --app-image fails on mac
herrick
parents:
57290
diff
changeset
|
357 |
// So easy aproach will be to copy user provided app-image into temp folder |
221a589c52ee
8222676: create-installer with --app-image fails on mac
herrick
parents:
57290
diff
changeset
|
358 |
// if root path contains other files. |
221a589c52ee
8222676: create-installer with --app-image fails on mac
herrick
parents:
57290
diff
changeset
|
359 |
private String getRoot(Map<String, ? super Object> params, |
221a589c52ee
8222676: create-installer with --app-image fails on mac
herrick
parents:
57290
diff
changeset
|
360 |
File appLocation) throws IOException { |
221a589c52ee
8222676: create-installer with --app-image fails on mac
herrick
parents:
57290
diff
changeset
|
361 |
String root = appLocation.getParent() == null ? |
221a589c52ee
8222676: create-installer with --app-image fails on mac
herrick
parents:
57290
diff
changeset
|
362 |
"." : appLocation.getParent(); |
221a589c52ee
8222676: create-installer with --app-image fails on mac
herrick
parents:
57290
diff
changeset
|
363 |
File rootDir = new File(root); |
221a589c52ee
8222676: create-installer with --app-image fails on mac
herrick
parents:
57290
diff
changeset
|
364 |
File[] list = rootDir.listFiles(); |
221a589c52ee
8222676: create-installer with --app-image fails on mac
herrick
parents:
57290
diff
changeset
|
365 |
if (list != null) { // Should not happend |
221a589c52ee
8222676: create-installer with --app-image fails on mac
herrick
parents:
57290
diff
changeset
|
366 |
// We should only have app image and/or .DS_Store |
221a589c52ee
8222676: create-installer with --app-image fails on mac
herrick
parents:
57290
diff
changeset
|
367 |
if (list.length == 1) { |
221a589c52ee
8222676: create-installer with --app-image fails on mac
herrick
parents:
57290
diff
changeset
|
368 |
return root; |
221a589c52ee
8222676: create-installer with --app-image fails on mac
herrick
parents:
57290
diff
changeset
|
369 |
} else if (list.length == 2) { |
221a589c52ee
8222676: create-installer with --app-image fails on mac
herrick
parents:
57290
diff
changeset
|
370 |
// Check case with app image and .DS_Store |
221a589c52ee
8222676: create-installer with --app-image fails on mac
herrick
parents:
57290
diff
changeset
|
371 |
if (list[0].toString().toLowerCase().endsWith(".ds_store") || |
221a589c52ee
8222676: create-installer with --app-image fails on mac
herrick
parents:
57290
diff
changeset
|
372 |
list[1].toString().toLowerCase().endsWith(".ds_store")) { |
221a589c52ee
8222676: create-installer with --app-image fails on mac
herrick
parents:
57290
diff
changeset
|
373 |
return root; // Only app image and .DS_Store |
221a589c52ee
8222676: create-installer with --app-image fails on mac
herrick
parents:
57290
diff
changeset
|
374 |
} |
221a589c52ee
8222676: create-installer with --app-image fails on mac
herrick
parents:
57290
diff
changeset
|
375 |
} |
221a589c52ee
8222676: create-installer with --app-image fails on mac
herrick
parents:
57290
diff
changeset
|
376 |
} |
221a589c52ee
8222676: create-installer with --app-image fails on mac
herrick
parents:
57290
diff
changeset
|
377 |
|
221a589c52ee
8222676: create-installer with --app-image fails on mac
herrick
parents:
57290
diff
changeset
|
378 |
// Copy to new root |
221a589c52ee
8222676: create-installer with --app-image fails on mac
herrick
parents:
57290
diff
changeset
|
379 |
Path newRoot = Files.createTempDirectory( |
221a589c52ee
8222676: create-installer with --app-image fails on mac
herrick
parents:
57290
diff
changeset
|
380 |
TEMP_ROOT.fetchFrom(params).toPath(), |
221a589c52ee
8222676: create-installer with --app-image fails on mac
herrick
parents:
57290
diff
changeset
|
381 |
"root-"); |
221a589c52ee
8222676: create-installer with --app-image fails on mac
herrick
parents:
57290
diff
changeset
|
382 |
|
221a589c52ee
8222676: create-installer with --app-image fails on mac
herrick
parents:
57290
diff
changeset
|
383 |
IOUtils.copyRecursive(appLocation.toPath(), |
221a589c52ee
8222676: create-installer with --app-image fails on mac
herrick
parents:
57290
diff
changeset
|
384 |
newRoot.resolve(appLocation.getName())); |
221a589c52ee
8222676: create-installer with --app-image fails on mac
herrick
parents:
57290
diff
changeset
|
385 |
|
221a589c52ee
8222676: create-installer with --app-image fails on mac
herrick
parents:
57290
diff
changeset
|
386 |
return newRoot.toString(); |
221a589c52ee
8222676: create-installer with --app-image fails on mac
herrick
parents:
57290
diff
changeset
|
387 |
} |
221a589c52ee
8222676: create-installer with --app-image fails on mac
herrick
parents:
57290
diff
changeset
|
388 |
|
57038 | 389 |
private File createPKG(Map<String, ? super Object> params, |
390 |
File outdir, File appLocation) { |
|
391 |
// generic find attempt |
|
392 |
try { |
|
393 |
File appPKG = getPackages_AppPackage(params); |
|
394 |
||
57331
221a589c52ee
8222676: create-installer with --app-image fails on mac
herrick
parents:
57290
diff
changeset
|
395 |
String root = getRoot(params, appLocation); |
221a589c52ee
8222676: create-installer with --app-image fails on mac
herrick
parents:
57290
diff
changeset
|
396 |
|
57217
b1291b2cedc9
8219144: Cannot find installed application on Mac
herrick
parents:
57150
diff
changeset
|
397 |
// Generate default CPL file |
b1291b2cedc9
8219144: Cannot find installed application on Mac
herrick
parents:
57150
diff
changeset
|
398 |
File cpl = new File(CONFIG_ROOT.fetchFrom(params).getAbsolutePath() |
b1291b2cedc9
8219144: Cannot find installed application on Mac
herrick
parents:
57150
diff
changeset
|
399 |
+ File.separator + "cpl.plist"); |
57038 | 400 |
ProcessBuilder pb = new ProcessBuilder("pkgbuild", |
57217
b1291b2cedc9
8219144: Cannot find installed application on Mac
herrick
parents:
57150
diff
changeset
|
401 |
"--root", |
57331
221a589c52ee
8222676: create-installer with --app-image fails on mac
herrick
parents:
57290
diff
changeset
|
402 |
root, |
57038 | 403 |
"--install-location", |
404 |
MAC_INSTALL_DIR.fetchFrom(params), |
|
57217
b1291b2cedc9
8219144: Cannot find installed application on Mac
herrick
parents:
57150
diff
changeset
|
405 |
"--analyze", |
b1291b2cedc9
8219144: Cannot find installed application on Mac
herrick
parents:
57150
diff
changeset
|
406 |
cpl.getAbsolutePath()); |
b1291b2cedc9
8219144: Cannot find installed application on Mac
herrick
parents:
57150
diff
changeset
|
407 |
|
57391 | 408 |
IOUtils.exec(pb); |
57217
b1291b2cedc9
8219144: Cannot find installed application on Mac
herrick
parents:
57150
diff
changeset
|
409 |
|
b1291b2cedc9
8219144: Cannot find installed application on Mac
herrick
parents:
57150
diff
changeset
|
410 |
patchCPLFile(cpl); |
b1291b2cedc9
8219144: Cannot find installed application on Mac
herrick
parents:
57150
diff
changeset
|
411 |
|
57290
47c2aca6c306
8215241: Permissions are not set correctly on sub-folders in /Applications
ssadetsky
parents:
57256
diff
changeset
|
412 |
preparePackageScripts(params); |
47c2aca6c306
8215241: Permissions are not set correctly on sub-folders in /Applications
ssadetsky
parents:
57256
diff
changeset
|
413 |
|
57217
b1291b2cedc9
8219144: Cannot find installed application on Mac
herrick
parents:
57150
diff
changeset
|
414 |
// build application package |
b1291b2cedc9
8219144: Cannot find installed application on Mac
herrick
parents:
57150
diff
changeset
|
415 |
pb = new ProcessBuilder("pkgbuild", |
b1291b2cedc9
8219144: Cannot find installed application on Mac
herrick
parents:
57150
diff
changeset
|
416 |
"--root", |
57331
221a589c52ee
8222676: create-installer with --app-image fails on mac
herrick
parents:
57290
diff
changeset
|
417 |
root, |
57217
b1291b2cedc9
8219144: Cannot find installed application on Mac
herrick
parents:
57150
diff
changeset
|
418 |
"--install-location", |
b1291b2cedc9
8219144: Cannot find installed application on Mac
herrick
parents:
57150
diff
changeset
|
419 |
MAC_INSTALL_DIR.fetchFrom(params), |
b1291b2cedc9
8219144: Cannot find installed application on Mac
herrick
parents:
57150
diff
changeset
|
420 |
"--component-plist", |
b1291b2cedc9
8219144: Cannot find installed application on Mac
herrick
parents:
57150
diff
changeset
|
421 |
cpl.getAbsolutePath(), |
57290
47c2aca6c306
8215241: Permissions are not set correctly on sub-folders in /Applications
ssadetsky
parents:
57256
diff
changeset
|
422 |
"--scripts", |
47c2aca6c306
8215241: Permissions are not set correctly on sub-folders in /Applications
ssadetsky
parents:
57256
diff
changeset
|
423 |
SCRIPTS_DIR.fetchFrom(params).getAbsolutePath(), |
57038 | 424 |
appPKG.getAbsolutePath()); |
57391 | 425 |
IOUtils.exec(pb); |
57038 | 426 |
|
427 |
// build final package |
|
428 |
File finalPKG = new File(outdir, INSTALLER_NAME.fetchFrom(params) |
|
429 |
+ INSTALLER_SUFFIX.fetchFrom(params) |
|
430 |
+ ".pkg"); |
|
431 |
outdir.mkdirs(); |
|
432 |
||
433 |
List<String> commandLine = new ArrayList<>(); |
|
434 |
commandLine.add("productbuild"); |
|
435 |
||
436 |
commandLine.add("--resources"); |
|
437 |
commandLine.add(CONFIG_ROOT.fetchFrom(params).getAbsolutePath()); |
|
438 |
||
439 |
// maybe sign |
|
440 |
if (Optional.ofNullable(MacAppImageBuilder. |
|
441 |
SIGN_BUNDLE.fetchFrom(params)).orElse(Boolean.TRUE)) { |
|
442 |
if (Platform.getMajorVersion() > 10 || |
|
443 |
(Platform.getMajorVersion() == 10 && |
|
444 |
Platform.getMinorVersion() >= 12)) { |
|
445 |
// we need this for OS X 10.12+ |
|
446 |
Log.verbose(I18N.getString("message.signing.pkg")); |
|
447 |
} |
|
448 |
||
449 |
String signingIdentity = |
|
450 |
DEVELOPER_ID_INSTALLER_SIGNING_KEY.fetchFrom(params); |
|
451 |
if (signingIdentity != null) { |
|
452 |
commandLine.add("--sign"); |
|
453 |
commandLine.add(signingIdentity); |
|
454 |
} |
|
455 |
||
456 |
String keychainName = SIGNING_KEYCHAIN.fetchFrom(params); |
|
457 |
if (keychainName != null && !keychainName.isEmpty()) { |
|
458 |
commandLine.add("--keychain"); |
|
459 |
commandLine.add(keychainName); |
|
460 |
} |
|
461 |
} |
|
462 |
||
463 |
commandLine.add("--distribution"); |
|
464 |
commandLine.add( |
|
465 |
getConfig_DistributionXMLFile(params).getAbsolutePath()); |
|
466 |
commandLine.add("--package-path"); |
|
467 |
commandLine.add(PACKAGES_ROOT.fetchFrom(params).getAbsolutePath()); |
|
468 |
||
469 |
commandLine.add(finalPKG.getAbsolutePath()); |
|
470 |
||
471 |
pb = new ProcessBuilder(commandLine); |
|
57391 | 472 |
IOUtils.exec(pb); |
57038 | 473 |
|
474 |
return finalPKG; |
|
475 |
} catch (Exception ignored) { |
|
476 |
Log.verbose(ignored); |
|
477 |
return null; |
|
478 |
} |
|
479 |
} |
|
480 |
||
481 |
////////////////////////////////////////////////////////////////////////// |
|
482 |
// Implement Bundler |
|
483 |
////////////////////////////////////////////////////////////////////////// |
|
484 |
||
485 |
@Override |
|
486 |
public String getName() { |
|
57059 | 487 |
return I18N.getString("pkg.bundler.name"); |
57038 | 488 |
} |
489 |
||
490 |
@Override |
|
491 |
public String getID() { |
|
492 |
return "pkg"; |
|
493 |
} |
|
494 |
||
495 |
@Override |
|
496 |
public boolean validate(Map<String, ? super Object> params) |
|
57438
4a31db8d42bd
8226599: use code coverage results to remove dead code
herrick
parents:
57407
diff
changeset
|
497 |
throws ConfigException { |
57038 | 498 |
try { |
499 |
if (params == null) throw new ConfigException( |
|
500 |
I18N.getString("error.parameters-null"), |
|
501 |
I18N.getString("error.parameters-null.advice")); |
|
502 |
||
503 |
// run basic validation to ensure requirements are met |
|
504 |
// we are not interested in return code, only possible exception |
|
505 |
validateAppImageAndBundeler(params); |
|
506 |
||
507 |
// reject explicitly set sign to true and no valid signature key |
|
508 |
if (Optional.ofNullable(MacAppImageBuilder. |
|
509 |
SIGN_BUNDLE.fetchFrom(params)).orElse(Boolean.FALSE)) { |
|
510 |
String signingIdentity = |
|
511 |
DEVELOPER_ID_INSTALLER_SIGNING_KEY.fetchFrom(params); |
|
512 |
if (signingIdentity == null) { |
|
513 |
throw new ConfigException( |
|
514 |
I18N.getString("error.explicit-sign-no-cert"), |
|
515 |
I18N.getString( |
|
516 |
"error.explicit-sign-no-cert.advice")); |
|
517 |
} |
|
518 |
} |
|
519 |
||
520 |
// hdiutil is always available so there's no need |
|
521 |
// to test for availability. |
|
522 |
||
523 |
return true; |
|
524 |
} catch (RuntimeException re) { |
|
525 |
if (re.getCause() instanceof ConfigException) { |
|
526 |
throw (ConfigException) re.getCause(); |
|
527 |
} else { |
|
528 |
throw new ConfigException(re); |
|
529 |
} |
|
530 |
} |
|
531 |
} |
|
532 |
||
533 |
@Override |
|
57140 | 534 |
public File execute(Map<String, ? super Object> params, |
535 |
File outputParentDir) throws PackagerException { |
|
57038 | 536 |
return bundle(params, outputParentDir); |
537 |
} |
|
538 |
||
539 |
@Override |
|
57150 | 540 |
public boolean supported(boolean runtimeInstaller) { |
57438
4a31db8d42bd
8226599: use code coverage results to remove dead code
herrick
parents:
57407
diff
changeset
|
541 |
return true; |
57038 | 542 |
} |
543 |
||
544 |
} |