src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/MacPkgBundler.java
author herrick
Wed, 23 Oct 2019 10:37:54 -0400
branchJDK-8200758-branch
changeset 58762 0fe62353385b
parent 58696 61c44899b4eb
permissions -rw-r--r--
8232281: jpackage is not always reporting an error when no main class specified Reviewed-by: asemenyuk, asemenuk
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
58696
61c44899b4eb 8223325: Improve wix sources generated by jpackage
herrick
parents: 58647
diff changeset
    28
import java.io.*;
58584
910b14f4fe3a 8232042: [macos] Installation fails if application name contains spaces
herrick
parents: 58582
diff changeset
    29
import java.net.URI;
910b14f4fe3a 8232042: [macos] Installation fails if application name contains spaces
herrick
parents: 58582
diff changeset
    30
import java.net.URISyntaxException;
57217
b1291b2cedc9 8219144: Cannot find installed application on Mac
herrick
parents: 57150
diff changeset
    31
import java.nio.file.Files;
57331
221a589c52ee 8222676: create-installer with --app-image fails on mac
herrick
parents: 57290
diff changeset
    32
import java.nio.file.Path;
57038
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    33
import java.text.MessageFormat;
58762
0fe62353385b 8232281: jpackage is not always reporting an error when no main class specified
herrick
parents: 58696
diff changeset
    34
import java.util.*;
57038
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    35
57039
98d3963b0b7b 8214051: rename jpackager tool to jpackage
herrick
parents: 57038
diff changeset
    36
import static jdk.jpackage.internal.StandardBundlerParam.*;
57067
9c17d779808e 8213425: Analyze output from Source code scanner and fix where needed.
herrick
parents: 57059
diff changeset
    37
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
    38
import static jdk.jpackage.internal.MacBaseInstallerBundler.SIGNING_KEY_USER;
58415
73f8e557549a 8231281: Eliminate the --identifier option
herrick
parents: 58114
diff changeset
    39
import static jdk.jpackage.internal.MacAppImageBuilder.MAC_CF_BUNDLE_IDENTIFIER;
58647
2c43b89b1679 8231862: Decouple DesktopIntegration and LinuxPackageBundler classes
herrick
parents: 58584
diff changeset
    40
import static jdk.jpackage.internal.OverridableResource.createResource;
57038
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    41
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    42
public class MacPkgBundler extends MacBaseInstallerBundler {
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    43
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    44
    private static final ResourceBundle I18N = ResourceBundle.getBundle(
57059
9bb2a4dc3af7 8214143: Reduce Resource files
herrick
parents: 57039
diff changeset
    45
            "jdk.jpackage.internal.resources.MacResources");
57038
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    46
58582
558a0842c5aa 8231856: pkg installer dialog contains background image which does not look correc
herrick
parents: 58581
diff changeset
    47
    private static final String DEFAULT_BACKGROUND_IMAGE = "background_pkg.png";
57038
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    48
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    49
    private static final String TEMPLATE_PREINSTALL_SCRIPT =
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    50
            "preinstall.template";
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    51
    private static final String TEMPLATE_POSTINSTALL_SCRIPT =
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    52
            "postinstall.template";
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 BundlerParamInfo<File> PACKAGES_ROOT =
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    55
            new StandardBundlerParam<>(
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    56
            "mac.pkg.packagesRoot",
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    57
            File.class,
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    58
            params -> {
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    59
                File packagesRoot =
57256
d7c27451f759 8219678: CLI changes in jpackage
herrick
parents: 57217
diff changeset
    60
                        new File(TEMP_ROOT.fetchFrom(params), "packages");
57038
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    61
                packagesRoot.mkdirs();
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    62
                return packagesRoot;
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
            (s, p) -> new File(s));
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    65
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
    protected final BundlerParamInfo<File> SCRIPTS_DIR =
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.scriptsDir",
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 scriptsDir =
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    73
                        new File(CONFIG_ROOT.fetchFrom(params), "scripts");
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    74
                scriptsDir.mkdirs();
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    75
                return scriptsDir;
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
    public static final
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    80
            BundlerParamInfo<String> DEVELOPER_ID_INSTALLER_SIGNING_KEY =
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.signing-key-developer-id-installer",
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    83
            String.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
                    String result = MacBaseInstallerBundler.findKey(
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    86
                            "Developer ID Installer: "
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    87
                            + SIGNING_KEY_USER.fetchFrom(params),
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    88
                            SIGNING_KEYCHAIN.fetchFrom(params),
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    89
                            VERBOSE.fetchFrom(params));
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    90
                    if (result != null) {
58647
2c43b89b1679 8231862: Decouple DesktopIntegration and LinuxPackageBundler classes
herrick
parents: 58584
diff changeset
    91
                        MacCertificate certificate = new MacCertificate(result);
57038
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    92
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    93
                        if (!certificate.isValid()) {
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    94
                            Log.error(MessageFormat.format(
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    95
                                    I18N.getString("error.certificate.expired"),
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    96
                                    result));
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    97
                        }
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    98
                    }
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    99
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   100
                    return result;
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   101
                },
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   102
            (s, p) -> s);
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
    public static final BundlerParamInfo<String> MAC_INSTALL_DIR =
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   105
            new StandardBundlerParam<>(
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   106
            "mac-install-dir",
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   107
            String.class,
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   108
             params -> {
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   109
                 String dir = INSTALL_DIR.fetchFrom(params);
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   110
                 return (dir != null) ? dir : "/Applications";
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
            (s, p) -> s
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   113
    );
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> INSTALLER_SUFFIX =
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.pkg.installerName.suffix",
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
            (s, p) -> s);
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   121
57140
3dcb33ce7ced 8217751: jpackage messages and failures
herrick
parents: 57119
diff changeset
   122
    public File bundle(Map<String, ? super Object> params,
3dcb33ce7ced 8217751: jpackage messages and failures
herrick
parents: 57119
diff changeset
   123
            File outdir) throws PackagerException {
57038
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   124
        Log.verbose(MessageFormat.format(I18N.getString("message.building-pkg"),
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   125
                APP_NAME.fetchFrom(params)));
57407
2c14fbeff1dc 8225569: jpackage app-image layout
herrick
parents: 57397
diff changeset
   126
2c14fbeff1dc 8225569: jpackage app-image layout
herrick
parents: 57397
diff changeset
   127
        IOUtils.writableOutputDir(outdir.toPath());
57038
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   128
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   129
        try {
57554
cb6733b3ed62 JDK-8227312: Remove pkg bundle from DMG image.
herrick
parents: 57529
diff changeset
   130
            File appImageDir = prepareAppBundle(params);
57038
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   131
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   132
            if (appImageDir != null && prepareConfigFiles(params)) {
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   133
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   134
                File configScript = getConfig_Script(params);
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   135
                if (configScript.exists()) {
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   136
                    Log.verbose(MessageFormat.format(I18N.getString(
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   137
                            "message.running-script"),
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   138
                            configScript.getAbsolutePath()));
57391
970f28090a06 8223334: Additional cleanup in jpackage tool
herrick
parents: 57390
diff changeset
   139
                    IOUtils.run("bash", configScript);
57038
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   140
                }
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
                return createPKG(params, outdir, appImageDir);
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   143
            }
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   144
            return null;
58696
61c44899b4eb 8223325: Improve wix sources generated by jpackage
herrick
parents: 58647
diff changeset
   145
        } catch (IOException ex) {
57038
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   146
            Log.verbose(ex);
57140
3dcb33ce7ced 8217751: jpackage messages and failures
herrick
parents: 57119
diff changeset
   147
            throw new PackagerException(ex);
57038
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   148
        }
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   149
    }
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   150
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   151
    private File getPackages_AppPackage(Map<String, ? super Object> params) {
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   152
        return new File(PACKAGES_ROOT.fetchFrom(params),
57119
b3dda8d77d8a 8217331: Problems when space in application name
herrick
parents: 57106
diff changeset
   153
                APP_NAME.fetchFrom(params) + "-app.pkg");
57038
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
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   156
    private File getConfig_DistributionXMLFile(
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   157
            Map<String, ? super Object> params) {
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   158
        return new File(CONFIG_ROOT.fetchFrom(params), "distribution.dist");
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   159
    }
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
    private File getConfig_BackgroundImage(Map<String, ? super Object> params) {
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   162
        return new File(CONFIG_ROOT.fetchFrom(params),
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   163
                APP_NAME.fetchFrom(params) + "-background.png");
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   164
    }
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   165
58582
558a0842c5aa 8231856: pkg installer dialog contains background image which does not look correc
herrick
parents: 58581
diff changeset
   166
    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
   167
        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
   168
                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
   169
    }
