src/jdk.packager/windows/classes/jdk/packager/internal/windows/WinExeBundler.java
author herrick
Mon, 08 Oct 2018 18:17:37 -0400
branchJDK-8200758-branch
changeset 56941 20568f1e1aa7
child 56947 5a03c4524b90
permissions -rw-r--r--
JDK-8211282: Support creation of 'exe' installers on Windows. Reviewed-by: almatvee, kcr
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
56941
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
     1
/*
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
     2
 * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
     4
 *
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    10
 *
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    15
 * accompanied this code).
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    16
 *
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    20
 *
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    23
 * questions.
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    24
 */
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    25
package jdk.packager.internal.windows;
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    26
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    27
import jdk.packager.internal.*;
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    28
import jdk.packager.internal.ConfigException;
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    29
import jdk.packager.internal.Arguments;
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    30
import jdk.packager.internal.UnsupportedPlatformException;
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    31
import jdk.packager.internal.resources.windows.WinResources;
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    32
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    33
import java.io.*;
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    34
import java.nio.charset.Charset;
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    35
import java.nio.file.Files;
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    36
import java.text.MessageFormat;
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    37
import java.util.*;
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    38
import java.util.regex.Matcher;
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    39
import java.util.regex.Pattern;
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    40
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    41
import static jdk.packager.internal.windows.WindowsBundlerParam.*;
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    42
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    43
public class WinExeBundler extends AbstractBundler {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    44
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    45
    private static final ResourceBundle I18N = ResourceBundle.getBundle(
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    46
            "jdk.packager.internal.resources.windows.WinExeBundler");
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    47
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    48
    public static final BundlerParamInfo<WinAppBundler> APP_BUNDLER =
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    49
            new WindowsBundlerParam<>(
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    50
            getString("param.app-bundler.name"),
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    51
            getString("param.app-bundler.description"),
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    52
            "win.app.bundler",
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    53
            WinAppBundler.class,
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    54
            params -> new WinAppBundler(),
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    55
            null);
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    56
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    57
    public static final BundlerParamInfo<File> CONFIG_ROOT =
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    58
            new WindowsBundlerParam<>(
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    59
            getString("param.config-root.name"),
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    60
            getString("param.config-root.description"),
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    61
            "configRoot",
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    62
            File.class,
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    63
            params -> {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    64
                File imagesRoot =
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    65
                        new File(BUILD_ROOT.fetchFrom(params), "windows");
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    66
                imagesRoot.mkdirs();
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    67
                return imagesRoot;
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    68
            },
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    69
            (s, p) -> null);
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    70
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    71
    public static final BundlerParamInfo<File> EXE_IMAGE_DIR =
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    72
            new WindowsBundlerParam<>(
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    73
            getString("param.image-dir.name"),
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    74
            getString("param.image-dir.description"),
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    75
            "win.exe.imageDir",
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    76
            File.class,
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    77
            params -> {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    78
                File imagesRoot = IMAGES_ROOT.fetchFrom(params);
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    79
                if (!imagesRoot.exists()) imagesRoot.mkdirs();
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    80
                return new File(imagesRoot, "win-exe.image");
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    81
            },
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    82
            (s, p) -> null);
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    83
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    84
    public static final BundlerParamInfo<File> WIN_APP_IMAGE =
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    85
            new WindowsBundlerParam<>(
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    86
            getString("param.app-dir.name"),
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    87
            getString("param.app-dir.description"),
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    88
            "win.app.image",
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    89
            File.class,
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    90
            null,
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    91
            (s, p) -> null);
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    92
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    93
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    94
    public static final StandardBundlerParam<Boolean> EXE_SYSTEM_WIDE  =
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    95
            new StandardBundlerParam<>(
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    96
            getString("param.system-wide.name"),
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    97
            getString("param.system-wide.description"),
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    98
            Arguments.CLIOptions.WIN_PER_USER_INSTALLATION.getId(),
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    99
            Boolean.class,
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   100
            params -> true, // default to system wide
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   101
            (s, p) -> (s == null || "null".equalsIgnoreCase(s))? null
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   102
                    : Boolean.valueOf(s)
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   103
            );
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   104
    public static final StandardBundlerParam<String> PRODUCT_VERSION =
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   105
            new StandardBundlerParam<>(
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   106
                    getString("param.product-version.name"),
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   107
                    getString("param.product-version.description"),
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   108
                    "win.msi.productVersion",
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   109
                    String.class,
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   110
                    VERSION::fetchFrom,
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   111
                    (s, p) -> s
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   112
            );
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   113
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   114
    public static final StandardBundlerParam<Boolean> MENU_HINT =
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   115
        new WindowsBundlerParam<>(
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   116
                getString("param.menu-shortcut-hint.name"),
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   117
                getString("param.menu-shortcut-hint.description"),
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   118
                Arguments.CLIOptions.WIN_MENU_HINT.getId(),
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   119
                Boolean.class,
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   120
                params -> false,
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   121
                (s, p) -> (s == null ||
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   122
                        "null".equalsIgnoreCase(s))? true : Boolean.valueOf(s)
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   123
        );
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   124
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   125
    public static final StandardBundlerParam<Boolean> SHORTCUT_HINT =
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   126
        new WindowsBundlerParam<>(
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   127
                getString("param.desktop-shortcut-hint.name"),
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   128
                getString("param.desktop-shortcut-hint.description"),
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   129
                Arguments.CLIOptions.WIN_SHORTCUT_HINT.getId(),
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   130
                Boolean.class,
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   131
                params -> false,
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   132
                (s, p) -> (s == null ||
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   133
                       "null".equalsIgnoreCase(s))? false : Boolean.valueOf(s)
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   134
        );
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   135
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   136
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   137
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   138
    private final static String DEFAULT_EXE_PROJECT_TEMPLATE = "template.iss";
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   139
    private static final String TOOL_INNO_SETUP_COMPILER = "iscc.exe";
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   140
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   141
    public static final BundlerParamInfo<String>
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   142
            TOOL_INNO_SETUP_COMPILER_EXECUTABLE = new WindowsBundlerParam<>(
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   143
            getString("param.iscc-path.name"),
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   144
            getString("param.iscc-path.description"),
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   145
            "win.exe.iscc.exe",
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   146
            String.class,
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   147
            params -> {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   148
                for (String dirString : (System.getenv("PATH") + ";C:\\Program Files (x86)\\Inno Setup 5;C:\\Program Files\\Inno Setup 5").split(";")) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   149
                    File f = new File(dirString.replace("\"", ""),
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   150
                            TOOL_INNO_SETUP_COMPILER);
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   151
                    if (f.isFile()) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   152
                        return f.toString();
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   153
                    }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   154
                }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   155
                return null;
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   156
            },
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   157
            null);
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   158
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   159
    public WinExeBundler() {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   160
        super();
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   161
        baseResourceLoader = WinResources.class;
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   162
    }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   163
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   164
    @Override
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   165
    public String getName() {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   166
        return getString("bundler.name");
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   167
    }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   168
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   169
    @Override
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   170
    public String getDescription() {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   171
        return getString("bundler.description");
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   172
    }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   173
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   174
    @Override
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   175
    public String getID() {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   176
        return "exe";
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   177
    }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   178
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   179
    @Override
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   180
    public String getBundleType() {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   181
        return "INSTALLER";
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   182
    }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   183
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   184
    @Override
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   185
    public Collection<BundlerParamInfo<?>> getBundleParameters() {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   186
        Collection<BundlerParamInfo<?>> results = new LinkedHashSet<>();
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   187
        results.addAll(WinAppBundler.getAppBundleParameters());
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   188
        results.addAll(getExeBundleParameters());
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   189
        return results;
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   190
    }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   191
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   192
    public static Collection<BundlerParamInfo<?>> getExeBundleParameters() {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   193
        return Arrays.asList(
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   194
                DESCRIPTION,
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   195
                COPYRIGHT,
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   196
                LICENSE_FILE,
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   197
                MENU_GROUP,
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   198
                MENU_HINT,
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   199
                // RUN_AT_STARTUP,
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   200
                SHORTCUT_HINT,
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   201
                // SERVICE_HINT,
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   202
                // START_ON_INSTALL,
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   203
                // STOP_ON_UNINSTALL,
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   204
                EXE_SYSTEM_WIDE,
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   205
                TITLE,
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   206
                VENDOR,
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   207
                INSTALLDIR_CHOOSER
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   208
        );
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   209
    }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   210
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   211
    @Override
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   212
    public File execute(
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   213
            Map<String, ? super Object> p, File outputParentDir) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   214
        return bundle(p, outputParentDir);
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   215
    }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   216
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   217
    @Override
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   218
    public boolean supported() {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   219
        return (Platform.getPlatform() == Platform.WINDOWS);
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   220
    }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   221
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   222
    static class VersionExtractor extends PrintStream {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   223
        double version = 0f;
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   224
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   225
        public VersionExtractor() {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   226
            super(new ByteArrayOutputStream());
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   227
        }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   228
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   229
        double getVersion() {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   230
            if (version == 0f) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   231
                String content =
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   232
                        new String(((ByteArrayOutputStream) out).toByteArray());
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   233
                Pattern pattern = Pattern.compile("Inno Setup (\\d+.?\\d*)");
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   234
                Matcher matcher = pattern.matcher(content);
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   235
                if (matcher.find()) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   236
                    String v = matcher.group(1);
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   237
                    version = new Double(v);
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   238
                }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   239
            }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   240
            return version;
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   241
        }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   242
    }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   243
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   244
    private static double findToolVersion(String toolName) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   245
        try {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   246
            if (toolName == null || "".equals(toolName)) return 0f;
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   247
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   248
            ProcessBuilder pb = new ProcessBuilder(
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   249
                    toolName,
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   250
                    "/?");
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   251
            VersionExtractor ve = new VersionExtractor();
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   252
            IOUtils.exec(pb, Log.isDebug(), true, ve);
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   253
            // not interested in the output
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   254
            double version = ve.getVersion();
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   255
            Log.verbose(MessageFormat.format(
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   256
                    getString("message.tool-version"), toolName, version));
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   257
            return version;
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   258
        } catch (Exception e) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   259
            if (Log.isDebug()) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   260
                Log.verbose(e);
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   261
            }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   262
            return 0f;
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   263
        }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   264
    }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   265
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   266
    @Override
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   267
    public boolean validate(Map<String, ? super Object> p)
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   268
            throws UnsupportedPlatformException, ConfigException {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   269
        try {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   270
            if (p == null) throw new ConfigException(
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   271
                      getString("error.parameters-null"),
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   272
                      getString("error.parameters-null.advice"));
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   273
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   274
            // run basic validation to ensure requirements are met
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   275
            // we are not interested in return code, only possible exception
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   276
            APP_BUNDLER.fetchFrom(p).validate(p);
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   277
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   278
            // make sure some key values don't have newlines
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   279
            for (BundlerParamInfo<String> pi : Arrays.asList(
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   280
                    APP_NAME,
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   281
                    COPYRIGHT,
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   282
                    DESCRIPTION,
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   283
                    MENU_GROUP,
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   284
                    TITLE,
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   285
                    VENDOR,
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   286
                    VERSION)
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   287
            ) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   288
                String v = pi.fetchFrom(p);
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   289
                if (v.contains("\n") | v.contains("\r")) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   290
                    throw new ConfigException("Parmeter '" + pi.getID() +
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   291
                            "' cannot contain a newline.",
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   292
                            " Change the value of '" + pi.getID() +
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   293
                            " so that it does not contain any newlines");
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   294
                }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   295
            }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   296
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   297
            // exe bundlers trim the copyright to 100 characters,
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   298
            // tell them this will happen
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   299
            if (COPYRIGHT.fetchFrom(p).length() > 100) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   300
                throw new ConfigException(
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   301
                        getString("error.copyright-is-too-long"),
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   302
                        getString("error.copyright-is-too-long.advice"));
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   303
            }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   304
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   305
            // validate license file, if used, exists in the proper place
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   306
            if (p.containsKey(LICENSE_FILE.getID())) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   307
                List<RelativeFileSet> appResourcesList =
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   308
                        APP_RESOURCES_LIST.fetchFrom(p);
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   309
                for (String license : LICENSE_FILE.fetchFrom(p)) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   310
                    boolean found = false;
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   311
                    for (RelativeFileSet appResources : appResourcesList) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   312
                        found = found || appResources.contains(license);
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   313
                    }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   314
                    if (!found) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   315
                        throw new ConfigException(
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   316
                                getString("error.license-missing"),
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   317
                                MessageFormat.format(getString(
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   318
                                "error.license-missing.advice"), license));
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   319
                    }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   320
                }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   321
            }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   322
