src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/MacPkgBundler.java
author herrick
Wed, 16 Oct 2019 09:57:23 -0400
branchJDK-8200758-branch
changeset 58647 2c43b89b1679
parent 58584 910b14f4fe3a
child 58696 61c44899b4eb
permissions -rw-r--r--
8231862: Decouple DesktopIntegration and LinuxPackageBundler classes Submitted-by: asemenyuk Reviewed-by: aherrick, almatvee
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
57038
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
     1
/*
57106
ea870b9ce89a 8216492: Update copyright of all new jpackage fils to 2019
kcr
parents: 57096
diff changeset
     2
 * Copyright (c) 2014, 2019, Oracle and/or its affiliates. All rights reserved.
57038
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
     4
 *
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    10
 *
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    15
 * accompanied this code).
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    16
 *
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    20
 *
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    23
 * questions.
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    24
 */
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    25
57039
98d3963b0b7b 8214051: rename jpackager tool to jpackage
herrick
parents: 57038
diff changeset
    26
package jdk.jpackage.internal;
57038
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    27
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    28
import java.io.File;
58582
558a0842c5aa 8231856: pkg installer dialog contains background image which does not look correc
herrick
parents: 58581
diff changeset
    29
import java.io.FileOutputStream;
57038
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    30
import java.io.IOException;
58582
558a0842c5aa 8231856: pkg installer dialog contains background image which does not look correc
herrick
parents: 58581
diff changeset
    31
import java.io.OutputStreamWriter;
57217
b1291b2cedc9 8219144: Cannot find installed application on Mac
herrick
parents: 57150
diff changeset
    32
import java.io.PrintWriter;
57038
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    33
import java.io.Writer;
58584
910b14f4fe3a 8232042: [macos] Installation fails if application name contains spaces
herrick
parents: 58582
diff changeset
    34
import java.net.URI;
910b14f4fe3a 8232042: [macos] Installation fails if application name contains spaces
herrick
parents: 58582
diff changeset
    35
import java.net.URISyntaxException;
57217
b1291b2cedc9 8219144: Cannot find installed application on Mac
herrick
parents: 57150
diff changeset
    36
import java.nio.file.Files;
57331
221a589c52ee 8222676: create-installer with --app-image fails on mac
herrick
parents: 57290
diff changeset
    37
import java.nio.file.Path;
57038
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    38
import java.text.MessageFormat;
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    39
import java.util.ArrayList;
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    40
import java.util.HashMap;
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    41
import java.util.List;
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    42
import java.util.Map;
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    43
import java.util.Optional;
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    44
import java.util.ResourceBundle;
58582
558a0842c5aa 8231856: pkg installer dialog contains background image which does not look correc
herrick
parents: 58581
diff changeset
    45
import javax.xml.stream.XMLOutputFactory;
558a0842c5aa 8231856: pkg installer dialog contains background image which does not look correc
herrick
parents: 58581
diff changeset
    46
import javax.xml.stream.XMLStreamException;
558a0842c5aa 8231856: pkg installer dialog contains background image which does not look correc
herrick
parents: 58581
diff changeset
    47
import javax.xml.stream.XMLStreamWriter;
57038
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    48
57039
98d3963b0b7b 8214051: rename jpackager tool to jpackage
herrick
parents: 57038
diff changeset
    49
import static jdk.jpackage.internal.StandardBundlerParam.*;
57067
9c17d779808e 8213425: Analyze output from Source code scanner and fix where needed.
herrick
parents: 57059
diff changeset
    50
import static jdk.jpackage.internal.MacBaseInstallerBundler.SIGNING_KEYCHAIN;
9c17d779808e 8213425: Analyze output from Source code scanner and fix where needed.
herrick
parents: 57059
diff changeset
    51
import static jdk.jpackage.internal.MacBaseInstallerBundler.SIGNING_KEY_USER;
58415
73f8e557549a 8231281: Eliminate the --identifier option
herrick
parents: 58114
diff changeset
    52
import static jdk.jpackage.internal.MacAppImageBuilder.MAC_CF_BUNDLE_IDENTIFIER;
58647
2c43b89b1679 8231862: Decouple DesktopIntegration and LinuxPackageBundler classes
herrick
parents: 58584
diff changeset
    53
