8231856: pkg installer dialog contains background image which does not look correc JDK-8200758-branch
authorherrick
Mon, 14 Oct 2019 11:05:39 -0400
branchJDK-8200758-branch
changeset 58582 558a0842c5aa
parent 58581 657e25d9e4e4
child 58583 b54f1adbf153
8231856: pkg installer dialog contains background image which does not look correc Submitted-by: almatvee Reviewed-by: aherrick, asemenyuk
src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/MacPkgBundler.java
--- a/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/MacPkgBundler.java	Mon Oct 14 11:04:06 2019 -0400
+++ b/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/MacPkgBundler.java	Mon Oct 14 11:05:39 2019 -0400
@@ -26,8 +26,9 @@
 package jdk.jpackage.internal;
 
 import java.io.File;
+import java.io.FileOutputStream;
 import java.io.IOException;
-import java.io.PrintStream;
+import java.io.OutputStreamWriter;
 import java.io.PrintWriter;
 import java.io.Writer;
 import java.net.URLEncoder;
@@ -40,6 +41,9 @@
 import java.util.Map;
 import java.util.Optional;
 import java.util.ResourceBundle;
+import javax.xml.stream.XMLOutputFactory;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamWriter;
 
 import static jdk.jpackage.internal.StandardBundlerParam.*;
 import static jdk.jpackage.internal.MacBaseInstallerBundler.SIGNING_KEYCHAIN;
@@ -51,7 +55,7 @@
     private static final ResourceBundle I18N = ResourceBundle.getBundle(
             "jdk.jpackage.internal.resources.MacResources");
 
-    private static final String DEFAULT_BACKGROUND_IMAGE = "background_dmg.png";
+    private static final String DEFAULT_BACKGROUND_IMAGE = "background_pkg.png";
 
     private static final String TEMPLATE_PREINSTALL_SCRIPT =
             "preinstall.template";
@@ -171,6 +175,11 @@
                 APP_NAME.fetchFrom(params) + "-background.png");
     }
 
+    private File getConfig_BackgroundImageDarkAqua(Map<String, ? super Object> params) {
+        return new File(CONFIG_ROOT.fetchFrom(params),
+                APP_NAME.fetchFrom(params) + "-background-darkAqua.png");
+    }
+
     private File getScripts_PreinstallFile(Map<String, ? super Object> params) {
         return new File(SCRIPTS_DIR.fetchFrom(params), "preinstall");
     }
@@ -181,7 +190,7 @@
     }
 
     private String getAppIdentifier(Map<String, ? super Object> params) {
-        return IDENTIFIER.fetchFrom(params);
+        return MAC_CF_BUNDLE_IDENTIFIER.fetchFrom(params);
     }
 
     private void preparePackageScripts(Map<String, ? super Object> params)
@@ -230,57 +239,91 @@
         Log.verbose(MessageFormat.format(I18N.getString(
                 "message.preparing-distribution-dist"), f.getAbsolutePath()));
 
