src/jdk.packager/windows/classes/jdk/packager/internal/windows/WinAppBundler.java
author herrick
Fri, 21 Sep 2018 09:32:02 -0400
branchJDK-8200758-branch
changeset 56902 6972c0e75e23
parent 56869 41e17fe9fbeb
child 56933 9f59eeb3cc0f
permissions -rw-r--r--
8210367: invalid --app-image arg causes exception runnning light.exe in windows Submitten-by: almatvee Reviewed-by: herrick
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) 2012, 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.windows;
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
import jdk.packager.internal.AbstractImageBundler;
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.ConfigException;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    31
import jdk.packager.internal.IOUtils;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    32
import jdk.packager.internal.Log;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    33
import jdk.packager.internal.Platform;
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
import jdk.packager.internal.UnsupportedPlatformException;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    36
import jdk.packager.internal.builders.windows.WindowsAppImageBuilder;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    37
import jdk.packager.internal.resources.windows.WinResources;
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.JLinkBundlerHelper;
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.ByteArrayOutputStream;
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.IOException;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    44
import java.io.PrintStream;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    45
import java.text.MessageFormat;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    46
import java.util.Arrays;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    47
import java.util.Collection;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    48
import java.util.Map;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    49
import java.util.ResourceBundle;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    50
import jdk.packager.internal.Arguments;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    51
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    52
import static jdk.packager.internal.windows.WindowsBundlerParam.*;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    53
import jdk.packager.internal.builders.AbstractAppImageBuilder;
56902
6972c0e75e23 8210367: invalid --app-image arg causes exception runnning light.exe in windows
herrick
parents: 56869
diff changeset
    54
import static jdk.packager.internal.windows.WinMsiBundler.WIN_APP_IMAGE;
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    55
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    56
public class WinAppBundler extends AbstractImageBundler {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    57
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    58
    private static final ResourceBundle I18N =
56869
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56821
diff changeset
    59
            ResourceBundle.getBundle(
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56821
diff changeset
    60
            "jdk.packager.internal.resources.windows.WinAppBundler");
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    61
56869
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56821
diff changeset
    62
    public static final BundlerParamInfo<File> ICON_ICO =
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56821
diff changeset
    63
            new StandardBundlerParam<>(
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    64
            I18N.getString("param.icon-ico.name"),
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    65
            I18N.getString("param.icon-ico.description"),
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    66
            "icon.ico",
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    67
            File.class,
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    68
            params -> {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    69
                File f = ICON.fetchFrom(params);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    70
                if (f != null && !f.getName().toLowerCase().endsWith(".ico")) {
56869
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56821
diff changeset
    71
                    Log.info(MessageFormat.format(
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56821
diff changeset
    72
                            I18N.getString("message.icon-not-ico"), f));
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    73
                    return null;
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
                return f;
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
            (s, p) -> new File(s));
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    78
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    79
    public WinAppBundler() {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    80
        super();
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    81
        baseResourceLoader = WinResources.class;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    82
    }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    83
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    84
    public final static String WIN_BUNDLER_PREFIX =
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    85
            BUNDLER_PREFIX + "windows/";
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
    @Override
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    88
    public boolean validate(Map<String, ? super Object> params)
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    89
            throws UnsupportedPlatformException, ConfigException {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    90
        try {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    91
            if (params == null) throw new ConfigException(
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    92
                    I18N.getString("error.parameters-null"),
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    93
                    I18N.getString("error.parameters-null.advice"));
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    94
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    95
            return doValidate(params);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    96
        } catch (RuntimeException re) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    97
            if (re.getCause() instanceof ConfigException) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    98
                throw (ConfigException) re.getCause();
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    99
            } else {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   100
                throw new ConfigException(re);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   101
            }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   102
        }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   103
    }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   104
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   105
    // to be used by chained bundlers, e.g. by EXE bundler to avoid
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   106
    // skipping validation if p.type does not include "image"
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   107
    boolean doValidate(Map<String, ? super Object> p)
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   108
            throws UnsupportedPlatformException, ConfigException {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   109
        if (Platform.getPlatform() != Platform.WINDOWS) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   110
            throw new UnsupportedPlatformException();
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   111
        }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   112
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   113
        imageBundleValidation(p);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   114
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   115
        if (StandardBundlerParam.getPredefinedAppImage(p) != null) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   116
            return true;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   117
        }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   118
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   119
        // Make sure that jpackager.exe exists.
