28 import java.io.*;
29 import java.nio.file.Files;
30 import java.text.MessageFormat;
31 import java.util.*;
32
33 import static jdk.jpackage.internal.StandardBundlerParam.*;
34
35 public class MacDmgBundler extends MacBaseInstallerBundler {
36
37 private static final ResourceBundle I18N = ResourceBundle.getBundle(
38 "jdk.jpackage.internal.resources.MacResources");
39
40 static final String DEFAULT_BACKGROUND_IMAGE="background_dmg.png";
41 static final String DEFAULT_DMG_SETUP_SCRIPT="DMGsetup.scpt";
42 static final String TEMPLATE_BUNDLE_ICON = "GenericApp.icns";
43
44 static final String DEFAULT_LICENSE_PLIST="lic_template.plist";
45
46 public static final BundlerParamInfo<String> INSTALLER_SUFFIX =
47 new StandardBundlerParam<> (
48 I18N.getString("param.installer-suffix.name"),
49 I18N.getString("param.installer-suffix.description"),
50 "mac.dmg.installerName.suffix",
51 String.class,
52 params -> "",
53 (s, p) -> s);
54
55 public File bundle(Map<String, ? super Object> params,
56 File outdir) throws PackagerException {
57 Log.verbose(MessageFormat.format(I18N.getString("message.building-dmg"),
58 APP_NAME.fetchFrom(params)));
59 if (!outdir.isDirectory() && !outdir.mkdirs()) {
60 throw new PackagerException(
61 "error.cannot-create-output-dir",
62 outdir.getAbsolutePath());
63 }
64 if (!outdir.canWrite()) {
65 throw new PackagerException(
66 "error.cannot-write-to-output-dir",
67 outdir.getAbsolutePath());
68 }
69
70 File appImageDir = APP_IMAGE_BUILD_ROOT.fetchFrom(params);
71 try {
72 appImageDir.mkdirs();
73
74 if (prepareAppBundle(params, true) != null &&
75 prepareConfigFiles(params)) {
76 File configScript = getConfig_Script(params);
77 if (configScript.exists()) {
78 Log.verbose(MessageFormat.format(
79 I18N.getString("message.running-script"),
80 configScript.getAbsolutePath()));
81 IOUtils.run("bash", configScript, false);
82 }
83
84 return buildDMG(params, outdir);
85 }
86 return null;
87 } catch (IOException ex) {
88 Log.verbose(ex);
89 throw new PackagerException(ex);
90 }
245 if (f.exists() && f.canExecute()) {
246 return f.getAbsolutePath();
247 }
248 }
249 } catch (IOException ignored) {}
250
251 return null;
252 }
253
254 private File buildDMG(
255 Map<String, ? super Object> p, File outdir)
256 throws IOException {
257 File imagesRoot = IMAGES_ROOT.fetchFrom(p);
258 if (!imagesRoot.exists()) imagesRoot.mkdirs();
259
260 File protoDMG = new File(imagesRoot, APP_NAME.fetchFrom(p) +"-tmp.dmg");
261 File finalDMG = new File(outdir, INSTALLER_NAME.fetchFrom(p)
262 + INSTALLER_SUFFIX.fetchFrom(p)
263 + ".dmg");
264
265 File srcFolder = APP_IMAGE_BUILD_ROOT.fetchFrom(p);
266 File predefinedImage = StandardBundlerParam.getPredefinedAppImage(p);
267 if (predefinedImage != null) {
268 srcFolder = predefinedImage;
269 }
270
271 Log.verbose(MessageFormat.format(I18N.getString(
272 "message.creating-dmg-file"), finalDMG.getAbsolutePath()));
273
274 protoDMG.delete();
275 if (finalDMG.exists() && !finalDMG.delete()) {
276 throw new IOException(MessageFormat.format(I18N.getString(
277 "message.dmg-cannot-be-overwritten"),
278 finalDMG.getAbsolutePath()));
279 }
280
281 protoDMG.getParentFile().mkdirs();
282 finalDMG.getParentFile().mkdirs();
283
284 String hdiUtilVerbosityFlag = Log.isDebug() ? "-verbose" : "-quiet";
285
|
28 import java.io.*;
29 import java.nio.file.Files;
30 import java.text.MessageFormat;
31 import java.util.*;
32
33 import static jdk.jpackage.internal.StandardBundlerParam.*;
34
35 public class MacDmgBundler extends MacBaseInstallerBundler {
36
37 private static final ResourceBundle I18N = ResourceBundle.getBundle(
38 "jdk.jpackage.internal.resources.MacResources");
39
40 static final String DEFAULT_BACKGROUND_IMAGE="background_dmg.png";
41 static final String DEFAULT_DMG_SETUP_SCRIPT="DMGsetup.scpt";
42 static final String TEMPLATE_BUNDLE_ICON = "GenericApp.icns";
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
53 public File bundle(Map<String, ? super Object> params,
54 File outdir) throws PackagerException {
55 Log.verbose(MessageFormat.format(I18N.getString("message.building-dmg"),
56 APP_NAME.fetchFrom(params)));
57 if (!outdir.isDirectory() && !outdir.mkdirs()) {
58 throw new PackagerException(
59 "error.cannot-create-output-dir",
60 outdir.getAbsolutePath());
61 }
62 if (!outdir.canWrite()) {
63 throw new PackagerException(
64 "error.cannot-write-to-output-dir",
65 outdir.getAbsolutePath());
66 }
67
68 File appImageDir = APP_IMAGE_TEMP_ROOT.fetchFrom(params);
69 try {
70 appImageDir.mkdirs();
71
72 if (prepareAppBundle(params, true) != null &&
73 prepareConfigFiles(params)) {
74 File configScript = getConfig_Script(params);
75 if (configScript.exists()) {
76 Log.verbose(MessageFormat.format(
77 I18N.getString("message.running-script"),
78 configScript.getAbsolutePath()));
79 IOUtils.run("bash", configScript, false);
80 }
81
82 return buildDMG(params, outdir);
83 }
84 return null;
85 } catch (IOException ex) {
86 Log.verbose(ex);
87 throw new PackagerException(ex);
88 }
243 if (f.exists() && f.canExecute()) {
244 return f.getAbsolutePath();
245 }
246 }
247 } catch (IOException ignored) {}
248
249 return null;
250 }
251
252 private File buildDMG(
253 Map<String, ? super Object> p, File outdir)
254 throws IOException {
255 File imagesRoot = IMAGES_ROOT.fetchFrom(p);
256 if (!imagesRoot.exists()) imagesRoot.mkdirs();
257
258 File protoDMG = new File(imagesRoot, APP_NAME.fetchFrom(p) +"-tmp.dmg");
259 File finalDMG = new File(outdir, INSTALLER_NAME.fetchFrom(p)
260 + INSTALLER_SUFFIX.fetchFrom(p)
261 + ".dmg");
262
263 File srcFolder = APP_IMAGE_TEMP_ROOT.fetchFrom(p);
264 File predefinedImage = StandardBundlerParam.getPredefinedAppImage(p);
265 if (predefinedImage != null) {
266 srcFolder = predefinedImage;
267 }
268
269 Log.verbose(MessageFormat.format(I18N.getString(
270 "message.creating-dmg-file"), finalDMG.getAbsolutePath()));
271
272 protoDMG.delete();
273 if (finalDMG.exists() && !finalDMG.delete()) {
274 throw new IOException(MessageFormat.format(I18N.getString(
275 "message.dmg-cannot-be-overwritten"),
276 finalDMG.getAbsolutePath()));
277 }
278
279 protoDMG.getParentFile().mkdirs();
280 finalDMG.getParentFile().mkdirs();
281
282 String hdiUtilVerbosityFlag = Log.isDebug() ? "-verbose" : "-quiet";
283
|