558a0842c5aa 8231856: pkg installer dialog contains background image which does not look correc
herrick
parents: 58581
diff changeset
   170
57038
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   171
    private File getScripts_PreinstallFile(Map<String, ? super Object> params) {
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   172
        return new File(SCRIPTS_DIR.fetchFrom(params), "preinstall");
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
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   175
    private File getScripts_PostinstallFile(
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   176
            Map<String, ? super Object> params) {
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   177
        return new File(SCRIPTS_DIR.fetchFrom(params), "postinstall");
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   178
    }
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
    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
   181
        return MAC_CF_BUNDLE_IDENTIFIER.fetchFrom(params);
57038
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   182
    }
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   183
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   184
    private void preparePackageScripts(Map<String, ? super Object> params)
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   185
            throws IOException {
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   186
        Log.verbose(I18N.getString("message.preparing-scripts"));
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
        Map<String, String> data = new HashMap<>();
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   189
58581
657e25d9e4e4 8231858:[macos] App does not run if installed with pkg
herrick
parents: 58415
diff changeset
   190
        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
   191
                         APP_NAME.fetchFrom(params) + ".app", "Contents", "app");
657e25d9e4e4 8231858:[macos] App does not run if installed with pkg
herrick
parents: 58415
diff changeset
   192
57290
47c2aca6c306 8215241: Permissions are not set correctly on sub-folders in /Applications
ssadetsky
parents: 57256
diff changeset
   193
        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
   194
        data.put("APP_LOCATION", appLocation.toString());
57038
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   195
58647
2c43b89b1679 8231862: Decouple DesktopIntegration and LinuxPackageBundler classes
herrick
parents: 58584
diff changeset
   196
        createResource(TEMPLATE_PREINSTALL_SCRIPT, params)
2c43b89b1679 8231862: Decouple DesktopIntegration and LinuxPackageBundler classes
herrick
parents: 58584
diff changeset
   197
                .setCategory(I18N.getString("resource.pkg-preinstall-script"))
2c43b89b1679 8231862: Decouple DesktopIntegration and LinuxPackageBundler classes
herrick
parents: 58584
diff changeset
   198
                .setSubstitutionData(data)
2c43b89b1679 8231862: Decouple DesktopIntegration and LinuxPackageBundler classes
herrick
parents: 58584
diff changeset
   199
                .saveToFile(getScripts_PreinstallFile(params));
57038
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   200
        getScripts_PreinstallFile(params).setExecutable(true, false);
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   201
58647
2c43b89b1679 8231862: Decouple DesktopIntegration and LinuxPackageBundler classes
herrick
parents: 58584
diff changeset
   202
        createResource(TEMPLATE_POSTINSTALL_SCRIPT, params)
2c43b89b1679 8231862: Decouple DesktopIntegration and LinuxPackageBundler classes
herrick
parents: 58584
diff changeset
   203
                .setCategory(I18N.getString("resource.pkg-postinstall-script"))
2c43b89b1679 8231862: Decouple DesktopIntegration and LinuxPackageBundler classes
herrick
parents: 58584
diff changeset
   204
                .setSubstitutionData(data)
2c43b89b1679 8231862: Decouple DesktopIntegration and LinuxPackageBundler classes
herrick
parents: 58584
diff changeset
   205
                .saveToFile(getScripts_PostinstallFile(params));