//
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   323
//            if (SERVICE_HINT.fetchFrom(p)) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   324
//                SERVICE_BUNDLER.fetchFrom(p).validate(p);
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   325
//            }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   326
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   327
            double innoVersion = findToolVersion(
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   328
                    TOOL_INNO_SETUP_COMPILER_EXECUTABLE.fetchFrom(p));
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   329
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   330
            //Inno Setup 5+ is required
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   331
            double minVersion = 5.0f;
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   332
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   333
            if (innoVersion < minVersion) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   334
                Log.info(MessageFormat.format(
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   335
                        getString("message.tool-wrong-version"),
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   336
                        TOOL_INNO_SETUP_COMPILER, innoVersion, minVersion));
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   337
                throw new ConfigException(
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   338
                        getString("error.iscc-not-found"),
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   339
                        getString("error.iscc-not-found.advice"));
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   340
            }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   341
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   342
            /********* validate bundle parameters *************/
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   343
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   344
            // only one mime type per association, at least one file extension
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   345
            List<Map<String, ? super Object>> associations =
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   346
                    FILE_ASSOCIATIONS.fetchFrom(p);
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   347
            if (associations != null) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   348
                for (int i = 0; i < associations.size(); i++) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   349
                    Map<String, ? super Object> assoc = associations.get(i);
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   350
                    List<String> mimes = FA_CONTENT_TYPE.fetchFrom(assoc);
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   351
                    if (mimes.size() > 1) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   352
                        throw new ConfigException(MessageFormat.format(
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   353
                                getString("error.too-many-content-"
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   354
                                + "types-for-file-association"), i),
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   355
                                getString("error.too-many-content-"
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   356
                                + "types-for-file-association.advice"));
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   357
                    }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   358
                }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   359
            }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   360
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   361
            // validate license file, if used, exists in the proper place
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   362
            if (p.containsKey(LICENSE_FILE.getID())) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   363
                List<RelativeFileSet> appResourcesList =
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   364
                        APP_RESOURCES_LIST.fetchFrom(p);
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   365
                for (String license : LICENSE_FILE.fetchFrom(p)) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   366
                    boolean found = false;
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   367
                    for (RelativeFileSet appResources : appResourcesList) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   368
                        found = found || appResources.contains(license);
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   369
                    }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   370
                    if (!found) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   371
                        throw new ConfigException(
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   372
                            MessageFormat.format(getString(
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   373
                               "error.license-missing"), license),
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   374
                            MessageFormat.format(getString(
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   375
                               "error.license-missing.advice"), license));
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   376
                    }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   377
                }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   378
            }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   379
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   380
            return true;
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   381
        } catch (RuntimeException re) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   382
            if (re.getCause() instanceof ConfigException) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   383
                throw (ConfigException) re.getCause();
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   384
            } else {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   385
                throw new ConfigException(re);
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   386
            }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   387
        }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   388
    }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   389
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   390
    private boolean prepareProto(Map<String, ? super Object> p)
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   391
                throws IOException {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   392
        File appImage = StandardBundlerParam.getPredefinedAppImage(p);
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   393
        File appDir = null;
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   394
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   395
        // we either have an application image or need to build one
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   396
        if (appImage != null) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   397
            appDir = new File(
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   398
                    EXE_IMAGE_DIR.fetchFrom(p), APP_NAME.fetchFrom(p));
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   399
            // copy everything from appImage dir into appDir/name
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   400
            IOUtils.copyRecursive(appImage.toPath(), appDir.toPath());
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   401
        } else {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   402
            appDir = APP_BUNDLER.fetchFrom(p).doBundle(p,
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   403
                    EXE_IMAGE_DIR.fetchFrom(p), true);
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   404
        }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   405
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   406
        if (appDir == null) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   407
            return false;
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   408
        }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   409
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   410
        p.put(WIN_APP_IMAGE.getID(), appDir);
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   411
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   412
        List<String> licenseFiles = LICENSE_FILE.fetchFrom(p);
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   413
        if (licenseFiles != null) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   414
            // need to copy license file to the root of win.app.image
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   415
            outerLoop:
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   416
            for (RelativeFileSet rfs : APP_RESOURCES_LIST.fetchFrom(p)) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   417
                for (String s : licenseFiles) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   418
                    if (rfs.contains(s)) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   419
                        File lfile = new File(rfs.getBaseDirectory(), s);
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   420
                        File destFile = new File(appDir, lfile.getName());
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   421
                        IOUtils.copyFile(lfile, destFile);
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   422
                        ensureByMutationFileIsRTF(destFile);
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   423
                        break outerLoop;
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   424
                    }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   425
                }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   426
            }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   427
        }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   428
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   429
        // copy file association icons
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   430
        List<Map<String, ? super Object>> fileAssociations =
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   431
                FILE_ASSOCIATIONS.fetchFrom(p);
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   432
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   433
        for (Map<String, ? super Object> fa : fileAssociations) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   434
            File icon = FA_ICON.fetchFrom(fa); // TODO FA_ICON_ICO
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   435
            if (icon == null) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   436
                continue;
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   437
            }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   438
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   439
            File faIconFile = new File(appDir, icon.getName());
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   440
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   441
            if (icon.exists()) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   442
                try {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   443
                    IOUtils.copyFile(icon, faIconFile);
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   444
                } catch (IOException e) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   445
                    e.printStackTrace();
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   446
                }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   447
            }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   448
        }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   449
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   450
//
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   451
//        if (SERVICE_HINT.fetchFrom(p)) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   452
//            // copies the service launcher to the app root folder
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   453
//            appDir = SERVICE_BUNDLER.fetchFrom(p).doBundle(
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   454
//                    p, appOutputDir, true);
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   455
//            if (appDir == null) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   456
//                return false;
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   457
//            }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   458
//        }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   459
        return true;
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   460
    }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   461
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   462
    public File bundle(Map<String, ? super Object> p, File outdir) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   463
        if (!outdir.isDirectory() && !outdir.mkdirs()) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   464
            throw new RuntimeException(MessageFormat.format(
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   465
                    getString("error.cannot-create-output-dir"),
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   466
                    outdir.getAbsolutePath()));
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   467
        }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   468
        if (!outdir.canWrite()) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   469
            throw new RuntimeException(MessageFormat.format(
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   470
                    getString("error.cannot-write-to-output-dir"),
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   471
                    outdir.getAbsolutePath()));
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   472
        }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   473
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   474
        if (WindowsDefender.isThereAPotentialWindowsDefenderIssue()) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   475
            Log.info(MessageFormat.format(
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   476
                    getString("message.potential.windows.defender.issue"),
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   477
                    WindowsDefender.getUserTempDirectory()));
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   478
        }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   479
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   480
        // validate we have valid tools before continuing
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   481
        String iscc = TOOL_INNO_SETUP_COMPILER_EXECUTABLE.fetchFrom(p);
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   482
        if (iscc == null || !new File(iscc).isFile()) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   483
            Log.info(getString("error.iscc-not-found"));
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   484
            Log.info(MessageFormat.format(
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   485
                    getString("message.iscc-file-string"), iscc));
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   486
            return null;
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   487
        }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   488
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   489
        File imageDir = EXE_IMAGE_DIR.fetchFrom(p);
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   490
        try {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   491
            imageDir.mkdirs();
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   492
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   493
            boolean menuShortcut = MENU_HINT.fetchFrom(p);
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   494
            boolean desktopShortcut = SHORTCUT_HINT.fetchFrom(p);
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   495
            if (!menuShortcut && !desktopShortcut) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   496
                // both can not be false - user will not find the app
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   497
                Log.verbose(getString("message.one-shortcut-required"));
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   498
                p.put(MENU_HINT.getID(), true);
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   499
            }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   500
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   501
            if (prepareProto(p) && prepareProjectConfig(p)) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   502
                File configScript = getConfig_Script(p);
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   503
                if (configScript.exists()) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   504
                    Log.info(MessageFormat.format(
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   505
                            getString("message.running-wsh-script"),
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   506
                            configScript.getAbsolutePath()));
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   507
                    IOUtils.run("wscript", configScript, VERBOSE.fetchFrom(p));
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   508
                }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   509
                return buildEXE(p, outdir);
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   510
            }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   511
            return null;
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   512
        } catch (IOException ex) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   513
            ex.printStackTrace();
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   514
            return null;
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   515
        } finally {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   516
            try {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   517
                if (VERBOSE.fetchFrom(p)) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   518
                    saveConfigFiles(p);
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   519
                }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   520
                if (imageDir != null && !Log.isDebug()) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   521
                    IOUtils.deleteRecursive(imageDir);
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   522
                } else if (imageDir != null) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   523
                    Log.info(MessageFormat.format(
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   524
                            getString("message.debug-working-directory"),
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   525
                            imageDir.getAbsolutePath()));
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   526
                }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   527
            } catch (IOException ex) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   528
                // noinspection ReturnInsideFinallyBlock
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   529
                Log.debug(ex.getMessage());
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   530
                return null;
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   531
            }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   532
        }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   533
    }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   534
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   535
    // name of post-image script
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   536
    private File getConfig_Script(Map<String, ? super Object> p) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   537
        return new File(EXE_IMAGE_DIR.fetchFrom(p),
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   538
                APP_NAME.fetchFrom(p) + "-post-image.wsf");
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   539
    }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   540
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   541
    protected void saveConfigFiles(Map<String, ? super Object> p) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   542
        try {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   543
            File configRoot = CONFIG_ROOT.fetchFrom(p);
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   544
            if (getConfig_ExeProjectFile(p).exists()) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   545
                IOUtils.copyFile(getConfig_ExeProjectFile(p),
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   546
                        new File(configRoot,
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   547
                        getConfig_ExeProjectFile(p).getName()));
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   548
            }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   549
            if (getConfig_Script(p).exists()) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   550
                IOUtils.copyFile(getConfig_Script(p),
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   551
                        new File(configRoot,
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   552
                         getConfig_Script(p).getName()));
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   553
            }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   554
            if (getConfig_SmallInnoSetupIcon(p).exists()) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   555
                IOUtils.copyFile(getConfig_SmallInnoSetupIcon(p),
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   556
                        new File(configRoot,
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   557
                        getConfig_SmallInnoSetupIcon(p).getName()));
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   558
            }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   559
            Log.info(MessageFormat.format(
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   560
                        getString("message.config-save-location"),
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   561
                        configRoot.getAbsolutePath()));
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   562
        } catch (IOException ioe) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   563
            ioe.printStackTrace();
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   564
        }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   565
    }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   566
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   567
    private String getAppIdentifier(Map<String, ? super Object> p) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   568
        String nm = IDENTIFIER.fetchFrom(p);
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   569
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   570
        //limitation of innosetup
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   571
        if (nm.length() > 126)
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   572
            nm = nm.substring(0, 126);
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   573
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   574
        return nm;
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   575
    }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   576
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   577
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   578
    private String getLicenseFile(Map<String, ? super Object> p) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   579
        List<String> licenseFiles = LICENSE_FILE.fetchFrom(p);
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   580
        if (licenseFiles == null || licenseFiles.isEmpty()) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   581
            return "";
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   582
        } else {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   583
            return licenseFiles.get(0);
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   584
        }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   585
    }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   586
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   587
    void validateValueAndPut(Map<String, String> data, String key,
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   588
                BundlerParamInfo<String> param,
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   589
                Map<String, ? super Object> p) throws IOException {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   590
        String value = param.fetchFrom(p);
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   591
        if (value.contains("\r") || value.contains("\n")) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   592
            throw new IOException("Configuration Parameter " +
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   593
                     param.getID() + " cannot contain multiple lines of text");
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   594
        }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   595
        data.put(key, innosetupEscape(value));
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   596
    }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   597
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   598
    private String innosetupEscape(String value) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   599
        if (value.contains("\"") || !value.trim().equals(value)) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   600
            value = "\"" + value.replace("\"", "\"\"") + "\"";
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   601
        }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   602
        return value;
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   603
    }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   604
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   605
    boolean prepareMainProjectFile(Map<String, ? super Object> p)
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   606
            throws IOException {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   607
        Map<String, String> data = new HashMap<>();
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   608
        data.put("PRODUCT_APP_IDENTIFIER",
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   609
                innosetupEscape(getAppIdentifier(p)));
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   610
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   611
        validateValueAndPut(data, "APPLICATION_NAME", APP_NAME, p);
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   612
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   613
        validateValueAndPut(data, "APPLICATION_VENDOR", VENDOR, p);
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   614
        validateValueAndPut(data, "APPLICATION_VERSION", VERSION, p);
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   615
        validateValueAndPut(data, "INSTALLER_FILE_NAME",
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   616
                INSTALLER_FILE_NAME, p);
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   617
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   618
        data.put("APPLICATION_LAUNCHER_FILENAME",
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   619
                innosetupEscape(WinAppBundler.getLauncherName(p)));
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   620
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   621
        data.put("APPLICATION_DESKTOP_SHORTCUT",
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   622
                SHORTCUT_HINT.fetchFrom(p) ? "returnTrue" : "returnFalse");
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   623
        data.put("APPLICATION_MENU_SHORTCUT",
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   624
                MENU_HINT.fetchFrom(p) ? "returnTrue" : "returnFalse");
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   625
        validateValueAndPut(data, "APPLICATION_GROUP", MENU_GROUP, p);
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   626
        validateValueAndPut(data, "APPLICATION_COMMENTS",
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   627
                TITLE, p); // TODO this seems strange, at least in name
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   628
        validateValueAndPut(data, "APPLICATION_COPYRIGHT", COPYRIGHT, p);
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   629
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   630
        data.put("APPLICATION_LICENSE_FILE",
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   631
                innosetupEscape(getLicenseFile(p)));
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   632
        data.put("DISABLE_DIR_PAGE",
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   633
                INSTALLDIR_CHOOSER.fetchFrom(p) ? "No" : "Yes");
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   634
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   635
        Boolean isSystemWide = EXE_SYSTEM_WIDE.fetchFrom(p);
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   636
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   637
        if (isSystemWide) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   638
            data.put("APPLICATION_INSTALL_ROOT", "{pf}");
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   639
            data.put("APPLICATION_INSTALL_PRIVILEGE", "admin");
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   640
        } else {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   641
            data.put("APPLICATION_INSTALL_ROOT", "{localappdata}");
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   642
            data.put("APPLICATION_INSTALL_PRIVILEGE", "lowest");
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   643
        }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   644
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   645
        if (BIT_ARCH_64.fetchFrom(p)) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   646
            data.put("ARCHITECTURE_BIT_MODE", "x64");
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   647
        } else {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   648
            data.put("ARCHITECTURE_BIT_MODE", "");
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   649
        }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   650