import static jdk.jpackage.internal.OverridableResource.createResource;
57038
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    54
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    55
public class MacPkgBundler extends MacBaseInstallerBundler {
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    56
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    57
    private static final ResourceBundle I18N = ResourceBundle.getBundle(
57059
9bb2a4dc3af7 8214143: Reduce Resource files
herrick
parents: 57039
diff changeset
    58
            "jdk.jpackage.internal.resources.MacResources");
57038
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    59
58582
558a0842c5aa 8231856: pkg installer dialog contains background image which does not look correc
herrick
parents: 58581
diff changeset
    60
    private static final String DEFAULT_BACKGROUND_IMAGE = "background_pkg.png";
57038
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    61
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    62
    private static final String TEMPLATE_PREINSTALL_SCRIPT =
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    63
            "preinstall.template";
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    64
    private static final String TEMPLATE_POSTINSTALL_SCRIPT =
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    65
            "postinstall.template";
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    66
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    67
    private static final BundlerParamInfo<File> PACKAGES_ROOT =
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    68
            new StandardBundlerParam<>(
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    69
            "mac.pkg.packagesRoot",
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    70
            File.class,
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    71
            params -> {
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    72
                File packagesRoot =
57256
d7c27451f759 8219678: CLI changes in jpackage
herrick
parents: 57217
diff changeset
    73
                        new File(TEMP_ROOT.fetchFrom(params), "packages");
57038
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    74
                packagesRoot.mkdirs();
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    75
                return packagesRoot;
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    76
            },
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    77
            (s, p) -> new File(s));
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    78
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    79
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    80
    protected final BundlerParamInfo<File> SCRIPTS_DIR =
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    81
            new StandardBundlerParam<>(
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    82
            "mac.pkg.scriptsDir",
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    83
            File.class,
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    84
            params -> {
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    85
                File scriptsDir =
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    86
                        new File(CONFIG_ROOT.fetchFrom(params), "scripts");
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    87
                scriptsDir.mkdirs();
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    88
                return scriptsDir;
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    89
            },
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    90
            (s, p) -> new File(s));
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    91
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    92
    public static final
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    93
            BundlerParamInfo<String> DEVELOPER_ID_INSTALLER_SIGNING_KEY =
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    94
            new StandardBundlerParam<>(
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    95
            "mac.signing-key-developer-id-installer",
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    96
            String.class,
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    97
            params -> {
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    98
                    String result = MacBaseInstallerBundler.findKey(
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    99
                            "Developer ID Installer: "
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   100
                            + SIGNING_KEY_USER.fetchFrom(params),
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   101
                            SIGNING_KEYCHAIN.fetchFrom(params),
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   102
                            VERBOSE.fetchFrom(params));
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   103
                    if (result != null) {
58647
2c43b89b1679 8231862: Decouple DesktopIntegration and LinuxPackageBundler classes
herrick
parents: 58584
diff changeset
   104
                        MacCertificate certificate = new MacCertificate(result);
57038
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   105
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   106
                        if (!certificate.isValid()) {
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   107
                            Log.error(MessageFormat.format(
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   108
                                    I18N.getString("error.certificate.expired"),
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   109
                                    result));
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   110
                        }
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   111
                    }
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   112
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   113
                    return result;
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   114
                },
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   115
            (s, p) -> s);
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   116
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   117
    public static final BundlerParamInfo<String> MAC_INSTALL_DIR =
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   118
            new StandardBundlerParam<>(
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   119
            "mac-install-dir",
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   120
            String.class,
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   121
             params -> {
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   122
                 String dir = INSTALL_DIR.fetchFrom(params);
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   123
                 return (dir != null) ? dir : "/Applications";
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   124
             },
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   125
            (s, p) -> s
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   126
    );
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   127
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   128
    public static final BundlerParamInfo<String> INSTALLER_SUFFIX =
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   129
            new StandardBundlerParam<> (
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   130
            "mac.pkg.installerName.suffix",
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   131
            String.class,
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   132
            params -> "",
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   133
            (s, p) -> s);
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   134
57140
3dcb33ce7ced 8217751: jpackage messages and failures
herrick
parents: 57119
diff changeset
   135
    public File bundle(Map<String, ? super Object> params,
3dcb33ce7ced 8217751: jpackage messages and failures
herrick
parents: 57119
diff changeset
   136
            File outdir) throws PackagerException {
57038
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   137
        Log.verbose(MessageFormat.format(I18N.getString("message.building-pkg"),
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   138
                APP_NAME.fetchFrom(params)));
57407
2c14fbeff1dc 8225569: jpackage app-image layout
herrick
parents: 57397
diff changeset
   139
2c14fbeff1dc 8225569: jpackage app-image layout
herrick
parents: 57397
diff changeset
   140
        IOUtils.writableOutputDir(outdir.toPath());
57038
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   141
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   142
        try {
57554
cb6733b3ed62 JDK-8227312: Remove pkg bundle from DMG image.
herrick
parents: 57529
diff changeset
   143
            File appImageDir = prepareAppBundle(params);
57038
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   144
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   145
            if (appImageDir != null && prepareConfigFiles(params)) {
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   146
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   147
                File configScript = getConfig_Script(params);
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   148
                if (configScript.exists()) {
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   149
                    Log.verbose(MessageFormat.format(I18N.getString(
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   150
                            "message.running-script"),
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   151
                            configScript.getAbsolutePath()));
57391
970f28090a06 8223334: Additional cleanup in jpackage tool
herrick
parents: 57390
diff changeset
   152
                    IOUtils.run("bash", configScript);
57038
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   153
                }
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   154
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   155
                return createPKG(params, outdir, appImageDir);
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   156
            }
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   157
            return null;
58584
910b14f4fe3a 8232042: [macos] Installation fails if application name contains spaces
herrick
parents: 58582
diff changeset
   158
        } catch (IOException|URISyntaxException ex) {
57038
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   159
            Log.verbose(ex);
57140
3dcb33ce7ced 8217751: jpackage messages and failures
herrick
parents: 57119
diff changeset
   160
            throw new PackagerException(ex);
57038
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   161
        }
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   162
    }
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   163
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   164
    private File getPackages_AppPackage(Map<String, ? super Object> params) {
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   165
        return new File(PACKAGES_ROOT.fetchFrom(params),
57119
b3dda8d77d8a 8217331: Problems when space in application name
herrick
parents: 57106
diff changeset
   166
                APP_NAME.fetchFrom(params) + "-app.pkg");
57038
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   167
    }
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   168
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   169
    private File getConfig_DistributionXMLFile(
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   170
            Map<String, ? super Object> params) {
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   171
        return new File(CONFIG_ROOT.fetchFrom(params), "distribution.dist");
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   172
    }
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   173
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   174
    private File getConfig_BackgroundImage(Map<String, ? super Object> params) {
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   175
        return new File(CONFIG_ROOT.fetchFrom(params),
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   176
                APP_NAME.fetchFrom(params) + "-background.png");
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   177
    }
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   178
58582
558a0842c5aa 8231856: pkg installer dialog contains background image which does not look correc
herrick
parents: 58581
diff changeset
   179
    private File getConfig_BackgroundImageDarkAqua(Map<String, ? super Object> params) {
558a0842c5aa 8231856: pkg installer dialog contains background image which does not look correc
herrick
parents: 58581
diff changeset
   180
        return new File(CONFIG_ROOT.fetchFrom(params),
558a0842c5aa 8231856: pkg installer dialog contains background image which does not look correc
herrick
parents: 58581
diff changeset
   181
                APP_NAME.fetchFrom(params) + "-background-darkAqua.png");
558a0842c5aa 8231856: pkg installer dialog contains background image which does not look correc
herrick
parents: 58581
diff changeset
   182
    }
558a0842c5aa 8231856: pkg installer dialog contains background image which does not look correc
herrick
parents: 58581
diff changeset
   183
57038
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   184
    private File getScripts_PreinstallFile(Map<String, ? super Object> params) {
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   185
        return new File(SCRIPTS_DIR.fetchFrom(params), "preinstall");
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   186
    }
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   187
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   188
    private File getScripts_PostinstallFile(
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   189
            Map<String, ? super Object> params) {
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   190
        return new File(SCRIPTS_DIR.fetchFrom(params), "postinstall");
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   191
    }
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   192
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   193
    private String getAppIdentifier(Map<String, ? super Object> params) {
58582
558a0842c5aa 8231856: pkg installer dialog contains background image which does not look correc
herrick
parents: 58581
diff changeset
   194
        return MAC_CF_BUNDLE_IDENTIFIER.fetchFrom(params);
57038
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   195
    }
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   196
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   197
    private void preparePackageScripts(Map<String, ? super Object> params)
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   198
            throws IOException {
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   199
        Log.verbose(I18N.getString("message.preparing-scripts"));
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   200
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   201
        Map<String, String> data = new HashMap<>();
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   202
58581
657e25d9e4e4 8231858:[macos] App does not run if installed with pkg
herrick
parents: 58415
diff changeset
   203
        Path appLocation = Path.of(MAC_INSTALL_DIR.fetchFrom(params),
657e25d9e4e4 8231858:[macos] App does not run if installed with pkg
herrick
parents: 58415
diff changeset
   204
                         APP_NAME.fetchFrom(params) + ".app", "Contents", "app");
657e25d9e4e4 8231858:[macos] App does not run if installed with pkg
herrick
parents: 58415
diff changeset
   205
57290
47c2aca6c306 8215241: Permissions are not set correctly on sub-folders in /Applications
ssadetsky
parents: 57256
diff changeset
   206
        data.put("INSTALL_LOCATION", MAC_INSTALL_DIR.fetchFrom(params));
58581
657e25d9e4e4 8231858:[macos] App does not run if installed with pkg
herrick
parents: 58415
diff changeset
   207
        data.put("APP_LOCATION", appLocation.toString());
57038
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   208
58647
2c43b89b1679 8231862: Decouple DesktopIntegration and LinuxPackageBundler classes
herrick
parents: 58584
diff changeset
   209
        createResource(TEMPLATE_PREINSTALL_SCRIPT, params)
2c43b89b1679 8231862: Decouple DesktopIntegration and LinuxPackageBundler classes
herrick
parents: 58584
diff changeset
   210
                .setCategory(I18N.getString("resource.pkg-preinstall-script"))
2c43b89b1679 8231862: Decouple DesktopIntegration and LinuxPackageBundler classes
herrick
parents: 58584
diff changeset
   211
                .setSubstitutionData(data)
2c43b89b1679 8231862: Decouple DesktopIntegration and LinuxPackageBundler classes
herrick
parents: 58584
diff changeset
   212
                .saveToFile(getScripts_PreinstallFile(params));
57038
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   213
        getScripts_PreinstallFile(params).setExecutable(true, false);
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   214
58647
2c43b89b1679 8231862: Decouple DesktopIntegration and LinuxPackageBundler classes
herrick
parents: 58584
diff changeset
   215
        createResource(TEMPLATE_POSTINSTALL_SCRIPT, params)
2c43b89b1679 8231862: Decouple DesktopIntegration and LinuxPackageBundler classes
herrick
parents: 58584
diff changeset
   216
                .setCategory(I18N.getString("resource.pkg-postinstall-script"))
2c43b89b1679 8231862: Decouple DesktopIntegration and LinuxPackageBundler classes
herrick
parents: 58584
diff changeset
   217
                .setSubstitutionData(data)
2c43b89b1679 8231862: Decouple DesktopIntegration and LinuxPackageBundler classes
herrick
parents: 58584
diff changeset
   218
                .saveToFile(getScripts_PostinstallFile(params));
57038
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   219
        getScripts_PostinstallFile(params).setExecutable(true, false);
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   220
    }
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   221
58584
910b14f4fe3a 8232042: [macos] Installation fails if application name contains spaces
herrick
parents: 58582
diff changeset
   222
    private String URLEncoding(String pkgName) throws URISyntaxException {
910b14f4fe3a 8232042: [macos] Installation fails if application name contains spaces
herrick
parents: 58582
diff changeset
   223
        URI uri = new URI(null, null, pkgName, null);
910b14f4fe3a 8232042: [macos] Installation fails if application name contains spaces
herrick
parents: 58582
diff changeset
   224
        return uri.toASCIIString();
910b14f4fe3a 8232042: [macos] Installation fails if application name contains spaces
herrick
parents: 58582
diff changeset
   225
    }
910b14f4fe3a 8232042: [macos] Installation fails if application name contains spaces
herrick
parents: 58582
diff changeset
   226
57038
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   227
    private void prepareDistributionXMLFile(Map<String, ? super Object> params)
58584
910b14f4fe3a 8232042: [macos] Installation fails if application name contains spaces
herrick
parents: 58582
diff changeset
   228
            throws IOException, URISyntaxException {
57038
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   229
        File f = getConfig_DistributionXMLFile(params);
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   230
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   231
        Log.verbose(MessageFormat.format(I18N.getString(
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   232
                "message.preparing-distribution-dist"), f.getAbsolutePath()));
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   233
58582
558a0842c5aa 8231856: pkg installer dialog contains background image which does not look correc
herrick
parents: 58581
diff changeset
   234
        XMLOutputFactory xmlFactory = XMLOutputFactory.newInstance();
558a0842c5aa 8231856: pkg installer dialog contains background image which does not look correc
herrick
parents: 58581
diff changeset
   235
558a0842c5aa 8231856: pkg installer dialog contains background image which does not look correc
herrick
parents: 58581
diff changeset
   236
        try (Writer w = new OutputStreamWriter(new FileOutputStream(f), "UTF-8")) {
558a0842c5aa 8231856: pkg installer dialog contains background image which does not look correc
herrick
parents: 58581
diff changeset
   237
            XMLStreamWriter xml = xmlFactory.createXMLStreamWriter(w);
558a0842c5aa 8231856: pkg installer dialog contains background image which does not look correc
herrick
parents: 58581
diff changeset
   238
558a0842c5aa 8231856: pkg installer dialog contains background image which does not look correc
herrick
parents: 58581
diff changeset
   239
            xml.writeStartDocument("UTF-8", "1.0");
57038
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   240
58582
558a0842c5aa 8231856: pkg installer dialog contains background image which does not look correc
herrick
parents: 58581
diff changeset
   241
            xml.writeStartElement("installer-gui-script");
558a0842c5aa 8231856: pkg installer dialog contains background image which does not look correc
herrick
parents: 58581
diff changeset
   242
            xml.writeAttribute("minSpecVersion", "1");
558a0842c5aa 8231856: pkg installer dialog contains background image which does not look correc
herrick
parents: 58581
diff changeset
   243
558a0842c5aa 8231856: pkg installer dialog contains background image which does not look correc
herrick
parents: 58581
diff changeset
   244
            xml.writeStartElement("title");
558a0842c5aa 8231856: pkg installer dialog contains background image which does not look correc
herrick
parents: 58581
diff changeset
   245
            xml.writeCharacters(APP_NAME.fetchFrom(params));
558a0842c5aa 8231856: pkg installer dialog contains background image which does not look correc
herrick
parents: 58581
diff changeset
   246
            xml.writeEndElement();
57038
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   247
58582
558a0842c5aa 8231856: pkg installer dialog contains background image which does not look correc
herrick
parents: 58581
diff changeset
   248
            xml.writeStartElement("background");
558a0842c5aa 8231856: pkg installer dialog contains background image which does not look correc
herrick
parents: 58581
diff changeset
   249
            xml.writeAttribute("file", getConfig_BackgroundImage(params).getName());
558a0842c5aa 8231856: pkg installer dialog contains background image which does not look correc
herrick
parents: 58581
diff changeset
   250
            xml.writeAttribute("mime-type", "image/png");
558a0842c5aa 8231856: pkg installer dialog contains background image which does not look correc
herrick
parents: 58581
diff changeset
   251
            xml.writeAttribute("alignment", "bottomleft");
558a0842c5aa 8231856: pkg installer dialog contains background image which does not look correc
herrick
parents: 58581
diff changeset
   252
            xml.writeAttribute("scaling", "none");
558a0842c5aa 8231856: pkg installer dialog contains background image which does not look correc
herrick
parents: 58581
diff changeset
   253
            xml.writeEndElement();
558a0842c5aa 8231856: pkg installer dialog contains background image which does not look correc
herrick
parents: 58581
diff changeset
   254
558a0842c5aa 8231856: pkg installer dialog contains background image which does not look correc
herrick
parents: 58581
diff changeset
   255
            xml.writeStartElement("background-darkAqua");
558a0842c5aa 8231856: pkg installer dialog contains background image which does not look correc
herrick
parents: 58581
diff changeset
   256
            xml.writeAttribute("file", getConfig_BackgroundImageDarkAqua(params).getName());
558a0842c5aa 8231856: pkg installer dialog contains background image which does not look correc
herrick
parents: 58581
diff changeset
   257
            xml.writeAttribute("mime-type", "image/png");
558a0842c5aa 8231856: pkg installer dialog contains background image which does not look correc
herrick
parents: 58581
diff changeset
   258
            xml.writeAttribute("alignment", "bottomleft");
558a0842c5aa 8231856: pkg installer dialog contains background image which does not look correc
herrick
parents: 58581
diff changeset
   259
            xml.writeAttribute("scaling", "none");
558a0842c5aa 8231856: pkg installer dialog contains background image which does not look correc
herrick
parents: 58581
diff changeset
   260
            xml.writeEndElement();
57038
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   261
57390
1cb722a11ead 8223333: Use try-with-resources where feasible
herrick
parents: 57331
diff changeset
   262
            String licFileStr = LICENSE_FILE.fetchFrom(params);
1cb722a11ead 8223333: Use try-with-resources where feasible
herrick
parents: 57331
diff changeset
   263
            if (licFileStr != null) {
1cb722a11ead 8223333: Use try-with-resources where feasible
herrick
parents: 57331
diff changeset
   264
                File licFile = new File(licFileStr);
58582
558a0842c5aa 8231856: pkg installer dialog contains background image which does not look correc
herrick
parents: 58581
diff changeset
   265
                xml.writeStartElement("license");
558a0842c5aa 8231856: pkg installer dialog contains background image which does not look correc
herrick
parents: 58581
diff changeset
   266
                xml.writeAttribute("file", licFile.getAbsolutePath());
558a0842c5aa 8231856: pkg installer dialog contains background image which does not look correc
herrick
parents: 58581
diff changeset
   267
                xml.writeAttribute("mime-type", "text/rtf");
558a0842c5aa 8231856: pkg installer dialog contains background image which does not look correc
herrick
parents: 58581
diff changeset
   268
                xml.writeEndElement();
57390
1cb722a11ead 8223333: Use try-with-resources where feasible
herrick
parents: 57331
diff changeset
   269
            }
57038
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   270
57390
1cb722a11ead 8223333: Use try-with-resources where feasible
herrick
parents: 57331
diff changeset
   271
            /*
1cb722a11ead 8223333: Use try-with-resources where feasible
herrick
parents: 57331
diff changeset
   272
             * Note that the content of the distribution file
1cb722a11ead 8223333: Use try-with-resources where feasible
herrick
parents: 57331
diff changeset
   273
             * below is generated by productbuild --synthesize
1cb722a11ead 8223333: Use try-with-resources where feasible
herrick
parents: 57331
diff changeset
   274
             */
1cb722a11ead 8223333: Use try-with-resources where feasible
herrick
parents: 57331
diff changeset
   275
            String appId = getAppIdentifier(params);
57038
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   276
58582
558a0842c5aa 8231856: pkg installer dialog contains background image which does not look correc
herrick
parents: 58581
diff changeset
   277
            xml.writeStartElement("pkg-ref");
558a0842c5aa 8231856: pkg installer dialog contains background image which does not look correc
herrick
parents: 58581
diff changeset
   278
            xml.writeAttribute("id", appId);
558a0842c5aa 8231856: pkg installer dialog contains background image which does not look correc
herrick
parents: 58581
diff changeset
   279
            xml.writeEndElement(); // </pkg-ref>
558a0842c5aa 8231856: pkg installer dialog contains background image which does not look correc
herrick
parents: 58581
diff changeset
   280
            xml.writeStartElement("options");
558a0842c5aa 8231856: pkg installer dialog contains background image which does not look correc
herrick
parents: 58581
diff changeset
   281
            xml.writeAttribute("customize", "never");
558a0842c5aa 8231856: pkg installer dialog contains background image which does not look correc
herrick
parents: 58581
diff changeset
   282
            xml.writeAttribute("require-scripts", "false");
558a0842c5aa 8231856: pkg installer dialog contains background image which does not look correc
herrick
parents: 58581
diff changeset
   283
            xml.writeEndElement(); // </options>
558a0842c5aa 8231856: pkg installer dialog contains background image which does not look correc
herrick
parents: 58581
diff changeset
   284
            xml.writeStartElement("choices-outline");
558a0842c5aa 8231856: pkg installer dialog contains background image which does not look correc
herrick
parents: 58581
diff changeset
   285
            xml.writeStartElement("line");
558a0842c5aa 8231856: pkg installer dialog contains background image which does not look correc
herrick
parents: 58581
diff changeset
   286
            xml.writeAttribute("choice", "default");
558a0842c5aa 8231856: pkg installer dialog contains background image which does not look correc
herrick
parents: 58581
diff changeset
   287
            xml.writeStartElement("line");
558a0842c5aa 8231856: pkg installer dialog contains background image which does not look correc
herrick
parents: 58581
diff changeset
   288
            xml.writeAttribute("choice", appId);
558a0842c5aa 8231856: pkg installer dialog contains background image which does not look correc
herrick
parents: 58581
diff changeset
   289
            xml.writeEndElement(); // </line>
558a0842c5aa 8231856: pkg installer dialog contains background image which does not look correc
herrick
parents: 58581
diff changeset
   290
            xml.writeEndElement(); // </line>
558a0842c5aa 8231856: pkg installer dialog contains background image which does not look correc
herrick
parents: 58581
diff changeset
   291
            xml.writeEndElement(); // </choices-outline>
558a0842c5aa 8231856: pkg installer dialog contains background image which does not look correc
herrick
parents: 58581
diff changeset
   292
            xml.writeStartElement("choice");
558a0842c5aa 8231856: pkg installer dialog contains background image which does not look correc
herrick
parents: 58581
diff changeset
   293
            xml.writeAttribute("id", "default");
558a0842c5aa 8231856: pkg installer dialog contains background image which does not look correc
herrick
parents: 58581
diff changeset
   294
            xml.writeEndElement(); // </choice>
558a0842c5aa 8231856: pkg installer dialog contains background image which does not look correc
herrick
parents: 58581
diff changeset
   295
            xml.writeStartElement("choice");
558a0842c5aa 8231856: pkg installer dialog contains background image which does not look correc
herrick
parents: 58581
diff changeset
   296
            xml.writeAttribute("id", appId);
558a0842c5aa 8231856: pkg installer dialog contains background image which does not look correc
herrick
parents: 58581
diff changeset
   297
            xml.writeAttribute("visible", "false");
558a0842c5aa 8231856: pkg installer dialog contains background image which does not look correc
herrick
parents: 58581
diff changeset
   298
            xml.writeStartElement("pkg-ref");
558a0842c5aa 8231856: pkg installer dialog contains background image which does not look correc
herrick
parents: 58581
diff changeset
   299
            xml.writeAttribute("id", appId);
558a0842c5aa 8231856: pkg installer dialog contains background image which does not look correc
herrick
parents: 58581
diff changeset
   300
            xml.writeEndElement(); // </pkg-ref>
558a0842c5aa 8231856: pkg installer dialog contains background image which does not look correc
herrick
parents: 58581
diff changeset
   301
            xml.writeEndElement(); // </choice>
558a0842c5aa 8231856: pkg installer dialog contains background image which does not look correc
herrick
parents: 58581
diff changeset
   302
            xml.writeStartElement("pkg-ref");
558a0842c5aa 8231856: pkg installer dialog contains background image which does not look correc
herrick
parents: 58581
diff changeset
   303
            xml.writeAttribute("id", appId);
558a0842c5aa 8231856: pkg installer dialog contains background image which does not look correc
herrick
parents: 58581
diff changeset
   304
            xml.writeAttribute("version", VERSION.fetchFrom(params));
558a0842c5aa 8231856: pkg installer dialog contains background image which does not look correc
herrick
parents: 58581
diff changeset
   305
            xml.writeAttribute("onConclusion", "none");
58584
910b14f4fe3a 8232042: [macos] Installation fails if application name contains spaces
herrick
parents: 58582
diff changeset
   306
            xml.writeCharacters(URLEncoding(
910b14f4fe3a 8232042: [macos] Installation fails if application name contains spaces
herrick
parents: 58582
diff changeset
   307
                    getPackages_AppPackage(params).getName()));
58582
558a0842c5aa 8231856: pkg installer dialog contains background image which does not look correc
herrick
parents: 58581
diff changeset
   308
            xml.writeEndElement(); // </pkg-ref>
57038
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   309
58582
558a0842c5aa 8231856: pkg installer dialog contains background image which does not look correc
herrick
parents: 58581
diff changeset
   310
            xml.writeEndElement(); // </installer-gui-script>
57038
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   311
58582
558a0842c5aa 8231856: pkg installer dialog contains background image which does not look correc
herrick
parents: 58581
diff changeset
   312
            xml.writeEndDocument();
558a0842c5aa 8231856: pkg installer dialog contains background image which does not look correc
herrick
parents: 58581
diff changeset
   313
            xml.flush();
558a0842c5aa 8231856: pkg installer dialog contains background image which does not look correc
herrick
parents: 58581
diff changeset
   314
            xml.close();
558a0842c5aa 8231856: pkg installer dialog contains background image which does not look correc
herrick
parents: 58581
diff changeset
   315
558a0842c5aa 8231856: pkg installer dialog contains background image which does not look correc
herrick
parents: 58581
diff changeset
   316
        } catch (XMLStreamException ex) {
558a0842c5aa 8231856: pkg installer dialog contains background image which does not look correc
herrick
parents: 58581
diff changeset
   317
            Log.verbose(ex);
558a0842c5aa 8231856: pkg installer dialog contains background image which does not look correc
herrick
parents: 58581
diff changeset
   318
            throw new IOException(ex);
57390
1cb722a11ead 8223333: Use try-with-resources where feasible
herrick
parents: 57331
diff changeset
   319
        }
57038
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   320
    }
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   321
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   322
    private boolean prepareConfigFiles(Map<String, ? super Object> params)
58584
910b14f4fe3a 8232042: [macos] Installation fails if application name contains spaces
herrick
parents: 58582
diff changeset
   323
            throws IOException, URISyntaxException {
57038
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   324
58647
2c43b89b1679 8231862: Decouple DesktopIntegration and LinuxPackageBundler classes
herrick
parents: 58584
diff changeset
   325
        createResource(DEFAULT_BACKGROUND_IMAGE, params)
2c43b89b1679 8231862: Decouple DesktopIntegration and LinuxPackageBundler classes
herrick
parents: 58584
diff changeset
   326
                .setCategory(I18N.getString("resource.pkg-background-image"))
2c43b89b1679 8231862: Decouple DesktopIntegration and LinuxPackageBundler classes
herrick
parents: 58584
diff changeset
   327
                .saveToFile(getConfig_BackgroundImage(params));
2c43b89b1679 8231862: Decouple DesktopIntegration and LinuxPackageBundler classes
herrick
parents: 58584
diff changeset
   328
2c43b89b1679 8231862: Decouple DesktopIntegration and LinuxPackageBundler classes
herrick
parents: 58584
diff changeset
   329
        createResource(DEFAULT_BACKGROUND_IMAGE, params)
2c43b89b1679 8231862: Decouple DesktopIntegration and LinuxPackageBundler classes
herrick
parents: 58584
diff changeset
   330
                .setCategory(I18N.getString("resource.pkg-background-image"))
2c43b89b1679 8231862: Decouple DesktopIntegration and LinuxPackageBundler classes
herrick
parents: 58584
diff changeset
   331
                .saveToFile(getConfig_BackgroundImageDarkAqua(params));
58582
558a0842c5aa 8231856: pkg installer dialog contains background image which does not look correc
herrick
parents: 58581
diff changeset
   332
57038
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   333
        prepareDistributionXMLFile(params);
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   334
58647
2c43b89b1679 8231862: Decouple DesktopIntegration and LinuxPackageBundler classes
herrick
parents: 58584
diff changeset
   335
        createResource(null, params)
2c43b89b1679 8231862: Decouple DesktopIntegration and LinuxPackageBundler classes
herrick
parents: 58584
diff changeset
   336
                .setCategory(I18N.getString("resource.post-install-script"))
2c43b89b1679 8231862: Decouple DesktopIntegration and LinuxPackageBundler classes
herrick
parents: 58584
diff changeset
   337
                .saveToFile(getConfig_Script(params));
57038
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   338
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   339
        return true;
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   340
    }
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   341
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   342
    // name of post-image script
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   343
    private File getConfig_Script(Map<String, ? super Object> params) {
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   344
        return new File(CONFIG_ROOT.fetchFrom(params),
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   345
                APP_NAME.fetchFrom(params) + "-post-image.sh");
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   346
    }
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   347
57217
b1291b2cedc9 8219144: Cannot find installed application on Mac
herrick
parents: 57150
diff changeset
   348
    private void patchCPLFile(File cpl) throws IOException {
b1291b2cedc9 8219144: Cannot find installed application on Mac
herrick
parents: 57150
diff changeset
   349
        String cplData = Files.readString(cpl.toPath());
b1291b2cedc9 8219144: Cannot find installed application on Mac
herrick
parents: 57150
diff changeset
   350
        String[] lines = cplData.split("\n");
57390
1cb722a11ead 8223333: Use try-with-resources where feasible
herrick
parents: 57331
diff changeset
   351
        try (PrintWriter out = new PrintWriter(Files.newBufferedWriter(
1cb722a11ead 8223333: Use try-with-resources where feasible
herrick
parents: 57331
diff changeset
   352
                cpl.toPath()))) {
57529
e3b156ad362f 8224627: Creating installer with --runtime-image on OS X fails
herrick
parents: 57438
diff changeset
   353
            int skip = 0;
e3b156ad362f 8224627: Creating installer with --runtime-image on OS X fails
herrick
parents: 57438
diff changeset
   354
            // Used to skip Java.runtime bundle, since
57217
b1291b2cedc9 8219144: Cannot find installed application on Mac
herrick
parents: 57150
diff changeset
   355
            // pkgbuild with --root will find two bundles app and Java runtime.
b1291b2cedc9 8219144: Cannot find installed application on Mac
herrick
parents: 57150
diff changeset
   356
            // We cannot generate component proprty list when using
b1291b2cedc9 8219144: Cannot find installed application on Mac
herrick
parents: 57150
diff changeset
   357
            // --component argument.
b1291b2cedc9 8219144: Cannot find installed application on Mac
herrick
parents: 57150
diff changeset
   358
            for (int i = 0; i < lines.length; i++) {
b1291b2cedc9 8219144: Cannot find installed application on Mac
herrick
parents: 57150
diff changeset
   359
                if (lines[i].trim().equals("<key>BundleIsRelocatable</key>")) {
b1291b2cedc9 8219144: Cannot find installed application on Mac
herrick
parents: 57150
diff changeset
   360
                    out.println(lines[i]);
b1291b2cedc9 8219144: Cannot find installed application on Mac
herrick
parents: 57150
diff changeset
   361
                    out.println("<false/>");
b1291b2cedc9 8219144: Cannot find installed application on Mac
herrick
parents: 57150
diff changeset
   362
                    i++;
b1291b2cedc9 8219144: Cannot find installed application on Mac
herrick
parents: 57150
diff changeset
   363
                } else if (lines[i].trim().equals("<key>ChildBundles</key>")) {
57529
e3b156ad362f 8224627: Creating installer with --runtime-image on OS X fails
herrick
parents: 57438
diff changeset
   364
                    ++skip;
e3b156ad362f 8224627: Creating installer with --runtime-image on OS X fails
herrick
parents: 57438
diff changeset
   365
                } else if ((skip > 0) && lines[i].trim().equals("</array>")) {
e3b156ad362f 8224627: Creating installer with --runtime-image on OS X fails
herrick
parents: 57438
diff changeset
   366
                    --skip;
57217
b1291b2cedc9 8219144: Cannot find installed application on Mac
herrick
parents: 57150
diff changeset
   367
                } else {
57529
e3b156ad362f 8224627: Creating installer with --runtime-image on OS X fails
herrick
parents: 57438
diff changeset
   368
                    if (skip == 0) {
57217
b1291b2cedc9 8219144: Cannot find installed application on Mac
herrick
parents: 57150
diff changeset
   369
                        out.println(lines[i]);
b1291b2cedc9 8219144: Cannot find installed application on Mac
herrick
parents: 57150
diff changeset
   370
                    }
b1291b2cedc9 8219144: Cannot find installed application on Mac
herrick
parents: 57150
diff changeset
   371
                }
b1291b2cedc9 8219144: Cannot find installed application on Mac
herrick
parents: 57150
diff changeset
   372
            }
b1291b2cedc9 8219144: Cannot find installed application on Mac
herrick
parents: 57150
diff changeset
   373
        }
b1291b2cedc9 8219144: Cannot find installed application on Mac
herrick
parents: 57150
diff changeset
   374
    }
b1291b2cedc9 8219144: Cannot find installed application on Mac
herrick
parents: 57150
diff changeset
   375
57331
221a589c52ee 8222676: create-installer with --app-image fails on mac
herrick
parents: 57290
diff changeset
   376
    // pkgbuild includes all components from "--root" and subfolders,
221a589c52ee 8222676: create-installer with --app-image fails on mac
herrick
parents: 57290
diff changeset
   377
    // so if we have app image in folder which contains other images, then they
221a589c52ee 8222676: create-installer with --app-image fails on mac
herrick
parents: 57290
diff changeset
   378
    // will be included as well. It does have "--filter" option which use regex
221a589c52ee 8222676: create-installer with --app-image fails on mac
herrick
parents: 57290
diff changeset
   379
    // to exclude files/folder, but it will overwrite default one which excludes
221a589c52ee 8222676: create-installer with --app-image fails on mac
herrick
parents: 57290
diff changeset
   380
    // based on doc "any .svn or CVS directories, and any .DS_Store files".
221a589c52ee 8222676: create-installer with --app-image fails on mac
herrick
parents: 57290
diff changeset
   381
    // So easy aproach will be to copy user provided app-image into temp folder
221a589c52ee 8222676: create-installer with --app-image fails on mac
herrick
parents: 57290
diff changeset
   382
    // if root path contains other files.
221a589c52ee 8222676: create-installer with --app-image fails on mac
herrick
parents: 57290
diff changeset
   383
    private String getRoot(Map<String, ? super Object> params,
221a589c52ee 8222676: create-installer with --app-image fails on mac
herrick
parents: 57290
diff changeset
   384
            File appLocation) throws IOException {
221a589c52ee 8222676: create-installer with --app-image fails on mac
herrick
parents: 57290
diff changeset
   385
        String root = appLocation.getParent() == null ?
221a589c52ee 8222676: create-installer with --app-image fails on mac
herrick
parents: 57290
diff changeset
   386
                "." : appLocation.getParent();
221a589c52ee 8222676: create-installer with --app-image fails on mac
herrick
parents: 57290
diff changeset
   387
        File rootDir = new File(root);
221a589c52ee 8222676: create-installer with --app-image fails on mac
herrick
parents: 57290
diff changeset
   388
        File[] list = rootDir.listFiles();
221a589c52ee 8222676: create-installer with --app-image fails on mac
herrick
parents: 57290
diff changeset
   389
        if (list != null) { // Should not happend
221a589c52ee 8222676: create-installer with --app-image fails on mac
herrick
parents: 57290
diff changeset
   390
            // We should only have app image and/or .DS_Store
221a589c52ee 8222676: create-installer with --app-image fails on mac
herrick
parents: 57290
diff changeset
   391
            if (list.length == 1) {
221a589c52ee 8222676: create-installer with --app-image fails on mac
herrick
parents: 57290
diff changeset
   392
                return root;
221a589c52ee 8222676: create-installer with --app-image fails on mac
herrick
parents: 57290
diff changeset
   393
            } else if (list.length == 2) {
221a589c52ee 8222676: create-installer with --app-image fails on mac
herrick
parents: 57290
diff changeset
   394
                // Check case with app image and .DS_Store
221a589c52ee 8222676: create-installer with --app-image fails on mac
herrick
parents: 57290
diff changeset
   395
                if (list[0].toString().toLowerCase().endsWith(".ds_store") ||
221a589c52ee 8222676: create-installer with --app-image fails on mac
herrick
parents: 57290
diff changeset
   396
                    list[1].toString().toLowerCase().endsWith(".ds_store")) {
221a589c52ee 8222676: create-installer with --app-image fails on mac
herrick
parents: 57290
diff changeset
   397
                    return root; // Only app image and .DS_Store
221a589c52ee 8222676: create-installer with --app-image fails on mac
herrick
parents: 57290
diff changeset
   398
                }
221a589c52ee 8222676: create-installer with --app-image fails on mac
herrick
parents: 57290
diff changeset
   399
            }
221a589c52ee 8222676: create-installer with --app-image fails on mac
herrick
parents: 57290
diff changeset
   400
        }
221a589c52ee 8222676: create-installer with --app-image fails on mac
herrick
parents: 57290
diff changeset
   401
221a589c52ee 8222676: create-installer with --app-image fails on mac
herrick
parents: 57290
diff changeset
   402
        // Copy to new root
221a589c52ee 8222676: create-installer with --app-image fails on mac
herrick
parents: 57290
diff changeset
   403
        Path newRoot = Files.createTempDirectory(
221a589c52ee 8222676: create-installer with --app-image fails on mac
herrick
parents: 57290
diff changeset
   404
                TEMP_ROOT.fetchFrom(params).toPath(),
221a589c52ee 8222676: create-installer with --app-image fails on mac
herrick
parents: 57290
diff changeset
   405
                "root-");
221a589c52ee 8222676: create-installer with --app-image fails on mac
herrick
parents: 57290
diff changeset
   406
221a589c52ee 8222676: create-installer with --app-image fails on mac
herrick
parents: 57290
diff changeset
   407
        IOUtils.copyRecursive(appLocation.toPath(),
221a589c52ee 8222676: create-installer with --app-image fails on mac
herrick
parents: 57290
diff changeset
   408
                newRoot.resolve(appLocation.getName()));
221a589c52ee 8222676: create-installer with --app-image fails on mac
herrick
parents: 57290
diff changeset
   409
221a589c52ee 8222676: create-installer with --app-image fails on mac
herrick
parents: 57290
diff changeset
   410
        return newRoot.toString();
221a589c52ee 8222676: create-installer with --app-image fails on mac
herrick
parents: 57290
diff changeset
   411
    }
221a589c52ee 8222676: create-installer with --app-image fails on mac
herrick
parents: 57290
diff changeset
   412
57038
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   413
    private File createPKG(Map<String, ? super Object> params,
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   414
            File outdir, File appLocation) {
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   415
        // generic find attempt
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   416
        try {
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   417
            File appPKG = getPackages_AppPackage(params);
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   418
57331
221a589c52ee 8222676: create-installer with --app-image fails on mac
herrick
parents: 57290
diff changeset
   419
            String root = getRoot(params, appLocation);
221a589c52ee 8222676: create-installer with --app-image fails on mac
herrick
parents: 57290
diff changeset
   420
57217
b1291b2cedc9 8219144: Cannot find installed application on Mac
herrick
parents: 57150
diff changeset
   421
            // Generate default CPL file
b1291b2cedc9 8219144: Cannot find installed application on Mac
herrick
parents: 57150
diff changeset
   422
            File cpl = new File(CONFIG_ROOT.fetchFrom(params).getAbsolutePath()
b1291b2cedc9 8219144: Cannot find installed application on Mac
herrick
parents: 57150
diff changeset
   423
                    + File.separator + "cpl.plist");
57038
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   424
            ProcessBuilder pb = new ProcessBuilder("pkgbuild",
57217
b1291b2cedc9 8219144: Cannot find installed application on Mac
herrick
parents: 57150
diff changeset
   425
                    "--root",
57331
221a589c52ee 8222676: create-installer with --app-image fails on mac
herrick
parents: 57290
diff changeset
   426
                    root,
57038
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   427
                    "--install-location",
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   428
                    MAC_INSTALL_DIR.fetchFrom(params),
57217
b1291b2cedc9 8219144: Cannot find installed application on Mac
herrick
parents: 57150
diff changeset
   429
                    "--analyze",
b1291b2cedc9 8219144: Cannot find installed application on Mac
herrick
parents: 57150
diff changeset
   430
                    cpl.getAbsolutePath());
b1291b2cedc9 8219144: Cannot find installed application on Mac
herrick
parents: 57150
diff changeset
   431
57391
970f28090a06 8223334: Additional cleanup in jpackage tool
herrick
parents: 57390
diff changeset
   432
            IOUtils.exec(pb);
57217
b1291b2cedc9 8219144: Cannot find installed application on Mac
herrick
parents: 57150
diff changeset
   433
b1291b2cedc9 8219144: Cannot find installed application on Mac
herrick
parents: 57150
diff changeset
   434
            patchCPLFile(cpl);
b1291b2cedc9 8219144: Cannot find installed application on Mac
herrick
parents: 57150
diff changeset
   435
57290
47c2aca6c306 8215241: Permissions are not set correctly on sub-folders in /Applications
ssadetsky
parents: 57256
diff changeset
   436
            preparePackageScripts(params);
47c2aca6c306 8215241: Permissions are not set correctly on sub-folders in /Applications
ssadetsky
parents: 57256
diff changeset
   437
57217
b1291b2cedc9 8219144: Cannot find installed application on Mac
herrick
parents: 57150
diff changeset
   438
            // build application package
b1291b2cedc9 8219144: Cannot find installed application on Mac
herrick
parents: 57150
diff changeset
   439
            pb = new ProcessBuilder("pkgbuild",
b1291b2cedc9 8219144: Cannot find installed application on Mac
herrick
parents: 57150
diff changeset
   440
                    "--root",
57331
221a589c52ee 8222676: create-installer with --app-image fails on mac
herrick
parents: 57290
diff changeset
   441
                    root,
57217
b1291b2cedc9 8219144: Cannot find installed application on Mac
herrick
parents: 57150
diff changeset
   442
                    "--install-location",
b1291b2cedc9 8219144: Cannot find installed application on Mac
herrick
parents: 57150
diff changeset
   443
                    MAC_INSTALL_DIR.fetchFrom(params),
b1291b2cedc9 8219144: Cannot find installed application on Mac
herrick
parents: 57150
diff changeset
   444
                    "--component-plist",
b1291b2cedc9 8219144: Cannot find installed application on Mac
herrick
parents: 57150
diff changeset
   445
                    cpl.getAbsolutePath(),
57290
47c2aca6c306 8215241: Permissions are not set correctly on sub-folders in /Applications
ssadetsky
parents: 57256
diff changeset
   446
                    "--scripts",
47c2aca6c306 8215241: Permissions are not set correctly on sub-folders in /Applications
ssadetsky
parents: 57256
diff changeset
   447
                    SCRIPTS_DIR.fetchFrom(params).getAbsolutePath(),
57038
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   448
                    appPKG.getAbsolutePath());
57391
970f28090a06 8223334: Additional cleanup in jpackage tool
herrick
parents: 57390
diff changeset
   449
            IOUtils.exec(pb);
57038
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   450
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   451
            // build final package
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   452
            File finalPKG = new File(outdir, INSTALLER_NAME.fetchFrom(params)
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   453
                    + INSTALLER_SUFFIX.fetchFrom(params)
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   454
                    + ".pkg");
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   455
            outdir.mkdirs();
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   456
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   457
            List<String> commandLine = new ArrayList<>();
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   458
            commandLine.add("productbuild");
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   459
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   460
            commandLine.add("--resources");
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   461
            commandLine.add(CONFIG_ROOT.fetchFrom(params).getAbsolutePath());
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   462
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   463
            // maybe sign
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   464
            if (Optional.ofNullable(MacAppImageBuilder.
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   465
                    SIGN_BUNDLE.fetchFrom(params)).orElse(Boolean.TRUE)) {
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   466
                if (Platform.getMajorVersion() > 10 ||
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   467
                    (Platform.getMajorVersion() == 10 &&
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   468
                    Platform.getMinorVersion() >= 12)) {
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   469
                    // we need this for OS X 10.12+
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   470
                    Log.verbose(I18N.getString("message.signing.pkg"));
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   471
                }
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   472
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   473
                String signingIdentity =
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   474
                        DEVELOPER_ID_INSTALLER_SIGNING_KEY.fetchFrom(params);
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   475
                if (signingIdentity != null) {
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   476
                    commandLine.add("--sign");
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   477
                    commandLine.add(signingIdentity);
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   478
                }
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   479
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   480
                String keychainName = SIGNING_KEYCHAIN.fetchFrom(params);
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   481
                if (keychainName != null && !keychainName.isEmpty()) {
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   482
                    commandLine.add("--keychain");
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   483
                    commandLine.add(keychainName);
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   484
                }
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   485
            }
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   486
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   487
            commandLine.add("--distribution");
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   488
            commandLine.add(
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   489
                    getConfig_DistributionXMLFile(params).getAbsolutePath());
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   490
            commandLine.add("--package-path");
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   491
            commandLine.add(PACKAGES_ROOT.fetchFrom(params).getAbsolutePath());
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   492
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   493
            commandLine.add(finalPKG.getAbsolutePath());
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   494
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   495
            pb = new ProcessBuilder(commandLine);
57391
970f28090a06 8223334: Additional cleanup in jpackage tool
herrick
parents: 57390
diff changeset
   496
            IOUtils.exec(pb);
57038
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   497
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   498
            return finalPKG;
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   499
        } catch (Exception ignored) {
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   500
            Log.verbose(ignored);
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   501
            return null;
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   502
        }
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   503
    }
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   504
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   505
    //////////////////////////////////////////////////////////////////////////
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   506
    // Implement Bundler
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   507
    //////////////////////////////////////////////////////////////////////////
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   508
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   509
    @Override
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   510
    public String getName() {
57059
9bb2a4dc3af7 8214143: Reduce Resource files
herrick
parents: 57039
diff changeset
   511
        return I18N.getString("pkg.bundler.name");
57038
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   512
    }
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   513
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   514
    @Override
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   515
    public String getID() {
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   516
        return "pkg";
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   517
    }
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   518
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   519
    @Override
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   520
    public boolean validate(Map<String, ? super Object> params)
57438
4a31db8d42bd 8226599: use code coverage results to remove dead code
herrick
parents: 57407
diff changeset
   521
            throws ConfigException {
57038
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   522
        try {
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   523
            if (params == null) throw new ConfigException(
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   524
                    I18N.getString("error.parameters-null"),
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   525
                    I18N.getString("error.parameters-null.advice"));
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   526
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   527
            // run basic validation to ensure requirements are met
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   528
            // we are not interested in return code, only possible exception
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   529
            validateAppImageAndBundeler(params);
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   530
58415
73f8e557549a 8231281: Eliminate the --identifier option
herrick
parents: 58114
diff changeset
   531
            if (MAC_CF_BUNDLE_IDENTIFIER.fetchFrom(params) == null) {
73f8e557549a 8231281: Eliminate the --identifier option
herrick
parents: 58114
diff changeset
   532
                throw new ConfigException(
73f8e557549a 8231281: Eliminate the --identifier option
herrick
parents: 58114
diff changeset
   533
                        I18N.getString("message.app-image-requires-identifier"),
73f8e557549a 8231281: Eliminate the --identifier option
herrick
parents: 58114
diff changeset
   534
                        I18N.getString(
73f8e557549a 8231281: Eliminate the --identifier option
herrick
parents: 58114
diff changeset
   535
                            "message.app-image-requires-identifier.advice"));
73f8e557549a 8231281: Eliminate the --identifier option
herrick
parents: 58114
diff changeset
   536
            }
73f8e557549a 8231281: Eliminate the --identifier option
herrick
parents: 58114
diff changeset
   537
57038
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   538
            // reject explicitly set sign to true and no valid signature key
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   539
            if (Optional.ofNullable(MacAppImageBuilder.
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   540
                    SIGN_BUNDLE.fetchFrom(params)).orElse(Boolean.FALSE)) {
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   541
                String signingIdentity =
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   542
                        DEVELOPER_ID_INSTALLER_SIGNING_KEY.fetchFrom(params);
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   543
                if (signingIdentity == null) {
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   544
                    throw new ConfigException(
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   545
                            I18N.getString("error.explicit-sign-no-cert"),
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   546
                            I18N.getString(
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   547
                            "error.explicit-sign-no-cert.advice"));
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   548
                }
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   549
            }
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   550
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   551
            // hdiutil is always available so there's no need
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   552
            // to test for availability.
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   553
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   554
            return true;
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   555
        } catch (RuntimeException re) {
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   556
            if (re.getCause() instanceof ConfigException) {
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   557
                throw (ConfigException) re.getCause();
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   558
            } else {
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   559
                throw new ConfigException(re);
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   560
            }
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   561
        }
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   562
    }
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   563
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   564
    @Override
57140
3dcb33ce7ced 8217751: jpackage messages and failures
herrick
parents: 57119
diff changeset
   565
    public File execute(Map<String, ? super Object> params,
3dcb33ce7ced 8217751: jpackage messages and failures
herrick
parents: 57119
diff changeset
   566
            File outputParentDir) throws PackagerException {
57038
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   567
        return bundle(params, outputParentDir);
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   568
    }
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   569
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   570
    @Override
57150
fa68c2ab636d 8217894: jpackage CLI syntax changes
herrick
parents: 57140
diff changeset
   571
    public boolean supported(boolean runtimeInstaller) {
57438
4a31db8d42bd 8226599: use code coverage results to remove dead code
herrick
parents: 57407
diff changeset
   572
        return true;
57038
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   573
    }
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   574
58114
42df7de58e39 8230519: jpackage "--package-type" values and default
herrick
parents: 58037
diff changeset
   575
    @Override
42df7de58e39 8230519: jpackage "--package-type" values and default
herrick
parents: 58037
diff changeset
   576
    public boolean isDefault() {
42df7de58e39 8230519: jpackage "--package-type" values and default
herrick
parents: 58037
diff changeset
   577
        return false;
42df7de58e39 8230519: jpackage "--package-type" values and default
herrick
parents: 58037
diff changeset
   578
    }
42df7de58e39 8230519: jpackage "--package-type" values and default
herrick
parents: 58037
diff changeset
   579
57038
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   580
}