< prev index next >

src/jdk.incubator.jpackage/macosx/classes/jdk/incubator/jpackage/internal/MacDmgBundler.java

Print this page




 293                 "create",
 294                 hdiUtilVerbosityFlag,
 295                 "-srcfolder", srcFolder.getAbsolutePath(),
 296                 "-volname", APP_NAME.fetchFrom(params),
 297                 "-ov", protoDMG.getAbsolutePath(),
 298                 "-fs", "HFS+",
 299                 "-format", "UDRW");
 300         IOUtils.exec(pb);
 301 
 302         // mount temp image
 303         pb = new ProcessBuilder(
 304                 hdiutil,
 305                 "attach",
 306                 protoDMG.getAbsolutePath(),
 307                 hdiUtilVerbosityFlag,
 308                 "-mountroot", imagesRoot.getAbsolutePath());
 309         IOUtils.exec(pb, false, null, true);
 310 
 311         File mountedRoot = new File(imagesRoot.getAbsolutePath(),
 312                     APP_NAME.fetchFrom(params));
 313 
 314         try {
 315             // volume icon
 316             File volumeIconFile = new File(mountedRoot, ".VolumeIcon.icns");
 317             IOUtils.copyFile(getConfig_VolumeIcon(params),
 318                     volumeIconFile);
 319 
 320             // background image
 321             File bgdir = new File(mountedRoot, BACKGROUND_IMAGE_FOLDER);
 322             bgdir.mkdirs();
 323             IOUtils.copyFile(getConfig_VolumeBackground(params),
 324                     new File(bgdir, BACKGROUND_IMAGE));
 325 
















 326             // Indicate that we want a custom icon
 327             // NB: attributes of the root directory are ignored
 328             // when creating the volume
 329             // Therefore we have to do this after we mount image
 330             String setFileUtility = findSetFileUtility();
 331             if (setFileUtility != null) {
 332                 //can not find utility => keep going without icon
 333                 try {
 334                     volumeIconFile.setWritable(true);
 335                     // The "creator" attribute on a file is a legacy attribute
 336                     // but it seems Finder excepts these bytes to be
 337                     // "icnC" for the volume icon
 338                     // (might not work on Mac 10.13 with old XCode)
 339                     pb = new ProcessBuilder(
 340                             setFileUtility,
 341                             "-c", "icnC",
 342                             volumeIconFile.getAbsolutePath());
 343                     IOUtils.exec(pb);
 344                     volumeIconFile.setReadOnly();
 345 
 346                     pb = new ProcessBuilder(
 347                             setFileUtility,
 348                             "-a", "C",
 349                             mountedRoot.getAbsolutePath());
 350                     IOUtils.exec(pb);
 351                 } catch (IOException ex) {
 352                     Log.error(ex.getMessage());
 353                     Log.verbose("Cannot enable custom icon using SetFile utility");
 354                 }
 355             } else {
 356                 Log.verbose(I18N.getString("message.setfile.dmg"));
 357             }
 358 
 359             // We will not consider setting background image and creating link to
 360             // /Application folder in DMG as critical error, since it can fail in
 361             // headless enviroment.
 362             try {
 363                 pb = new ProcessBuilder("osascript",
 364                         getConfig_VolumeScript(params).getAbsolutePath());
 365                 IOUtils.exec(pb);
 366             } catch (IOException ex) {
 367                 Log.verbose(ex);
 368             }
 369         } finally {
 370             // Detach the temporary image
 371             pb = new ProcessBuilder(
 372                     hdiutil,
 373                     "detach",
 374                     "-force",
 375                     hdiUtilVerbosityFlag,
 376                     mountedRoot.getAbsolutePath());
 377             IOUtils.exec(pb);
 378         }
 379 
 380         // Compress it to a new image
 381         pb = new ProcessBuilder(
 382                 hdiutil,
 383                 "convert",
 384                 protoDMG.getAbsolutePath(),
 385                 hdiUtilVerbosityFlag,
 386                 "-format", "UDZO",
 387                 "-o", finalDMG.getAbsolutePath());
 388         IOUtils.exec(pb);


 476     public final static String[] required =
 477             {"/usr/bin/hdiutil", "/usr/bin/osascript"};
 478     public static boolean isSupported() {
 479         try {
 480             for (String s : required) {
 481                 File f = new File(s);
 482                 if (!f.exists() || !f.canExecute()) {
 483                     return false;
 484                 }
 485             }
 486             return true;
 487         } catch (Exception e) {
 488             return false;
 489         }
 490     }
 491 
 492     @Override
 493     public boolean isDefault() {
 494         return true;
 495     }
 496 
 497 }


 293                 "create",
 294                 hdiUtilVerbosityFlag,
 295                 "-srcfolder", srcFolder.getAbsolutePath(),
 296                 "-volname", APP_NAME.fetchFrom(params),
 297                 "-ov", protoDMG.getAbsolutePath(),
 298                 "-fs", "HFS+",
 299                 "-format", "UDRW");
 300         IOUtils.exec(pb);
 301 
 302         // mount temp image
 303         pb = new ProcessBuilder(
 304                 hdiutil,
 305                 "attach",
 306                 protoDMG.getAbsolutePath(),
 307                 hdiUtilVerbosityFlag,
 308                 "-mountroot", imagesRoot.getAbsolutePath());
 309         IOUtils.exec(pb, false, null, true);
 310 
 311         File mountedRoot = new File(imagesRoot.getAbsolutePath(),
 312                     APP_NAME.fetchFrom(params));

 313         try {





 314             // background image
 315             File bgdir = new File(mountedRoot, BACKGROUND_IMAGE_FOLDER);
 316             bgdir.mkdirs();
 317             IOUtils.copyFile(getConfig_VolumeBackground(params),
 318                     new File(bgdir, BACKGROUND_IMAGE));
 319 
 320             // We will not consider setting background image and creating link 
 321             // to install-dir in DMG as critical error, since it can fail in
 322             // headless enviroment.
 323             try {
 324                 pb = new ProcessBuilder("osascript",
 325                         getConfig_VolumeScript(params).getAbsolutePath());
 326                 IOUtils.exec(pb);
 327             } catch (IOException ex) {
 328                 Log.verbose(ex);
 329             }
 330 
 331             // volume icon
 332             File volumeIconFile = new File(mountedRoot, ".VolumeIcon.icns");
 333             IOUtils.copyFile(getConfig_VolumeIcon(params),
 334                     volumeIconFile);
 335 
 336             // Indicate that we want a custom icon
 337             // NB: attributes of the root directory are ignored
 338             // when creating the volume
 339             // Therefore we have to do this after we mount image
 340             String setFileUtility = findSetFileUtility();
 341             if (setFileUtility != null) {
 342                 //can not find utility => keep going without icon
 343                 try {
 344                     volumeIconFile.setWritable(true);
 345                     // The "creator" attribute on a file is a legacy attribute
 346                     // but it seems Finder excepts these bytes to be
 347                     // "icnC" for the volume icon
 348                     // (might not work on Mac 10.13 with old XCode)
 349                     pb = new ProcessBuilder(
 350                             setFileUtility,
 351                             "-c", "icnC",
 352                             volumeIconFile.getAbsolutePath());
 353                     IOUtils.exec(pb);
 354                     volumeIconFile.setReadOnly();
 355 
 356                     pb = new ProcessBuilder(
 357                             setFileUtility,
 358                             "-a", "C",
 359                             mountedRoot.getAbsolutePath());
 360                     IOUtils.exec(pb);
 361                 } catch (IOException ex) {
 362                     Log.error(ex.getMessage());
 363                     Log.verbose("Cannot enable custom icon using SetFile utility");
 364                 }
 365             } else {
 366                 Log.verbose(I18N.getString("message.setfile.dmg"));
 367             }
 368 










 369         } finally {
 370             // Detach the temporary image
 371             pb = new ProcessBuilder(
 372                     hdiutil,
 373                     "detach",
 374                     "-force",
 375                     hdiUtilVerbosityFlag,
 376                     mountedRoot.getAbsolutePath());
 377             IOUtils.exec(pb);
 378         }
 379 
 380         // Compress it to a new image
 381         pb = new ProcessBuilder(
 382                 hdiutil,
 383                 "convert",
 384                 protoDMG.getAbsolutePath(),
 385                 hdiUtilVerbosityFlag,
 386                 "-format", "UDZO",
 387                 "-o", finalDMG.getAbsolutePath());
 388         IOUtils.exec(pb);


 476     public final static String[] required =
 477             {"/usr/bin/hdiutil", "/usr/bin/osascript"};
 478     public static boolean isSupported() {
 479         try {
 480             for (String s : required) {
 481                 File f = new File(s);
 482                 if (!f.exists() || !f.canExecute()) {
 483                     return false;
 484                 }
 485             }
 486             return true;
 487         } catch (Exception e) {
 488             return false;
 489         }
 490     }
 491 
 492     @Override
 493     public boolean isDefault() {
 494         return true;
 495     }

 496 }
< prev index next >