57038
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   206
        getScripts_PostinstallFile(params).setExecutable(true, false);
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
58696
61c44899b4eb 8223325: Improve wix sources generated by jpackage
herrick
parents: 58647
diff changeset
   209
    private static String URLEncoding(String pkgName) throws URISyntaxException {
58584
910b14f4fe3a 8232042: [macos] Installation fails if application name contains spaces
herrick
parents: 58582
diff changeset
   210
        URI uri = new URI(null, null, pkgName, null);
910b14f4fe3a 8232042: [macos] Installation fails if application name contains spaces
herrick
parents: 58582
diff changeset
   211
        return uri.toASCIIString();
910b14f4fe3a 8232042: [macos] Installation fails if application name contains spaces
herrick
parents: 58582
diff changeset
   212
    }
910b14f4fe3a 8232042: [macos] Installation fails if application name contains spaces
herrick
parents: 58582
diff changeset
   213
57038
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   214
    private void prepareDistributionXMLFile(Map<String, ? super Object> params)
58696
61c44899b4eb 8223325: Improve wix sources generated by jpackage
herrick
parents: 58647
diff changeset
   215
            throws IOException {
57038
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   216
        File f = getConfig_DistributionXMLFile(params);
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
        Log.verbose(MessageFormat.format(I18N.getString(
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   219
                "message.preparing-distribution-dist"), f.getAbsolutePath()));
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   220
58696
61c44899b4eb 8223325: Improve wix sources generated by jpackage
herrick
parents: 58647
diff changeset
   221
        IOUtils.createXml(f.toPath(), xml -> {
58582
558a0842c5aa 8231856: pkg installer dialog contains background image which does not look correc
herrick
parents: 58581
diff changeset
   222
            xml.writeStartElement("installer-gui-script");
558a0842c5aa 8231856: pkg installer dialog contains background image which does not look correc
herrick
parents: 58581
diff changeset
   223
            xml.writeAttribute("minSpecVersion", "1");
558a0842c5aa 8231856: pkg installer dialog contains background image which does not look correc
herrick
parents: 58581
diff changeset
   224
558a0842c5aa 8231856: pkg installer dialog contains background image which does not look correc
herrick
parents: 58581
diff changeset
   225
            xml.writeStartElement("title");
558a0842c5aa 8231856: pkg installer dialog contains background image which does not look correc
herrick
parents: 58581
diff changeset
   226
            xml.writeCharacters(APP_NAME.fetchFrom(params));
558a0842c5aa 8231856: pkg installer dialog contains background image which does not look correc
herrick
parents: 58581
diff changeset
   227
            xml.writeEndElement();
57038
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   228
58582
558a0842c5aa 8231856: pkg installer dialog contains background image which does not look correc
herrick
parents: 58581
diff changeset
   229
            xml.writeStartElement("background");
558a0842c5aa 8231856: pkg installer dialog contains background image which does not look correc
herrick
parents: 58581
diff changeset
   230
            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
   231
            xml.writeAttribute("mime-type", "image/png");
558a0842c5aa 8231856: pkg installer dialog contains background image which does not look correc
herrick
parents: 58581
diff changeset
   232
            xml.writeAttribute("alignment", "bottomleft");
558a0842c5aa 8231856: pkg installer dialog contains background image which does not look correc
herrick
parents: 58581
diff changeset
   233
            xml.writeAttribute("scaling", "none");
558a0842c5aa 8231856: pkg installer dialog contains background image which does not look correc
herrick
parents: 58581
diff changeset
   234
            xml.writeEndElement();
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
            xml.writeStartElement("background-darkAqua");
558a0842c5aa 8231856: pkg installer dialog contains background image which does not look correc
herrick
parents: 58581
diff changeset
   237
            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
   238
            xml.writeAttribute("mime-type", "image/png");
558a0842c5aa 8231856: pkg installer dialog contains background image which does not look correc
herrick
parents: 58581
diff changeset
   239
            xml.writeAttribute("alignment", "bottomleft");
558a0842c5aa 8231856: pkg installer dialog contains background image which does not look correc
herrick
parents: 58581
diff changeset
   240
            xml.writeAttribute("scaling", "none");
558a0842c5aa 8231856: pkg installer dialog contains background image which does not look correc
herrick
parents: 58581
diff changeset
   241
            xml.writeEndElement();
57038
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   242
57390
1cb722a11ead 8223333: Use try-with-resources where feasible
herrick
parents: 57331
diff changeset
   243
            String licFileStr = LICENSE_FILE.fetchFrom(params);
1cb722a11ead 8223333: Use try-with-resources where feasible
herrick
parents: 57331
diff changeset
   244
            if (licFileStr != null) {
1cb722a11ead 8223333: Use try-with-resources where feasible
herrick
parents: 57331
diff changeset
   245
                File licFile = new File(licFileStr);
58582
558a0842c5aa 8231856: pkg installer dialog contains background image which does not look correc
herrick
parents: 58581
diff changeset
   246
                xml.writeStartElement("license");
558a0842c5aa 8231856: pkg installer dialog contains background image which does not look correc
herrick
parents: 58581
diff changeset
   247
                xml.writeAttribute("file", licFile.getAbsolutePath());
558a0842c5aa 8231856: pkg installer dialog contains background image which does not look correc
herrick
parents: 58581
diff changeset
   248
                xml.writeAttribute("mime-type", "text/rtf");
558a0842c5aa 8231856: pkg installer dialog contains background image which does not look correc
herrick
parents: 58581
diff changeset
   249
                xml.writeEndElement();
57390
1cb722a11ead 8223333: Use try-with-resources where feasible
herrick
parents: 57331
diff changeset
   250
            }
57038
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   251
57390
1cb722a11ead 8223333: Use try-with-resources where feasible
herrick
parents: 57331
diff changeset
   252
            /*
1cb722a11ead 8223333: Use try-with-resources where feasible
herrick
parents: 57331
diff changeset
   253
             * Note that the content of the distribution file
1cb722a11ead 8223333: Use try-with-resources where feasible
herrick
parents: 57331
diff changeset
   254
             * below is generated by productbuild --synthesize
1cb722a11ead 8223333: Use try-with-resources where feasible
herrick
parents: 57331
diff changeset
   255
             */
1cb722a11ead 8223333: Use try-with-resources where feasible
herrick
parents: 57331
diff changeset
   256
            String appId = getAppIdentifier(params);
57038
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   257
58582
558a0842c5aa 8231856: pkg installer dialog contains background image which does not look correc
herrick
parents: 58581
diff changeset
   258
            xml.writeStartElement("pkg-ref");
558a0842c5aa 8231856: pkg installer dialog contains background image which does not look correc
herrick
parents: 58581
diff changeset
   259
            xml.writeAttribute("id", appId);
558a0842c5aa 8231856: pkg installer dialog contains background image which does not look correc
herrick
parents: 58581
diff changeset
   260
            xml.writeEndElement(); // </pkg-ref>
558a0842c5aa 8231856: pkg installer dialog contains background image which does not look correc
herrick
parents: 58581
diff changeset
   261
            xml.writeStartElement("options");
558a0842c5aa 8231856: pkg installer dialog contains background image which does not look correc
herrick
parents: 58581
diff changeset
   262
            xml.writeAttribute("customize", "never");
558a0842c5aa 8231856: pkg installer dialog contains background image which does not look correc
herrick
parents: 58581
diff changeset
   263
            xml.writeAttribute("require-scripts", "false");
558a0842c5aa 8231856: pkg installer dialog contains background image which does not look correc
herrick
parents: 58581
diff changeset
   264
            xml.writeEndElement(); // </options>
558a0842c5aa 8231856: pkg installer dialog contains background image which does not look correc
herrick
parents: 58581
diff changeset
   265
            xml.writeStartElement("choices-outline");
558a0842c5aa 8231856: pkg installer dialog contains background image which does not look correc
herrick
parents: 58581
diff changeset
   266
            xml.writeStartElement("line");
558a0842c5aa 8231856: pkg installer dialog contains background image which does not look correc
herrick
parents: 58581
diff changeset
   267
            xml.writeAttribute("choice", "default");
558a0842c5aa 8231856: pkg installer dialog contains background image which does not look correc
herrick
parents: 58581
diff changeset
   268
            xml.writeStartElement("line");
558a0842c5aa 8231856: pkg installer dialog contains background image which does not look correc
herrick
parents: 58581
diff changeset
   269
            xml.writeAttribute("choice", appId);
558a0842c5aa 8231856: pkg installer dialog contains background image which does not look correc
herrick
parents: 58581
diff changeset
   270
            xml.writeEndElement(); // </line>
558a0842c5aa 8231856: pkg installer dialog contains background image which does not look correc
herrick
parents: 58581
diff changeset
   271
            xml.writeEndElement(); // </line>
558a0842c5aa 8231856: pkg installer dialog contains background image which does not look correc
herrick
parents: 58581
diff changeset
   272
            xml.writeEndElement(); // </choices-outline>
558a0842c5aa 8231856: pkg installer dialog contains background image which does not look correc
herrick
parents: 58581
diff changeset
   273
            xml.writeStartElement("choice");
558a0842c5aa 8231856: pkg installer dialog contains background image which does not look correc
herrick
parents: 58581
diff changeset
   274
            xml.writeAttribute("id", "default");
558a0842c5aa 8231856: pkg installer dialog contains background image which does not look correc
herrick
parents: 58581
diff changeset
   275
            xml.writeEndElement(); // </choice>
558a0842c5aa 8231856: pkg installer dialog contains background image which does not look correc
herrick
parents: 58581
diff changeset
   276
            xml.writeStartElement("choice");
558a0842c5aa 8231856: pkg installer dialog contains background image which does not look correc
herrick
parents: 58581
diff changeset
   277
            xml.writeAttribute("id", appId);
558a0842c5aa 8231856: pkg installer dialog contains background image which does not look correc
herrick
parents: 58581
diff changeset
   278
            xml.writeAttribute("visible", "false");
558a0842c5aa 8231856: pkg installer dialog contains background image which does not look correc
herrick
parents: 58581
diff changeset
   279
            xml.writeStartElement("pkg-ref");
558a0842c5aa 8231856: pkg installer dialog contains background image which does not look correc
herrick
parents: 58581
diff changeset
   280
            xml.writeAttribute("id", appId);
558a0842c5aa 8231856: pkg installer dialog contains background image which does not look correc
herrick
parents: 58581
diff changeset
   281
            xml.writeEndElement(); // </pkg-ref>
558a0842c5aa 8231856: pkg installer dialog contains background image which does not look correc
herrick
parents: 58581
diff changeset
   282
            xml.writeEndElement(); // </choice>
558a0842c5aa 8231856: pkg installer dialog contains background image which does not look correc
herrick
parents: 58581
diff changeset
   283
            xml.writeStartElement("pkg-ref");
558a0842c5aa 8231856: pkg installer dialog contains background image which does not look correc
herrick
parents: 58581
diff changeset
   284
            xml.writeAttribute("id", appId);
558a0842c5aa 8231856: pkg installer dialog contains background image which does not look correc
herrick
parents: 58581
diff changeset
   285
            xml.writeAttribute("version", VERSION.fetchFrom(params));
558a0842c5aa 8231856: pkg installer dialog contains background image which does not look correc
herrick
parents: 58581
diff changeset
   286
            xml.writeAttribute("onConclusion", "none");
58696
61c44899b4eb 8223325: Improve wix sources generated by jpackage
herrick
parents: 58647
diff changeset
   287
            try {
61c44899b4eb 8223325: Improve wix sources generated by jpackage
herrick
parents: 58647
diff changeset
   288
                xml.writeCharacters(URLEncoding(
61c44899b4eb 8223325: Improve wix sources generated by jpackage
herrick
parents: 58647
diff changeset
   289
                        getPackages_AppPackage(params).getName()));
61c44899b4eb 8223325: Improve wix sources generated by jpackage
herrick
parents: 58647
diff changeset
   290
            } catch (URISyntaxException ex) {
61c44899b4eb 8223325: Improve wix sources generated by jpackage
herrick
parents: 58647
diff changeset
   291
                throw new IOException(ex);
61c44899b4eb 8223325: Improve wix sources generated by jpackage
herrick
parents: 58647
diff changeset
   292
            }
58582
558a0842c5aa 8231856: pkg installer dialog contains background image which does not look correc
herrick
parents: 58581
diff changeset
   293
            xml.writeEndElement(); // </pkg-ref>
57038
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   294
58582
558a0842c5aa 8231856: pkg installer dialog contains background image which does not look correc
herrick
parents: 58581
diff changeset
   295
            xml.writeEndElement(); // </installer-gui-script>
58696
61c44899b4eb 8223325: Improve wix sources generated by jpackage
herrick
parents: 58647
diff changeset
   296
        });
57038
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   297
    }
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   298
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   299
    private boolean prepareConfigFiles(Map<String, ? super Object> params)
