src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/MacPkgBundler.java
branchJDK-8200758-branch
changeset 58696 61c44899b4eb
parent 58647 2c43b89b1679
child 58762 0fe62353385b
equal deleted inserted replaced
58695:64adf683bc7b 58696:61c44899b4eb
    23  * questions.
    23  * questions.
    24  */
    24  */
    25 
    25 
    26 package jdk.jpackage.internal;
    26 package jdk.jpackage.internal;
    27 
    27 
    28 import java.io.File;
    28 import java.io.*;
    29 import java.io.FileOutputStream;
       
    30 import java.io.IOException;
       
    31 import java.io.OutputStreamWriter;
       
    32 import java.io.PrintWriter;
       
    33 import java.io.Writer;
       
    34 import java.net.URI;
    29 import java.net.URI;
    35 import java.net.URISyntaxException;
    30 import java.net.URISyntaxException;
    36 import java.nio.file.Files;
    31 import java.nio.file.Files;
    37 import java.nio.file.Path;
    32 import java.nio.file.Path;
    38 import java.text.MessageFormat;
    33 import java.text.MessageFormat;
    40 import java.util.HashMap;
    35 import java.util.HashMap;
    41 import java.util.List;
    36 import java.util.List;
    42 import java.util.Map;
    37 import java.util.Map;
    43 import java.util.Optional;
    38 import java.util.Optional;
    44 import java.util.ResourceBundle;
    39 import java.util.ResourceBundle;
    45 import javax.xml.stream.XMLOutputFactory;
       
    46 import javax.xml.stream.XMLStreamException;
       
    47 import javax.xml.stream.XMLStreamWriter;
       
    48 
    40 
    49 import static jdk.jpackage.internal.StandardBundlerParam.*;
    41 import static jdk.jpackage.internal.StandardBundlerParam.*;
    50 import static jdk.jpackage.internal.MacBaseInstallerBundler.SIGNING_KEYCHAIN;
    42 import static jdk.jpackage.internal.MacBaseInstallerBundler.SIGNING_KEYCHAIN;
    51 import static jdk.jpackage.internal.MacBaseInstallerBundler.SIGNING_KEY_USER;
    43 import static jdk.jpackage.internal.MacBaseInstallerBundler.SIGNING_KEY_USER;
    52 import static jdk.jpackage.internal.MacAppImageBuilder.MAC_CF_BUNDLE_IDENTIFIER;
    44 import static jdk.jpackage.internal.MacAppImageBuilder.MAC_CF_BUNDLE_IDENTIFIER;
   153                 }
   145                 }
   154 
   146 
   155                 return createPKG(params, outdir, appImageDir);
   147                 return createPKG(params, outdir, appImageDir);
   156             }
   148             }
   157             return null;
   149             return null;
   158         } catch (IOException|URISyntaxException ex) {
   150         } catch (IOException ex) {
   159             Log.verbose(ex);
   151             Log.verbose(ex);
   160             throw new PackagerException(ex);
   152             throw new PackagerException(ex);
   161         }
   153         }
   162     }
   154     }
   163 
   155 
   217                 .setSubstitutionData(data)
   209                 .setSubstitutionData(data)
   218                 .saveToFile(getScripts_PostinstallFile(params));
   210                 .saveToFile(getScripts_PostinstallFile(params));
   219         getScripts_PostinstallFile(params).setExecutable(true, false);
   211         getScripts_PostinstallFile(params).setExecutable(true, false);
   220     }
   212     }
   221 
   213 
   222     private String URLEncoding(String pkgName) throws URISyntaxException {
   214     private static String URLEncoding(String pkgName) throws URISyntaxException {
   223         URI uri = new URI(null, null, pkgName, null);
   215         URI uri = new URI(null, null, pkgName, null);
   224         return uri.toASCIIString();
   216         return uri.toASCIIString();
   225     }
   217     }
   226 
   218 
   227     private void prepareDistributionXMLFile(Map<String, ? super Object> params)
   219     private void prepareDistributionXMLFile(Map<String, ? super Object> params)
   228             throws IOException, URISyntaxException {
   220             throws IOException {
   229         File f = getConfig_DistributionXMLFile(params);
   221         File f = getConfig_DistributionXMLFile(params);
   230 
   222 
   231         Log.verbose(MessageFormat.format(I18N.getString(
   223         Log.verbose(MessageFormat.format(I18N.getString(
   232                 "message.preparing-distribution-dist"), f.getAbsolutePath()));
   224                 "message.preparing-distribution-dist"), f.getAbsolutePath()));
   233 
   225 
   234         XMLOutputFactory xmlFactory = XMLOutputFactory.newInstance();
   226         IOUtils.createXml(f.toPath(), xml -> {
   235 
       
   236         try (Writer w = new OutputStreamWriter(new FileOutputStream(f), "UTF-8")) {
       
   237             XMLStreamWriter xml = xmlFactory.createXMLStreamWriter(w);
       
   238 
       
   239             xml.writeStartDocument("UTF-8", "1.0");
       
   240 
       
   241             xml.writeStartElement("installer-gui-script");
   227             xml.writeStartElement("installer-gui-script");
   242             xml.writeAttribute("minSpecVersion", "1");
   228             xml.writeAttribute("minSpecVersion", "1");
   243 
   229 
   244             xml.writeStartElement("title");
   230             xml.writeStartElement("title");
   245             xml.writeCharacters(APP_NAME.fetchFrom(params));
   231             xml.writeCharacters(APP_NAME.fetchFrom(params));
   301             xml.writeEndElement(); // </choice>
   287             xml.writeEndElement(); // </choice>
   302             xml.writeStartElement("pkg-ref");
   288             xml.writeStartElement("pkg-ref");
   303             xml.writeAttribute("id", appId);
   289             xml.writeAttribute("id", appId);
   304             xml.writeAttribute("version", VERSION.fetchFrom(params));
   290             xml.writeAttribute("version", VERSION.fetchFrom(params));
   305             xml.writeAttribute("onConclusion", "none");
   291             xml.writeAttribute("onConclusion", "none");
   306             xml.writeCharacters(URLEncoding(
   292             try {
   307                     getPackages_AppPackage(params).getName()));
   293                 xml.writeCharacters(URLEncoding(
       
   294                         getPackages_AppPackage(params).getName()));
       
   295             } catch (URISyntaxException ex) {
       
   296                 throw new IOException(ex);
       
   297             }
   308             xml.writeEndElement(); // </pkg-ref>
   298             xml.writeEndElement(); // </pkg-ref>
   309 
   299 
   310             xml.writeEndElement(); // </installer-gui-script>
   300             xml.writeEndElement(); // </installer-gui-script>
   311 
   301         });
   312             xml.writeEndDocument();
       
   313             xml.flush();
       
   314             xml.close();
       
   315 
       
   316         } catch (XMLStreamException ex) {
       
   317             Log.verbose(ex);
       
   318             throw new IOException(ex);
       
   319         }
       
   320     }
   302     }
   321 
   303 
   322     private boolean prepareConfigFiles(Map<String, ? super Object> params)
   304     private boolean prepareConfigFiles(Map<String, ? super Object> params)
   323             throws IOException, URISyntaxException {
   305             throws IOException {
   324 
   306 
   325         createResource(DEFAULT_BACKGROUND_IMAGE, params)
   307         createResource(DEFAULT_BACKGROUND_IMAGE, params)
   326                 .setCategory(I18N.getString("resource.pkg-background-image"))
   308                 .setCategory(I18N.getString("resource.pkg-background-image"))
   327                 .saveToFile(getConfig_BackgroundImage(params));
   309                 .saveToFile(getConfig_BackgroundImage(params));
   328 
   310