56869
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56821
diff changeset
   120
        File tool = new File(
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56821
diff changeset
   121
                System.getProperty("java.home") + "\\bin\\jpackager.exe");
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   122
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   123
        if (!tool.exists()) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   124
            throw new ConfigException(
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   125
                    I18N.getString("error.no-windows-resources"),
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   126
                    I18N.getString("error.no-windows-resources.advice"));
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   127
        }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   128
56869
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56821
diff changeset
   129
        // validate runtime bit-architectire
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   130
        testRuntimeBitArchitecture(p);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   131
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   132
        return true;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   133
    }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   134
56869
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56821
diff changeset
   135
    private static void testRuntimeBitArchitecture(
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56821
diff changeset
   136
            Map<String, ? super Object> params) throws ConfigException {
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   137
        if ("true".equalsIgnoreCase(System.getProperty(
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   138
                "fxpackager.disableBitArchitectureMismatchCheck"))) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   139
            Log.debug(I18N.getString("message.disable-bit-architecture-check"));
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   140
            return;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   141
        }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   142
56869
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56821
diff changeset
   143
        if ((BIT_ARCH_64.fetchFrom(params) !=
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56821
diff changeset
   144
                BIT_ARCH_64_RUNTIME.fetchFrom(params))) {
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   145
            throw new ConfigException(
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   146
                    I18N.getString("error.bit-architecture-mismatch"),
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   147
                    I18N.getString("error.bit-architecture-mismatch.advice"));
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   148
        }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   149
    }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   150
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   151
    // it is static for the sake of sharing with "Exe" bundles
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   152
    // that may skip calls to validate/bundle in this class!
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   153
    private static File getRootDir(File outDir, Map<String, ? super Object> p) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   154
        return new File(outDir, APP_NAME.fetchFrom(p));
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
56902
6972c0e75e23 8210367: invalid --app-image arg causes exception runnning light.exe in windows
herrick
parents: 56869
diff changeset
   157
    private static boolean usePredefineAppName(Map<String, ? super Object> p) {
6972c0e75e23 8210367: invalid --app-image arg causes exception runnning light.exe in windows
herrick
parents: 56869
diff changeset
   158
        return (PREDEFINED_APP_IMAGE.fetchFrom(p) != null);
6972c0e75e23 8210367: invalid --app-image arg causes exception runnning light.exe in windows
herrick
parents: 56869
diff changeset
   159
    }
6972c0e75e23 8210367: invalid --app-image arg causes exception runnning light.exe in windows
herrick
parents: 56869
diff changeset
   160
6972c0e75e23 8210367: invalid --app-image arg causes exception runnning light.exe in windows
herrick
parents: 56869
diff changeset
   161
    private static String appName;
