src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/MacPkgBundler.java
branchJDK-8200758-branch
changeset 57390 1cb722a11ead
parent 57331 221a589c52ee
child 57391 970f28090a06
equal deleted inserted replaced
57389:cce526c681dc 57390:1cb722a11ead
   212 
   212 
   213         Map<String, String> data = new HashMap<>();
   213         Map<String, String> data = new HashMap<>();
   214 
   214 
   215         data.put("INSTALL_LOCATION", MAC_INSTALL_DIR.fetchFrom(params));
   215         data.put("INSTALL_LOCATION", MAC_INSTALL_DIR.fetchFrom(params));
   216 
   216 
   217         Writer w = new BufferedWriter(
   217         try (Writer w = Files.newBufferedWriter(
   218                 new FileWriter(getScripts_PreinstallFile(params)));
   218                 getScripts_PreinstallFile(params).toPath())) {
   219         String content = preprocessTextResource(
   219             String content = preprocessTextResource(
   220                 getScripts_PreinstallFile(params).getName(),
   220                     getScripts_PreinstallFile(params).getName(),
   221                 I18N.getString("resource.pkg-preinstall-script"),
   221                     I18N.getString("resource.pkg-preinstall-script"),
   222                 TEMPLATE_PREINSTALL_SCRIPT,
   222                     TEMPLATE_PREINSTALL_SCRIPT,
   223                 data,
   223                     data,
   224                 VERBOSE.fetchFrom(params),
   224                     VERBOSE.fetchFrom(params),
   225                 RESOURCE_DIR.fetchFrom(params));
   225                     RESOURCE_DIR.fetchFrom(params));
   226         w.write(content);
   226             w.write(content);
   227         w.close();
   227         }
   228         getScripts_PreinstallFile(params).setExecutable(true, false);
   228         getScripts_PreinstallFile(params).setExecutable(true, false);
   229 
   229 
   230         w = new BufferedWriter(
   230         try (Writer w = Files.newBufferedWriter(
   231                 new FileWriter(getScripts_PostinstallFile(params)));
   231                 getScripts_PostinstallFile(params).toPath())) {
   232         content = preprocessTextResource(
   232             String content = preprocessTextResource(
   233                 getScripts_PostinstallFile(params).getName(),
   233                     getScripts_PostinstallFile(params).getName(),
   234                 I18N.getString("resource.pkg-postinstall-script"),
   234                     I18N.getString("resource.pkg-postinstall-script"),
   235                 TEMPLATE_POSTINSTALL_SCRIPT,
   235                     TEMPLATE_POSTINSTALL_SCRIPT,
   236                 data,
   236                     data,
   237                 VERBOSE.fetchFrom(params),
   237                     VERBOSE.fetchFrom(params),
   238                 RESOURCE_DIR.fetchFrom(params));
   238                     RESOURCE_DIR.fetchFrom(params));
   239         w.write(content);
   239             w.write(content);
   240         w.close();
   240         }
   241         getScripts_PostinstallFile(params).setExecutable(true, false);
   241         getScripts_PostinstallFile(params).setExecutable(true, false);
   242     }
   242     }
   243 
   243 
   244     private void prepareDistributionXMLFile(Map<String, ? super Object> params)
   244     private void prepareDistributionXMLFile(Map<String, ? super Object> params)
   245             throws IOException {
   245             throws IOException {
   246         File f = getConfig_DistributionXMLFile(params);
   246         File f = getConfig_DistributionXMLFile(params);
   247 
   247 
   248         Log.verbose(MessageFormat.format(I18N.getString(
   248         Log.verbose(MessageFormat.format(I18N.getString(
   249                 "message.preparing-distribution-dist"), f.getAbsolutePath()));
   249                 "message.preparing-distribution-dist"), f.getAbsolutePath()));
   250 
   250 
   251         PrintStream out = new PrintStream(f);
   251         try (PrintStream out = new PrintStream(f)) {
   252 
   252 
   253         out.println(
   253             out.println(
   254                 "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>");
   254                 "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>");
   255         out.println("<installer-gui-script minSpecVersion=\"1\">");
   255             out.println("<installer-gui-script minSpecVersion=\"1\">");
   256 
   256 
   257         out.println("<title>" + APP_NAME.fetchFrom(params) + "</title>");
   257             out.println("<title>" + APP_NAME.fetchFrom(params) + "</title>");
   258         out.println("<background" + " file=\""
   258             out.println("<background" + " file=\""
   259                 + getConfig_BackgroundImage(params).getName()
   259                     + getConfig_BackgroundImage(params).getName()
   260                 + "\""
   260                     + "\""
   261                 + " mime-type=\"image/png\""
   261                     + " mime-type=\"image/png\""
   262                 + " alignment=\"bottomleft\" "
   262                     + " alignment=\"bottomleft\" "
   263                 + " scaling=\"none\""
   263                     + " scaling=\"none\""
   264                 + "/>");
       
   265 
       
   266         String licFileStr = LICENSE_FILE.fetchFrom(params);
       
   267         if (licFileStr != null) {
       
   268             File licFile = new File(licFileStr);
       
   269             out.println("<license"
       
   270                     + " file=\"" + licFile.getAbsolutePath() + "\""
       
   271                     + " mime-type=\"text/rtf\""
       
   272                     + "/>");
   264                     + "/>");
   273         }
   265 
   274 
   266             String licFileStr = LICENSE_FILE.fetchFrom(params);
   275         /*
   267             if (licFileStr != null) {
   276          * Note that the content of the distribution file
   268                 File licFile = new File(licFileStr);
   277          * below is generated by productbuild --synthesize
   269                 out.println("<license"
   278          */
   270                         + " file=\"" + licFile.getAbsolutePath() + "\""
   279 
   271                         + " mime-type=\"text/rtf\""
   280         String appId = getAppIdentifier(params);
   272                         + "/>");
   281 
   273             }
   282         out.println("<pkg-ref id=\"" + appId + "\"/>");
   274 
   283 
   275             /*
   284         out.println("<options customize=\"never\" require-scripts=\"false\"/>");
   276              * Note that the content of the distribution file
   285         out.println("<choices-outline>");
   277              * below is generated by productbuild --synthesize
   286         out.println("    <line choice=\"default\">");
   278              */
   287         out.println("        <line choice=\"" + appId + "\"/>");
   279 
   288         out.println("    </line>");
   280             String appId = getAppIdentifier(params);
   289         out.println("</choices-outline>");
   281 
   290         out.println("<choice id=\"default\"/>");
   282             out.println("<pkg-ref id=\"" + appId + "\"/>");
   291         out.println("<choice id=\"" + appId + "\" visible=\"false\">");
   283             out.println(
   292         out.println("    <pkg-ref id=\"" + appId + "\"/>");
   284                     "<options customize=\"never\" require-scripts=\"false\"/>");
   293         out.println("</choice>");
   285             out.println("<choices-outline>");
   294         out.println("<pkg-ref id=\"" + appId + "\" version=\""
   286             out.println("    <line choice=\"default\">");
   295                 + VERSION.fetchFrom(params) + "\" onConclusion=\"none\">"
   287             out.println("        <line choice=\"" + appId + "\"/>");
   296                 + URLEncoder.encode(getPackages_AppPackage(params).getName(),
   288             out.println("    </line>");
   297                 "UTF-8") + "</pkg-ref>");
   289             out.println("</choices-outline>");
   298 
   290             out.println("<choice id=\"default\"/>");
   299         out.println("</installer-gui-script>");
   291             out.println("<choice id=\"" + appId + "\" visible=\"false\">");
   300 
   292             out.println("    <pkg-ref id=\"" + appId + "\"/>");
   301         out.close();
   293             out.println("</choice>");
       
   294             out.println("<pkg-ref id=\"" + appId + "\" version=\""
       
   295                     + VERSION.fetchFrom(params) + "\" onConclusion=\"none\">"
       
   296                     + URLEncoder.encode(
       
   297                     getPackages_AppPackage(params).getName(),
       
   298                     "UTF-8") + "</pkg-ref>");
       
   299 
       
   300             out.println("</installer-gui-script>");
       
   301 
       
   302         }
   302     }
   303     }
   303 
   304 
   304     private boolean prepareConfigFiles(Map<String, ? super Object> params)
   305     private boolean prepareConfigFiles(Map<String, ? super Object> params)
   305             throws IOException {
   306             throws IOException {
   306         File imageTarget = getConfig_BackgroundImage(params);
   307         File imageTarget = getConfig_BackgroundImage(params);
   330     }
   331     }
   331 
   332 
   332     private void patchCPLFile(File cpl) throws IOException {
   333     private void patchCPLFile(File cpl) throws IOException {
   333         String cplData = Files.readString(cpl.toPath());
   334         String cplData = Files.readString(cpl.toPath());
   334         String[] lines = cplData.split("\n");
   335         String[] lines = cplData.split("\n");
   335         try (PrintWriter out = new PrintWriter(new BufferedWriter(
   336         try (PrintWriter out = new PrintWriter(Files.newBufferedWriter(
   336                 new FileWriter(cpl)))) {
   337                 cpl.toPath()))) {
   337             boolean skip = false; // Used to skip Java.runtime bundle, since
   338             boolean skip = false; // Used to skip Java.runtime bundle, since
   338             // pkgbuild with --root will find two bundles app and Java runtime.
   339             // pkgbuild with --root will find two bundles app and Java runtime.
   339             // We cannot generate component proprty list when using
   340             // We cannot generate component proprty list when using
   340             // --component argument.
   341             // --component argument.
   341             for (int i = 0; i < lines.length; i++) {
   342             for (int i = 0; i < lines.length; i++) {