58696
61c44899b4eb 8223325: Improve wix sources generated by jpackage
herrick
parents: 58647
diff changeset
   300
            throws IOException {
57038
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   301
58647
2c43b89b1679 8231862: Decouple DesktopIntegration and LinuxPackageBundler classes
herrick
parents: 58584
diff changeset
   302
        createResource(DEFAULT_BACKGROUND_IMAGE, params)
2c43b89b1679 8231862: Decouple DesktopIntegration and LinuxPackageBundler classes
herrick
parents: 58584
diff changeset
   303
                .setCategory(I18N.getString("resource.pkg-background-image"))
2c43b89b1679 8231862: Decouple DesktopIntegration and LinuxPackageBundler classes
herrick
parents: 58584
diff changeset
   304
                .saveToFile(getConfig_BackgroundImage(params));
2c43b89b1679 8231862: Decouple DesktopIntegration and LinuxPackageBundler classes
herrick
parents: 58584
diff changeset
   305
2c43b89b1679 8231862: Decouple DesktopIntegration and LinuxPackageBundler classes
herrick
parents: 58584
diff changeset
   306
        createResource(DEFAULT_BACKGROUND_IMAGE, params)
2c43b89b1679 8231862: Decouple DesktopIntegration and LinuxPackageBundler classes
herrick
parents: 58584
diff changeset
   307
                .setCategory(I18N.getString("resource.pkg-background-image"))
2c43b89b1679 8231862: Decouple DesktopIntegration and LinuxPackageBundler classes
herrick
parents: 58584
diff changeset
   308
                .saveToFile(getConfig_BackgroundImageDarkAqua(params));
58582
558a0842c5aa 8231856: pkg installer dialog contains background image which does not look correc
herrick
parents: 58581
diff changeset
   309
57038
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   310
        prepareDistributionXMLFile(params);
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   311
58647
2c43b89b1679 8231862: Decouple DesktopIntegration and LinuxPackageBundler classes
herrick
parents: 58584
diff changeset
   312
        createResource(null, params)
2c43b89b1679 8231862: Decouple DesktopIntegration and LinuxPackageBundler classes
herrick
parents: 58584
diff changeset
   313
                .setCategory(I18N.getString("resource.post-install-script"))
2c43b89b1679 8231862: Decouple DesktopIntegration and LinuxPackageBundler classes
herrick
parents: 58584
diff changeset
   314
                .saveToFile(getConfig_Script(params));
57038
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   315
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   316
        return true;
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   317
    }
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   318
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   319
    // name of post-image script
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   320
    private File getConfig_Script(Map<String, ? super Object> params) {
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   321
        return new File(CONFIG_ROOT.fetchFrom(params),
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   322
                APP_NAME.fetchFrom(params) + "-post-image.sh");
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
57217
b1291b2cedc9 8219144: Cannot find installed application on Mac
herrick
parents: 57150
diff changeset
   325
    private void patchCPLFile(File cpl) throws IOException {
b1291b2cedc9 8219144: Cannot find installed application on Mac
herrick
parents: 57150
diff changeset
   326
        String cplData = Files.readString(cpl.toPath());
b1291b2cedc9 8219144: Cannot find installed application on Mac
herrick
parents: 57150
diff changeset
   327
        String[] lines = cplData.split("\n");
57390
1cb722a11ead 8223333: Use try-with-resources where feasible
herrick
parents: 57331
diff changeset
   328
        try (PrintWriter out = new PrintWriter(Files.newBufferedWriter(
1cb722a11ead 8223333: Use try-with-resources where feasible
herrick
parents: 57331
diff changeset
   329
                cpl.toPath()))) {
57529
e3b156ad362f 8224627: Creating installer with --runtime-image on OS X fails
herrick
parents: 57438
diff changeset
   330
            int skip = 0;
e3b156ad362f 8224627: Creating installer with --runtime-image on OS X fails
herrick
parents: 57438
diff changeset
   331
            // Used to skip Java.runtime bundle, since
57217
b1291b2cedc9 8219144: Cannot find installed application on Mac
herrick
parents: 57150
diff changeset
   332
            // pkgbuild with --root will find two bundles app and Java runtime.
b1291b2cedc9 8219144: Cannot find installed application on Mac
herrick
parents: 57150
diff changeset
   333
            // We cannot generate component proprty list when using
b1291b2cedc9 8219144: Cannot find installed application on Mac
herrick
parents: 57150
diff changeset
   334
            // --component argument.
b1291b2cedc9 8219144: Cannot find installed application on Mac
herrick
parents: 57150
diff changeset
   335
            for (int i = 0; i < lines.length; i++) {
b1291b2cedc9 8219144: Cannot find installed application on Mac
herrick
parents: 57150
diff changeset
   336
                if (lines[i].trim().equals("<key>BundleIsRelocatable</key>")) {
b1291b2cedc9 8219144: Cannot find installed application on Mac
herrick
parents: 57150
diff changeset
   337
                    out.println(lines[i]);
b1291b2cedc9 8219144: Cannot find installed application on Mac
herrick
parents: 57150
diff changeset
   338
                    out.println("<false/>");
b1291b2cedc9 8219144: Cannot find installed application on Mac
herrick
parents: 57150
diff changeset
   339
                    i++;
b1291b2cedc9 8219144: Cannot find installed application on Mac
herrick
parents: 57150
diff changeset
   340
                } 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
   341
                    ++skip;
e3b156ad362f 8224627: Creating installer with --runtime-image on OS X fails
herrick
parents: 57438
diff changeset
   342
                } 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
   343
                    --skip;
57217
b1291b2cedc9 8219144: Cannot find installed application on Mac
herrick
parents: 57150
diff changeset
   344
                } else {
57529
e3b156ad362f 8224627: Creating installer with --runtime-image on OS X fails
herrick
parents: 57438
diff changeset
   345
                    if (skip == 0) {
57217
b1291b2cedc9 8219144: Cannot find installed application on Mac
herrick
parents: 57150
diff changeset
   346
                        out.println(lines[i]);
b1291b2cedc9 8219144: Cannot find installed application on Mac
herrick
parents: 57150
diff changeset
   347
                    }
b1291b2cedc9 8219144: Cannot find installed application on Mac
herrick
parents: 57150
diff changeset
   348
                }
b1291b2cedc9 8219144: Cannot find installed application on Mac
herrick
parents: 57150
diff changeset
   349
            }
b1291b2cedc9 8219144: Cannot find installed application on Mac
herrick
parents: 57150
diff changeset
   350
        }