6972c0e75e23 8210367: invalid --app-image arg causes exception runnning light.exe in windows
herrick
parents: 56869
diff changeset
   162
    private synchronized static String getAppName(Map<String, ? super Object> p) {
6972c0e75e23 8210367: invalid --app-image arg causes exception runnning light.exe in windows
herrick
parents: 56869
diff changeset
   163
        // If we building from predefined app image, then we should use names
6972c0e75e23 8210367: invalid --app-image arg causes exception runnning light.exe in windows
herrick
parents: 56869
diff changeset
   164
        // from image and not from CLI.
6972c0e75e23 8210367: invalid --app-image arg causes exception runnning light.exe in windows
herrick
parents: 56869
diff changeset
   165
        if (usePredefineAppName(p)) {
6972c0e75e23 8210367: invalid --app-image arg causes exception runnning light.exe in windows
herrick
parents: 56869
diff changeset
   166
            if (appName == null) {
6972c0e75e23 8210367: invalid --app-image arg causes exception runnning light.exe in windows
herrick
parents: 56869
diff changeset
   167
                // Use WIN_APP_IMAGE here, since we already copy pre-defined image to WIN_APP_IMAGE
6972c0e75e23 8210367: invalid --app-image arg causes exception runnning light.exe in windows
herrick
parents: 56869
diff changeset
   168
                File appImageDir = new File(WIN_APP_IMAGE.fetchFrom(p).toString() + "\\app");
6972c0e75e23 8210367: invalid --app-image arg causes exception runnning light.exe in windows
herrick
parents: 56869
diff changeset
   169
                File [] files = appImageDir.listFiles((File dir, String name) -> name.endsWith(".cfg"));
6972c0e75e23 8210367: invalid --app-image arg causes exception runnning light.exe in windows
herrick
parents: 56869
diff changeset
   170
                if (files == null || files.length != 1) {
6972c0e75e23 8210367: invalid --app-image arg causes exception runnning light.exe in windows
herrick
parents: 56869
diff changeset
   171
                    throw new RuntimeException(MessageFormat.format(
6972c0e75e23 8210367: invalid --app-image arg causes exception runnning light.exe in windows
herrick
parents: 56869
diff changeset
   172
                        I18N.getString("error.cannot-find-cfg"),
6972c0e75e23 8210367: invalid --app-image arg causes exception runnning light.exe in windows
herrick
parents: 56869
diff changeset
   173
                        appImageDir));
6972c0e75e23 8210367: invalid --app-image arg causes exception runnning light.exe in windows
herrick
parents: 56869
diff changeset
   174
                } else {
6972c0e75e23 8210367: invalid --app-image arg causes exception runnning light.exe in windows
herrick
parents: 56869
diff changeset
   175
                    appName = files[0].getName();
6972c0e75e23 8210367: invalid --app-image arg causes exception runnning light.exe in windows
herrick
parents: 56869
diff changeset
   176
                    int index = appName.indexOf(".");
6972c0e75e23 8210367: invalid --app-image arg causes exception runnning light.exe in windows
herrick
parents: 56869
diff changeset
   177
                    if (index != -1) {
6972c0e75e23 8210367: invalid --app-image arg causes exception runnning light.exe in windows
herrick
parents: 56869
diff changeset
   178
                        appName = appName.substring(0, index);
6972c0e75e23 8210367: invalid --app-image arg causes exception runnning light.exe in windows
herrick
parents: 56869
diff changeset
   179
                    }
6972c0e75e23 8210367: invalid --app-image arg causes exception runnning light.exe in windows
herrick
parents: 56869
diff changeset
   180
                }
6972c0e75e23 8210367: invalid --app-image arg causes exception runnning light.exe in windows
herrick
parents: 56869
diff changeset
   181
6972c0e75e23 8210367: invalid --app-image arg causes exception runnning light.exe in windows
herrick
parents: 56869
diff changeset
   182
                return appName;
6972c0e75e23 8210367: invalid --app-image arg causes exception runnning light.exe in windows
herrick
parents: 56869
diff changeset
   183
            } else {
6972c0e75e23 8210367: invalid --app-image arg causes exception runnning light.exe in windows
herrick
parents: 56869
diff changeset
   184
                return appName;
6972c0e75e23 8210367: invalid --app-image arg causes exception runnning light.exe in windows
herrick
parents: 56869
diff changeset
   185
            }
6972c0e75e23 8210367: invalid --app-image arg causes exception runnning light.exe in windows
herrick
parents: 56869
diff changeset
   186
        }
6972c0e75e23 8210367: invalid --app-image arg causes exception runnning light.exe in windows
herrick
parents: 56869
diff changeset
   187
6972c0e75e23 8210367: invalid --app-image arg causes exception runnning light.exe in windows
herrick
parents: 56869
diff changeset
   188
        return APP_NAME.fetchFrom(p);
6972c0e75e23 8210367: invalid --app-image arg causes exception runnning light.exe in windows
herrick
parents: 56869
diff changeset
   189
    }
6972c0e75e23 8210367: invalid --app-image arg causes exception runnning light.exe in windows
herrick
parents: 56869
diff changeset
   190
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   191
    public static String getLauncherName(Map<String, ? super Object> p) {
56902
6972c0e75e23 8210367: invalid --app-image arg causes exception runnning light.exe in windows
herrick
parents: 56869
diff changeset
   192
        return getAppName(p) + ".exe";
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   193
    }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   194
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   195
    public static String getLauncherCfgName(Map<String, ? super Object> p) {
56902
6972c0e75e23 8210367: invalid --app-image arg causes exception runnning light.exe in windows
herrick
parents: 56869
diff changeset
   196
        return "app\\" + getAppName(p) +".cfg";
56821
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
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   199
    public boolean bundle(Map<String, ? super Object> p, File outputDirectory) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   200
        return doBundle(p, outputDirectory, false) != null;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   201
    }
