src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/MacDmgBundler.java
branchJDK-8200758-branch
changeset 58647 2c43b89b1679
parent 58607 7451b17b40d3
child 58762 0fe62353385b
equal deleted inserted replaced
58608:a561014c28d0 58647:2c43b89b1679
    27 
    27 
    28 import java.io.*;
    28 import java.io.*;
    29 import java.nio.file.Files;
    29 import java.nio.file.Files;
    30 import java.text.MessageFormat;
    30 import java.text.MessageFormat;
    31 import java.util.*;
    31 import java.util.*;
       
    32 import static jdk.jpackage.internal.OverridableResource.createResource;
    32 
    33 
    33 import static jdk.jpackage.internal.StandardBundlerParam.*;
    34 import static jdk.jpackage.internal.StandardBundlerParam.*;
    34 
    35 
    35 public class MacDmgBundler extends MacBaseInstallerBundler {
    36 public class MacDmgBundler extends MacBaseInstallerBundler {
    36 
    37 
    95         data.put("DEPLOY_APPLICATION_NAME", APP_NAME.fetchFrom(params));
    96         data.put("DEPLOY_APPLICATION_NAME", APP_NAME.fetchFrom(params));
    96 
    97 
    97         data.put("DEPLOY_INSTALL_LOCATION", "(path to applications folder)");
    98         data.put("DEPLOY_INSTALL_LOCATION", "(path to applications folder)");
    98         data.put("DEPLOY_INSTALL_NAME", "Applications");
    99         data.put("DEPLOY_INSTALL_NAME", "Applications");
    99 
   100 
   100         try (Writer w = Files.newBufferedWriter(dmgSetup.toPath())) {
   101         createResource(DEFAULT_DMG_SETUP_SCRIPT, params)
   101             w.write(preprocessTextResource(dmgSetup.getName(),
   102                 .setCategory(I18N.getString("resource.dmg-setup-script"))
   102                     I18N.getString("resource.dmg-setup-script"),
   103                 .setSubstitutionData(data)
   103                     DEFAULT_DMG_SETUP_SCRIPT, data, VERBOSE.fetchFrom(params),
   104                 .saveToFile(dmgSetup);
   104                     RESOURCE_DIR.fetchFrom(params)));
       
   105         }
       
   106     }
   105     }
   107 
   106 
   108     private File getConfig_VolumeScript(Map<String, ? super Object> params) {
   107     private File getConfig_VolumeScript(Map<String, ? super Object> params) {
   109         return new File(CONFIG_ROOT.fetchFrom(params),
   108         return new File(CONFIG_ROOT.fetchFrom(params),
   110                 APP_NAME.fetchFrom(params) + "-dmg-setup.scpt");
   109                 APP_NAME.fetchFrom(params) + "-dmg-setup.scpt");
   140                     Base64.getEncoder().encodeToString(licenseContentOriginal);
   139                     Base64.getEncoder().encodeToString(licenseContentOriginal);
   141 
   140 
   142             Map<String, String> data = new HashMap<>();
   141             Map<String, String> data = new HashMap<>();
   143             data.put("APPLICATION_LICENSE_TEXT", licenseInBase64);
   142             data.put("APPLICATION_LICENSE_TEXT", licenseInBase64);
   144 
   143 
   145             try (Writer w = Files.newBufferedWriter(
   144             createResource(DEFAULT_LICENSE_PLIST, params)
   146                     getConfig_LicenseFile(params).toPath())) {
   145                     .setCategory(I18N.getString("resource.license-setup"))
   147                 w.write(preprocessTextResource(
   146                     .setSubstitutionData(data)
   148                         getConfig_LicenseFile(params).getName(),
   147                     .saveToFile(getConfig_LicenseFile(params));
   149                         I18N.getString("resource.license-setup"),
       
   150                         DEFAULT_LICENSE_PLIST, data, VERBOSE.fetchFrom(params),
       
   151                         RESOURCE_DIR.fetchFrom(params)));
       
   152             }
       
   153 
   148 
   154         } catch (IOException ex) {
   149         } catch (IOException ex) {
   155             Log.verbose(ex);
   150             Log.verbose(ex);
   156         }
   151         }
   157     }
   152     }
   158 
   153 
   159     private boolean prepareConfigFiles(Map<String, ? super Object> params)
   154     private boolean prepareConfigFiles(Map<String, ? super Object> params)
   160             throws IOException {
   155             throws IOException {
   161         File bgTarget = getConfig_VolumeBackground(params);
   156 
   162         fetchResource(bgTarget.getName(),
   157         createResource(DEFAULT_BACKGROUND_IMAGE, params)
   163                 I18N.getString("resource.dmg-background"),
   158                     .setCategory(I18N.getString("resource.dmg-background"))
   164                 DEFAULT_BACKGROUND_IMAGE,
   159                     .saveToFile(getConfig_VolumeBackground(params));
   165                 bgTarget,
   160 
   166                 VERBOSE.fetchFrom(params),
   161         createResource(TEMPLATE_BUNDLE_ICON, params)
   167                 RESOURCE_DIR.fetchFrom(params));
   162                 .setCategory(I18N.getString("resource.volume-icon"))
   168 
   163                 .setExternal(MacAppBundler.ICON_ICNS.fetchFrom(params))
   169         File iconTarget = getConfig_VolumeIcon(params);
   164                 .saveToFile(getConfig_VolumeIcon(params));
   170         if (MacAppBundler.ICON_ICNS.fetchFrom(params) == null ||
   165 
   171                 !MacAppBundler.ICON_ICNS.fetchFrom(params).exists()) {
   166         createResource(null, params)
   172             fetchResource(iconTarget.getName(),
   167                 .setCategory(I18N.getString("resource.post-install-script"))
   173                     I18N.getString("resource.volume-icon"),
   168                 .saveToFile(getConfig_Script(params));
   174                     TEMPLATE_BUNDLE_ICON,
       
   175                     iconTarget,
       
   176                     VERBOSE.fetchFrom(params),
       
   177                     RESOURCE_DIR.fetchFrom(params));
       
   178         } else {
       
   179             fetchResource(iconTarget.getName(),
       
   180                     I18N.getString("resource.volume-icon"),
       
   181                     MacAppBundler.ICON_ICNS.fetchFrom(params),
       
   182                     iconTarget,
       
   183                     VERBOSE.fetchFrom(params),
       
   184                     RESOURCE_DIR.fetchFrom(params));
       
   185         }
       
   186 
       
   187 
       
   188         fetchResource(getConfig_Script(params).getName(),
       
   189                 I18N.getString("resource.post-install-script"),
       
   190                 (String) null,
       
   191                 getConfig_Script(params),
       
   192                 VERBOSE.fetchFrom(params),
       
   193                 RESOURCE_DIR.fetchFrom(params));
       
   194 
   169 
   195         prepareLicense(params);
   170         prepareLicense(params);
   196 
   171 
   197         // In theory we need to extract name from results of attach command
   172         // In theory we need to extract name from results of attach command
   198         // However, this will be a problem for customization as name will
   173         // However, this will be a problem for customization as name will