b1291b2cedc9 8219144: Cannot find installed application on Mac
herrick
parents: 57150
diff changeset
   351
    }
b1291b2cedc9 8219144: Cannot find installed application on Mac
herrick
parents: 57150
diff changeset
   352
57331
221a589c52ee 8222676: create-installer with --app-image fails on mac
herrick
parents: 57290
diff changeset
   353
    // pkgbuild includes all components from "--root" and subfolders,
221a589c52ee 8222676: create-installer with --app-image fails on mac
herrick
parents: 57290
diff changeset
   354
    // 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
   355
    // 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
   356
    // 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
   357
    // 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
   358
    // 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
   359
    // if root path contains other files.
221a589c52ee 8222676: create-installer with --app-image fails on mac
herrick
parents: 57290
diff changeset
   360
    private String getRoot(Map<String, ? super Object> params,
221a589c52ee 8222676: create-installer with --app-image fails on mac
herrick
parents: 57290
diff changeset
   361
            File appLocation) throws IOException {
221a589c52ee 8222676: create-installer with --app-image fails on mac
herrick
parents: 57290
diff changeset
   362
        String root = appLocation.getParent() == null ?
221a589c52ee 8222676: create-installer with --app-image fails on mac
herrick
parents: 57290
diff changeset
   363
                "." : appLocation.getParent();
221a589c52ee 8222676: create-installer with --app-image fails on mac
herrick
parents: 57290
diff changeset
   364
        File rootDir = new File(root);
221a589c52ee 8222676: create-installer with --app-image fails on mac
herrick
parents: 57290
diff changeset
   365
        File[] list = rootDir.listFiles();
221a589c52ee 8222676: create-installer with --app-image fails on mac
herrick
parents: 57290
diff changeset
   366
        if (list != null) { // Should not happend
221a589c52ee 8222676: create-installer with --app-image fails on mac
herrick
parents: 57290
diff changeset
   367
            // 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
   368
            if (list.length == 1) {
221a589c52ee 8222676: create-installer with --app-image fails on mac
herrick
parents: 57290
diff changeset
   369
                return root;
221a589c52ee 8222676: create-installer with --app-image fails on mac
herrick
parents: 57290
diff changeset
   370
            } else if (list.length == 2) {
221a589c52ee 8222676: create-installer with --app-image fails on mac
herrick
parents: 57290
diff changeset
   371
                // Check case with app image and .DS_Store
221a589c52ee 8222676: create-installer with --app-image fails on mac
herrick
parents: 57290
diff changeset
   372
                if (list[0].toString().toLowerCase().endsWith(".ds_store") ||
221a589c52ee 8222676: create-installer with --app-image fails on mac
herrick
parents: 57290
diff changeset
   373
                    list[1].toString().toLowerCase().endsWith(".ds_store")) {
221a589c52ee 8222676: create-installer with --app-image fails on mac
herrick
parents: 57290
diff changeset
   374
                    return root; // Only app image and .DS_Store
221a589c52ee 8222676: create-installer with --app-image fails on mac
herrick
parents: 57290
diff changeset
   375
                }
221a589c52ee 8222676: create-installer with --app-image fails on mac
herrick
parents: 57290
diff changeset
   376
            }
221a589c52ee 8222676: create-installer with --app-image fails on mac
herrick
parents: 57290
diff changeset
   377
        }
221a589c52ee 8222676: create-installer with --app-image fails on mac
herrick
parents: 57290
diff changeset
   378
221a589c52ee 8222676: create-installer with --app-image fails on mac
herrick
parents: 57290
diff changeset
   379
        // Copy to new root
221a589c52ee 8222676: create-installer with --app-image fails on mac
herrick
parents: 57290
diff changeset
   380
        Path newRoot = Files.createTempDirectory(
221a589c52ee 8222676: create-installer with --app-image fails on mac
herrick
parents: 57290
diff changeset
   381
                TEMP_ROOT.fetchFrom(params).toPath(),
221a589c52ee 8222676: create-installer with --app-image fails on mac
herrick
parents: 57290
diff changeset
   382
                "root-");
221a589c52ee 8222676: create-installer with --app-image fails on mac
herrick
parents: 57290
diff changeset
   383
221a589c52ee 8222676: create-installer with --app-image fails on mac
herrick
parents: 57290
diff changeset
   384
        IOUtils.copyRecursive(appLocation.toPath(),
221a589c52ee 8222676: create-installer with --app-image fails on mac
herrick
parents: 57290
diff changeset
   385
                newRoot.resolve(appLocation.getName()));
221a589c52ee 8222676: create-installer with --app-image fails on mac
herrick
parents: 57290
diff changeset
   386
221a589c52ee 8222676: create-installer with --app-image fails on mac
herrick
parents: 57290
diff changeset
   387
        return newRoot.toString();
221a589c52ee 8222676: create-installer with --app-image fails on mac
herrick
parents: 57290
diff changeset
   388
    }