56902
6972c0e75e23 8210367: invalid --app-image arg causes exception runnning light.exe in windows
herrick
parents: 56869
diff changeset
   202
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   203
    private File createRoot(Map<String, ? super Object> p,
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   204
            File outputDirectory, boolean dependentTask) throws IOException {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   205
        if (!outputDirectory.isDirectory() && !outputDirectory.mkdirs()) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   206
            throw new RuntimeException(MessageFormat.format(
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   207
                    I18N.getString("error.cannot-create-output-dir"),
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   208
                    outputDirectory.getAbsolutePath()));
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
        if (!outputDirectory.canWrite()) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   211
            throw new RuntimeException(MessageFormat.format(
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   212
                    I18N.getString("error.cannot-write-to-output-dir"),
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   213
                    outputDirectory.getAbsolutePath()));
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   214
        }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   215
        if (!dependentTask) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   216
            Log.info(MessageFormat.format(
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   217
                    I18N.getString("message.creating-app-bundle"),
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   218
                    APP_NAME.fetchFrom(p), outputDirectory.getAbsolutePath()));
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
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   221
        // Create directory structure
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   222
        File rootDirectory = getRootDir(outputDirectory, p);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   223
        IOUtils.deleteRecursive(rootDirectory);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   224
        rootDirectory.mkdirs();
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   225
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   226
        if (!p.containsKey(JLinkBundlerHelper.JLINK_BUILDER.getID())) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   227
            p.put(JLinkBundlerHelper.JLINK_BUILDER.getID(),
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   228
                    "windowsapp-image-builder");
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   229
        }
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 rootDirectory;
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
56869
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56821
diff changeset
   234
    File doBundle(Map<String, ? super Object> p,
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56821
diff changeset
   235
                File outputDirectory, boolean dependentTask) {
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   236
        if (Arguments.CREATE_JRE_INSTALLER.fetchFrom(p)) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   237
            return doJreBundle(p, outputDirectory, dependentTask);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   238
        } else {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   239
            return doAppBundle(p, outputDirectory, dependentTask);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   240
        }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   241
    }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   242
56869
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56821
diff changeset
   243
    File doJreBundle(Map<String, ? super Object> p,
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56821
diff changeset
   244
            File outputDirectory, boolean dependentTask) {
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   245
        try {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   246
            File rootDirectory = createRoot(p, outputDirectory, dependentTask);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   247
            AbstractAppImageBuilder appBuilder = new WindowsAppImageBuilder(
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   248
                    APP_NAME.fetchFrom(p),
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   249
                    outputDirectory.toPath());
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   250
            File predefined = PREDEFINED_RUNTIME_IMAGE.fetchFrom(p);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   251
            if (predefined == null ) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   252
                JLinkBundlerHelper.generateServerJre(p, appBuilder);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   253
            } else {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   254
                return predefined;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   255
            }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   256
            return rootDirectory;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   257
        } catch (IOException ex) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   258
            Log.info("Exception: "+ex);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   259
            Log.debug(ex);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   260
            return null;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   261
        } catch (Exception ex) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   262
            Log.info("Exception: "+ex);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   263
            Log.debug(ex);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   264
            return null;
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
    }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   267
