src/jdk.packager/macosx/classes/jdk/packager/internal/builders/mac/MacAppImageBuilder.java
author herrick
Fri, 06 Jul 2018 09:27:32 -0400
branchJDK-8200758-branch
changeset 56821 565d54ca1f41
child 56869 41e17fe9fbeb
permissions -rw-r--r--
8206005: Move prototype jpackager from closed sandbox to open sandbox Reviewed-by: asemenyuk
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
     1
/*
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
     2
 * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
     4
 *
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    10
 *
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    15
 * accompanied this code).
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    16
 *
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    20
 *
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    23
 * questions.
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    24
 */
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    25
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    26
package jdk.packager.internal.builders.mac;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    27
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    28
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    29
import jdk.packager.internal.BundlerParamInfo;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    30
import jdk.packager.internal.IOUtils;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    31
import jdk.packager.internal.Log;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    32
import jdk.packager.internal.Platform;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    33
import jdk.packager.internal.RelativeFileSet;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    34
import jdk.packager.internal.StandardBundlerParam;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    35
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    36
import jdk.packager.internal.Arguments;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    37
import jdk.packager.internal.resources.mac.MacResources;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    38
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    39
import jdk.packager.internal.builders.AbstractAppImageBuilder;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    40
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    41
import java.io.BufferedWriter;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    42
import java.io.File;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    43
import java.io.FileInputStream;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    44
import java.io.FileOutputStream;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    45
import java.io.FileWriter;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    46
import java.io.IOException;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    47
import java.io.InputStream;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    48
import java.io.OutputStream;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    49
import java.io.OutputStreamWriter;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    50
import java.io.UncheckedIOException;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    51
import java.io.Writer;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    52
import java.math.BigInteger;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    53
import java.nio.file.Files;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    54
import java.nio.file.Path;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    55
import java.nio.file.attribute.PosixFilePermission;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    56
import java.text.MessageFormat;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    57
import java.util.ArrayList;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    58
import java.util.Arrays;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    59
import java.util.EnumSet;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    60
import java.util.HashMap;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    61
import java.util.List;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    62
import java.util.Map;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    63
import java.util.Objects;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    64
import java.util.Optional;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    65
import java.util.ResourceBundle;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    66
import java.util.Set;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    67
import java.util.concurrent.atomic.AtomicReference;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    68
import java.util.function.Consumer;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    69
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    70
import static jdk.packager.internal.StandardBundlerParam.*;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    71
import static jdk.packager.internal.mac.MacBaseInstallerBundler.*;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    72
import static jdk.packager.internal.mac.MacAppBundler.*;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    73
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    74
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    75
public class MacAppImageBuilder extends AbstractAppImageBuilder {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    76
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    77
    private static final ResourceBundle I18N =
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    78
            ResourceBundle.getBundle("jdk.packager.internal.resources.builders.mac.MacAppImageBuilder");
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    79
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    80
    private static final String EXECUTABLE_NAME = "JavaAppLauncher";
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    81
    private static final String LIBRARY_NAME = "libpackager.dylib";
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    82
    private static final String TEMPLATE_BUNDLE_ICON = "GenericApp.icns";
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    83
    private static final String OS_TYPE_CODE = "APPL";
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    84
    private static final String TEMPLATE_INFO_PLIST_LITE = "Info-lite.plist.template";
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    85
    private static final String TEMPLATE_RUNTIME_INFO_PLIST = "Runtime-Info.plist.template";
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    86
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    87
    private final Path root;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    88
    private final Path contentsDir;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    89
    private final Path javaDir;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    90
    private final Path resourcesDir;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    91
    private final Path macOSDir;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    92
    private final Path runtimeDir;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    93
    private final Path runtimeRoot;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    94
    private final Path mdir;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    95
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    96
    private final Map<String, ? super Object> params;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    97
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    98
    private static List<String> keyChains;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    99
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   100
    private static Map<String, String> getMacCategories() {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   101
        Map<String, String> map = new HashMap<>();
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   102
        map.put("Business", "public.app-category.business");
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   103
        map.put("Developer Tools", "public.app-category.developer-tools");
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   104
        map.put("Education", "public.app-category.education");
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   105
        map.put("Entertainment", "public.app-category.entertainment");
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   106
        map.put("Finance", "public.app-category.finance");
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   107
        map.put("Games", "public.app-category.games");
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   108
        map.put("Graphics & Design", "public.app-category.graphics-design");
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   109
        map.put("Healthcare & Fitness", "public.app-category.healthcare-fitness");
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   110
        map.put("Lifestyle", "public.app-category.lifestyle");
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   111
        map.put("Medical", "public.app-category.medical");
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   112
        map.put("Music", "public.app-category.music");
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   113
        map.put("News", "public.app-category.news");
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   114
        map.put("Photography", "public.app-category.photography");
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   115
        map.put("Productivity", "public.app-category.productivity");
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   116
        map.put("Reference", "public.app-category.reference");
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   117
        map.put("Social Networking", "public.app-category.social-networking");
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   118
        map.put("Sports", "public.app-category.sports");
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   119
        map.put("Travel", "public.app-category.travel");
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   120
        map.put("Utilities", "public.app-category.utilities");
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   121
        map.put("Video", "public.app-category.video");
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   122
        map.put("Weather", "public.app-category.weather");
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   123
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   124
        map.put("Action Games", "public.app-category.action-games");
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   125
        map.put("Adventure Games", "public.app-category.adventure-games");
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   126
        map.put("Arcade Games", "public.app-category.arcade-games");
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   127
        map.put("Board Games", "public.app-category.board-games");
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   128
        map.put("Card Games", "public.app-category.card-games");
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   129
        map.put("Casino Games", "public.app-category.casino-games");
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   130
        map.put("Dice Games", "public.app-category.dice-games");
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   131
        map.put("Educational Games", "public.app-category.educational-games");
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   132
        map.put("Family Games", "public.app-category.family-games");
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   133
        map.put("Kids Games", "public.app-category.kids-games");
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   134
        map.put("Music Games", "public.app-category.music-games");
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   135
        map.put("Puzzle Games", "public.app-category.puzzle-games");
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   136
        map.put("Racing Games", "public.app-category.racing-games");
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   137
        map.put("Role Playing Games", "public.app-category.role-playing-games");
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   138
        map.put("Simulation Games", "public.app-category.simulation-games");
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   139
        map.put("Sports Games", "public.app-category.sports-games");
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   140
        map.put("Strategy Games", "public.app-category.strategy-games");
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   141
        map.put("Trivia Games", "public.app-category.trivia-games");
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   142
        map.put("Word Games", "public.app-category.word-games");
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   143
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   144
        return map;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   145
    }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   146
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   147
    public static final BundlerParamInfo<Boolean> MAC_CONFIGURE_LAUNCHER_IN_PLIST =
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   148
            new StandardBundlerParam<>(
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   149
                    I18N.getString("param.configure-launcher-in-plist"),
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   150
                    I18N.getString("param.configure-launcher-in-plist.description"),
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   151
                    "mac.configure-launcher-in-plist",
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   152
                    Boolean.class,
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   153
                    params -> Boolean.FALSE,
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   154
                    (s, p) -> Boolean.valueOf(s));
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   155
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   156
    public static final BundlerParamInfo<String> MAC_CATEGORY =
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   157
            new StandardBundlerParam<>(
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   158
                    I18N.getString("param.category-name"),
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   159
                    I18N.getString("param.category-name.description"),
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   160
                    "mac.category",
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   161
                    String.class,
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   162
                    CATEGORY::fetchFrom,
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   163
                    (s, p) -> s
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   164
            );
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   165
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   166
    public static final BundlerParamInfo<String> MAC_CF_BUNDLE_NAME =
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   167
            new StandardBundlerParam<>(
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   168
                    I18N.getString("param.cfbundle-name.name"),
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   169
                    I18N.getString("param.cfbundle-name.description"),
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   170
                    "mac.CFBundleName",
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   171
                    String.class,
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   172
                    params -> null,
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   173
                    (s, p) -> s);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   174
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   175
    public static final BundlerParamInfo<String> MAC_CF_BUNDLE_IDENTIFIER =
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   176
            new StandardBundlerParam<>(
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   177
                    I18N.getString("param.cfbundle-identifier.name"),
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   178
                    I18N.getString("param.cfbundle-identifier.description"),
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   179
                    Arguments.CLIOptions.MAC_BUNDLE_IDENTIFIER.getId(),
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   180
                    String.class,
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   181
                    IDENTIFIER::fetchFrom,
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   182
                    (s, p) -> s);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   183
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   184
    public static final BundlerParamInfo<String> MAC_CF_BUNDLE_VERSION =
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   185
            new StandardBundlerParam<>(
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   186
                    I18N.getString("param.cfbundle-version.name"),
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   187
                    I18N.getString("param.cfbundle-version.description"),
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   188
                    "mac.CFBundleVersion",
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   189
                    String.class,
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   190
                    p -> {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   191
                        String s = VERSION.fetchFrom(p);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   192
                        if (validCFBundleVersion(s)) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   193
                            return s;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   194
                        } else {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   195
                            return "100";
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   196
                        }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   197
                    },
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   198
                    (s, p) -> s);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   199
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   200
    public static final BundlerParamInfo<File> CONFIG_ROOT = new StandardBundlerParam<>(
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   201
            I18N.getString("param.config-root.name"),
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   202
            I18N.getString("param.config-root.description"),
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   203
            "configRoot",
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   204
            File.class,
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   205
            params -> {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   206
                File configRoot = new File(BUILD_ROOT.fetchFrom(params), "macosx");
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   207
                configRoot.mkdirs();
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   208
                return configRoot;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   209
            },
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   210
            (s, p) -> new File(s));
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   211
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   212
    public static final BundlerParamInfo<String> DEFAULT_ICNS_ICON = new StandardBundlerParam<>(
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   213
            I18N.getString("param.default-icon-icns"),
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   214
            I18N.getString("param.default-icon-icns.description"),
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   215
            ".mac.default.icns",
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   216
            String.class,
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   217
            params -> TEMPLATE_BUNDLE_ICON,
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   218
            (s, p) -> s);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   219
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   220
    public static final BundlerParamInfo<File> ICON_ICNS = new StandardBundlerParam<>(
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   221
            I18N.getString("param.icon-icns.name"),
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   222
            I18N.getString("param.icon-icns.description"),
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   223
            "icon.icns",
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   224
            File.class,
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   225
            params -> {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   226
                File f = ICON.fetchFrom(params);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   227
                if (f != null && !f.getName().toLowerCase().endsWith(".icns")) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   228
                    Log.info(MessageFormat.format(I18N.getString("message.icon-not-icns"), f));
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   229
                    return null;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   230
                }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   231
                return f;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   232
            },
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   233
            (s, p) -> new File(s));
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   234
    
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   235
    public static final StandardBundlerParam<Boolean> SIGN_BUNDLE  =
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   236
    new StandardBundlerParam<>(
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   237
            I18N.getString("param.sign-bundle.name"),
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   238
            I18N.getString("param.sign-bundle.description"),
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   239
            Arguments.CLIOptions.MAC_SIGN.getId(),
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   240
            Boolean.class,
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   241
            params -> false,
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   242
            // valueOf(null) is false, and we actually do want null in some cases
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   243
            (s, p) -> (s == null || "null".equalsIgnoreCase(s))? null : Boolean.valueOf(s)
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   244
        );
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   245
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   246
    public MacAppImageBuilder(Map<String, Object> config, Path imageOutDir) throws IOException {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   247
        super(config, imageOutDir.resolve(APP_NAME.fetchFrom(config) + ".app/Contents/PlugIns/Java.runtime/Contents/Home"));
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   248
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   249
        Objects.requireNonNull(imageOutDir);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   250
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   251
        this.params = config;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   252
        this.root = imageOutDir.resolve(APP_NAME.fetchFrom(params) + ".app");
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   253
        this.contentsDir = root.resolve("Contents");
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   254
        this.javaDir = contentsDir.resolve("Java");
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   255
        this.resourcesDir = contentsDir.resolve("Resources");
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   256
        this.macOSDir = contentsDir.resolve("MacOS");
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   257
        this.runtimeDir = contentsDir.resolve("PlugIns/Java.runtime");
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   258
        this.runtimeRoot = runtimeDir.resolve("Contents/Home");
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   259
        this.mdir = runtimeRoot.resolve("lib");
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   260
        Files.createDirectories(javaDir);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   261
        Files.createDirectories(resourcesDir);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   262
        Files.createDirectories(macOSDir);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   263
        Files.createDirectories(runtimeDir);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   264
    }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   265
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   266
    public MacAppImageBuilder(Map<String, Object> config, String jreName,
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   267
            Path imageOutDir) throws IOException {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   268
        super(null, imageOutDir.resolve(jreName + "/Contents/Home"));
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   269
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   270
        Objects.requireNonNull(imageOutDir);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   271
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   272
        this.params = config;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   273
        this.root = imageOutDir.resolve(jreName );
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   274
        this.contentsDir = root.resolve("Contents");
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   275
        this.javaDir = null;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   276
        this.resourcesDir = null;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   277
        this.macOSDir = null;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   278
        this.runtimeDir = this.root;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   279
        this.runtimeRoot = runtimeDir.resolve("Contents/Home");
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   280
        this.mdir = runtimeRoot.resolve("lib");
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   281
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   282
        Files.createDirectories(runtimeDir);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   283
    }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   284
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   285
    private void writeEntry(InputStream in, Path dstFile) throws IOException {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   286
        Files.createDirectories(dstFile.getParent());
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   287
        Files.copy(in, dstFile);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   288
    }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   289
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   290
    // chmod ugo+x file
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   291
    private void setExecutable(Path file) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   292
        try {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   293
            Set<PosixFilePermission> perms = Files.getPosixFilePermissions(file);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   294
            perms.add(PosixFilePermission.OWNER_EXECUTE);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   295
            perms.add(PosixFilePermission.GROUP_EXECUTE);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   296
            perms.add(PosixFilePermission.OTHERS_EXECUTE);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   297
            Files.setPosixFilePermissions(file, perms);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   298
        } catch (IOException ioe) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   299
            throw new UncheckedIOException(ioe);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   300
        }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   301
    }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   302
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   303
    private static void createUtf8File(File file, String content) throws IOException {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   304
        try (OutputStream fout = new FileOutputStream(file);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   305
             Writer output = new OutputStreamWriter(fout, "UTF-8")) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   306
            output.write(content);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   307
        }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   308
    }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   309
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   310
    @Override
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   311
    protected String getCacheLocation(Map<String, ? super Object> params) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   312
        return "$CACHEDIR/";
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   313
    }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   314
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   315
    public static boolean validCFBundleVersion(String v) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   316
        // CFBundleVersion (String - iOS, OS X) specifies the build version
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   317
        // number of the bundle, which identifies an iteration (released or
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   318
        // unreleased) of the bundle. The build version number should be a
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   319
        // string comprised of three non-negative, period-separated integers
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   320
        // with the first integer being greater than zero. The string should
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   321
        // only contain numeric (0-9) and period (.) characters. Leading zeros
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   322
        // are truncated from each integer and will be ignored (that is,
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   323
        // 1.02.3 is equivalent to 1.2.3). This key is not localizable.
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   324
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   325
        if (v == null) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   326
            return false;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   327
        }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   328
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   329
        String p[] = v.split("\\.");
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   330
        if (p.length > 3 || p.length < 1) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   331
            Log.verbose(I18N.getString("message.version-string-too-many-components"));
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   332
            return false;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   333
        }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   334
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   335
        try {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   336
            BigInteger n = new BigInteger(p[0]);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   337
            if (BigInteger.ONE.compareTo(n) > 0) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   338
                Log.verbose(I18N.getString("message.version-string-first-number-not-zero"));
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   339
                return false;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   340
            }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   341
            if (p.length > 1) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   342
                n = new BigInteger(p[1]);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   343
                if (BigInteger.ZERO.compareTo(n) > 0) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   344
                    Log.verbose(I18N.getString("message.version-string-no-negative-numbers"));
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   345
                    return false;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   346
                }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   347
            }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   348
            if (p.length > 2) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   349
                n = new BigInteger(p[2]);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   350
                if (BigInteger.ZERO.compareTo(n) > 0) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   351
                    Log.verbose(I18N.getString("message.version-string-no-negative-numbers"));
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   352
                    return false;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   353
                }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   354
            }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   355
        } catch (NumberFormatException ne) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   356
            Log.verbose(I18N.getString("message.version-string-numbers-only"));
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   357
            Log.verbose(ne);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   358
            return false;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   359
        }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   360
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   361
        return true;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   362
    }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   363
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   364
    @Override
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   365
    public InputStream getResourceAsStream(String name) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   366
        return MacResources.class.getResourceAsStream(name);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   367
    }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   368
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   369
    @Override
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   370
    public void prepareApplicationFiles() throws IOException {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   371
        File f;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   372
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   373
        // Generate PkgInfo
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   374
        File pkgInfoFile = new File(contentsDir.toFile(), "PkgInfo");
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   375
        pkgInfoFile.createNewFile();
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   376
        writePkgInfo(pkgInfoFile);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   377
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   378
        Path executable = macOSDir.resolve(getLauncherName(params));
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   379
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   380
        try (InputStream is_launcher = getResourceAsStream("papplauncher");
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   381
             InputStream is_lib = getResourceAsStream(LIBRARY_NAME)) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   382
            // Copy executable and library to MacOS folder
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   383
            writeEntry(is_launcher, executable);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   384
            writeEntry(is_lib, macOSDir.resolve(LIBRARY_NAME));
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   385
        }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   386
        executable.toFile().setExecutable(true, false);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   387
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   388
        // generate launcher config
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   389
        writeCfgFile(params, new File(root.toFile(), getLauncherCfgName(params)),
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   390
                "$APPDIR/PlugIns/Java.runtime");
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   391
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   392
        // Copy class path entries to Java folder
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   393
        copyClassPathEntries(javaDir);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   394
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   395
        /*********** Take care of "config" files *******/
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   396
        File icon = ICON_ICNS.fetchFrom(params);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   397
        InputStream in = locateResource("package/macosx/" + APP_NAME.fetchFrom(params) + ".icns",
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   398
                "icon",
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   399
                DEFAULT_ICNS_ICON.fetchFrom(params),
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   400
                icon,
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   401
                VERBOSE.fetchFrom(params),
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   402
                DROP_IN_RESOURCES_ROOT.fetchFrom(params));
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   403
        Files.copy(in, resourcesDir.resolve(APP_NAME.fetchFrom(params) + ".icns"));
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   404
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   405
        // copy file association icons
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   406
        for (Map<String, ? super Object> fa : FILE_ASSOCIATIONS.fetchFrom(params)) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   407
            f = FA_ICON.fetchFrom(fa);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   408
            if (f != null && f.exists()) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   409
                try (InputStream in2 = new FileInputStream(f)) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   410
                    Files.copy(in2, resourcesDir.resolve(f.getName()));
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   411
                }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   412
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   413
            }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   414
        }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   415
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   416
        copyRuntimeFiles();
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   417
        sign();
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   418
    }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   419
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   420
    @Override
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   421
    public void prepareServerJreFiles() throws IOException {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   422
        copyRuntimeFiles();
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   423
        sign();
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   424
    }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   425
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   426
    private void copyRuntimeFiles() throws IOException {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   427
        // Generate Info.plist
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   428
        writeInfoPlist(contentsDir.resolve("Info.plist").toFile());
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   429
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   430
        // generate java runtime info.plist
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   431
        writeRuntimeInfoPlist(runtimeDir.resolve("Contents/Info.plist").toFile());
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   432
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   433
        // copy library
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   434
        Path runtimeMacOSDir = Files.createDirectories(
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   435
                runtimeDir.resolve("Contents/MacOS"));
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   436
        Files.copy(runtimeRoot.resolve("lib/jli/libjli.dylib"),
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   437
                runtimeMacOSDir.resolve("libjli.dylib"));
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   438
    }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   439
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   440
    private void sign() throws IOException {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   441
        if (Optional.ofNullable(SIGN_BUNDLE.fetchFrom(params)).orElse(Boolean.TRUE)) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   442
            try {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   443
                addNewKeychain(params);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   444
            } catch (InterruptedException e) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   445
                Log.error(e.getMessage());
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   446
            }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   447
            String signingIdentity = DEVELOPER_ID_APP_SIGNING_KEY.fetchFrom(params);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   448
            if (signingIdentity != null) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   449
                signAppBundle(params, root, signingIdentity,
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   450
                        BUNDLE_ID_SIGNING_PREFIX.fetchFrom(params), null, null);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   451
            }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   452
            restoreKeychainList(params);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   453
        }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   454
    }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   455
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   456
    private String getLauncherName(Map<String, ? super Object> params) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   457
        if (APP_NAME.fetchFrom(params) != null) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   458
            return APP_NAME.fetchFrom(params);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   459
        } else {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   460
            return MAIN_CLASS.fetchFrom(params);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   461
        }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   462
    }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   463
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   464
    public static String getLauncherCfgName(Map<String, ? super Object> p) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   465
        return "Contents/Java/" + APP_NAME.fetchFrom(p) + ".cfg";
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   466
    }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   467
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   468
    private void copyClassPathEntries(Path javaDirectory) throws IOException {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   469
        List<RelativeFileSet> resourcesList = APP_RESOURCES_LIST.fetchFrom(params);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   470
        if (resourcesList == null) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   471
            throw new RuntimeException(I18N.getString("message.null-classpath"));
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   472
        }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   473
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   474
        for (RelativeFileSet classPath : resourcesList) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   475
            File srcdir = classPath.getBaseDirectory();
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   476
            for (String fname : classPath.getIncludedFiles()) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   477
                copyEntry(javaDirectory, srcdir, fname);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   478
            }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   479
        }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   480
    }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   481
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   482
    private String getBundleName(Map<String, ? super Object> params) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   483
        if (MAC_CF_BUNDLE_NAME.fetchFrom(params) != null) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   484
            String bn = MAC_CF_BUNDLE_NAME.fetchFrom(params);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   485
            if (bn.length() > 16) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   486
                Log.info(MessageFormat.format(I18N.getString(
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   487
                        "message.bundle-name-too-long-warning"), MAC_CF_BUNDLE_NAME.getID(), bn));
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   488
            }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   489
            return MAC_CF_BUNDLE_NAME.fetchFrom(params);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   490
        } else if (APP_NAME.fetchFrom(params) != null) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   491
            return APP_NAME.fetchFrom(params);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   492
        } else {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   493
            String nm = MAIN_CLASS.fetchFrom(params);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   494
            if (nm.length() > 16) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   495
                nm = nm.substring(0, 16);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   496
            }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   497
            return nm;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   498
        }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   499
    }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   500
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   501
    private void writeRuntimeInfoPlist(File file) throws IOException {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   502
        Map<String, String> data = new HashMap<>();
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   503
        String identifier = Arguments.CREATE_JRE_INSTALLER.fetchFrom(params) ?
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   504
                MAC_CF_BUNDLE_IDENTIFIER.fetchFrom(params) :
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   505
                "com.oracle.java." + MAC_CF_BUNDLE_IDENTIFIER.fetchFrom(params);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   506
        data.put("CF_BUNDLE_IDENTIFIER", identifier);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   507
        String name = Arguments.CREATE_JRE_INSTALLER.fetchFrom(params) ?
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   508
                getBundleName(params): "Java Runtime Image";
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   509
        data.put("CF_BUNDLE_NAME", name);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   510
        data.put("CF_BUNDLE_VERSION", VERSION.fetchFrom(params));
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   511
        data.put("CF_BUNDLE_SHORT_VERSION_STRING", VERSION.fetchFrom(params));
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   512
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   513
        Writer w = new BufferedWriter(new FileWriter(file));
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   514
        w.write(preprocessTextResource(
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   515
                "package/macosx/Runtime-Info.plist",
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   516
                I18N.getString("resource.runtime-info-plist"),
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   517
                TEMPLATE_RUNTIME_INFO_PLIST,
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   518
                data,
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   519
                VERBOSE.fetchFrom(params),
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   520
                DROP_IN_RESOURCES_ROOT.fetchFrom(params)));
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   521
        w.close();
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   522
    }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   523
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   524
    private void writeInfoPlist(File file) throws IOException {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   525
        Log.verbose(MessageFormat.format(I18N.getString("message.preparing-info-plist"), file.getAbsolutePath()));
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   526
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   527
        //prepare config for exe
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   528
        //Note: do not need CFBundleDisplayName if we do not support localization
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   529
        Map<String, String> data = new HashMap<>();
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   530
        data.put("DEPLOY_ICON_FILE", APP_NAME.fetchFrom(params) + ".icns");
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   531
        data.put("DEPLOY_BUNDLE_IDENTIFIER",
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   532
                MAC_CF_BUNDLE_IDENTIFIER.fetchFrom(params));
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   533
        data.put("DEPLOY_BUNDLE_NAME",
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   534
                getBundleName(params));
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   535
        data.put("DEPLOY_BUNDLE_COPYRIGHT",
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   536
                COPYRIGHT.fetchFrom(params) != null ? COPYRIGHT.fetchFrom(params) : "Unknown");
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   537
        data.put("DEPLOY_LAUNCHER_NAME", getLauncherName(params));
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   538
        data.put("DEPLOY_JAVA_RUNTIME_NAME", "$APPDIR/PlugIns/Java.runtime");
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   539
        data.put("DEPLOY_BUNDLE_SHORT_VERSION",
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   540
                VERSION.fetchFrom(params) != null ? VERSION.fetchFrom(params) : "1.0.0");
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   541
        data.put("DEPLOY_BUNDLE_CFBUNDLE_VERSION",
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   542
                MAC_CF_BUNDLE_VERSION.fetchFrom(params) != null ? MAC_CF_BUNDLE_VERSION.fetchFrom(params) : "100");
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   543
        data.put("DEPLOY_BUNDLE_CATEGORY", MAC_CATEGORY.fetchFrom(params));
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   544
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   545
        boolean hasMainJar = MAIN_JAR.fetchFrom(params) != null;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   546
        boolean hasMainModule = StandardBundlerParam.MODULE.fetchFrom(params) != null;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   547
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   548
        if (hasMainJar) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   549
            data.put("DEPLOY_MAIN_JAR_NAME", MAIN_JAR.fetchFrom(params).getIncludedFiles().iterator().next());
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   550
        }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   551
        else if (hasMainModule) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   552
            data.put("DEPLOY_MODULE_NAME", StandardBundlerParam.MODULE.fetchFrom(params));
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   553
        }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   554
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   555
        data.put("DEPLOY_PREFERENCES_ID", PREFERENCES_ID.fetchFrom(params).toLowerCase());
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   556
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   557
        StringBuilder sb = new StringBuilder();
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   558
        List<String> jvmOptions = JVM_OPTIONS.fetchFrom(params);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   559
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   560
        String newline = ""; //So we don't add unneccessary extra line after last append
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   561
        for (String o : jvmOptions) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   562
            sb.append(newline).append("    <string>").append(o).append("</string>");
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   563
            newline = "\n";
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   564
        }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   565
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   566
        Map<String, String> jvmProps = JVM_PROPERTIES.fetchFrom(params);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   567
        for (Map.Entry<String, String> entry : jvmProps.entrySet()) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   568
            sb.append(newline)
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   569
                    .append("    <string>-D")
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   570
                    .append(entry.getKey())
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   571
                    .append("=")
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   572
                    .append(entry.getValue())
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   573
                    .append("</string>");
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   574
            newline = "\n";
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   575
        }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   576
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   577
        String preloader = PRELOADER_CLASS.fetchFrom(params);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   578
        if (preloader != null) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   579
            sb.append(newline)
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   580
                    .append("    <string>-Djavafx.preloader=")
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   581
                    .append(preloader)
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   582
                    .append("</string>");
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   583
        }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   584
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   585
        data.put("DEPLOY_JVM_OPTIONS", sb.toString());
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   586
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   587
        sb = new StringBuilder();
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   588
        List<String> args = ARGUMENTS.fetchFrom(params);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   589
        newline = ""; //So we don't add unneccessary extra line after last append
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   590
        for (String o : args) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   591
            sb.append(newline).append("    <string>").append(o).append("</string>");
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   592
            newline = "\n";
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   593
        }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   594
        data.put("DEPLOY_ARGUMENTS", sb.toString());
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   595
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   596
        newline = "";
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   597
        sb = new StringBuilder();
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   598
        Map<String, String> overridableJVMOptions = USER_JVM_OPTIONS.fetchFrom(params);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   599
        for (Map.Entry<String, String> arg : overridableJVMOptions.entrySet()) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   600
            sb.append(newline)
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   601
                    .append("      <key>").append(arg.getKey()).append("</key>\n")
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   602
                    .append("      <string>").append(arg.getValue()).append("</string>");
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   603
            newline = "\n";
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   604
        }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   605
        data.put("DEPLOY_JVM_USER_OPTIONS", sb.toString());
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   606
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   607
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   608
        data.put("DEPLOY_LAUNCHER_CLASS", MAIN_CLASS.fetchFrom(params));
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   609
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   610
        StringBuilder macroedPath = new StringBuilder();
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   611
        for (String s : CLASSPATH.fetchFrom(params).split("[ ;:]+")) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   612
            macroedPath.append(s);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   613
            macroedPath.append(":");
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   614
        }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   615
        macroedPath.deleteCharAt(macroedPath.length() - 1);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   616
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   617
        data.put("DEPLOY_APP_CLASSPATH", macroedPath.toString());
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   618
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   619
        StringBuilder bundleDocumentTypes = new StringBuilder();
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   620
        StringBuilder exportedTypes = new StringBuilder();
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   621
        for (Map<String, ? super Object> fileAssociation : FILE_ASSOCIATIONS.fetchFrom(params)) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   622
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   623
            List<String> extensions = FA_EXTENSIONS.fetchFrom(fileAssociation);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   624
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   625
            if (extensions == null) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   626
                Log.info(I18N.getString("message.creating-association-with-null-extension"));
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   627
            }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   628
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   629
            List<String> mimeTypes = FA_CONTENT_TYPE.fetchFrom(fileAssociation);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   630
            String itemContentType = MAC_CF_BUNDLE_IDENTIFIER.fetchFrom(params) +
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   631
                    "." + ((extensions == null || extensions.isEmpty())
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   632
                    ? "mime"
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   633
                    : extensions.get(0));
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   634
            String description = FA_DESCRIPTION.fetchFrom(fileAssociation);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   635
            File icon = FA_ICON.fetchFrom(fileAssociation); //TODO FA_ICON_ICNS
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   636
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   637
            bundleDocumentTypes.append("    <dict>\n")
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   638
                    .append("      <key>LSItemContentTypes</key>\n")
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   639
                    .append("      <array>\n")
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   640
                    .append("        <string>")
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   641
                    .append(itemContentType)
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   642
                    .append("</string>\n")
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   643
                    .append("      </array>\n")
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   644
                    .append("\n")
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   645
                    .append("      <key>CFBundleTypeName</key>\n")
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   646
                    .append("      <string>")
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   647
                    .append(description)
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   648
                    .append("</string>\n")
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   649
                    .append("\n")
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   650
                    .append("      <key>LSHandlerRank</key>\n")
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   651
                    .append("      <string>Owner</string>\n") //TODO make a bundler arg
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   652
                    .append("\n")
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   653
                    .append("      <key>CFBundleTypeRole</key>\n")
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   654
                    .append("      <string>Editor</string>\n") // TODO make a bundler arg
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   655
                    .append("\n")
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   656
                    .append("      <key>LSIsAppleDefaultForType</key>\n")
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   657
                    .append("      <true/>\n") // TODO make a bundler arg
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   658
                    .append("\n");
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   659
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   660
            if (icon != null && icon.exists()) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   661
                //?
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   662
                bundleDocumentTypes.append("      <key>CFBundleTypeIconFile</key>\n")
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   663
                        .append("      <string>")
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   664
                        .append(icon.getName())
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   665
                        .append("</string>\n");
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   666
            }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   667
            bundleDocumentTypes.append("    </dict>\n");
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   668
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   669
            exportedTypes.append("    <dict>\n")
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   670
                    .append("      <key>UTTypeIdentifier</key>\n")
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   671
                    .append("      <string>")
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   672
                    .append(itemContentType)
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   673
                    .append("</string>\n")
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   674
                    .append("\n")
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   675
                    .append("      <key>UTTypeDescription</key>\n")
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   676
                    .append("      <string>")
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   677
                    .append(description)
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   678
                    .append("</string>\n")
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   679
                    .append("      <key>UTTypeConformsTo</key>\n")
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   680
                    .append("      <array>\n")
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   681
                    .append("          <string>public.data</string>\n") //TODO expose this?
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   682
                    .append("      </array>\n")
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   683
                    .append("\n");
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   684
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   685
            if (icon != null && icon.exists()) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   686
                exportedTypes.append("      <key>UTTypeIconFile</key>\n")
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   687
                        .append("      <string>")
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   688
                        .append(icon.getName())
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   689
                        .append("</string>\n")
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   690
                        .append("\n");
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   691
            }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   692
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   693
            exportedTypes.append("\n")
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   694
                    .append("      <key>UTTypeTagSpecification</key>\n")
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   695
                    .append("      <dict>\n")
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   696
                            //TODO expose via param? .append("        <key>com.apple.ostype</key>\n");
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   697
                            //TODO expose via param? .append("        <string>ABCD</string>\n")
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   698
                    .append("\n");
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   699
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   700
            if (extensions != null && !extensions.isEmpty()) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   701
                exportedTypes.append("        <key>public.filename-extension</key>\n")
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   702
                        .append("        <array>\n");
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   703
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   704
                for (String ext : extensions) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   705
                    exportedTypes.append("          <string>")
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   706
                            .append(ext)
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   707
                            .append("</string>\n");
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   708
                }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   709
                exportedTypes.append("        </array>\n");
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   710
            }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   711
            if (mimeTypes != null && !mimeTypes.isEmpty()) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   712
                exportedTypes.append("        <key>public.mime-type</key>\n")
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   713
                        .append("        <array>\n");
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   714
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   715
                for (String mime : mimeTypes) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   716
                    exportedTypes.append("          <string>")
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   717
                            .append(mime)
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   718
                            .append("</string>\n");
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   719
                }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   720
                exportedTypes.append("        </array>\n");
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   721
            }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   722
            exportedTypes.append("      </dict>\n")
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   723
                    .append("    </dict>\n");
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   724
        }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   725
        String associationData;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   726
        if (bundleDocumentTypes.length() > 0) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   727
            associationData = "\n  <key>CFBundleDocumentTypes</key>\n  <array>\n"
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   728
                    + bundleDocumentTypes.toString()
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   729
                    + "  </array>\n\n  <key>UTExportedTypeDeclarations</key>\n  <array>\n"
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   730
                    + exportedTypes.toString()
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   731
                    + "  </array>\n";
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   732
        } else {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   733
            associationData = "";
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   734
        }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   735
        data.put("DEPLOY_FILE_ASSOCIATIONS", associationData);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   736
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   737
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   738
        Writer w = new BufferedWriter(new FileWriter(file));
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   739
        w.write(preprocessTextResource(
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   740
                //MAC_BUNDLER_PREFIX + getConfig_InfoPlist(params).getName(),
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   741
                "package/macosx/Info.plist",
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   742
                I18N.getString("resource.app-info-plist"),
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   743
                TEMPLATE_INFO_PLIST_LITE,
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   744
                data, VERBOSE.fetchFrom(params),
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   745
                DROP_IN_RESOURCES_ROOT.fetchFrom(params)));
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   746
        w.close();
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   747
    }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   748
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   749
    private void writePkgInfo(File file) throws IOException {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   750
        //hardcoded as it does not seem we need to change it ever
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   751
        String signature = "????";
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   752
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   753
        try (Writer out = new BufferedWriter(new FileWriter(file))) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   754
            out.write(OS_TYPE_CODE + signature);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   755
            out.flush();
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   756
        }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   757
    }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   758
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   759
    public static void addNewKeychain(Map<String, ? super Object> params)
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   760
                                    throws IOException, InterruptedException {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   761
        if (Platform.getMajorVersion() < 10 ||
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   762
            (Platform.getMajorVersion() == 10 && Platform.getMinorVersion() < 12)) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   763
            // we need this for OS X 10.12+
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   764
            return;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   765
        }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   766
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   767
        String keyChain = SIGNING_KEYCHAIN.fetchFrom(params);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   768
        if (keyChain == null || keyChain.isEmpty()) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   769
            return;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   770
        }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   771
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   772
        // get current keychain list
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   773
        String keyChainPath = new File (keyChain).getAbsolutePath().toString();
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   774
        List<String> keychainList = new ArrayList<>();
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   775
        int ret = IOUtils.getProcessOutput(keychainList, "security", "list-keychains");
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   776
        if (ret != 0) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   777
            Log.error(I18N.getString("message.keychain.error"));
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   778
            return;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   779
        }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   780
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   781
        boolean contains = keychainList.stream().anyMatch(
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   782
                    str -> str.trim().equals("\""+keyChainPath.trim()+"\""));
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   783
        if (contains) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   784
            // keychain is already added in the search list
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   785
            return;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   786
        }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   787
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   788
        keyChains = new ArrayList<>();
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   789
        // remove "
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   790
        keychainList.forEach((String s) -> {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   791
            String path = s.trim();
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   792
            if (path.startsWith("\"") && path.endsWith("\"")) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   793
                path = path.substring(1, path.length()-1);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   794
            }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   795
            keyChains.add(path);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   796
        });
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   797
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   798
        List<String> args = new ArrayList<>();
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   799
        args.add("security");
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   800
        args.add("list-keychains");
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   801
        args.add("-s");
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   802
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   803
        args.addAll(keyChains);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   804
        args.add(keyChain);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   805
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   806
        ProcessBuilder  pb = new ProcessBuilder(args);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   807
        IOUtils.exec(pb, ECHO_MODE.fetchFrom(params));
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   808
    }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   809
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   810
    public static void restoreKeychainList(Map<String, ? super Object> params) throws IOException{
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   811
        if (Platform.getMajorVersion() < 10 ||
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   812
            (Platform.getMajorVersion() == 10 && Platform.getMinorVersion() < 12)) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   813
            // we need this for OS X 10.12+
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   814
            return;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   815
        }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   816
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   817
        if (keyChains == null || keyChains.isEmpty()) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   818
            return;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   819
        }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   820
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   821
        List<String> args = new ArrayList<>();
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   822
        args.add("security");
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   823
        args.add("list-keychains");
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   824
        args.add("-s");
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   825
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   826
        args.addAll(keyChains);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   827
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   828
        ProcessBuilder  pb = new ProcessBuilder(args);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   829
        IOUtils.exec(pb, ECHO_MODE.fetchFrom(params));
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   830
    }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   831
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   832
    public static void signAppBundle(Map<String, ? super Object> params, Path appLocation, String signingIdentity, String identifierPrefix, String entitlementsFile, String inheritedEntitlements) throws IOException {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   833
        AtomicReference<IOException> toThrow = new AtomicReference<>();
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   834
        String appExecutable = "/Contents/MacOS/" + APP_NAME.fetchFrom(params);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   835
        String keyChain = SIGNING_KEYCHAIN.fetchFrom(params);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   836
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   837
        // sign all dylibs and jars
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   838
        Files.walk(appLocation)
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   839
                // fix permissions
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   840
                .peek(path -> {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   841
                    try {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   842
                        Set<PosixFilePermission> pfp = Files.getPosixFilePermissions(path);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   843
                        if (!pfp.contains(PosixFilePermission.OWNER_WRITE)) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   844
                            pfp = EnumSet.copyOf(pfp);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   845
                            pfp.add(PosixFilePermission.OWNER_WRITE);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   846
                            Files.setPosixFilePermissions(path, pfp);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   847
                        }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   848
                    } catch (IOException e) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   849
                        Log.debug(e);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   850
                    }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   851
                })
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   852
                .filter(p -> Files.isRegularFile(p) &&
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   853
                                !(p.toString().contains("/Contents/MacOS/libjli.dylib")
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   854
                                        || p.toString().contains("/Contents/MacOS/JavaAppletPlugin")
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   855
                                        || p.toString().endsWith(appExecutable))
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   856
                ).forEach(p -> {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   857
            //noinspection ThrowableResultOfMethodCallIgnored
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   858
            if (toThrow.get() != null) return;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   859
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   860
            // If p is a symlink then skip the signing process.
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   861
            if (Files.isSymbolicLink(p)) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   862
                if (VERBOSE.fetchFrom(params)) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   863
                    Log.verbose(MessageFormat.format(I18N.getString("message.ignoring.symlink"), p.toString()));
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   864
                }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   865
            }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   866
            else {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   867
                List<String> args = new ArrayList<>();
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   868
                args.addAll(Arrays.asList("codesign",
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   869
                        "-s", signingIdentity, // sign with this key
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   870
                        "--prefix", identifierPrefix, // use the identifier as a prefix
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   871
                        "-vvvv"));
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   872
                if (entitlementsFile != null &&
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   873
                        (p.toString().endsWith(".jar")
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   874
                                || p.toString().endsWith(".dylib"))) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   875
                    args.add("--entitlements");
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   876
                    args.add(entitlementsFile); // entitlements
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   877
                } else if (inheritedEntitlements != null && Files.isExecutable(p)) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   878
                    args.add("--entitlements");
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   879
                    args.add(inheritedEntitlements); // inherited entitlements for executable processes
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   880
                }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   881
                if (keyChain != null && !keyChain.isEmpty()) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   882
                    args.add("--keychain");
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   883
                    args.add(keyChain);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   884
                }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   885
                args.add(p.toString());
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   886
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   887
                try {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   888
                    Set<PosixFilePermission> oldPermissions = Files.getPosixFilePermissions(p);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   889
                    File f = p.toFile();
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   890
                    f.setWritable(true, true);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   891
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   892
                    ProcessBuilder pb = new ProcessBuilder(args);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   893
                    IOUtils.exec(pb, ECHO_MODE.fetchFrom(params));
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   894
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   895
                    Files.setPosixFilePermissions(p, oldPermissions);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   896
                } catch (IOException ioe) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   897
                    toThrow.set(ioe);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   898
                }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   899
            }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   900
        });
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   901
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   902
        IOException ioe = toThrow.get();
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   903
        if (ioe != null) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   904
            throw ioe;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   905
        }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   906
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   907
        // sign all plugins and frameworks
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   908
        Consumer<? super Path> signIdentifiedByPList = path -> {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   909
            //noinspection ThrowableResultOfMethodCallIgnored
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   910
            if (toThrow.get() != null) return;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   911
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   912
            try {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   913
                List<String> args = new ArrayList<>();
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   914
                args.addAll(Arrays.asList("codesign",
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   915
                        "-s", signingIdentity, // sign with this key
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   916
                        "--prefix", identifierPrefix, // use the identifier as a prefix
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   917
                        "-vvvv"));
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   918
                if (keyChain != null && !keyChain.isEmpty()) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   919
                    args.add("--keychain");
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   920
                    args.add(keyChain);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   921
                }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   922
                args.add(path.toString());
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   923
                ProcessBuilder pb = new ProcessBuilder(args);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   924
                IOUtils.exec(pb, ECHO_MODE.fetchFrom(params));
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   925
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   926
                args = new ArrayList<>();
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   927
                args.addAll(Arrays.asList("codesign",
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   928
                        "-s", signingIdentity, // sign with this key
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   929
                        "--prefix", identifierPrefix, // use the identifier as a prefix
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   930
                        "-vvvv"));
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   931
                if (keyChain != null && !keyChain.isEmpty()) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   932
                    args.add("--keychain");
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   933
                    args.add(keyChain);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   934
                }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   935
                args.add(path.toString() + "/Contents/_CodeSignature/CodeResources");
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   936
                pb = new ProcessBuilder(args);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   937
                IOUtils.exec(pb, ECHO_MODE.fetchFrom(params));
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   938
            } catch (IOException e) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   939
                toThrow.set(e);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   940
            }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   941
        };
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   942
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   943
        Path pluginsPath = appLocation.resolve("Contents/PlugIns");
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   944
        if (Files.isDirectory(pluginsPath)) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   945
            Files.list(pluginsPath)
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   946
                    .forEach(signIdentifiedByPList);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   947
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   948
            ioe = toThrow.get();
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   949
            if (ioe != null) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   950
                throw ioe;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   951
            }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   952
        }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   953
        Path frameworkPath = appLocation.resolve("Contents/Frameworks");
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   954
        if (Files.isDirectory(frameworkPath)) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   955
            Files.list(frameworkPath)
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   956
                    .forEach(signIdentifiedByPList);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   957
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   958
            ioe = toThrow.get();
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   959
            if (ioe != null) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   960
                throw ioe;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   961
            }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   962
        }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   963
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   964
        // sign the app itself
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   965
        List<String> args = new ArrayList<>();
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   966
        args.addAll(Arrays.asList("codesign",
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   967
                "-s", signingIdentity, // sign with this key
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   968
                "-vvvv")); // super verbose output
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   969
        if (entitlementsFile != null) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   970
            args.add("--entitlements");
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   971
            args.add(entitlementsFile); // entitlements
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   972
        }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   973
        if (keyChain != null && !keyChain.isEmpty()) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   974
            args.add("--keychain");
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   975
            args.add(keyChain);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   976
        }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   977
        args.add(appLocation.toString());
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   978
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   979
        ProcessBuilder pb = new ProcessBuilder(args.toArray(new String[args.size()]));
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   980
        IOUtils.exec(pb, ECHO_MODE.fetchFrom(params));
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   981
    }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   982
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   983
}