src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/MacBaseInstallerBundler.java
author herrick
Tue, 09 Apr 2019 16:06:21 -0400
branchJDK-8200758-branch
changeset 57316 2891b3ae222d
parent 57256 d7c27451f759
child 57391 970f28090a06
permissions -rw-r--r--
8221641: Follow up code clean up for JDK-8221582 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: 57103
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.ByteArrayOutputStream;
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.IOException;
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    31
import java.io.PrintStream;
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    32
import java.nio.file.Files;
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    33
import java.text.MessageFormat;
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    34
import java.util.ArrayList;
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    35
import java.util.Arrays;
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    36
import java.util.Collection;
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    37
import java.util.LinkedHashSet;
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    38
import java.util.List;
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    39
import java.util.Map;
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    40
import java.util.ResourceBundle;
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    41
import java.util.regex.Matcher;
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    42
import java.util.regex.Pattern;
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    43
57039
98d3963b0b7b 8214051: rename jpackager tool to jpackage
herrick
parents: 57038
diff changeset
    44
import static jdk.jpackage.internal.StandardBundlerParam.*;
57038
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    45
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    46
public abstract class MacBaseInstallerBundler extends AbstractBundler {
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    47
57059
9bb2a4dc3af7 8214143: Reduce Resource files
herrick
parents: 57039
diff changeset
    48
    private static final ResourceBundle I18N = ResourceBundle.getBundle(
9bb2a4dc3af7 8214143: Reduce Resource files
herrick
parents: 57039
diff changeset
    49
            "jdk.jpackage.internal.resources.MacResources");
57038
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    50
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    51
    // This could be generalized more to be for any type of Image Bundler
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    52
    public static final BundlerParamInfo<MacAppBundler> APP_BUNDLER =
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    53
            new StandardBundlerParam<>(
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    54
            "mac.app.bundler",
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    55
            MacAppBundler.class,
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    56
            params -> new MacAppBundler(),
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    57
            (s, p) -> null);
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    58
57256
d7c27451f759 8219678: CLI changes in jpackage
herrick
parents: 57140
diff changeset
    59
    public final BundlerParamInfo<File> APP_IMAGE_TEMP_ROOT =
57038
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    60
            new StandardBundlerParam<>(
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    61
            "mac.app.imageRoot",
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    62
            File.class,
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    63
            params -> {
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    64
                File imageDir = IMAGES_ROOT.fetchFrom(params);
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    65
                if (!imageDir.exists()) imageDir.mkdirs();
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    66
                try {
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    67
                    return Files.createTempDirectory(
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    68
                            imageDir.toPath(), "image-").toFile();
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    69
                } catch (IOException e) {
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    70
                    return new File(imageDir, getID()+ ".image");
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    71
                }
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    72
            },
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    73
            (s, p) -> new File(s));
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    74
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    75
    public static final BundlerParamInfo<String> SIGNING_KEY_USER =
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    76
            new StandardBundlerParam<>(
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    77
            Arguments.CLIOptions.MAC_SIGNING_KEY_NAME.getId(),
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    78
            String.class,
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    79
            params -> "",
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    80
            null);
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    81
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    82
    public static final BundlerParamInfo<String> SIGNING_KEYCHAIN =
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    83
            new StandardBundlerParam<>(
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    84
            Arguments.CLIOptions.MAC_SIGNING_KEYCHAIN.getId(),
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    85
            String.class,
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    86
            params -> "",
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    87
            null);
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 BundlerParamInfo<String> INSTALLER_NAME =
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    90
            new StandardBundlerParam<> (
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    91
            "mac.installerName",
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    92
            String.class,
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    93
            params -> {
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    94
                String nm = APP_NAME.fetchFrom(params);
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    95
                if (nm == null) return null;
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    96
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    97
                String version = VERSION.fetchFrom(params);
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    98
                if (version == null) {
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    99
                    return nm;
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   100
                } else {
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   101
                    return nm + "-" + version;
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   102
                }
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
            (s, p) -> s);
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   105
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   106
    protected void validateAppImageAndBundeler(
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   107
            Map<String, ? super Object> params)
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   108
            throws ConfigException, UnsupportedPlatformException {
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   109
        if (PREDEFINED_APP_IMAGE.fetchFrom(params) != null) {
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   110
            File applicationImage = PREDEFINED_APP_IMAGE.fetchFrom(params);
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   111
            if (!applicationImage.exists()) {
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   112
                throw new ConfigException(
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   113
                        MessageFormat.format(I18N.getString(
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   114
                                "message.app-image-dir-does-not-exist"),
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   115
                                PREDEFINED_APP_IMAGE.getID(),
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   116
                                applicationImage.toString()),
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   117
                        MessageFormat.format(I18N.getString(
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   118
                                "message.app-image-dir-does-not-exist.advice"),
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   119
                                PREDEFINED_APP_IMAGE.getID()));
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   120
            }
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   121
            if (APP_NAME.fetchFrom(params) == null) {
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   122
                throw new ConfigException(
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   123
                        I18N.getString("message.app-image-requires-app-name"),
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   124
                        I18N.getString(
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   125
                            "message.app-image-requires-app-name.advice"));
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   126
            }
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   127
            if (IDENTIFIER.fetchFrom(params) == null) {
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   128
                throw new ConfigException(
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   129
                        I18N.getString("message.app-image-requires-identifier"),
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   130
                        I18N.getString(
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   131
                            "message.app-image-requires-identifier.advice"));
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   132
            }
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   133
        } else {
57067
9c17d779808e 8213425: Analyze output from Source code scanner and fix where needed.
herrick
parents: 57059
diff changeset
   134
            APP_BUNDLER.fetchFrom(params).validate(params);
57038
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   135
        }
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   136
    }
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   137
57140
3dcb33ce7ced 8217751: jpackage messages and failures
herrick
parents: 57106
diff changeset
   138
    protected File prepareAppBundle(Map<String, ? super Object> p,
3dcb33ce7ced 8217751: jpackage messages and failures
herrick
parents: 57106
diff changeset
   139
            boolean pkg) throws PackagerException {
57038
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   140
        File predefinedImage = StandardBundlerParam.getPredefinedAppImage(p);
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   141
        if (predefinedImage != null) {
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   142
            return predefinedImage;
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   143
        }
57256
d7c27451f759 8219678: CLI changes in jpackage
herrick
parents: 57140
diff changeset
   144
        File appImageRoot = APP_IMAGE_TEMP_ROOT.fetchFrom(p);
57038
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   145
        if (pkg) {
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   146
            // create pkg in dmg
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   147
            return new MacPkgBundler().bundle(p, appImageRoot);
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   148
        } else {
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   149
            return APP_BUNDLER.fetchFrom(p).doBundle(p, appImageRoot, true);
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
    }
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   152
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   153
    @Override
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   154
    public Collection<BundlerParamInfo<?>> getBundleParameters() {
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   155
        Collection<BundlerParamInfo<?>> results = new LinkedHashSet<>();
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   156
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   157
        results.addAll(MacAppBundler.getAppBundleParameters());
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   158
        results.addAll(Arrays.asList(
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   159
                APP_BUNDLER,
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   160
                CONFIG_ROOT,
57256
d7c27451f759 8219678: CLI changes in jpackage
herrick
parents: 57140
diff changeset
   161
                APP_IMAGE_TEMP_ROOT,
57038
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   162
                PREDEFINED_APP_IMAGE
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
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   165
        return results;
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   166
    }
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   167
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   168
    @Override
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   169
    public String getBundleType() {
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   170
        return "INSTALLER";
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   171
    }
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   172
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   173
    public static String findKey(String key, String keychainName,
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   174
            boolean verbose) {
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   175
        if (Platform.getPlatform() != Platform.MAC) {
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   176
            return null;
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   177
        }
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   178
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   179
        try (ByteArrayOutputStream baos = new ByteArrayOutputStream();
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   180
                PrintStream ps = new PrintStream(baos)) {
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   181
            List<String> searchOptions = new ArrayList<>();
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   182
            searchOptions.add("security");
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   183
            searchOptions.add("find-certificate");
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   184
            searchOptions.add("-c");
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   185
            searchOptions.add(key);
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   186
            searchOptions.add("-a");
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   187
            if (keychainName != null && !keychainName.isEmpty()) {
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   188
                searchOptions.add(keychainName);
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
            ProcessBuilder pb = new ProcessBuilder(searchOptions);
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   192
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   193
            IOUtils.exec(pb, verbose, false, ps);
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   194
            Pattern p = Pattern.compile("\"alis\"<blob>=\"([^\"]+)\"");
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   195
            Matcher m = p.matcher(baos.toString());
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   196
            if (!m.find()) {
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   197
                Log.error("Did not find a key matching '" + key + "'");
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   198
                return null;
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
            String matchedKey = m.group(1);
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   201
            if (m.find()) {
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   202
                Log.error("Found more than one key matching '"  + key + "'");
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   203
                return null;
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   204
            }
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   205
            Log.debug("Using key '" + matchedKey + "'");
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   206
            return matchedKey;
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   207
        } catch (IOException ioe) {
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   208
            Log.verbose(ioe);
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   209
            return null;
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   210
        }
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
}