-        try (PrintStream out = new PrintStream(f)) {
+        XMLOutputFactory xmlFactory = XMLOutputFactory.newInstance();
+
+        try (Writer w = new OutputStreamWriter(new FileOutputStream(f), "UTF-8")) {
+            XMLStreamWriter xml = xmlFactory.createXMLStreamWriter(w);
+
+            xml.writeStartDocument("UTF-8", "1.0");
 
-            out.println(
-                "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>");
-            out.println("<installer-gui-script minSpecVersion=\"1\">");
+            xml.writeStartElement("installer-gui-script");
+            xml.writeAttribute("minSpecVersion", "1");
+
+            xml.writeStartElement("title");
+            xml.writeCharacters(APP_NAME.fetchFrom(params));
+            xml.writeEndElement();
 
-            out.println("<title>" + APP_NAME.fetchFrom(params) + "</title>");
-            out.println("<background" + " file=\""
-                    + getConfig_BackgroundImage(params).getName()
-                    + "\""
-                    + " mime-type=\"image/png\""
-                    + " alignment=\"bottomleft\" "
-                    + " scaling=\"none\""
-                    + "/>");
+            xml.writeStartElement("background");
+            xml.writeAttribute("file", getConfig_BackgroundImage(params).getName());
+            xml.writeAttribute("mime-type", "image/png");
+            xml.writeAttribute("alignment", "bottomleft");
+            xml.writeAttribute("scaling", "none");
+            xml.writeEndElement();
+
+            xml.writeStartElement("background-darkAqua");
+            xml.writeAttribute("file", getConfig_BackgroundImageDarkAqua(params).getName());
+            xml.writeAttribute("mime-type", "image/png");
+            xml.writeAttribute("alignment", "bottomleft");
+            xml.writeAttribute("scaling", "none");
+            xml.writeEndElement();
 
             String licFileStr = LICENSE_FILE.fetchFrom(params);
             if (licFileStr != null) {
                 File licFile = new File(licFileStr);
-                out.println("<license"
-                        + " file=\"" + licFile.getAbsolutePath() + "\""
-                        + " mime-type=\"text/rtf\""
-                        + "/>");
+                xml.writeStartElement("license");
+                xml.writeAttribute("file", licFile.getAbsolutePath());
+                xml.writeAttribute("mime-type", "text/rtf");
+                xml.writeEndElement();
             }
 
             /*
              * Note that the content of the distribution file
              * below is generated by productbuild --synthesize
              */
-
             String appId = getAppIdentifier(params);
 
-            out.println("<pkg-ref id=\"" + appId + "\"/>");
-            out.println(
-                    "<options customize=\"never\" require-scripts=\"false\"/>");
-            out.println("<choices-outline>");
-            out.println("    <line choice=\"default\">");
-            out.println("        <line choice=\"" + appId + "\"/>");
-            out.println("    </line>");
-            out.println("</choices-outline>");
-            out.println("<choice id=\"default\"/>");
-            out.println("<choice id=\"" + appId + "\" visible=\"false\">");
-            out.println("    <pkg-ref id=\"" + appId + "\"/>");
-            out.println("</choice>");
-            out.println("<pkg-ref id=\"" + appId + "\" version=\""
-                    + VERSION.fetchFrom(params) + "\" onConclusion=\"none\">"
-                    + URLEncoder.encode(
-                    getPackages_AppPackage(params).getName(),
-                    "UTF-8") + "</pkg-ref>");
+            xml.writeStartElement("pkg-ref");
+            xml.writeAttribute("id", appId);
+            xml.writeEndElement(); // </pkg-ref>
+            xml.writeStartElement("options");
+            xml.writeAttribute("customize", "never");
+            xml.writeAttribute("require-scripts", "false");
+            xml.writeEndElement(); // </options>
+            xml.writeStartElement("choices-outline");
+            xml.writeStartElement("line");
+            xml.writeAttribute("choice", "default");
+            xml.writeStartElement("line");
+            xml.writeAttribute("choice", appId);
+            xml.writeEndElement(); // </line>
+            xml.writeEndElement(); // </line>
+            xml.writeEndElement(); // </choices-outline>
+            xml.writeStartElement("choice");
+            xml.writeAttribute("id", "default");
+            xml.writeEndElement(); // </choice>
+            xml.writeStartElement("choice");
+            xml.writeAttribute("id", appId);
+            xml.writeAttribute("visible", "false");
+            xml.writeStartElement("pkg-ref");
+            xml.writeAttribute("id", appId);
+            xml.writeEndElement(); // </pkg-ref>
+            xml.writeEndElement(); // </choice>
+            xml.writeStartElement("pkg-ref");
+            xml.writeAttribute("id", appId);
+            xml.writeAttribute("version", VERSION.fetchFrom(params));
+            xml.writeAttribute("onConclusion", "none");
+            xml.writeCharacters(URLEncoder.encode(
+                    getPackages_AppPackage(params).getName(), "UTF-8"));
+            xml.writeEndElement(); // </pkg-ref>
 
-            out.println("</installer-gui-script>");
+            xml.writeEndElement(); // </installer-gui-script>
 
+            xml.writeEndDocument();
+            xml.flush();
+            xml.close();
+
+        } catch (XMLStreamException ex) {
+            Log.verbose(ex);
+            throw new IOException(ex);
         }
     }
 
@@ -294,6 +337,14 @@
                 VERBOSE.fetchFrom(params),
                 RESOURCE_DIR.fetchFrom(params));
 
+        imageTarget = getConfig_BackgroundImageDarkAqua(params);
+        fetchResource(imageTarget.getName(),
+                I18N.getString("resource.pkg-background-image"),
+                DEFAULT_BACKGROUND_IMAGE,
+                imageTarget,
+                VERBOSE.fetchFrom(params),
+                RESOURCE_DIR.fetchFrom(params));
+
         prepareDistributionXMLFile(params);
 
         fetchResource(getConfig_Script(params).getName(),