src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/MacPkgBundler.java
author herrick
Mon, 11 Mar 2019 14:44:00 -0400
branchJDK-8200758-branch
changeset 57256 d7c27451f759
parent 57217 b1291b2cedc9
child 57290 47c2aca6c306
permissions -rw-r--r--
8219678: CLI changes in jpackage Reviewed-by: 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.BufferedWriter;
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    29
import java.io.File;
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    30
import java.io.FileWriter;
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    31
import java.io.IOException;
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    32
import java.io.PrintStream;
57217
b1291b2cedc9 8219144: Cannot find installed application on Mac
herrick
parents: 57150
diff changeset
    33
import java.io.PrintWriter;
57038
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    34
import java.io.Writer;
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    35
import java.net.URLEncoder;
57217
b1291b2cedc9 8219144: Cannot find installed application on Mac
herrick
parents: 57150
diff changeset
    36
import java.nio.file.Files;
57038
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    37
import java.text.MessageFormat;
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    38
import java.util.ArrayList;
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    39
import java.util.Arrays;
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    40
import java.util.Collection;
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    41
import java.util.HashMap;
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    42
import java.util.LinkedHashSet;
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    43
import java.util.List;
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    44
import java.util.Map;
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    45
import java.util.Optional;
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    46
import java.util.ResourceBundle;
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    47
57039
98d3963b0b7b 8214051: rename jpackager tool to jpackage
herrick
parents: 57038
diff changeset
    48
import static jdk.jpackage.internal.StandardBundlerParam.*;
57067
9c17d779808e 8213425: Analyze output from Source code scanner and fix where needed.
herrick
parents: 57059
diff changeset
    49
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
    50