//
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   651
//        if (SERVICE_HINT.fetchFrom(p)) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   652
//            data.put("RUN_FILENAME",
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   653
//                innosetupEscape(WinServiceBundler.getAppSvcName(p)));
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   654
//        } else {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   655
              validateValueAndPut(data, "RUN_FILENAME", APP_NAME, p);
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   656
//        }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   657
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   658
        validateValueAndPut(data, "APPLICATION_DESCRIPTION",
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   659
                DESCRIPTION, p);
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   660
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   661
//        data.put("APPLICATION_SERVICE",
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   662
//                SERVICE_HINT.fetchFrom(p) ? "returnTrue" : "returnFalse");
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   663
        data.put("APPLICATION_SERVICE", "returnFalse");
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   664
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   665
//        data.put("APPLICATION_NOT_SERVICE",
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   666
//                SERVICE_HINT.fetchFrom(p) ? "returnFalse" : "returnTrue");
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   667
        data.put("APPLICATION_NOT_SERVICE", "returnFalse");
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   668
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   669
//        data.put("APPLICATION_APP_CDS_INSTALL",
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   670
//                (UNLOCK_COMMERCIAL_FEATURES.fetchFrom(p) &&
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   671
//                ENABLE_APP_CDS.fetchFrom(p) &&
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   672
//                ("install".equals(APP_CDS_CACHE_MODE.fetchFrom(p)) ||
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   673
//                "auto+install".equals(APP_CDS_CACHE_MODE.fetchFrom(p))))
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   674
//                ? "returnTrue" : "returnFalse");
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   675
        data.put("APPLICATION_APP_CDS_INSTALL", "returnFalse");
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   676
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   677
//        data.put("START_ON_INSTALL",
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   678
//                START_ON_INSTALL.fetchFrom(p) ? "-startOnInstall" : "");
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   679
//        data.put("STOP_ON_UNINSTALL",
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   680
//                STOP_ON_UNINSTALL.fetchFrom(p) ? "-stopOnUninstall" : "");
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   681
//        data.put("RUN_AT_STARTUP",
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   682
//                RUN_AT_STARTUP.fetchFrom(p) ? "-runAtStartup" : "");
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   683
        data.put("START_ON_INSTALL", "");
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   684
        data.put("STOP_ON_UNINSTALL", "");
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   685
        data.put("RUN_AT_STARTUP", "");
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   686
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   687
        StringBuilder secondaryLaunchersCfg = new StringBuilder();
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   688
        for (Map<String, ? super Object>
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   689
                launcher : SECONDARY_LAUNCHERS.fetchFrom(p)) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   690
            String application_name = APP_NAME.fetchFrom(launcher);
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   691
            if (MENU_HINT.fetchFrom(launcher)) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   692
                // Name: "{group}\APPLICATION_NAME";
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   693
                // Filename: "{app}\APPLICATION_NAME.exe";
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   694
                // IconFilename: "{app}\APPLICATION_NAME.ico"
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   695
                secondaryLaunchersCfg.append("Name: \"{group}\\");
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   696
                secondaryLaunchersCfg.append(application_name);
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   697
                secondaryLaunchersCfg.append("\"; Filename: \"{app}\\");
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   698
                secondaryLaunchersCfg.append(application_name);
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   699
                secondaryLaunchersCfg.append(".exe\"; IconFilename: \"{app}\\");
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   700
                secondaryLaunchersCfg.append(application_name);
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   701
                secondaryLaunchersCfg.append(".ico\"\r\n");
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   702
            }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   703
            if (SHORTCUT_HINT.fetchFrom(launcher)) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   704
                // Name: "{commondesktop}\APPLICATION_NAME";
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   705
                // Filename: "{app}\APPLICATION_NAME.exe";
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   706
                // IconFilename: "{app}\APPLICATION_NAME.ico"
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   707
                secondaryLaunchersCfg.append("Name: \"{commondesktop}\\");
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   708
                secondaryLaunchersCfg.append(application_name);
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   709
                secondaryLaunchersCfg.append("\"; Filename: \"{app}\\");
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   710
                secondaryLaunchersCfg.append(application_name);
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   711
                secondaryLaunchersCfg.append(".exe\";  IconFilename: \"{app}\\");
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   712
                secondaryLaunchersCfg.append(application_name);
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   713
                secondaryLaunchersCfg.append(".ico\"\r\n");
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   714
            }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   715
        }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   716
        data.put("SECONDARY_LAUNCHERS", secondaryLaunchersCfg.toString());
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   717
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   718
        StringBuilder registryEntries = new StringBuilder();
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   719
        String regName = APP_REGISTRY_NAME.fetchFrom(p);
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   720
        List<Map<String, ? super Object>> fetchFrom =
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   721
                FILE_ASSOCIATIONS.fetchFrom(p);
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   722
        for (int i = 0; i < fetchFrom.size(); i++) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   723
            Map<String, ? super Object> fileAssociation = fetchFrom.get(i);
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   724
            String description = FA_DESCRIPTION.fetchFrom(fileAssociation);
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   725
            File icon = FA_ICON.fetchFrom(fileAssociation); //TODO FA_ICON_ICO
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   726
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   727
            List<String> extensions = FA_EXTENSIONS.fetchFrom(fileAssociation);
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   728
            String entryName = regName + "File";
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   729
            if (i > 0) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   730
                entryName += "." + i;
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   731
            }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   732
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   733
            if (extensions == null) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   734
                Log.info(getString(
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   735
                        "message.creating-association-with-null-extension"));
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   736
            } else {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   737
                for (String ext : extensions) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   738
                    if (isSystemWide) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   739
                        // "Root: HKCR; Subkey: \".myp\";
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   740
                        // ValueType: string; ValueName: \"\";
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   741
                        // ValueData: \"MyProgramFile\";
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   742
                        // Flags: uninsdeletevalue"
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   743
                        registryEntries.append("Root: HKCR; Subkey: \".")
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   744
                                .append(ext)
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   745
                                .append("\"; ValueType: string; ValueName: \"\"; ValueData: \"")
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   746
                                .append(entryName)
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   747
                                .append("\"; Flags: uninsdeletevalue\r\n");
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   748
                    } else {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   749
                        registryEntries.append("Root: HKCU; Subkey: \"Software\\Classes\\.")
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   750
                                .append(ext)
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   751
                                .append("\"; ValueType: string; ValueName: \"\"; ValueData: \"")
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   752
                                .append(entryName)
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   753
                                .append("\"; Flags: uninsdeletevalue\r\n");
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   754
                    }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   755
                }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   756
            }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   757
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   758
            if (extensions != null && !extensions.isEmpty()) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   759
                String ext = extensions.get(0);
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   760
                List<String> mimeTypes = FA_CONTENT_TYPE.fetchFrom(fileAssociation);
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   761
                for (String mime : mimeTypes) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   762
                    if (isSystemWide) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   763
                        // "Root: HKCR;
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   764
                        // Subkey: HKCR\\Mime\\Database\\Content Type\\application/chaos;
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   765
                        // ValueType: string;
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   766
                        // ValueName: Extension;
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   767
                        // ValueData: .chaos;
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   768
                        // Flags: uninsdeletevalue"
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   769
                        registryEntries.append("Root: HKCR; Subkey: " +
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   770
                                 "\"Mime\\Database\\Content Type\\")
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   771
                            .append(mime)
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   772
                            .append("\"; ValueType: string; ValueName: " +
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   773
                                 "\"Extension\"; ValueData: \".")
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   774
                            .append(ext)
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   775
                            .append("\"; Flags: uninsdeletevalue\r\n");
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   776
                    } else {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   777
                        registryEntries.append(
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   778
                                "Root: HKCU; Subkey: \"Software\\" +
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   779
                                "Classes\\Mime\\Database\\Content Type\\")
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   780
                                .append(mime)
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   781
                                .append("\"; ValueType: string; " +
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   782
                                "ValueName: \"Extension\"; ValueData: \".")
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   783
                                .append(ext)
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   784
                                .append("\"; Flags: uninsdeletevalue\r\n");
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   785
                    }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   786
                }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   787
            }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   788
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   789
            if (isSystemWide) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   790
                // "Root: HKCR;
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   791
                // Subkey: \"MyProgramFile\";
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   792
                // ValueType: string;
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   793
                // ValueName: \"\";
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   794
                // ValueData: \"My Program File\";
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   795
                // Flags: uninsdeletekey"
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   796
                registryEntries.append("Root: HKCR; Subkey: \"")
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   797
                    .append(entryName)
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   798
                    .append(
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   799
                    "\"; ValueType: string; ValueName: \"\"; ValueData: \"")
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   800
                    .append(description)
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   801
                    .append("\"; Flags: uninsdeletekey\r\n");
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   802
            } else {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   803
                registryEntries.append(
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   804
                    "Root: HKCU; Subkey: \"Software\\Classes\\")
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   805
                    .append(entryName)
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   806
                    .append(
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   807
                    "\"; ValueType: string; ValueName: \"\"; ValueData: \"")
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   808
                    .append(description)
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   809
                    .append("\"; Flags: uninsdeletekey\r\n");
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   810
            }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   811
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   812
            if (icon != null && icon.exists()) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   813
                if (isSystemWide) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   814
                    // "Root: HKCR;
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   815
                    // Subkey: \"MyProgramFile\\DefaultIcon\";
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   816
                    // ValueType: string;
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   817
                    // ValueName: \"\";
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   818
                    // ValueData: \"{app}\\MYPROG.EXE,0\"\n" +
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   819
                    registryEntries.append("Root: HKCR; Subkey: \"")
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   820
                            .append(entryName)
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   821
                            .append("\\DefaultIcon\"; ValueType: string; " +
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   822
                            "ValueName: \"\"; ValueData: \"{app}\\")
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   823
                            .append(icon.getName())
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   824
                            .append("\"\r\n");
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   825
                } else {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   826
                    registryEntries.append(
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   827
                            "Root: HKCU; Subkey: \"Software\\Classes\\")
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   828
                            .append(entryName)
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   829
                            .append("\\DefaultIcon\"; ValueType: string; " +
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   830
                            "ValueName: \"\"; ValueData: \"{app}\\")
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   831
                            .append(icon.getName())
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   832
                            .append("\"\r\n");
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   833
                }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   834
            }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   835
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   836
            if (isSystemWide) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   837
                // "Root: HKCR;
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   838
                // Subkey: \"MyProgramFile\\shell\\open\\command\";
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   839
                // ValueType: string;
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   840
                // ValueName: \"\";
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   841
                // ValueData: \"\"\"{app}\\MYPROG.EXE\"\" \"\"%1\"\"\"\n"
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   842
                registryEntries.append("Root: HKCR; Subkey: \"")
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   843
                        .append(entryName)
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   844
                        .append("\\shell\\open\\command\"; ValueType: " +
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   845
                        "string; ValueName: \"\"; ValueData: \"\"\"{app}\\")
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   846
                        .append(APP_NAME.fetchFrom(p))
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   847
                        .append("\"\" \"\"%1\"\"\"\r\n");
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   848
            } else {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   849
                registryEntries.append(
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   850
                        "Root: HKCU; Subkey: \"Software\\Classes\\")
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   851
                        .append(entryName)
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   852
                        .append("\\shell\\open\\command\"; ValueType: " +
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   853
                        "string; ValueName: \"\"; ValueData: \"\"\"{app}\\")
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   854
                        .append(APP_NAME.fetchFrom(p))
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   855
                        .append("\"\" \"\"%1\"\"\"\r\n");
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   856
            }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   857
        }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   858
        if (registryEntries.length() > 0) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   859
            data.put("FILE_ASSOCIATIONS",
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   860
                    "ChangesAssociations=yes\r\n\r\n[Registry]\r\n" +
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   861
                    registryEntries.toString());
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   862
        } else {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   863
            data.put("FILE_ASSOCIATIONS", "");
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   864
        }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   865
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   866
        // TODO - alternate template for JRE installer
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   867
        String iss = Arguments.CREATE_JRE_INSTALLER.fetchFrom(p) ?
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   868
                DEFAULT_EXE_PROJECT_TEMPLATE : DEFAULT_EXE_PROJECT_TEMPLATE;
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   869
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   870
        Writer w = new BufferedWriter(new FileWriter(
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   871
                getConfig_ExeProjectFile(p)));
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   872
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   873
        String content = preprocessTextResource(
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   874
                WinAppBundler.WIN_BUNDLER_PREFIX +
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   875
                getConfig_ExeProjectFile(p).getName(),
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   876
                getString("resource.inno-setup-project-file"),
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   877
                iss, data, VERBOSE.fetchFrom(p),
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   878
                DROP_IN_RESOURCES_ROOT.fetchFrom(p));
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   879
        w.write(content);
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   880
        w.close();
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   881
        return true;
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   882
    }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   883
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   884
    private final static String DEFAULT_INNO_SETUP_ICON =
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   885
            "icon_inno_setup.bmp";
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   886
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   887
    private boolean prepareProjectConfig(Map<String, ? super Object> p)
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   888
            throws IOException {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   889
        prepareMainProjectFile(p);
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   890
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   891
        //prepare installer icon
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   892
        File iconTarget = getConfig_SmallInnoSetupIcon(p);
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   893
        fetchResource(WinAppBundler.WIN_BUNDLER_PREFIX + iconTarget.getName(),
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   894
                getString("resource.setup-icon"),
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   895
                DEFAULT_INNO_SETUP_ICON,
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   896
                iconTarget,
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   897
                VERBOSE.fetchFrom(p),
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   898
                DROP_IN_RESOURCES_ROOT.fetchFrom(p));
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   899
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   900
        fetchResource(WinAppBundler.WIN_BUNDLER_PREFIX +
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   901
                getConfig_Script(p).getName(),
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   902
                getString("resource.post-install-script"),
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   903
                (String) null,
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   904
                getConfig_Script(p),
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   905
                VERBOSE.fetchFrom(p),
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   906
                DROP_IN_RESOURCES_ROOT.fetchFrom(p));
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   907
        return true;
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   908
    }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   909
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   910
    private File getConfig_SmallInnoSetupIcon(
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   911
            Map<String, ? super Object> p) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   912
        return new File(EXE_IMAGE_DIR.fetchFrom(p),
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   913
                APP_NAME.fetchFrom(p) + "-setup-icon.bmp");
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   914
    }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   915
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   916
    private File getConfig_ExeProjectFile(Map<String, ? super Object> p) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   917
        return new File(EXE_IMAGE_DIR.fetchFrom(p),
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   918
                APP_NAME.fetchFrom(p) + ".iss");
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   919
    }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   920
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   921
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   922
    private File buildEXE(Map<String, ? super Object> p, File outdir)
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   923
             throws IOException {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   924
        Log.verbose(MessageFormat.format(
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   925
             getString("message.outputting-to-location"),
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   926
             outdir.getAbsolutePath()));
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   927
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   928
        outdir.mkdirs();
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   929
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   930
        //run candle
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   931
        ProcessBuilder pb = new ProcessBuilder(
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   932
                TOOL_INNO_SETUP_COMPILER_EXECUTABLE.fetchFrom(p),
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   933
                "/o"+outdir.getAbsolutePath(),
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   934
                getConfig_ExeProjectFile(p).getAbsolutePath());
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   935
        pb = pb.directory(EXE_IMAGE_DIR.fetchFrom(p));
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   936
        IOUtils.exec(pb, VERBOSE.fetchFrom(p));
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   937
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   938
        Log.info(MessageFormat.format(
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   939
                getString("message.output-location"),
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   940
                outdir.getAbsolutePath()));
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   941
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   942
        // presume the result is the ".exe" file with the newest modified time
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   943
        // not the best solution, but it is the most reliable
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   944
        File result = null;
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   945
        long lastModified = 0;
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   946
        File[] list = outdir.listFiles();
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   947
        if (list != null) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   948
            for (File f : list) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   949
                if (f.getName().endsWith(".exe") &&
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   950
                        f.lastModified() > lastModified) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   951
                    result = f;
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   952
                    lastModified = f.lastModified();
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   953
                }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   954
            }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   955
        }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   956
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   957
        return result;
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   958
    }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   959
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   960
   public static void ensureByMutationFileIsRTF(File f) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   961
        if (f == null || !f.isFile()) return;
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   962
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   963
        try {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   964
            boolean existingLicenseIsRTF = false;
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   965
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   966
            try (FileInputStream fin = new FileInputStream(f)) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   967
                byte[] firstBits = new byte[7];
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   968
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   969
                if (fin.read(firstBits) == firstBits.length) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   970
                    String header = new String(firstBits);
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   971
                    existingLicenseIsRTF = "{\\rtf1\\".equals(header);
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   972
                }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   973
            }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   974
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   975
            if (!existingLicenseIsRTF) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   976
                List<String> oldLicense = Files.readAllLines(f.toPath());
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   977
                try (Writer w = Files.newBufferedWriter(
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   978
                        f.toPath(), Charset.forName("Windows-1252"))) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   979
                    w.write("{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang1033"
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   980
                            + "{\\fonttbl{\\f0\\fnil\\fcharset0 Arial;}}\n"
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   981
                            + "\\viewkind4\\uc1\\pard\\sa200\\sl276"
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   982
                            + "\\slmult1\\lang9\\fs20 ");
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   983
                    oldLicense.forEach(l -> {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   984
                        try {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   985
                            for (char c : l.toCharArray()) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   986
                                if (c < 0x10) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   987
                                    w.write("\\'0");
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   988
                                    w.write(Integer.toHexString(c));
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   989
                                } else if (c > 0xff) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   990
                                    w.write("\\ud");
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   991
                                    w.write(Integer.toString(c));
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   992
                                    w.write("?");
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   993
                                } else if ((c < 0x20) || (c >= 0x80) ||
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   994
                                        (c == 0x5C) || (c == 0x7B) ||
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   995
                                        (c == 0x7D)) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   996
                                    w.write("\\'");
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   997
                                    w.write(Integer.toHexString(c));
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   998
                                } else {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   999
                                    w.write(c);
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
  1000
                                }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
  1001
                            }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
  1002
                            if (l.length() < 1) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
  1003
                                w.write("\\par");
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
  1004
                            } else {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
  1005
                                w.write(" ");
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
  1006
                            }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
  1007
                            w.write("\r\n");
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
  1008
                        } catch (IOException e) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
  1009
                            Log.verbose(e);
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
  1010
                        }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
  1011
                    });
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
  1012
                    w.write("}\r\n");
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
  1013
                }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
  1014
            }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
  1015
        } catch (IOException e) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
  1016
            Log.verbose(e);
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
  1017
        }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
  1018
    }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
  1019
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
  1020
    private static String getString(String key)
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
  1021
            throws MissingResourceException {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
  1022
        return I18N.getString(key);
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
  1023
    }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
  1024
}