56869
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56821
diff changeset
   268
    File doAppBundle(Map<String, ? super Object> p,
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56821
diff changeset
   269
            File outputDirectory, boolean dependentTask) {
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   270
        try {
56869
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56821
diff changeset
   271
            File rootDirectory =
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56821
diff changeset
   272
                    createRoot(p, outputDirectory, dependentTask);
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56821
diff changeset
   273
            AbstractAppImageBuilder appBuilder =
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56821
diff changeset
   274
                    new WindowsAppImageBuilder(p, outputDirectory.toPath());
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   275
            if (PREDEFINED_RUNTIME_IMAGE.fetchFrom(p) == null ) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   276
                JLinkBundlerHelper.execute(p, appBuilder);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   277
            } else {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   278
                StandardBundlerParam.copyPredefinedRuntimeImage(p, appBuilder);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   279
            }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   280
            if (!dependentTask) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   281
                Log.info(MessageFormat.format(
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   282
                        I18N.getString("message.result-dir"),
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   283
                        outputDirectory.getAbsolutePath()));
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
            return rootDirectory;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   286
        } catch (IOException ex) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   287
            Log.info(ex.toString());
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   288
            Log.verbose(ex);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   289
            return null;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   290
        } catch (Exception ex) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   291
            Log.info("Exception: "+ex);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   292
            Log.debug(ex);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   293
            return null;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   294
        }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   295
    }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   296
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   297
    private static final String RUNTIME_AUTO_DETECT = ".runtime.autodetect";
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   298
56869
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56821
diff changeset
   299
    public static void extractFlagsFromRuntime(
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56821
diff changeset
   300
            Map<String, ? super Object> params) {
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   301
        if (params.containsKey(".runtime.autodetect")) return;
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
        params.put(RUNTIME_AUTO_DETECT, "attempted");
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   304
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   305
        String commandline;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   306
        File runtimePath = JLinkBundlerHelper.getJDKHome(params).toFile();
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   307
        File launcherPath = new File(runtimePath, "bin\\java.exe");
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   308
56869
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56821
diff changeset
   309
        ProcessBuilder pb =
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56821
diff changeset
   310
                 new ProcessBuilder(launcherPath.getAbsolutePath(), "-version");
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   311
        try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   312
            try (PrintStream pout = new PrintStream(baos)) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   313
                IOUtils.exec(pb, Log.isDebug(), true, pout);
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
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   316
            commandline = baos.toString();
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   317
        } catch (IOException e) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   318
            e.printStackTrace();
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   319
            params.put(RUNTIME_AUTO_DETECT, "failed");
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   320
            return;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   321
        }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   322
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   323
        AbstractImageBundler.extractFlagsFromVersion(params, commandline);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   324
        params.put(RUNTIME_AUTO_DETECT, "succeeded");
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   325
    }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   326
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   327
    @Override
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   328
    public String getName() {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   329
        return I18N.getString("bundler.name");
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   330
    }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   331
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   332
    @Override
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   333
    public String getDescription() {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   334
        return I18N.getString("bundler.description");
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   335
    }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   336
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   337
    @Override
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   338
    public String getID() {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   339
        return "windows.app";
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
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   342
    @Override
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   343
    public String getBundleType() {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   344
        return "IMAGE";
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   345
    }
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
    @Override
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   348
    public Collection<BundlerParamInfo<?>> getBundleParameters() {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   349
        return getAppBundleParameters();
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   350
    }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   351
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   352
    public static Collection<BundlerParamInfo<?>> getAppBundleParameters() {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   353
        return Arrays.asList(
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   354
                APP_NAME,
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   355
                APP_RESOURCES,
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   356
                ARGUMENTS,
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   357
                CLASSPATH,
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   358
                ICON_ICO,
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   359
                JVM_OPTIONS,
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   360
                JVM_PROPERTIES,
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   361
                MAIN_CLASS,
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   362
                MAIN_JAR,
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   363
                PREFERENCES_ID,
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   364
                PRELOADER_CLASS,
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   365
                USER_JVM_OPTIONS,
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   366
                VERSION,
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   367
                VERBOSE
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
    }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   370
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   371
    @Override
56869
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56821
diff changeset
   372
    public File execute(
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56821
diff changeset
   373
            Map<String, ? super Object> params, File outputParentDir) {
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   374
        return doBundle(params, outputParentDir, false);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   375
    }
56902
6972c0e75e23 8210367: invalid --app-image arg causes exception runnning light.exe in windows
herrick
parents: 56869
diff changeset
   376
6972c0e75e23 8210367: invalid --app-image arg causes exception runnning light.exe in windows
herrick
parents: 56869
diff changeset
   377
    @Override
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   378
    public boolean supported() {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   379
        return (Platform.getPlatform() == Platform.WINDOWS);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   380
    }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   381
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   382
}