author | herrick |
Tue, 15 Oct 2019 13:44:36 -0400 | |
branch | JDK-8200758-branch |
changeset 58607 | 7451b17b40d3 |
parent 58306 | 42c7f9800e30 |
child 58647 | 2c43b89b1679 |
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) 2012, 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.*; |
|
29 |
import java.nio.file.Files; |
|
30 |
import java.text.MessageFormat; |
|
31 |
import java.util.*; |
|
32 |
||
57039 | 33 |
import static jdk.jpackage.internal.StandardBundlerParam.*; |
57038 | 34 |
|
35 |
public class MacDmgBundler extends MacBaseInstallerBundler { |
|
36 |
||
57059 | 37 |
private static final ResourceBundle I18N = ResourceBundle.getBundle( |
38 |
"jdk.jpackage.internal.resources.MacResources"); |
|
57038 | 39 |
|
40 |
static final String DEFAULT_BACKGROUND_IMAGE="background_dmg.png"; |
|
41 |
static final String DEFAULT_DMG_SETUP_SCRIPT="DMGsetup.scpt"; |
|
57908
9a005146bc1c
8230191: Replace javacup logo with duke everywhere in jpackage
herrick
parents:
57776
diff
changeset
|
42 |
static final String TEMPLATE_BUNDLE_ICON = "java.icns"; |
57038 | 43 |
|
44 |
static final String DEFAULT_LICENSE_PLIST="lic_template.plist"; |
|
45 |
||
46 |
public static final BundlerParamInfo<String> INSTALLER_SUFFIX = |
|
47 |
new StandardBundlerParam<> ( |
|
48 |
"mac.dmg.installerName.suffix", |
|
49 |
String.class, |
|
50 |
params -> "", |
|
51 |
(s, p) -> s); |
|
52 |
||
57140 | 53 |
public File bundle(Map<String, ? super Object> params, |
54 |
File outdir) throws PackagerException { |
|
57038 | 55 |
Log.verbose(MessageFormat.format(I18N.getString("message.building-dmg"), |
56 |
APP_NAME.fetchFrom(params))); |
|
57407 | 57 |
|
58 |
IOUtils.writableOutputDir(outdir.toPath()); |
|
57038 | 59 |
|
57256 | 60 |
File appImageDir = APP_IMAGE_TEMP_ROOT.fetchFrom(params); |
57038 | 61 |
try { |
62 |
appImageDir.mkdirs(); |
|
63 |
||
57554 | 64 |
if (prepareAppBundle(params) != null && |
57038 | 65 |
prepareConfigFiles(params)) { |
66 |
File configScript = getConfig_Script(params); |
|
67 |
if (configScript.exists()) { |
|
68 |
Log.verbose(MessageFormat.format( |
|
69 |
I18N.getString("message.running-script"), |
|
70 |
configScript.getAbsolutePath())); |
|
57391 | 71 |
IOUtils.run("bash", configScript); |
57038 | 72 |
} |
73 |
||
74 |
return buildDMG(params, outdir); |
|
75 |
} |
|
76 |
return null; |
|
77 |
} catch (IOException ex) { |
|
78 |
Log.verbose(ex); |
|
57140 | 79 |
throw new PackagerException(ex); |
57038 | 80 |
} |
81 |
} |
|
82 |
||
83 |
private static final String hdiutil = "/usr/bin/hdiutil"; |
|
84 |
||
85 |
private void prepareDMGSetupScript(String volumeName, |
|
57396
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57391
diff
changeset
|
86 |
Map<String, ? super Object> params) throws IOException { |
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57391
diff
changeset
|
87 |
File dmgSetup = getConfig_VolumeScript(params); |
57038 | 88 |
Log.verbose(MessageFormat.format( |
89 |
I18N.getString("message.preparing-dmg-setup"), |
|
90 |
dmgSetup.getAbsolutePath())); |
|
91 |
||
92 |
//prepare config for exe |
|
93 |
Map<String, String> data = new HashMap<>(); |
|
94 |
data.put("DEPLOY_ACTUAL_VOLUME_NAME", volumeName); |
|
57396
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57391
diff
changeset
|
95 |
data.put("DEPLOY_APPLICATION_NAME", APP_NAME.fetchFrom(params)); |
57038 | 96 |
|
58306 | 97 |
data.put("DEPLOY_INSTALL_LOCATION", "(path to applications folder)"); |
98 |
data.put("DEPLOY_INSTALL_NAME", "Applications"); |
|
57038 | 99 |
|
57390 | 100 |
try (Writer w = Files.newBufferedWriter(dmgSetup.toPath())) { |
101 |
w.write(preprocessTextResource(dmgSetup.getName(), |
|
102 |
I18N.getString("resource.dmg-setup-script"), |
|
57396
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57391
diff
changeset
|
103 |
DEFAULT_DMG_SETUP_SCRIPT, data, VERBOSE.fetchFrom(params), |
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57391
diff
changeset
|
104 |
RESOURCE_DIR.fetchFrom(params))); |
57390 | 105 |
} |
57038 | 106 |
} |
107 |
||
108 |
private File getConfig_VolumeScript(Map<String, ? super Object> params) { |
|
109 |
return new File(CONFIG_ROOT.fetchFrom(params), |
|
110 |
APP_NAME.fetchFrom(params) + "-dmg-setup.scpt"); |
|
111 |
} |
|
112 |
||
113 |
private File getConfig_VolumeBackground( |
|
114 |
Map<String, ? super Object> params) { |
|
115 |
return new File(CONFIG_ROOT.fetchFrom(params), |
|
116 |
APP_NAME.fetchFrom(params) + "-background.png"); |
|
117 |
} |
|
118 |
||
119 |
private File getConfig_VolumeIcon(Map<String, ? super Object> params) { |
|
120 |
return new File(CONFIG_ROOT.fetchFrom(params), |
|
121 |
APP_NAME.fetchFrom(params) + "-volume.icns"); |
|
122 |
} |
|
123 |
||
124 |
private File getConfig_LicenseFile(Map<String, ? super Object> params) { |
|
125 |
return new File(CONFIG_ROOT.fetchFrom(params), |
|
126 |
APP_NAME.fetchFrom(params) + "-license.plist"); |
|
127 |
} |
|
128 |
||
129 |
private void prepareLicense(Map<String, ? super Object> params) { |
|
130 |
try { |
|
57080 | 131 |
String licFileStr = LICENSE_FILE.fetchFrom(params); |
132 |
if (licFileStr == null) { |
|
57038 | 133 |
return; |
134 |
} |
|
135 |
||
57080 | 136 |
File licFile = new File(licFileStr); |
57909
c7de06ed4b54
8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents:
57908
diff
changeset
|
137 |
byte[] licenseContentOriginal = |
c7de06ed4b54
8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents:
57908
diff
changeset
|
138 |
Files.readAllBytes(licFile.toPath()); |
57038 | 139 |
String licenseInBase64 = |
140 |
Base64.getEncoder().encodeToString(licenseContentOriginal); |
|
141 |
||
142 |
Map<String, String> data = new HashMap<>(); |
|
143 |
data.put("APPLICATION_LICENSE_TEXT", licenseInBase64); |
|
144 |
||
57390 | 145 |
try (Writer w = Files.newBufferedWriter( |
146 |
getConfig_LicenseFile(params).toPath())) { |
|
147 |
w.write(preprocessTextResource( |
|
148 |
getConfig_LicenseFile(params).getName(), |
|
149 |
I18N.getString("resource.license-setup"), |
|
150 |
DEFAULT_LICENSE_PLIST, data, VERBOSE.fetchFrom(params), |
|
151 |
RESOURCE_DIR.fetchFrom(params))); |
|
152 |
} |
|
57038 | 153 |
|
154 |
} catch (IOException ex) { |
|
155 |
Log.verbose(ex); |
|
156 |
} |
|
157 |
} |
|
158 |
||
159 |
private boolean prepareConfigFiles(Map<String, ? super Object> params) |
|
160 |
throws IOException { |
|
161 |
File bgTarget = getConfig_VolumeBackground(params); |
|
57091
06bc4bd64599
8215515: Add a command line option to override internal resources.
herrick
parents:
57080
diff
changeset
|
162 |
fetchResource(bgTarget.getName(), |
57038 | 163 |
I18N.getString("resource.dmg-background"), |
164 |
DEFAULT_BACKGROUND_IMAGE, |
|
165 |
bgTarget, |
|
166 |
VERBOSE.fetchFrom(params), |
|
57091
06bc4bd64599
8215515: Add a command line option to override internal resources.
herrick
parents:
57080
diff
changeset
|
167 |
RESOURCE_DIR.fetchFrom(params)); |
57038 | 168 |
|
169 |
File iconTarget = getConfig_VolumeIcon(params); |
|
170 |
if (MacAppBundler.ICON_ICNS.fetchFrom(params) == null || |
|
171 |
!MacAppBundler.ICON_ICNS.fetchFrom(params).exists()) { |
|
57091
06bc4bd64599
8215515: Add a command line option to override internal resources.
herrick
parents:
57080
diff
changeset
|
172 |
fetchResource(iconTarget.getName(), |
57038 | 173 |
I18N.getString("resource.volume-icon"), |
174 |
TEMPLATE_BUNDLE_ICON, |
|
175 |
iconTarget, |
|
176 |
VERBOSE.fetchFrom(params), |
|
57091
06bc4bd64599
8215515: Add a command line option to override internal resources.
herrick
parents:
57080
diff
changeset
|
177 |
RESOURCE_DIR.fetchFrom(params)); |
57038 | 178 |
} else { |
57091
06bc4bd64599
8215515: Add a command line option to override internal resources.
herrick
parents:
57080
diff
changeset
|
179 |
fetchResource(iconTarget.getName(), |
57038 | 180 |
I18N.getString("resource.volume-icon"), |
181 |
MacAppBundler.ICON_ICNS.fetchFrom(params), |
|
182 |
iconTarget, |
|
183 |
VERBOSE.fetchFrom(params), |
|
57091
06bc4bd64599
8215515: Add a command line option to override internal resources.
herrick
parents:
57080
diff
changeset
|
184 |
RESOURCE_DIR.fetchFrom(params)); |
57038 | 185 |
} |
186 |
||
187 |
||
57091
06bc4bd64599
8215515: Add a command line option to override internal resources.
herrick
parents:
57080
diff
changeset
|
188 |
fetchResource(getConfig_Script(params).getName(), |
57038 | 189 |
I18N.getString("resource.post-install-script"), |
190 |
(String) null, |
|
191 |
getConfig_Script(params), |
|
192 |
VERBOSE.fetchFrom(params), |
|
57091
06bc4bd64599
8215515: Add a command line option to override internal resources.
herrick
parents:
57080
diff
changeset
|
193 |
RESOURCE_DIR.fetchFrom(params)); |
57038 | 194 |
|
195 |
prepareLicense(params); |
|
196 |
||
197 |
// In theory we need to extract name from results of attach command |
|
198 |
// However, this will be a problem for customization as name will |
|
199 |
// possibly change every time and developer will not be able to fix it |
|
200 |
// As we are using tmp dir chance we get "different" name are low => |
|
201 |
// Use fixed name we used for bundle |
|
202 |
prepareDMGSetupScript(APP_NAME.fetchFrom(params), params); |
|
203 |
||
204 |
return true; |
|
205 |
} |
|
206 |
||
207 |
// name of post-image script |
|
208 |
private File getConfig_Script(Map<String, ? super Object> params) { |
|
209 |
return new File(CONFIG_ROOT.fetchFrom(params), |
|
210 |
APP_NAME.fetchFrom(params) + "-post-image.sh"); |
|
211 |
} |
|
212 |
||
213 |
// Location of SetFile utility may be different depending on MacOS version |
|
214 |
// We look for several known places and if none of them work will |
|
215 |
// try ot find it |
|
216 |
private String findSetFileUtility() { |
|
217 |
String typicalPaths[] = {"/Developer/Tools/SetFile", |
|
218 |
"/usr/bin/SetFile", "/Developer/usr/bin/SetFile"}; |
|
219 |
||
58117
69465ef51b0c
8230653: jpackage error on macOS system without xcode
herrick
parents:
58114
diff
changeset
|
220 |
String setFilePath = null; |
57038 | 221 |
for (String path: typicalPaths) { |
222 |
File f = new File(path); |
|
223 |
if (f.exists() && f.canExecute()) { |
|
58117
69465ef51b0c
8230653: jpackage error on macOS system without xcode
herrick
parents:
58114
diff
changeset
|
224 |
setFilePath = path; |
69465ef51b0c
8230653: jpackage error on macOS system without xcode
herrick
parents:
58114
diff
changeset
|
225 |
break; |
57038 | 226 |
} |
227 |
} |
|
228 |
||
58117
69465ef51b0c
8230653: jpackage error on macOS system without xcode
herrick
parents:
58114
diff
changeset
|
229 |
// Validate SetFile, if Xcode is not installed it will run, but exit with error |
69465ef51b0c
8230653: jpackage error on macOS system without xcode
herrick
parents:
58114
diff
changeset
|
230 |
// code |
69465ef51b0c
8230653: jpackage error on macOS system without xcode
herrick
parents:
58114
diff
changeset
|
231 |
if (setFilePath != null) { |
69465ef51b0c
8230653: jpackage error on macOS system without xcode
herrick
parents:
58114
diff
changeset
|
232 |
try { |
69465ef51b0c
8230653: jpackage error on macOS system without xcode
herrick
parents:
58114
diff
changeset
|
233 |
ProcessBuilder pb = new ProcessBuilder(setFilePath, "-h"); |
69465ef51b0c
8230653: jpackage error on macOS system without xcode
herrick
parents:
58114
diff
changeset
|
234 |
Process p = pb.start(); |
69465ef51b0c
8230653: jpackage error on macOS system without xcode
herrick
parents:
58114
diff
changeset
|
235 |
int code = p.waitFor(); |
69465ef51b0c
8230653: jpackage error on macOS system without xcode
herrick
parents:
58114
diff
changeset
|
236 |
if (code == 0) { |
69465ef51b0c
8230653: jpackage error on macOS system without xcode
herrick
parents:
58114
diff
changeset
|
237 |
return setFilePath; |
69465ef51b0c
8230653: jpackage error on macOS system without xcode
herrick
parents:
58114
diff
changeset
|
238 |
} |
69465ef51b0c
8230653: jpackage error on macOS system without xcode
herrick
parents:
58114
diff
changeset
|
239 |
} catch (Exception ignored) {} |
69465ef51b0c
8230653: jpackage error on macOS system without xcode
herrick
parents:
58114
diff
changeset
|
240 |
|
69465ef51b0c
8230653: jpackage error on macOS system without xcode
herrick
parents:
58114
diff
changeset
|
241 |
// No need for generic find attempt. We found it, but it does not work. |
69465ef51b0c
8230653: jpackage error on macOS system without xcode
herrick
parents:
58114
diff
changeset
|
242 |
// Probably due to missing xcode. |
69465ef51b0c
8230653: jpackage error on macOS system without xcode
herrick
parents:
58114
diff
changeset
|
243 |
return null; |
69465ef51b0c
8230653: jpackage error on macOS system without xcode
herrick
parents:
58114
diff
changeset
|
244 |
} |
69465ef51b0c
8230653: jpackage error on macOS system without xcode
herrick
parents:
58114
diff
changeset
|
245 |
|
57038 | 246 |
// generic find attempt |
247 |
try { |
|
248 |
ProcessBuilder pb = new ProcessBuilder("xcrun", "-find", "SetFile"); |
|
249 |
Process p = pb.start(); |
|
250 |
InputStreamReader isr = new InputStreamReader(p.getInputStream()); |
|
251 |
BufferedReader br = new BufferedReader(isr); |
|
252 |
String lineRead = br.readLine(); |
|
253 |
if (lineRead != null) { |
|
254 |
File f = new File(lineRead); |
|
255 |
if (f.exists() && f.canExecute()) { |
|
256 |
return f.getAbsolutePath(); |
|
257 |
} |
|
258 |
} |
|
259 |
} catch (IOException ignored) {} |
|
260 |
||
261 |
return null; |
|
262 |
} |
|
263 |
||
264 |
private File buildDMG( |
|
57396
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57391
diff
changeset
|
265 |
Map<String, ? super Object> params, File outdir) |
57038 | 266 |
throws IOException { |
57396
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57391
diff
changeset
|
267 |
File imagesRoot = IMAGES_ROOT.fetchFrom(params); |
57038 | 268 |
if (!imagesRoot.exists()) imagesRoot.mkdirs(); |
269 |
||
57396
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57391
diff
changeset
|
270 |
File protoDMG = new File(imagesRoot, |
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57391
diff
changeset
|
271 |
APP_NAME.fetchFrom(params) +"-tmp.dmg"); |
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57391
diff
changeset
|
272 |
File finalDMG = new File(outdir, INSTALLER_NAME.fetchFrom(params) |
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57391
diff
changeset
|
273 |
+ INSTALLER_SUFFIX.fetchFrom(params) + ".dmg"); |
57038 | 274 |
|
57396
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57391
diff
changeset
|
275 |
File srcFolder = APP_IMAGE_TEMP_ROOT.fetchFrom(params); |
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57391
diff
changeset
|
276 |
File predefinedImage = |
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57391
diff
changeset
|
277 |
StandardBundlerParam.getPredefinedAppImage(params); |
57038 | 278 |
if (predefinedImage != null) { |
279 |
srcFolder = predefinedImage; |
|
280 |
} |
|
281 |
||
282 |
Log.verbose(MessageFormat.format(I18N.getString( |
|
283 |
"message.creating-dmg-file"), finalDMG.getAbsolutePath())); |
|
284 |
||
285 |
protoDMG.delete(); |
|
286 |
if (finalDMG.exists() && !finalDMG.delete()) { |
|
287 |
throw new IOException(MessageFormat.format(I18N.getString( |
|
288 |
"message.dmg-cannot-be-overwritten"), |
|
289 |
finalDMG.getAbsolutePath())); |
|
290 |
} |
|
291 |
||
292 |
protoDMG.getParentFile().mkdirs(); |
|
293 |
finalDMG.getParentFile().mkdirs(); |
|
294 |
||
57776 | 295 |
String hdiUtilVerbosityFlag = VERBOSE.fetchFrom(params) ? |
296 |
"-verbose" : "-quiet"; |
|
57038 | 297 |
|
298 |
// create temp image |
|
299 |
ProcessBuilder pb = new ProcessBuilder( |
|
300 |
hdiutil, |
|
301 |
"create", |
|
302 |
hdiUtilVerbosityFlag, |
|
303 |
"-srcfolder", srcFolder.getAbsolutePath(), |
|
57396
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57391
diff
changeset
|
304 |
"-volname", APP_NAME.fetchFrom(params), |
57038 | 305 |
"-ov", protoDMG.getAbsolutePath(), |
306 |
"-fs", "HFS+", |
|
307 |
"-format", "UDRW"); |
|
57391 | 308 |
IOUtils.exec(pb); |
57038 | 309 |
|
310 |
// mount temp image |
|
311 |
pb = new ProcessBuilder( |
|
312 |
hdiutil, |
|
313 |
"attach", |
|
314 |
protoDMG.getAbsolutePath(), |
|
315 |
hdiUtilVerbosityFlag, |
|
316 |
"-mountroot", imagesRoot.getAbsolutePath()); |
|
57391 | 317 |
IOUtils.exec(pb); |
57038 | 318 |
|
57396
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57391
diff
changeset
|
319 |
File mountedRoot = new File(imagesRoot.getAbsolutePath(), |
58306 | 320 |
APP_NAME.fetchFrom(params)); |
57038 | 321 |
|
58306 | 322 |
try { |
323 |
// volume icon |
|
324 |
File volumeIconFile = new File(mountedRoot, ".VolumeIcon.icns"); |
|
325 |
IOUtils.copyFile(getConfig_VolumeIcon(params), |
|
326 |
volumeIconFile); |
|
57038 | 327 |
|
58306 | 328 |
// background image |
329 |
File bgdir = new File(mountedRoot, ".background"); |
|
330 |
bgdir.mkdirs(); |
|
331 |
IOUtils.copyFile(getConfig_VolumeBackground(params), |
|
332 |
new File(bgdir, "background.png")); |
|
57038 | 333 |
|
58306 | 334 |
// Indicate that we want a custom icon |
335 |
// NB: attributes of the root directory are ignored |
|
336 |
// when creating the volume |
|
337 |
// Therefore we have to do this after we mount image |
|
338 |
String setFileUtility = findSetFileUtility(); |
|
339 |
if (setFileUtility != null) { |
|
57038 | 340 |
//can not find utility => keep going without icon |
58306 | 341 |
try { |
342 |
volumeIconFile.setWritable(true); |
|
343 |
// The "creator" attribute on a file is a legacy attribute |
|
344 |
// but it seems Finder excepts these bytes to be |
|
345 |
// "icnC" for the volume icon |
|
346 |
// (might not work on Mac 10.13 with old XCode) |
|
347 |
pb = new ProcessBuilder( |
|
348 |
setFileUtility, |
|
349 |
"-c", "icnC", |
|
350 |
volumeIconFile.getAbsolutePath()); |
|
351 |
IOUtils.exec(pb); |
|
352 |
volumeIconFile.setReadOnly(); |
|
353 |
||
354 |
pb = new ProcessBuilder( |
|
355 |
setFileUtility, |
|
356 |
"-a", "C", |
|
357 |
mountedRoot.getAbsolutePath()); |
|
358 |
IOUtils.exec(pb); |
|
359 |
} catch (IOException ex) { |
|
360 |
Log.error(ex.getMessage()); |
|
361 |
Log.verbose("Cannot enable custom icon using SetFile utility"); |
|
362 |
} |
|
363 |
} else { |
|
364 |
Log.verbose(I18N.getString("message.setfile.dmg")); |
|
365 |
} |
|
366 |
||
367 |
// We will not consider setting background image and creating link to |
|
368 |
// /Application folder in DMG as critical error, since it can fail in |
|
369 |
// headless enviroment. |
|
57038 | 370 |
try { |
58306 | 371 |
pb = new ProcessBuilder("osascript", |
372 |
getConfig_VolumeScript(params).getAbsolutePath()); |
|
57391 | 373 |
IOUtils.exec(pb); |
57038 | 374 |
} catch (IOException ex) { |
58306 | 375 |
Log.verbose(ex); |
57038 | 376 |
} |
58306 | 377 |
} finally { |
378 |
// Detach the temporary image |
|
379 |
pb = new ProcessBuilder( |
|
380 |
hdiutil, |
|
381 |
"detach", |
|
382 |
"-force", |
|
383 |
hdiUtilVerbosityFlag, |
|
384 |
mountedRoot.getAbsolutePath()); |
|
385 |
IOUtils.exec(pb); |
|
57038 | 386 |
} |
387 |
||
388 |
// Compress it to a new image |
|
389 |
pb = new ProcessBuilder( |
|
390 |
hdiutil, |
|
391 |
"convert", |
|
392 |
protoDMG.getAbsolutePath(), |
|
393 |
hdiUtilVerbosityFlag, |
|
394 |
"-format", "UDZO", |
|
395 |
"-o", finalDMG.getAbsolutePath()); |
|
57391 | 396 |
IOUtils.exec(pb); |
57038 | 397 |
|
398 |
//add license if needed |
|
57396
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57391
diff
changeset
|
399 |
if (getConfig_LicenseFile(params).exists()) { |
57038 | 400 |
//hdiutil unflatten your_image_file.dmg |
401 |
pb = new ProcessBuilder( |
|
402 |
hdiutil, |
|
403 |
"unflatten", |
|
404 |
finalDMG.getAbsolutePath() |
|
405 |
); |
|
57391 | 406 |
IOUtils.exec(pb); |
57038 | 407 |
|
408 |
//add license |
|
409 |
pb = new ProcessBuilder( |
|
410 |
hdiutil, |
|
411 |
"udifrez", |
|
412 |
finalDMG.getAbsolutePath(), |
|
413 |
"-xml", |
|
57396
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57391
diff
changeset
|
414 |
getConfig_LicenseFile(params).getAbsolutePath() |
57038 | 415 |
); |
57391 | 416 |
IOUtils.exec(pb); |
57038 | 417 |
|
418 |
//hdiutil flatten your_image_file.dmg |
|
419 |
pb = new ProcessBuilder( |
|
420 |
hdiutil, |
|
421 |
"flatten", |
|
422 |
finalDMG.getAbsolutePath() |
|
423 |
); |
|
57391 | 424 |
IOUtils.exec(pb); |
57038 | 425 |
|
426 |
} |
|
427 |
||
428 |
//Delete the temporary image |
|
429 |
protoDMG.delete(); |
|
430 |
||
431 |
Log.verbose(MessageFormat.format(I18N.getString( |
|
432 |
"message.output-to-location"), |
|
57396
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57391
diff
changeset
|
433 |
APP_NAME.fetchFrom(params), finalDMG.getAbsolutePath())); |
57038 | 434 |
|
435 |
return finalDMG; |
|
436 |
} |
|
437 |
||
438 |
||
439 |
////////////////////////////////////////////////////////////////////////// |
|
440 |
// Implement Bundler |
|
441 |
////////////////////////////////////////////////////////////////////////// |
|
442 |
||
443 |
@Override |
|
444 |
public String getName() { |
|
57059 | 445 |
return I18N.getString("dmg.bundler.name"); |
57038 | 446 |
} |
447 |
||
448 |
@Override |
|
449 |
public String getID() { |
|
450 |
return "dmg"; |
|
451 |
} |
|
452 |
||
453 |
@Override |
|
454 |
public boolean validate(Map<String, ? super Object> params) |
|
57438
4a31db8d42bd
8226599: use code coverage results to remove dead code
herrick
parents:
57407
diff
changeset
|
455 |
throws ConfigException { |
57038 | 456 |
try { |
457 |
if (params == null) throw new ConfigException( |
|
458 |
I18N.getString("error.parameters-null"), |
|
459 |
I18N.getString("error.parameters-null.advice")); |
|
460 |
||
461 |
//run basic validation to ensure requirements are met |
|
462 |
//we are not interested in return code, only possible exception |
|
463 |
validateAppImageAndBundeler(params); |
|
464 |
||
465 |
return true; |
|
466 |
} catch (RuntimeException re) { |
|
467 |
if (re.getCause() instanceof ConfigException) { |
|
468 |
throw (ConfigException) re.getCause(); |
|
469 |
} else { |
|
470 |
throw new ConfigException(re); |
|
471 |
} |
|
472 |
} |
|
473 |
} |
|
474 |
||
475 |
@Override |
|
57140 | 476 |
public File execute(Map<String, ? super Object> params, |
477 |
File outputParentDir) throws PackagerException { |
|
57038 | 478 |
return bundle(params, outputParentDir); |
479 |
} |
|
480 |
||
481 |
@Override |
|
57150 | 482 |
public boolean supported(boolean runtimeInstaller) { |
57438
4a31db8d42bd
8226599: use code coverage results to remove dead code
herrick
parents:
57407
diff
changeset
|
483 |
return isSupported(); |
4a31db8d42bd
8226599: use code coverage results to remove dead code
herrick
parents:
57407
diff
changeset
|
484 |
} |
4a31db8d42bd
8226599: use code coverage results to remove dead code
herrick
parents:
57407
diff
changeset
|
485 |
|
4a31db8d42bd
8226599: use code coverage results to remove dead code
herrick
parents:
57407
diff
changeset
|
486 |
public final static String[] required = |
4a31db8d42bd
8226599: use code coverage results to remove dead code
herrick
parents:
57407
diff
changeset
|
487 |
{"/usr/bin/hdiutil", "/usr/bin/osascript"}; |
4a31db8d42bd
8226599: use code coverage results to remove dead code
herrick
parents:
57407
diff
changeset
|
488 |
public static boolean isSupported() { |
4a31db8d42bd
8226599: use code coverage results to remove dead code
herrick
parents:
57407
diff
changeset
|
489 |
try { |
4a31db8d42bd
8226599: use code coverage results to remove dead code
herrick
parents:
57407
diff
changeset
|
490 |
for (String s : required) { |
4a31db8d42bd
8226599: use code coverage results to remove dead code
herrick
parents:
57407
diff
changeset
|
491 |
File f = new File(s); |
4a31db8d42bd
8226599: use code coverage results to remove dead code
herrick
parents:
57407
diff
changeset
|
492 |
if (!f.exists() || !f.canExecute()) { |
4a31db8d42bd
8226599: use code coverage results to remove dead code
herrick
parents:
57407
diff
changeset
|
493 |
return false; |
4a31db8d42bd
8226599: use code coverage results to remove dead code
herrick
parents:
57407
diff
changeset
|
494 |
} |
4a31db8d42bd
8226599: use code coverage results to remove dead code
herrick
parents:
57407
diff
changeset
|
495 |
} |
4a31db8d42bd
8226599: use code coverage results to remove dead code
herrick
parents:
57407
diff
changeset
|
496 |
return true; |
4a31db8d42bd
8226599: use code coverage results to remove dead code
herrick
parents:
57407
diff
changeset
|
497 |
} catch (Exception e) { |
4a31db8d42bd
8226599: use code coverage results to remove dead code
herrick
parents:
57407
diff
changeset
|
498 |
return false; |
4a31db8d42bd
8226599: use code coverage results to remove dead code
herrick
parents:
57407
diff
changeset
|
499 |
} |
57038 | 500 |
} |
58114
42df7de58e39
8230519: jpackage "--package-type" values and default
herrick
parents:
57909
diff
changeset
|
501 |
|
42df7de58e39
8230519: jpackage "--package-type" values and default
herrick
parents:
57909
diff
changeset
|
502 |
@Override |
42df7de58e39
8230519: jpackage "--package-type" values and default
herrick
parents:
57909
diff
changeset
|
503 |
public boolean isDefault() { |
42df7de58e39
8230519: jpackage "--package-type" values and default
herrick
parents:
57909
diff
changeset
|
504 |
return true; |
42df7de58e39
8230519: jpackage "--package-type" values and default
herrick
parents:
57909
diff
changeset
|
505 |
} |
42df7de58e39
8230519: jpackage "--package-type" values and default
herrick
parents:
57909
diff
changeset
|
506 |
|
57038 | 507 |
} |