import static jdk.jpackage.internal.MacBaseInstallerBundler.SIGNING_KEY_USER;
57038
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    51
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    52
public class MacPkgBundler extends MacBaseInstallerBundler {
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    53
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    54
    private static final ResourceBundle I18N = ResourceBundle.getBundle(
57059
9bb2a4dc3af7 8214143: Reduce Resource files
herrick
parents: 57039
diff changeset
    55
            "jdk.jpackage.internal.resources.MacResources");
57038
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 String DEFAULT_BACKGROUND_IMAGE = "background_pkg.png";
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    58
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    59
    private static final String TEMPLATE_PREINSTALL_SCRIPT =
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    60
            "preinstall.template";
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    61
    private static final String TEMPLATE_POSTINSTALL_SCRIPT =
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    62
            "postinstall.template";
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    63
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    64
    private static final BundlerParamInfo<File> PACKAGES_ROOT =
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    65
            new StandardBundlerParam<>(
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    66
            "mac.pkg.packagesRoot",
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    67
            File.class,
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    68
            params -> {
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    69
                File packagesRoot =
57256
d7c27451f759 8219678: CLI changes in jpackage
herrick
parents: 57217
diff changeset
    70
                        new File(TEMP_ROOT.fetchFrom(params), "packages");
57038
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    71
                packagesRoot.mkdirs();
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    72
                return packagesRoot;
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    73
            },
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    74
            (s, p) -> new File(s));
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    75
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
    protected final BundlerParamInfo<File> SCRIPTS_DIR =
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    78
            new StandardBundlerParam<>(
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    79
            "mac.pkg.scriptsDir",
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    80
            File.class,
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    81
            params -> {
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    82
                File scriptsDir =
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    83
                        new File(CONFIG_ROOT.fetchFrom(params), "scripts");
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    84
                scriptsDir.mkdirs();
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    85
                return scriptsDir;
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    86
            },
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    87
            (s, p) -> new File(s));
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    88
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    89
    public static final
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    90
            BundlerParamInfo<String> DEVELOPER_ID_INSTALLER_SIGNING_KEY =
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    91
            new StandardBundlerParam<>(
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    92
            "mac.signing-key-developer-id-installer",
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    93
            String.class,
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    94
            params -> {
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    95
                    String result = MacBaseInstallerBundler.findKey(
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    96
                            "Developer ID Installer: "
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    97
                            + SIGNING_KEY_USER.fetchFrom(params),
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    98
                            SIGNING_KEYCHAIN.fetchFrom(params),
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    99
                            VERBOSE.fetchFrom(params));
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   100
                    if (result != null) {
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   101
                        MacCertificate certificate = new MacCertificate(
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   102
                                result, VERBOSE.fetchFrom(params));
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   103
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   104
                        if (!certificate.isValid()) {
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   105
                            Log.error(MessageFormat.format(
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   106
                                    I18N.getString("error.certificate.expired"),
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   107
                                    result));
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   108
                        }
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   109
                    }
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
                    return result;
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
            (s, p) -> s);
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
    public static final BundlerParamInfo<String> MAC_INSTALL_DIR =
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   116
            new StandardBundlerParam<>(
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   117
            "mac-install-dir",
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   118
            String.class,
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   119
             params -> {
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   120
                 String dir = INSTALL_DIR.fetchFrom(params);
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   121
                 return (dir != null) ? dir : "/Applications";
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   122
             },
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   123
            (s, p) -> s
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
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   126
    public static final BundlerParamInfo<String> INSTALLER_SUFFIX =
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   127
            new StandardBundlerParam<> (
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   128
            "mac.pkg.installerName.suffix",
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   129
            String.class,
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   130
            params -> "",
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   131
            (s, p) -> s);
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   132
57140
3dcb33ce7ced 8217751: jpackage messages and failures
herrick
parents: 57119
diff changeset
   133
    public File bundle(Map<String, ? super Object> params,
3dcb33ce7ced 8217751: jpackage messages and failures
herrick
parents: 57119
diff changeset
   134
            File outdir) throws PackagerException {
57038
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   135
        Log.verbose(MessageFormat.format(I18N.getString("message.building-pkg"),
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   136
                APP_NAME.fetchFrom(params)));
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   137
        if (!outdir.isDirectory() && !outdir.mkdirs()) {
57140
3dcb33ce7ced 8217751: jpackage messages and failures
herrick
parents: 57119
diff changeset
   138
            throw new PackagerException(
3dcb33ce7ced 8217751: jpackage messages and failures
herrick
parents: 57119
diff changeset
   139
                    "error.cannot-create-output-dir",
3dcb33ce7ced 8217751: jpackage messages and failures
herrick
parents: 57119
diff changeset
   140
                    outdir.getAbsolutePath());
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
        if (!outdir.canWrite()) {
57140
3dcb33ce7ced 8217751: jpackage messages and failures
herrick
parents: 57119
diff changeset
   143
            throw new PackagerException(
3dcb33ce7ced 8217751: jpackage messages and failures
herrick
parents: 57119
diff changeset
   144
                    "error.cannot-write-to-output-dir",
3dcb33ce7ced 8217751: jpackage messages and failures
herrick
parents: 57119
diff changeset
   145
                    outdir.getAbsolutePath());
57038
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
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   148
        File appImageDir = null;
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   149
        try {
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   150
            appImageDir = prepareAppBundle(params, false);
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   151
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   152
            if (appImageDir != null && prepareConfigFiles(params)) {
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
                File configScript = getConfig_Script(params);
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   155
                if (configScript.exists()) {
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   156
                    Log.verbose(MessageFormat.format(I18N.getString(
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   157
                            "message.running-script"),
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   158
                            configScript.getAbsolutePath()));
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   159
                    IOUtils.run("bash", configScript, false);
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   160
                }
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
                return createPKG(params, outdir, appImageDir);
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
            return null;
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   165
        } catch (IOException ex) {
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   166
            Log.verbose(ex);
57140
3dcb33ce7ced 8217751: jpackage messages and failures
herrick
parents: 57119
diff changeset
   167
            throw new PackagerException(ex);
57038
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
    }
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   170
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   171
    private File getPackages_AppPackage(Map<String, ? super Object> params) {
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   172
        return new File(PACKAGES_ROOT.fetchFrom(params),
57119
b3dda8d77d8a 8217331: Problems when space in application name
herrick
parents: 57106
diff changeset
   173
                APP_NAME.fetchFrom(params) + "-app.pkg");
57038
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   174
    }
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   175
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   176
    private File getPackages_DaemonPackage(Map<String, ? super Object> params) {
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   177
        return new File(PACKAGES_ROOT.fetchFrom(params),
57119
b3dda8d77d8a 8217331: Problems when space in application name
herrick
parents: 57106
diff changeset
   178
                APP_NAME.fetchFrom(params) + "-daemon.pkg");
57038
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   179
    }
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   180
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   181
    private File getConfig_DistributionXMLFile(
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   182
            Map<String, ? super Object> params) {
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   183
        return new File(CONFIG_ROOT.fetchFrom(params), "distribution.dist");
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   184
    }
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   185
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   186
    private File getConfig_BackgroundImage(Map<String, ? super Object> params) {
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   187
        return new File(CONFIG_ROOT.fetchFrom(params),
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   188
                APP_NAME.fetchFrom(params) + "-background.png");
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   189
    }
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   190
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   191
    private File getScripts_PreinstallFile(Map<String, ? super Object> params) {
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   192
        return new File(SCRIPTS_DIR.fetchFrom(params), "preinstall");
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   193
    }
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   194
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   195
    private File getScripts_PostinstallFile(
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   196
            Map<String, ? super Object> params) {
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   197
        return new File(SCRIPTS_DIR.fetchFrom(params), "postinstall");
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   198
    }
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   199
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   200
    private String getAppIdentifier(Map<String, ? super Object> params) {
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   201
        return IDENTIFIER.fetchFrom(params);
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   202
    }
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   203
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   204
    private String getDaemonIdentifier(Map<String, ? super Object> params) {
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   205
        return IDENTIFIER.fetchFrom(params) + ".daemon";
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   206
    }
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   207
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   208
    private void preparePackageScripts(Map<String, ? super Object> params)
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   209
            throws IOException {
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   210
        Log.verbose(I18N.getString("message.preparing-scripts"));
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   211
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   212
        Map<String, String> data = new HashMap<>();
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   213
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   214
        data.put("DEPLOY_DAEMON_IDENTIFIER", getDaemonIdentifier(params));
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   215
        data.put("DEPLOY_LAUNCHD_PLIST_FILE",
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   216
                IDENTIFIER.fetchFrom(params).toLowerCase() + ".launchd.plist");
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   217
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   218
        Writer w = new BufferedWriter(
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   219
                new FileWriter(getScripts_PreinstallFile(params)));
57091
06bc4bd64599 8215515: Add a command line option to override internal resources.
herrick
parents: 57080
diff changeset
   220
        String content = preprocessTextResource(
06bc4bd64599 8215515: Add a command line option to override internal resources.
herrick
parents: 57080
diff changeset
   221
                getScripts_PreinstallFile(params).getName(),
57038
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   222
                I18N.getString("resource.pkg-preinstall-script"),
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   223
                TEMPLATE_PREINSTALL_SCRIPT,
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   224
                data,
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   225
                VERBOSE.fetchFrom(params),
57091
06bc4bd64599 8215515: Add a command line option to override internal resources.
herrick
parents: 57080
diff changeset
   226
                RESOURCE_DIR.fetchFrom(params));
57038
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   227
        w.write(content);
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   228
        w.close();
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   229
        getScripts_PreinstallFile(params).setExecutable(true, false);
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
        w = new BufferedWriter(
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   232
                new FileWriter(getScripts_PostinstallFile(params)));
57091
06bc4bd64599 8215515: Add a command line option to override internal resources.
herrick
parents: 57080
diff changeset
   233
        content = preprocessTextResource(
06bc4bd64599 8215515: Add a command line option to override internal resources.
herrick
parents: 57080
diff changeset
   234
                getScripts_PostinstallFile(params).getName(),
57038
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   235
                I18N.getString("resource.pkg-postinstall-script"),
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   236
                TEMPLATE_POSTINSTALL_SCRIPT,
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   237
                data,
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   238
                VERBOSE.fetchFrom(params),
57091
06bc4bd64599 8215515: Add a command line option to override internal resources.
herrick
parents: 57080
diff changeset
   239
                RESOURCE_DIR.fetchFrom(params));
57038
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   240
        w.write(content);
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   241
        w.close();
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   242
        getScripts_PostinstallFile(params).setExecutable(true, false);
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   243
    }
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   244
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   245
    private void prepareDistributionXMLFile(Map<String, ? super Object> params)
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   246
            throws IOException {
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   247
        File f = getConfig_DistributionXMLFile(params);
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   248
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   249
        Log.verbose(MessageFormat.format(I18N.getString(
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   250
                "message.preparing-distribution-dist"), f.getAbsolutePath()));
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   251
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   252
        PrintStream out = new PrintStream(f);
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   253
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   254
        out.println(
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   255
                "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>");
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   256
        out.println("<installer-gui-script minSpecVersion=\"1\">");
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   257
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   258
        out.println("<title>" + APP_NAME.fetchFrom(params) + "</title>");
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   259
        out.println("<background" + " file=\""
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   260
                + getConfig_BackgroundImage(params).getName()
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   261
                + "\""
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   262
                + " mime-type=\"image/png\""
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   263
                + " alignment=\"bottomleft\" "
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   264
                + " scaling=\"none\""
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   265
                + "/>");
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   266
57080
bd4ce7f9ea2c 8214495: Change behavior of --license-file
herrick
parents: 57067
diff changeset
   267
        String licFileStr = LICENSE_FILE.fetchFrom(params);
bd4ce7f9ea2c 8214495: Change behavior of --license-file
herrick
parents: 57067
diff changeset
   268
        if (licFileStr != null) {
bd4ce7f9ea2c 8214495: Change behavior of --license-file
herrick
parents: 57067
diff changeset
   269
            File licFile = new File(licFileStr);
bd4ce7f9ea2c 8214495: Change behavior of --license-file
herrick
parents: 57067
diff changeset
   270
            out.println("<license"
bd4ce7f9ea2c 8214495: Change behavior of --license-file
herrick
parents: 57067
diff changeset
   271
                    + " file=\"" + licFile.getAbsolutePath() + "\""
bd4ce7f9ea2c 8214495: Change behavior of --license-file
herrick
parents: 57067
diff changeset
   272
                    + " mime-type=\"text/rtf\""
bd4ce7f9ea2c 8214495: Change behavior of --license-file
herrick
parents: 57067
diff changeset
   273
                    + "/>");
57038
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   274
        }
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   275
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   276
        /*
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   277
         * Note that the content of the distribution file
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   278
         * below is generated by productbuild --synthesize
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   279
         */
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   280
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   281
        String appId = getAppIdentifier(params);
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   282
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   283
        out.println("<pkg-ref id=\"" + appId + "\"/>");
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   284
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   285
        out.println("<options customize=\"never\" require-scripts=\"false\"/>");
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   286
        out.println("<choices-outline>");
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   287
        out.println("    <line choice=\"default\">");
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   288
        out.println("        <line choice=\"" + appId + "\"/>");
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   289
        out.println("    </line>");
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   290
        out.println("</choices-outline>");
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   291
        out.println("<choice id=\"default\"/>");
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   292
        out.println("<choice id=\"" + appId + "\" visible=\"false\">");
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   293
        out.println("    <pkg-ref id=\"" + appId + "\"/>");
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   294
        out.println("</choice>");
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   295
        out.println("<pkg-ref id=\"" + appId + "\" version=\""
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   296
                + VERSION.fetchFrom(params) + "\" onConclusion=\"none\">"
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   297
                + URLEncoder.encode(getPackages_AppPackage(params).getName(),
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   298
                "UTF-8") + "</pkg-ref>");
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   299
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   300
        out.println("</installer-gui-script>");
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   301
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   302
        out.close();
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   303
    }
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   304
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   305
    private boolean prepareConfigFiles(Map<String, ? super Object> params)
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   306
            throws IOException {
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   307
        File imageTarget = getConfig_BackgroundImage(params);
57091
06bc4bd64599 8215515: Add a command line option to override internal resources.
herrick
parents: 57080
diff changeset
   308
        fetchResource(imageTarget.getName(),
57038
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   309
                I18N.getString("resource.pkg-background-image"),
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   310
                DEFAULT_BACKGROUND_IMAGE,
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   311
                imageTarget,
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   312
                VERBOSE.fetchFrom(params),
57091
06bc4bd64599 8215515: Add a command line option to override internal resources.
herrick
parents: 57080
diff changeset
   313
                RESOURCE_DIR.fetchFrom(params));
57038
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   314
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   315
        prepareDistributionXMLFile(params);
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   316
57091
06bc4bd64599 8215515: Add a command line option to override internal resources.
herrick
parents: 57080
diff changeset
   317
        fetchResource(getConfig_Script(params).getName(),
57038
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   318
                I18N.getString("resource.post-install-script"),
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   319
                (String) null,
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   320
                getConfig_Script(params),
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   321
                VERBOSE.fetchFrom(params),
57091
06bc4bd64599 8215515: Add a command line option to override internal resources.
herrick
parents: 57080
diff changeset
   322
                RESOURCE_DIR.fetchFrom(params));
57038
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   323
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   324
        return true;
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   325
    }
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   326
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   327
    // name of post-image script
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   328
    private File getConfig_Script(Map<String, ? super Object> params) {
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   329
        return new File(CONFIG_ROOT.fetchFrom(params),
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   330
                APP_NAME.fetchFrom(params) + "-post-image.sh");
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   331
    }
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   332
57217
b1291b2cedc9 8219144: Cannot find installed application on Mac
herrick
parents: 57150
diff changeset
   333
    private void patchCPLFile(File cpl) throws IOException {
b1291b2cedc9 8219144: Cannot find installed application on Mac
herrick
parents: 57150
diff changeset
   334
        String cplData = Files.readString(cpl.toPath());
b1291b2cedc9 8219144: Cannot find installed application on Mac
herrick
parents: 57150
diff changeset
   335
        String[] lines = cplData.split("\n");
b1291b2cedc9 8219144: Cannot find installed application on Mac
herrick
parents: 57150
diff changeset
   336
        try (PrintWriter out = new PrintWriter(new BufferedWriter(
b1291b2cedc9 8219144: Cannot find installed application on Mac
herrick
parents: 57150
diff changeset
   337
                new FileWriter(cpl)))) {
b1291b2cedc9 8219144: Cannot find installed application on Mac
herrick
parents: 57150
diff changeset
   338
            boolean skip = false; // Used to skip Java.runtime bundle, since
b1291b2cedc9 8219144: Cannot find installed application on Mac
herrick
parents: 57150
diff changeset
   339
            // pkgbuild with --root will find two bundles app and Java runtime.
b1291b2cedc9 8219144: Cannot find installed application on Mac
herrick
parents: 57150
diff changeset
   340
            // We cannot generate component proprty list when using
b1291b2cedc9 8219144: Cannot find installed application on Mac
herrick
parents: 57150
diff changeset
   341
            // --component argument.
b1291b2cedc9 8219144: Cannot find installed application on Mac
herrick
parents: 57150
diff changeset
   342
            for (int i = 0; i < lines.length; i++) {
b1291b2cedc9 8219144: Cannot find installed application on Mac
herrick
parents: 57150
diff changeset
   343
                if (lines[i].trim().equals("<key>BundleIsRelocatable</key>")) {
b1291b2cedc9 8219144: Cannot find installed application on Mac
herrick
parents: 57150
diff changeset
   344
                    out.println(lines[i]);
b1291b2cedc9 8219144: Cannot find installed application on Mac
herrick
parents: 57150
diff changeset
   345
                    out.println("<false/>");
b1291b2cedc9 8219144: Cannot find installed application on Mac
herrick
parents: 57150
diff changeset
   346
                    i++;
b1291b2cedc9 8219144: Cannot find installed application on Mac
herrick
parents: 57150
diff changeset
   347
                } else if (lines[i].trim().equals("<key>ChildBundles</key>")) {
b1291b2cedc9 8219144: Cannot find installed application on Mac
herrick
parents: 57150
diff changeset
   348
                    skip = true;
b1291b2cedc9 8219144: Cannot find installed application on Mac
herrick
parents: 57150
diff changeset
   349
                } else if (skip && lines[i].trim().equals("</array>")) {
b1291b2cedc9 8219144: Cannot find installed application on Mac
herrick
parents: 57150
diff changeset
   350
                    skip = false;
b1291b2cedc9 8219144: Cannot find installed application on Mac
herrick
parents: 57150
diff changeset
   351
                } else {
b1291b2cedc9 8219144: Cannot find installed application on Mac
herrick
parents: 57150
diff changeset
   352
                    if (!skip) {
b1291b2cedc9 8219144: Cannot find installed application on Mac
herrick
parents: 57150
diff changeset
   353
                        out.println(lines[i]);
b1291b2cedc9 8219144: Cannot find installed application on Mac
herrick
parents: 57150
diff changeset
   354
                    }
b1291b2cedc9 8219144: Cannot find installed application on Mac
herrick
parents: 57150
diff changeset
   355
                }
b1291b2cedc9 8219144: Cannot find installed application on Mac
herrick
parents: 57150
diff changeset
   356
            }
b1291b2cedc9 8219144: Cannot find installed application on Mac
herrick
parents: 57150
diff changeset
   357
        }
b1291b2cedc9 8219144: Cannot find installed application on Mac
herrick
parents: 57150
diff changeset
   358
    }
b1291b2cedc9 8219144: Cannot find installed application on Mac
herrick
parents: 57150
diff changeset
   359
57038
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   360
    private File createPKG(Map<String, ? super Object> params,
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   361
            File outdir, File appLocation) {
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   362
        // generic find attempt
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   363
        try {
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   364
            File appPKG = getPackages_AppPackage(params);
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   365
57217
b1291b2cedc9 8219144: Cannot find installed application on Mac
herrick
parents: 57150
diff changeset
   366
            // Generate default CPL file
b1291b2cedc9 8219144: Cannot find installed application on Mac
herrick
parents: 57150
diff changeset
   367
            File cpl = new File(CONFIG_ROOT.fetchFrom(params).getAbsolutePath()
b1291b2cedc9 8219144: Cannot find installed application on Mac
herrick
parents: 57150
diff changeset
   368
                    + File.separator + "cpl.plist");
57038
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   369
            ProcessBuilder pb = new ProcessBuilder("pkgbuild",
57217
b1291b2cedc9 8219144: Cannot find installed application on Mac
herrick
parents: 57150
diff changeset
   370
                    "--root",
b1291b2cedc9 8219144: Cannot find installed application on Mac
herrick
parents: 57150
diff changeset
   371
                    appLocation.getParent(),
57038
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   372
                    "--install-location",
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   373
                    MAC_INSTALL_DIR.fetchFrom(params),
57217
b1291b2cedc9 8219144: Cannot find installed application on Mac
herrick
parents: 57150
diff changeset
   374
                    "--analyze",
b1291b2cedc9 8219144: Cannot find installed application on Mac
herrick
parents: 57150
diff changeset
   375
                    cpl.getAbsolutePath());
b1291b2cedc9 8219144: Cannot find installed application on Mac
herrick
parents: 57150
diff changeset
   376
b1291b2cedc9 8219144: Cannot find installed application on Mac
herrick
parents: 57150
diff changeset
   377
            IOUtils.exec(pb, false);
b1291b2cedc9 8219144: Cannot find installed application on Mac
herrick
parents: 57150
diff changeset
   378
b1291b2cedc9 8219144: Cannot find installed application on Mac
herrick
parents: 57150
diff changeset
   379
            patchCPLFile(cpl);
b1291b2cedc9 8219144: Cannot find installed application on Mac
herrick
parents: 57150
diff changeset
   380
b1291b2cedc9 8219144: Cannot find installed application on Mac
herrick
parents: 57150
diff changeset
   381
            // build application package
b1291b2cedc9 8219144: Cannot find installed application on Mac
herrick
parents: 57150
diff changeset
   382
            pb = new ProcessBuilder("pkgbuild",
b1291b2cedc9 8219144: Cannot find installed application on Mac
herrick
parents: 57150
diff changeset
   383
                    "--root",
b1291b2cedc9 8219144: Cannot find installed application on Mac
herrick
parents: 57150
diff changeset
   384
                    appLocation.getParent(),
b1291b2cedc9 8219144: Cannot find installed application on Mac
herrick
parents: 57150
diff changeset
   385
                    "--install-location",
b1291b2cedc9 8219144: Cannot find installed application on Mac
herrick
parents: 57150
diff changeset
   386
                    MAC_INSTALL_DIR.fetchFrom(params),
b1291b2cedc9 8219144: Cannot find installed application on Mac
herrick
parents: 57150
diff changeset
   387
                    "--component-plist",
b1291b2cedc9 8219144: Cannot find installed application on Mac
herrick
parents: 57150
diff changeset
   388
                    cpl.getAbsolutePath(),
57038
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   389
                    appPKG.getAbsolutePath());
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   390
            IOUtils.exec(pb, false);
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   391
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   392
            // build final package
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   393
            File finalPKG = new File(outdir, INSTALLER_NAME.fetchFrom(params)
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   394
                    + INSTALLER_SUFFIX.fetchFrom(params)
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   395
                    + ".pkg");
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   396
            outdir.mkdirs();
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   397
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   398
            List<String> commandLine = new ArrayList<>();
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   399
            commandLine.add("productbuild");
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   400
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   401
            commandLine.add("--resources");
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   402
            commandLine.add(CONFIG_ROOT.fetchFrom(params).getAbsolutePath());
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   403
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   404
            // maybe sign
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   405
            if (Optional.ofNullable(MacAppImageBuilder.
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   406
                    SIGN_BUNDLE.fetchFrom(params)).orElse(Boolean.TRUE)) {
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   407
                if (Platform.getMajorVersion() > 10 ||
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   408
                    (Platform.getMajorVersion() == 10 &&
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   409
                    Platform.getMinorVersion() >= 12)) {
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   410
                    // we need this for OS X 10.12+
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   411
                    Log.verbose(I18N.getString("message.signing.pkg"));
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   412
                }
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   413
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   414
                String signingIdentity =
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   415
                        DEVELOPER_ID_INSTALLER_SIGNING_KEY.fetchFrom(params);
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   416
                if (signingIdentity != null) {
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   417
                    commandLine.add("--sign");
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   418
                    commandLine.add(signingIdentity);
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   419
                }
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   420
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   421
                String keychainName = SIGNING_KEYCHAIN.fetchFrom(params);
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   422
                if (keychainName != null && !keychainName.isEmpty()) {
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   423
                    commandLine.add("--keychain");
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   424
                    commandLine.add(keychainName);
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   425
                }
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   426
            }
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   427
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   428
            commandLine.add("--distribution");
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   429
            commandLine.add(
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   430
                    getConfig_DistributionXMLFile(params).getAbsolutePath());
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   431
            commandLine.add("--package-path");
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   432
            commandLine.add(PACKAGES_ROOT.fetchFrom(params).getAbsolutePath());
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   433
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   434
            commandLine.add(finalPKG.getAbsolutePath());
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   435
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   436
            pb = new ProcessBuilder(commandLine);
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   437
            IOUtils.exec(pb, false);
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   438
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   439
            return finalPKG;
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   440
        } catch (Exception ignored) {
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   441
            Log.verbose(ignored);
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   442
            return null;
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   443
        }
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   444
    }
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   445
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   446
    //////////////////////////////////////////////////////////////////////////
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   447
    // Implement Bundler
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   448
    //////////////////////////////////////////////////////////////////////////
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   449
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   450
    @Override
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   451
    public String getName() {
57059
9bb2a4dc3af7 8214143: Reduce Resource files
herrick
parents: 57039
diff changeset
   452
        return I18N.getString("pkg.bundler.name");
57038
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   453
    }
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   454
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   455
    @Override
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   456
    public String getDescription() {
57059
9bb2a4dc3af7 8214143: Reduce Resource files
herrick
parents: 57039
diff changeset
   457
        return I18N.getString("pkg.bundler.description");
57038
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   458
    }
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
    @Override
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   461
    public String getID() {
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   462
        return "pkg";
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   463
    }
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   464
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   465
    @Override
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   466
    public Collection<BundlerParamInfo<?>> getBundleParameters() {
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   467
        Collection<BundlerParamInfo<?>> results = new LinkedHashSet<>();
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   468
        results.addAll(MacAppBundler.getAppBundleParameters());
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   469
        results.addAll(getPKGBundleParameters());
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   470
        return results;
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
    public Collection<BundlerParamInfo<?>> getPKGBundleParameters() {
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   474
        Collection<BundlerParamInfo<?>> results = new LinkedHashSet<>();
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   475
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   476
        results.addAll(MacAppBundler.getAppBundleParameters());
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   477
        results.addAll(Arrays.asList(
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   478
                DEVELOPER_ID_INSTALLER_SIGNING_KEY,
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   479
                // IDENTIFIER,
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   480
                INSTALLER_SUFFIX,
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   481
                LICENSE_FILE,
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   482
                // SERVICE_HINT,
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   483
                SIGNING_KEYCHAIN));
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
        return results;
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
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   488
    @Override
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   489
    public boolean validate(Map<String, ? super Object> params)
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   490
            throws UnsupportedPlatformException, ConfigException {
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   491
        try {
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   492
            if (params == null) throw new ConfigException(
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   493
                    I18N.getString("error.parameters-null"),
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   494
                    I18N.getString("error.parameters-null.advice"));
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   495
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   496
            // run basic validation to ensure requirements are met
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   497
            // we are not interested in return code, only possible exception
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   498
            validateAppImageAndBundeler(params);
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   499
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   500
            // reject explicitly set sign to true and no valid signature key
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   501
            if (Optional.ofNullable(MacAppImageBuilder.
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   502
                    SIGN_BUNDLE.fetchFrom(params)).orElse(Boolean.FALSE)) {
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   503
                String signingIdentity =
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   504
                        DEVELOPER_ID_INSTALLER_SIGNING_KEY.fetchFrom(params);
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   505
                if (signingIdentity == null) {
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   506
                    throw new ConfigException(
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   507
                            I18N.getString("error.explicit-sign-no-cert"),
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   508
                            I18N.getString(
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   509
                            "error.explicit-sign-no-cert.advice"));
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   510
                }
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   511
            }
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
            // hdiutil is always available so there's no need
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   514
            // to test for availability.
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   515
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   516
            return true;
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   517
        } catch (RuntimeException re) {
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   518
            if (re.getCause() instanceof ConfigException) {
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   519
                throw (ConfigException) re.getCause();
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   520
            } else {
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   521
                throw new ConfigException(re);
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   522
            }
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   523
        }
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   524
    }
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   525
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   526
    @Override
57140
3dcb33ce7ced 8217751: jpackage messages and failures
herrick
parents: 57119
diff changeset
   527
    public File execute(Map<String, ? super Object> params,
3dcb33ce7ced 8217751: jpackage messages and failures
herrick
parents: 57119
diff changeset
   528
            File outputParentDir) throws PackagerException {
57038
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   529
        return bundle(params, outputParentDir);
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   530
    }
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   531
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   532
    @Override
57150
fa68c2ab636d 8217894: jpackage CLI syntax changes
herrick
parents: 57140
diff changeset
   533
    public boolean supported(boolean runtimeInstaller) {
57038
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   534
        return Platform.getPlatform() == Platform.MAC;
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   535
    }
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   536
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   537
}