221a589c52ee 8222676: create-installer with --app-image fails on mac
herrick
parents: 57290
diff changeset
   389
57038
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   390
    private File createPKG(Map<String, ? super Object> params,
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   391
            File outdir, File appLocation) {
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   392
        // generic find attempt
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   393
        try {
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   394
            File appPKG = getPackages_AppPackage(params);
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   395
57331
221a589c52ee 8222676: create-installer with --app-image fails on mac
herrick
parents: 57290
diff changeset
   396
            String root = getRoot(params, appLocation);
221a589c52ee 8222676: create-installer with --app-image fails on mac
herrick
parents: 57290
diff changeset
   397
57217
b1291b2cedc9 8219144: Cannot find installed application on Mac
herrick
parents: 57150
diff changeset
   398
            // Generate default CPL file
b1291b2cedc9 8219144: Cannot find installed application on Mac
herrick
parents: 57150
diff changeset
   399
            File cpl = new File(CONFIG_ROOT.fetchFrom(params).getAbsolutePath()
b1291b2cedc9 8219144: Cannot find installed application on Mac
herrick
parents: 57150
diff changeset
   400
                    + File.separator + "cpl.plist");
57038
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   401
            ProcessBuilder pb = new ProcessBuilder("pkgbuild",
57217
b1291b2cedc9 8219144: Cannot find installed application on Mac
herrick
parents: 57150
diff changeset
   402
                    "--root",
57331
221a589c52ee 8222676: create-installer with --app-image fails on mac
herrick
parents: 57290
diff changeset
   403
                    root,
57038
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   404
                    "--install-location",
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   405
                    MAC_INSTALL_DIR.fetchFrom(params),
57217
b1291b2cedc9 8219144: Cannot find installed application on Mac
herrick
parents: 57150
diff changeset
   406
                    "--analyze",
b1291b2cedc9 8219144: Cannot find installed application on Mac
herrick
parents: 57150
diff changeset
   407
                    cpl.getAbsolutePath());
b1291b2cedc9 8219144: Cannot find installed application on Mac
herrick
parents: 57150
diff changeset
   408
57391
970f28090a06 8223334: Additional cleanup in jpackage tool
herrick
parents: 57390
diff changeset
   409
            IOUtils.exec(pb);
57217
b1291b2cedc9 8219144: Cannot find installed application on Mac
herrick
parents: 57150
diff changeset
   410
b1291b2cedc9 8219144: Cannot find installed application on Mac
herrick
parents: 57150
diff changeset
   411
            patchCPLFile(cpl);
b1291b2cedc9 8219144: Cannot find installed application on Mac
herrick
parents: 57150
diff changeset
   412
57290
47c2aca6c306 8215241: Permissions are not set correctly on sub-folders in /Applications
ssadetsky
parents: 57256
diff changeset
   413
            preparePackageScripts(params);
47c2aca6c306 8215241: Permissions are not set correctly on sub-folders in /Applications
ssadetsky
parents: 57256
diff changeset
   414
57217
b1291b2cedc9 8219144: Cannot find installed application on Mac
herrick
parents: 57150
diff changeset
   415
            // build application package
b1291b2cedc9 8219144: Cannot find installed application on Mac
herrick
parents: 57150
diff changeset
   416
            pb = new ProcessBuilder("pkgbuild",
b1291b2cedc9 8219144: Cannot find installed application on Mac
herrick
parents: 57150
diff changeset
   417
                    "--root",
57331
221a589c52ee 8222676: create-installer with --app-image fails on mac
herrick
parents: 57290
diff changeset
   418
                    root,
57217
b1291b2cedc9 8219144: Cannot find installed application on Mac
herrick
parents: 57150
diff changeset
   419
                    "--install-location",
b1291b2cedc9 8219144: Cannot find installed application on Mac
herrick
parents: 57150
diff changeset
   420
                    MAC_INSTALL_DIR.fetchFrom(params),
b1291b2cedc9 8219144: Cannot find installed application on Mac
herrick
parents: 57150
diff changeset
   421
                    "--component-plist",
b1291b2cedc9 8219144: Cannot find installed application on Mac
herrick
parents: 57150
diff changeset
   422
                    cpl.getAbsolutePath(),
57290
47c2aca6c306 8215241: Permissions are not set correctly on sub-folders in /Applications
ssadetsky
parents: 57256
diff changeset
   423
                    "--scripts",
47c2aca6c306 8215241: Permissions are not set correctly on sub-folders in /Applications
ssadetsky
parents: 57256
diff changeset
   424
                    SCRIPTS_DIR.fetchFrom(params).getAbsolutePath(),
57038
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   425
                    appPKG.getAbsolutePath());
57391
970f28090a06 8223334: Additional cleanup in jpackage tool
herrick
parents: 57390
diff changeset
   426
            IOUtils.exec(pb);
57038
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
            // build final package
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   429
            File finalPKG = new File(outdir, INSTALLER_NAME.fetchFrom(params)
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   430
                    + INSTALLER_SUFFIX.fetchFrom(params)
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   431
                    + ".pkg");
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   432
            outdir.mkdirs();
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
            List<String> commandLine = new ArrayList<>();
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   435
            commandLine.add("productbuild");
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   436
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   437
            commandLine.add("--resources");
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   438
            commandLine.add(CONFIG_ROOT.fetchFrom(params).getAbsolutePath());
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   439
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   440
            // maybe sign
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   441
            if (Optional.ofNullable(MacAppImageBuilder.
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   442
                    SIGN_BUNDLE.fetchFrom(params)).orElse(Boolean.TRUE)) {
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   443
                if (Platform.getMajorVersion() > 10 ||
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   444
                    (Platform.getMajorVersion() == 10 &&
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   445
                    Platform.getMinorVersion() >= 12)) {
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   446
                    // we need this for OS X 10.12+
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   447
                    Log.verbose(I18N.getString("message.signing.pkg"));
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
                String signingIdentity =
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   451
                        DEVELOPER_ID_INSTALLER_SIGNING_KEY.fetchFrom(params);
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   452
                if (signingIdentity != null) {
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   453
                    commandLine.add("--sign");
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   454
                    commandLine.add(signingIdentity);
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   455
                }
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
                String keychainName = SIGNING_KEYCHAIN.fetchFrom(params);
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   458
                if (keychainName != null && !keychainName.isEmpty()) {
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   459
                    commandLine.add("--keychain");
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   460
                    commandLine.add(keychainName);
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   461
                }
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
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   464
            commandLine.add("--distribution");
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   465
            commandLine.add(
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   466
                    getConfig_DistributionXMLFile(params).getAbsolutePath());
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   467
            commandLine.add("--package-path");
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   468
            commandLine.add(PACKAGES_ROOT.fetchFrom(params).getAbsolutePath());
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   469
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   470
            commandLine.add(finalPKG.getAbsolutePath());
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
            pb = new ProcessBuilder(commandLine);
57391
970f28090a06 8223334: Additional cleanup in jpackage tool
herrick
parents: 57390
diff changeset
   473
            IOUtils.exec(pb);
57038
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   474
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   475
            return finalPKG;
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   476
        } catch (Exception ignored) {
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   477
            Log.verbose(ignored);
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   478
            return null;
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
    }
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   481
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   482
    //////////////////////////////////////////////////////////////////////////
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   483
    // Implement Bundler
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
    @Override
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   487
    public String getName() {
57059
9bb2a4dc3af7 8214143: Reduce Resource files
herrick
parents: 57039
diff changeset
   488
        return I18N.getString("pkg.bundler.name");
57038
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   489
    }
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   490
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   491
    @Override
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   492
    public String getID() {
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   493
        return "pkg";
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
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   496
    @Override
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   497
    public boolean validate(Map<String, ? super Object> params)
57438
4a31db8d42bd 8226599: use code coverage results to remove dead code
herrick
parents: 57407
diff changeset
   498
            throws ConfigException {
57038
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   499
        try {
58762
0fe62353385b 8232281: jpackage is not always reporting an error when no main class specified
herrick
parents: 58696
diff changeset
   500
            Objects.requireNonNull(params);
57038
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   501
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   502
            // run basic validation to ensure requirements are met
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   503
            // we are not interested in return code, only possible exception
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   504
            validateAppImageAndBundeler(params);
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   505
58415
73f8e557549a 8231281: Eliminate the --identifier option
herrick
parents: 58114
diff changeset
   506
            if (MAC_CF_BUNDLE_IDENTIFIER.fetchFrom(params) == null) {
73f8e557549a 8231281: Eliminate the --identifier option
herrick
parents: 58114
diff changeset
   507
                throw new ConfigException(
73f8e557549a 8231281: Eliminate the --identifier option
herrick
parents: 58114
diff changeset
   508
                        I18N.getString("message.app-image-requires-identifier"),
73f8e557549a 8231281: Eliminate the --identifier option
herrick
parents: 58114
diff changeset
   509
                        I18N.getString(
73f8e557549a 8231281: Eliminate the --identifier option
herrick
parents: 58114
diff changeset
   510
                            "message.app-image-requires-identifier.advice"));
73f8e557549a 8231281: Eliminate the --identifier option
herrick
parents: 58114
diff changeset
   511
            }
73f8e557549a 8231281: Eliminate the --identifier option
herrick
parents: 58114
diff changeset
   512
57038
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   513
            // reject explicitly set sign to true and no valid signature key
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   514
            if (Optional.ofNullable(MacAppImageBuilder.
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   515
                    SIGN_BUNDLE.fetchFrom(params)).orElse(Boolean.FALSE)) {
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   516
                String signingIdentity =
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   517
                        DEVELOPER_ID_INSTALLER_SIGNING_KEY.fetchFrom(params);
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   518
                if (signingIdentity == null) {
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   519
                    throw new ConfigException(
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   520
                            I18N.getString("error.explicit-sign-no-cert"),
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   521
                            I18N.getString(
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   522
                            "error.explicit-sign-no-cert.advice"));
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
            // hdiutil is always available so there's no need
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   527
            // to test for availability.
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   528
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   529
            return true;
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   530
        } catch (RuntimeException re) {
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   531
            if (re.getCause() instanceof ConfigException) {
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   532
                throw (ConfigException) re.getCause();
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   533
            } else {
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   534
                throw new ConfigException(re);
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
    }
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   538
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   539
    @Override
57140
3dcb33ce7ced 8217751: jpackage messages and failures
herrick
parents: 57119
diff changeset
   540
    public File execute(Map<String, ? super Object> params,
3dcb33ce7ced 8217751: jpackage messages and failures
herrick
parents: 57119
diff changeset
   541
            File outputParentDir) throws PackagerException {
57038
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   542
        return bundle(params, outputParentDir);
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   543
    }
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   544
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   545
    @Override
57150
fa68c2ab636d 8217894: jpackage CLI syntax changes
herrick
parents: 57140
diff changeset
   546
    public boolean supported(boolean runtimeInstaller) {
57438
4a31db8d42bd 8226599: use code coverage results to remove dead code
herrick
parents: 57407
diff changeset
   547
        return true;
57038
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
58114
42df7de58e39 8230519: jpackage "--package-type" values and default
herrick
parents: 58037
diff changeset
   550
    @Override
42df7de58e39 8230519: jpackage "--package-type" values and default
herrick
parents: 58037
diff changeset
   551
    public boolean isDefault() {
42df7de58e39 8230519: jpackage "--package-type" values and default
herrick
parents: 58037
diff changeset
   552
        return false;
42df7de58e39 8230519: jpackage "--package-type" values and default
herrick
parents: 58037
diff changeset
   553
    }
42df7de58e39 8230519: jpackage "--package-type" values and default
herrick
parents: 58037
diff changeset
   554
57038
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   555
}