src/jdk.packager/windows/classes/jdk/packager/internal/windows/WinExeBundler.java
author herrick
Thu, 01 Nov 2018 08:52:50 -0400
branchJDK-8200758-branch
changeset 57013 0ece1b6f0958
parent 57011 7df1e4bf870a
child 57015 5d2008115309
permissions -rw-r--r--
8213163: --app-image arg does not work creating exe installers Reviewed-by: almatvee
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
 */
56982
e094d5483bd6 8212048: Cleanup source code and fix issues discussed in preliminary review
herrick
parents: 56947
diff changeset
    25
56941
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    26
package jdk.packager.internal.windows;
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    27
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    28
import jdk.packager.internal.*;
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    29
import jdk.packager.internal.ConfigException;
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    30
import jdk.packager.internal.Arguments;
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    31
import jdk.packager.internal.UnsupportedPlatformException;
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    32
import jdk.packager.internal.resources.windows.WinResources;
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    33
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    34
import java.io.*;
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    35
import java.nio.charset.Charset;
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    36
import java.nio.file.Files;
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    37
import java.text.MessageFormat;
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    38
import java.util.*;
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    39
import java.util.regex.Matcher;
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    40
import java.util.regex.Pattern;
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    41
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    42
import static jdk.packager.internal.windows.WindowsBundlerParam.*;
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    43
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    44
public class WinExeBundler extends AbstractBundler {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    45
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    46
    private static final ResourceBundle I18N = ResourceBundle.getBundle(
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    47
            "jdk.packager.internal.resources.windows.WinExeBundler");
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    48
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    49
    public static final BundlerParamInfo<WinAppBundler> APP_BUNDLER =
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    50
            new WindowsBundlerParam<>(
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    51
            getString("param.app-bundler.name"),
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    52
            getString("param.app-bundler.description"),
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    53
            "win.app.bundler",
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    54
            WinAppBundler.class,
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    55
            params -> new WinAppBundler(),
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    56
            null);
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    57
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    58
    public static final BundlerParamInfo<File> CONFIG_ROOT =
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    59
            new WindowsBundlerParam<>(
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    60
            getString("param.config-root.name"),
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    61
            getString("param.config-root.description"),
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    62
            "configRoot",
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    63
            File.class,
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    64
            params -> {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    65
                File imagesRoot =
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    66
                        new File(BUILD_ROOT.fetchFrom(params), "windows");
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    67
                imagesRoot.mkdirs();
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    68
                return imagesRoot;
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    69
            },
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    70
            (s, p) -> null);
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    71
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    72
    public static final BundlerParamInfo<File> EXE_IMAGE_DIR =
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    73
            new WindowsBundlerParam<>(
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    74
            getString("param.image-dir.name"),
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    75
            getString("param.image-dir.description"),
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    76
            "win.exe.imageDir",
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    77
            File.class,
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    78
            params -> {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    79
                File imagesRoot = IMAGES_ROOT.fetchFrom(params);
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    80
                if (!imagesRoot.exists()) imagesRoot.mkdirs();
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    81
                return new File(imagesRoot, "win-exe.image");
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    82
            },
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    83
            (s, p) -> null);
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    84
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    85
    public static final BundlerParamInfo<File> WIN_APP_IMAGE =
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    86
            new WindowsBundlerParam<>(
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    87
            getString("param.app-dir.name"),
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    88
            getString("param.app-dir.description"),
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    89
            "win.app.image",
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    90
            File.class,
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    91
            null,
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    92
            (s, p) -> null);
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
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    95
    public static final StandardBundlerParam<Boolean> EXE_SYSTEM_WIDE  =
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    96
            new StandardBundlerParam<>(
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    97
            getString("param.system-wide.name"),
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    98
            getString("param.system-wide.description"),
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
    99
            Arguments.CLIOptions.WIN_PER_USER_INSTALLATION.getId(),
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   100
            Boolean.class,
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   101
            params -> true, // default to system wide
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   102
            (s, p) -> (s == null || "null".equalsIgnoreCase(s))? null
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   103
                    : Boolean.valueOf(s)
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   104
            );
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   105
    public static final StandardBundlerParam<String> PRODUCT_VERSION =
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   106
            new StandardBundlerParam<>(
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   107
                    getString("param.product-version.name"),
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   108
                    getString("param.product-version.description"),
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   109
                    "win.msi.productVersion",
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   110
                    String.class,
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   111
                    VERSION::fetchFrom,
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   112
                    (s, p) -> s
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
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   115
    public static final StandardBundlerParam<Boolean> MENU_HINT =
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   116
        new WindowsBundlerParam<>(
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   117
                getString("param.menu-shortcut-hint.name"),
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   118
                getString("param.menu-shortcut-hint.description"),
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   119
                Arguments.CLIOptions.WIN_MENU_HINT.getId(),
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   120
                Boolean.class,
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   121
                params -> false,
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   122
                (s, p) -> (s == null ||
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   123
                        "null".equalsIgnoreCase(s))? true : Boolean.valueOf(s)
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
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   126
    public static final StandardBundlerParam<Boolean> SHORTCUT_HINT =
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   127
        new WindowsBundlerParam<>(
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   128
                getString("param.desktop-shortcut-hint.name"),
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   129
                getString("param.desktop-shortcut-hint.description"),
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   130
                Arguments.CLIOptions.WIN_SHORTCUT_HINT.getId(),
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   131
                Boolean.class,
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   132
                params -> false,
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   133
                (s, p) -> (s == null ||
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   134
                       "null".equalsIgnoreCase(s))? false : Boolean.valueOf(s)
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
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   139
    private final static String DEFAULT_EXE_PROJECT_TEMPLATE = "template.iss";
56947
5a03c4524b90 JDK-8211857: Support "exe" format for create-jre-installers
herrick
parents: 56941
diff changeset
   140
    private final static String DEFAULT_JRE_EXE_TEMPLATE = "template.jre.iss";
56941
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   141
    private static final String TOOL_INNO_SETUP_COMPILER = "iscc.exe";
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   142
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   143
    public static final BundlerParamInfo<String>
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   144
            TOOL_INNO_SETUP_COMPILER_EXECUTABLE = new WindowsBundlerParam<>(
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   145
            getString("param.iscc-path.name"),
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   146
            getString("param.iscc-path.description"),
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   147
            "win.exe.iscc.exe",
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   148
            String.class,
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   149
            params -> {
56982
e094d5483bd6 8212048: Cleanup source code and fix issues discussed in preliminary review
herrick
parents: 56947
diff changeset
   150
                for (String dirString : (System.getenv("PATH")
e094d5483bd6 8212048: Cleanup source code and fix issues discussed in preliminary review
herrick
parents: 56947
diff changeset
   151
                        + ";C:\\Program Files (x86)\\Inno Setup 5;"
e094d5483bd6 8212048: Cleanup source code and fix issues discussed in preliminary review
herrick
parents: 56947
diff changeset
   152
                        + "C:\\Program Files\\Inno Setup 5").split(";")) {
56941
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   153
                    File f = new File(dirString.replace("\"", ""),
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   154
                            TOOL_INNO_SETUP_COMPILER);
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   155
                    if (f.isFile()) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   156
                        return f.toString();
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   157
                    }
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
                return null;
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   160
            },
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   161
            null);
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
    public WinExeBundler() {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   164
        super();
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   165
        baseResourceLoader = WinResources.class;
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   166
    }
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
    @Override
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   169
    public String getName() {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   170
        return getString("bundler.name");
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   171
    }
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
    @Override
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   174
    public String getDescription() {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   175
        return getString("bundler.description");
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   176
    }
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
    @Override
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   179
    public String getID() {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   180
        return "exe";
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   181
    }
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
    @Override
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   184
    public String getBundleType() {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   185
        return "INSTALLER";
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   186
    }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   187
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   188
    @Override
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   189
    public Collection<BundlerParamInfo<?>> getBundleParameters() {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   190
        Collection<BundlerParamInfo<?>> results = new LinkedHashSet<>();
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   191
        results.addAll(WinAppBundler.getAppBundleParameters());
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   192
        results.addAll(getExeBundleParameters());
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   193
        return results;
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   194
    }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   195
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   196
    public static Collection<BundlerParamInfo<?>> getExeBundleParameters() {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   197
        return Arrays.asList(
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   198
                DESCRIPTION,
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   199
                COPYRIGHT,
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   200
                LICENSE_FILE,
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   201
                MENU_GROUP,
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   202
                MENU_HINT,
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   203
                SHORTCUT_HINT,
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
            double innoVersion = findToolVersion(
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   306
                    TOOL_INNO_SETUP_COMPILER_EXECUTABLE.fetchFrom(p));
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   307
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   308
            //Inno Setup 5+ is required
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   309
            double minVersion = 5.0f;
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   310
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   311
            if (innoVersion < minVersion) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   312
                Log.info(MessageFormat.format(
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   313
                        getString("message.tool-wrong-version"),
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   314
                        TOOL_INNO_SETUP_COMPILER, innoVersion, minVersion));
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.iscc-not-found"),
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   317
                        getString("error.iscc-not-found.advice"));
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   318
            }
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
            /********* validate bundle parameters *************/
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
            // 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
   323
            List<Map<String, ? super Object>> associations =
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   324
                    FILE_ASSOCIATIONS.fetchFrom(p);
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   325
            if (associations != null) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   326
                for (int i = 0; i < associations.size(); i++) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   327
                    Map<String, ? super Object> assoc = associations.get(i);
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   328
                    List<String> mimes = FA_CONTENT_TYPE.fetchFrom(assoc);
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   329
                    if (mimes.size() > 1) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   330
                        throw new ConfigException(MessageFormat.format(
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   331
                                getString("error.too-many-content-"
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   332
                                + "types-for-file-association"), i),
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   333
                                getString("error.too-many-content-"
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   334
                                + "types-for-file-association.advice"));
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   335
                    }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   336
                }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   337
            }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   338
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   339
            // validate license file, if used, exists in the proper place
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   340
            if (p.containsKey(LICENSE_FILE.getID())) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   341
                List<RelativeFileSet> appResourcesList =
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   342
                        APP_RESOURCES_LIST.fetchFrom(p);
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   343
                for (String license : LICENSE_FILE.fetchFrom(p)) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   344
                    boolean found = false;
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   345
                    for (RelativeFileSet appResources : appResourcesList) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   346
                        found = found || appResources.contains(license);
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   347
                    }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   348
                    if (!found) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   349
                        throw new ConfigException(
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   350
                            MessageFormat.format(getString(
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   351
                               "error.license-missing"), license),
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   352
                            MessageFormat.format(getString(
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   353
                               "error.license-missing.advice"), license));
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   354
                    }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   355
                }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   356
            }
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
            return true;
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   359
        } catch (RuntimeException re) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   360
            if (re.getCause() instanceof ConfigException) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   361
                throw (ConfigException) re.getCause();
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   362
            } else {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   363
                throw new ConfigException(re);
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   364
            }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   365
        }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   366
    }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   367
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   368
    private boolean prepareProto(Map<String, ? super Object> p)
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   369
                throws IOException {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   370
        File appImage = StandardBundlerParam.getPredefinedAppImage(p);
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   371
        File appDir = null;
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   372
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   373
        // 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
   374
        if (appImage != null) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   375
            appDir = new File(
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   376
                    EXE_IMAGE_DIR.fetchFrom(p), APP_NAME.fetchFrom(p));
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   377
            // copy everything from appImage dir into appDir/name
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   378
            IOUtils.copyRecursive(appImage.toPath(), appDir.toPath());
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   379
        } else {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   380
            appDir = APP_BUNDLER.fetchFrom(p).doBundle(p,
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   381
                    EXE_IMAGE_DIR.fetchFrom(p), true);
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   382
        }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   383
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   384
        if (appDir == null) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   385
            return false;
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
        p.put(WIN_APP_IMAGE.getID(), appDir);
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
        List<String> licenseFiles = LICENSE_FILE.fetchFrom(p);
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   391
        if (licenseFiles != null) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   392
            // 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
   393
            outerLoop:
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   394
            for (RelativeFileSet rfs : APP_RESOURCES_LIST.fetchFrom(p)) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   395
                for (String s : licenseFiles) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   396
                    if (rfs.contains(s)) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   397
                        File lfile = new File(rfs.getBaseDirectory(), s);
56982
e094d5483bd6 8212048: Cleanup source code and fix issues discussed in preliminary review
herrick
parents: 56947
diff changeset
   398
                        File destFile =
e094d5483bd6 8212048: Cleanup source code and fix issues discussed in preliminary review
herrick
parents: 56947
diff changeset
   399
                            new File(appDir.getParentFile(), lfile.getName());
56941
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   400
                        IOUtils.copyFile(lfile, destFile);
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   401
                        ensureByMutationFileIsRTF(destFile);
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   402
                        break outerLoop;
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   403
                    }
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
        }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   407
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   408
        // copy file association icons
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   409
        List<Map<String, ? super Object>> fileAssociations =
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   410
                FILE_ASSOCIATIONS.fetchFrom(p);
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
        for (Map<String, ? super Object> fa : fileAssociations) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   413
            File icon = FA_ICON.fetchFrom(fa); // TODO FA_ICON_ICO
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   414
            if (icon == null) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   415
                continue;
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   416
            }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   417
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   418
            File faIconFile = new File(appDir, icon.getName());
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   419
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   420
            if (icon.exists()) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   421
                try {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   422
                    IOUtils.copyFile(icon, faIconFile);
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   423
                } catch (IOException e) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   424
                    e.printStackTrace();
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
        return true;
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   430
    }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   431
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   432
    public File bundle(Map<String, ? super Object> p, File outdir) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   433
        if (!outdir.isDirectory() && !outdir.mkdirs()) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   434
            throw new RuntimeException(MessageFormat.format(
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   435
                    getString("error.cannot-create-output-dir"),
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   436
                    outdir.getAbsolutePath()));
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
        if (!outdir.canWrite()) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   439
            throw new RuntimeException(MessageFormat.format(
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   440
                    getString("error.cannot-write-to-output-dir"),
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   441
                    outdir.getAbsolutePath()));
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   442
        }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   443
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   444
        if (WindowsDefender.isThereAPotentialWindowsDefenderIssue()) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   445
            Log.info(MessageFormat.format(
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   446
                    getString("message.potential.windows.defender.issue"),
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   447
                    WindowsDefender.getUserTempDirectory()));
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
        // validate we have valid tools before continuing
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   451
        String iscc = TOOL_INNO_SETUP_COMPILER_EXECUTABLE.fetchFrom(p);
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   452
        if (iscc == null || !new File(iscc).isFile()) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   453
            Log.info(getString("error.iscc-not-found"));
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   454
            Log.info(MessageFormat.format(
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   455
                    getString("message.iscc-file-string"), iscc));
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   456
            return null;
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
        File imageDir = EXE_IMAGE_DIR.fetchFrom(p);
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   460
        try {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   461
            imageDir.mkdirs();
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   462
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   463
            boolean menuShortcut = MENU_HINT.fetchFrom(p);
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   464
            boolean desktopShortcut = SHORTCUT_HINT.fetchFrom(p);
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   465
            if (!menuShortcut && !desktopShortcut) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   466
                // 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
   467
                Log.verbose(getString("message.one-shortcut-required"));
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   468
                p.put(MENU_HINT.getID(), true);
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   469
            }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   470
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   471
            if (prepareProto(p) && prepareProjectConfig(p)) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   472
                File configScript = getConfig_Script(p);
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   473
                if (configScript.exists()) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   474
                    Log.info(MessageFormat.format(
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   475
                            getString("message.running-wsh-script"),
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   476
                            configScript.getAbsolutePath()));
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   477
                    IOUtils.run("wscript", configScript, VERBOSE.fetchFrom(p));
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
                return buildEXE(p, outdir);
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   480
            }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   481
            return null;
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   482
        } catch (IOException ex) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   483
            ex.printStackTrace();
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   484
            return null;
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   485
        } finally {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   486
            try {
56947
5a03c4524b90 JDK-8211857: Support "exe" format for create-jre-installers
herrick
parents: 56941
diff changeset
   487
                if (imageDir != null &&
5a03c4524b90 JDK-8211857: Support "exe" format for create-jre-installers
herrick
parents: 56941
diff changeset
   488
                        PREDEFINED_APP_IMAGE.fetchFrom(p) == null &&
5a03c4524b90 JDK-8211857: Support "exe" format for create-jre-installers
herrick
parents: 56941
diff changeset
   489
                        (PREDEFINED_RUNTIME_IMAGE.fetchFrom(p) == null ||
5a03c4524b90 JDK-8211857: Support "exe" format for create-jre-installers
herrick
parents: 56941
diff changeset
   490
                        !Arguments.CREATE_JRE_INSTALLER.fetchFrom(p)) &&
5a03c4524b90 JDK-8211857: Support "exe" format for create-jre-installers
herrick
parents: 56941
diff changeset
   491
                        !Log.isDebug()) {
56941
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   492
                    IOUtils.deleteRecursive(imageDir);
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   493
                } else if (imageDir != null) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   494
                    Log.info(MessageFormat.format(
56947
5a03c4524b90 JDK-8211857: Support "exe" format for create-jre-installers
herrick
parents: 56941
diff changeset
   495
                            I18N.getString("message.debug-working-directory"),
56941
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   496
                            imageDir.getAbsolutePath()));
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   497
                }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   498
            } catch (IOException ex) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   499
                // noinspection ReturnInsideFinallyBlock
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   500
                Log.debug(ex.getMessage());
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   501
                return null;
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   502
            }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   503
        }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   504
    }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   505
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   506
    // name of post-image script
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   507
    private File getConfig_Script(Map<String, ? super Object> p) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   508
        return new File(EXE_IMAGE_DIR.fetchFrom(p),
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   509
                APP_NAME.fetchFrom(p) + "-post-image.wsf");
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
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   512
    private String getAppIdentifier(Map<String, ? super Object> p) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   513
        String nm = IDENTIFIER.fetchFrom(p);
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   514
56947
5a03c4524b90 JDK-8211857: Support "exe" format for create-jre-installers
herrick
parents: 56941
diff changeset
   515
        if (nm == null) {
5a03c4524b90 JDK-8211857: Support "exe" format for create-jre-installers
herrick
parents: 56941
diff changeset
   516
            nm = APP_NAME.fetchFrom(p);
5a03c4524b90 JDK-8211857: Support "exe" format for create-jre-installers
herrick
parents: 56941
diff changeset
   517
        }
5a03c4524b90 JDK-8211857: Support "exe" format for create-jre-installers
herrick
parents: 56941
diff changeset
   518
5a03c4524b90 JDK-8211857: Support "exe" format for create-jre-installers
herrick
parents: 56941
diff changeset
   519
        // limitation of innosetup
5a03c4524b90 JDK-8211857: Support "exe" format for create-jre-installers
herrick
parents: 56941
diff changeset
   520
        if (nm.length() > 126) {
5a03c4524b90 JDK-8211857: Support "exe" format for create-jre-installers
herrick
parents: 56941
diff changeset
   521
            Log.info(getString("message-truncating-id"));
56941
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   522
            nm = nm.substring(0, 126);
56947
5a03c4524b90 JDK-8211857: Support "exe" format for create-jre-installers
herrick
parents: 56941
diff changeset
   523
        }
56941
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   524
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   525
        return nm;
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
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   528
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   529
    private String getLicenseFile(Map<String, ? super Object> p) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   530
        List<String> licenseFiles = LICENSE_FILE.fetchFrom(p);
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   531
        if (licenseFiles == null || licenseFiles.isEmpty()) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   532
            return "";
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   533
        } else {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   534
            return licenseFiles.get(0);
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   535
        }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   536
    }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   537
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   538
    void validateValueAndPut(Map<String, String> data, String key,
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   539
                BundlerParamInfo<String> param,
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   540
                Map<String, ? super Object> p) throws IOException {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   541
        String value = param.fetchFrom(p);
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   542
        if (value.contains("\r") || value.contains("\n")) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   543
            throw new IOException("Configuration Parameter " +
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   544
                     param.getID() + " cannot contain multiple lines of text");
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   545
        }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   546
        data.put(key, innosetupEscape(value));
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   547
    }
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
    private String innosetupEscape(String value) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   550
        if (value.contains("\"") || !value.trim().equals(value)) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   551
            value = "\"" + value.replace("\"", "\"\"") + "\"";
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   552
        }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   553
        return value;
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   554
    }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   555
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   556
    boolean prepareMainProjectFile(Map<String, ? super Object> p)
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   557
            throws IOException {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   558
        Map<String, String> data = new HashMap<>();
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   559
        data.put("PRODUCT_APP_IDENTIFIER",
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   560
                innosetupEscape(getAppIdentifier(p)));
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   561
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   562
57013
0ece1b6f0958 8213163: --app-image arg does not work creating exe installers
herrick
parents: 57011
diff changeset
   563
        validateValueAndPut(data, "INSTALLER_NAME", APP_NAME, p);
56941
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   564
        validateValueAndPut(data, "APPLICATION_VENDOR", VENDOR, p);
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   565
        validateValueAndPut(data, "APPLICATION_VERSION", VERSION, p);
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   566
        validateValueAndPut(data, "INSTALLER_FILE_NAME",
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   567
                INSTALLER_FILE_NAME, p);
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   568
57013
0ece1b6f0958 8213163: --app-image arg does not work creating exe installers
herrick
parents: 57011
diff changeset
   569
        data.put("LAUNCHER_NAME",
0ece1b6f0958 8213163: --app-image arg does not work creating exe installers
herrick
parents: 57011
diff changeset
   570
                innosetupEscape(WinAppBundler.getAppName(p)));
0ece1b6f0958 8213163: --app-image arg does not work creating exe installers
herrick
parents: 57011
diff changeset
   571
56941
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   572
        data.put("APPLICATION_LAUNCHER_FILENAME",
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   573
                innosetupEscape(WinAppBundler.getLauncherName(p)));
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   574
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   575
        data.put("APPLICATION_DESKTOP_SHORTCUT",
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   576
                SHORTCUT_HINT.fetchFrom(p) ? "returnTrue" : "returnFalse");
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   577
        data.put("APPLICATION_MENU_SHORTCUT",
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   578
                MENU_HINT.fetchFrom(p) ? "returnTrue" : "returnFalse");
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   579
        validateValueAndPut(data, "APPLICATION_GROUP", MENU_GROUP, p);
56947
5a03c4524b90 JDK-8211857: Support "exe" format for create-jre-installers
herrick
parents: 56941
diff changeset
   580
        validateValueAndPut(data, "APPLICATION_COMMENTS", TITLE, p);
56941
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   581
        validateValueAndPut(data, "APPLICATION_COPYRIGHT", COPYRIGHT, p);
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   582
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   583
        data.put("APPLICATION_LICENSE_FILE",
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   584
                innosetupEscape(getLicenseFile(p)));
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   585
        data.put("DISABLE_DIR_PAGE",
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   586
                INSTALLDIR_CHOOSER.fetchFrom(p) ? "No" : "Yes");
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   587
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   588
        Boolean isSystemWide = EXE_SYSTEM_WIDE.fetchFrom(p);
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   589
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   590
        if (isSystemWide) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   591
            data.put("APPLICATION_INSTALL_ROOT", "{pf}");
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   592
            data.put("APPLICATION_INSTALL_PRIVILEGE", "admin");
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   593
        } else {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   594
            data.put("APPLICATION_INSTALL_ROOT", "{localappdata}");
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   595
            data.put("APPLICATION_INSTALL_PRIVILEGE", "lowest");
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
        if (BIT_ARCH_64.fetchFrom(p)) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   599
            data.put("ARCHITECTURE_BIT_MODE", "x64");
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   600
        } else {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   601
            data.put("ARCHITECTURE_BIT_MODE", "");
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   602
        }
56982
e094d5483bd6 8212048: Cleanup source code and fix issues discussed in preliminary review
herrick
parents: 56947
diff changeset
   603
        validateValueAndPut(data, "RUN_FILENAME", APP_NAME, p);
56941
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
        validateValueAndPut(data, "APPLICATION_DESCRIPTION",
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   606
                DESCRIPTION, p);
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   607
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   608
        data.put("APPLICATION_SERVICE", "returnFalse");
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   609
        data.put("APPLICATION_NOT_SERVICE", "returnFalse");
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   610
        data.put("APPLICATION_APP_CDS_INSTALL", "returnFalse");
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   611
        data.put("START_ON_INSTALL", "");
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   612
        data.put("STOP_ON_UNINSTALL", "");
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   613
        data.put("RUN_AT_STARTUP", "");
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   614
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   615
        StringBuilder secondaryLaunchersCfg = new StringBuilder();
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   616
        for (Map<String, ? super Object>
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   617
                launcher : SECONDARY_LAUNCHERS.fetchFrom(p)) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   618
            String application_name = APP_NAME.fetchFrom(launcher);
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   619
            if (MENU_HINT.fetchFrom(launcher)) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   620
                // Name: "{group}\APPLICATION_NAME";
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   621
                // Filename: "{app}\APPLICATION_NAME.exe";
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   622
                // IconFilename: "{app}\APPLICATION_NAME.ico"
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   623
                secondaryLaunchersCfg.append("Name: \"{group}\\");
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   624
                secondaryLaunchersCfg.append(application_name);
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   625
                secondaryLaunchersCfg.append("\"; Filename: \"{app}\\");
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   626
                secondaryLaunchersCfg.append(application_name);
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   627
                secondaryLaunchersCfg.append(".exe\"; IconFilename: \"{app}\\");
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   628
                secondaryLaunchersCfg.append(application_name);
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   629
                secondaryLaunchersCfg.append(".ico\"\r\n");
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   630
            }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   631
            if (SHORTCUT_HINT.fetchFrom(launcher)) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   632
                // Name: "{commondesktop}\APPLICATION_NAME";
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   633
                // Filename: "{app}\APPLICATION_NAME.exe";
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   634
                // IconFilename: "{app}\APPLICATION_NAME.ico"
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   635
                secondaryLaunchersCfg.append("Name: \"{commondesktop}\\");
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   636
                secondaryLaunchersCfg.append(application_name);
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   637
                secondaryLaunchersCfg.append("\"; Filename: \"{app}\\");
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   638
                secondaryLaunchersCfg.append(application_name);
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   639
                secondaryLaunchersCfg.append(".exe\";  IconFilename: \"{app}\\");
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   640
                secondaryLaunchersCfg.append(application_name);
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   641
                secondaryLaunchersCfg.append(".ico\"\r\n");
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   642
            }
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
        data.put("SECONDARY_LAUNCHERS", secondaryLaunchersCfg.toString());
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   645
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   646
        StringBuilder registryEntries = new StringBuilder();
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   647
        String regName = APP_REGISTRY_NAME.fetchFrom(p);
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   648
        List<Map<String, ? super Object>> fetchFrom =
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   649
                FILE_ASSOCIATIONS.fetchFrom(p);
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   650
        for (int i = 0; i < fetchFrom.size(); i++) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   651
            Map<String, ? super Object> fileAssociation = fetchFrom.get(i);
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   652
            String description = FA_DESCRIPTION.fetchFrom(fileAssociation);
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   653
            File icon = FA_ICON.fetchFrom(fileAssociation); //TODO FA_ICON_ICO
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   654
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   655
            List<String> extensions = FA_EXTENSIONS.fetchFrom(fileAssociation);
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   656
            String entryName = regName + "File";
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   657
            if (i > 0) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   658
                entryName += "." + i;
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   659
            }
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
            if (extensions == null) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   662
                Log.info(getString(
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   663
                        "message.creating-association-with-null-extension"));
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   664
            } else {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   665
                for (String ext : extensions) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   666
                    if (isSystemWide) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   667
                        // "Root: HKCR; Subkey: \".myp\";
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   668
                        // ValueType: string; ValueName: \"\";
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   669
                        // ValueData: \"MyProgramFile\";
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   670
                        // Flags: uninsdeletevalue"
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   671
                        registryEntries.append("Root: HKCR; Subkey: \".")
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   672
                                .append(ext)
56982
e094d5483bd6 8212048: Cleanup source code and fix issues discussed in preliminary review
herrick
parents: 56947
diff changeset
   673
                                .append("\"; ValueType: string;"
e094d5483bd6 8212048: Cleanup source code and fix issues discussed in preliminary review
herrick
parents: 56947
diff changeset
   674
                                + " ValueName: \"\"; ValueData: \"")
56941
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   675
                                .append(entryName)
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   676
                                .append("\"; Flags: uninsdeletevalue\r\n");
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   677
                    } else {
56982
e094d5483bd6 8212048: Cleanup source code and fix issues discussed in preliminary review
herrick
parents: 56947
diff changeset
   678
                        registryEntries.append(
e094d5483bd6 8212048: Cleanup source code and fix issues discussed in preliminary review
herrick
parents: 56947
diff changeset
   679
                                "Root: HKCU; Subkey: \"Software\\Classes\\.")
56941
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   680
                                .append(ext)
56982
e094d5483bd6 8212048: Cleanup source code and fix issues discussed in preliminary review
herrick
parents: 56947
diff changeset
   681
                                .append("\"; ValueType: string;"
e094d5483bd6 8212048: Cleanup source code and fix issues discussed in preliminary review
herrick
parents: 56947
diff changeset
   682
                                + " ValueName: \"\"; ValueData: \"")
56941
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   683
                                .append(entryName)
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   684
                                .append("\"; Flags: uninsdeletevalue\r\n");
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   685
                    }
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
            }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   688
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   689
            if (extensions != null && !extensions.isEmpty()) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   690
                String ext = extensions.get(0);
56982
e094d5483bd6 8212048: Cleanup source code and fix issues discussed in preliminary review
herrick
parents: 56947
diff changeset
   691
                List<String> mimeTypes =
e094d5483bd6 8212048: Cleanup source code and fix issues discussed in preliminary review
herrick
parents: 56947
diff changeset
   692
                        FA_CONTENT_TYPE.fetchFrom(fileAssociation);
56941
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   693
                for (String mime : mimeTypes) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   694
                    if (isSystemWide) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   695
                        // "Root: HKCR;
56982
e094d5483bd6 8212048: Cleanup source code and fix issues discussed in preliminary review
herrick
parents: 56947
diff changeset
   696
                        // Subkey: HKCR\\Mime\\Database\\
e094d5483bd6 8212048: Cleanup source code and fix issues discussed in preliminary review
herrick
parents: 56947
diff changeset
   697
                        //         Content Type\\application/chaos;
56941
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   698
                        // ValueType: string;
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   699
                        // ValueName: Extension;
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   700
                        // ValueData: .chaos;
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   701
                        // Flags: uninsdeletevalue"
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   702
                        registryEntries.append("Root: HKCR; Subkey: " +
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   703
                                 "\"Mime\\Database\\Content Type\\")
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   704
                            .append(mime)
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   705
                            .append("\"; ValueType: string; ValueName: " +
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   706
                                 "\"Extension\"; ValueData: \".")
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   707
                            .append(ext)
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   708
                            .append("\"; Flags: uninsdeletevalue\r\n");
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   709
                    } else {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   710
                        registryEntries.append(
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   711
                                "Root: HKCU; Subkey: \"Software\\" +
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   712
                                "Classes\\Mime\\Database\\Content Type\\")
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   713
                                .append(mime)
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   714
                                .append("\"; ValueType: string; " +
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   715
                                "ValueName: \"Extension\"; ValueData: \".")
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   716
                                .append(ext)
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   717
                                .append("\"; Flags: uninsdeletevalue\r\n");
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   718
                    }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   719
                }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   720
            }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   721
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   722
            if (isSystemWide) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   723
                // "Root: HKCR;
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   724
                // Subkey: \"MyProgramFile\";
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   725
                // ValueType: string;
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   726
                // ValueName: \"\";
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   727
                // ValueData: \"My Program File\";
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   728
                // Flags: uninsdeletekey"
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   729
                registryEntries.append("Root: HKCR; Subkey: \"")
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   730
                    .append(entryName)
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   731
                    .append(
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   732
                    "\"; ValueType: string; ValueName: \"\"; ValueData: \"")
57011
7df1e4bf870a 8213162: Association description in Inno Setup cannot contain double quotes
herrick
parents: 56989
diff changeset
   733
                    .append(removeQuotes(description))
56941
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   734
                    .append("\"; Flags: uninsdeletekey\r\n");
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   735
            } else {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   736
                registryEntries.append(
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   737
                    "Root: HKCU; Subkey: \"Software\\Classes\\")
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   738
                    .append(entryName)
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   739
                    .append(
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   740
                    "\"; ValueType: string; ValueName: \"\"; ValueData: \"")
57011
7df1e4bf870a 8213162: Association description in Inno Setup cannot contain double quotes
herrick
parents: 56989
diff changeset
   741
                    .append(removeQuotes(description))
56941
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   742
                    .append("\"; Flags: uninsdeletekey\r\n");
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   743
            }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   744
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   745
            if (icon != null && icon.exists()) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   746
                if (isSystemWide) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   747
                    // "Root: HKCR;
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   748
                    // Subkey: \"MyProgramFile\\DefaultIcon\";
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   749
                    // ValueType: string;
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   750
                    // ValueName: \"\";
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   751
                    // ValueData: \"{app}\\MYPROG.EXE,0\"\n" +
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   752
                    registryEntries.append("Root: HKCR; Subkey: \"")
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   753
                            .append(entryName)
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   754
                            .append("\\DefaultIcon\"; ValueType: string; " +
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   755
                            "ValueName: \"\"; ValueData: \"{app}\\")
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   756
                            .append(icon.getName())
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   757
                            .append("\"\r\n");
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   758
                } else {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   759
                    registryEntries.append(
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   760
                            "Root: HKCU; Subkey: \"Software\\Classes\\")
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   761
                            .append(entryName)
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   762
                            .append("\\DefaultIcon\"; ValueType: string; " +
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   763
                            "ValueName: \"\"; ValueData: \"{app}\\")
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   764
                            .append(icon.getName())
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   765
                            .append("\"\r\n");
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   766
                }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   767
            }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   768
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   769
            if (isSystemWide) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   770
                // "Root: HKCR;
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   771
                // Subkey: \"MyProgramFile\\shell\\open\\command\";
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   772
                // ValueType: string;
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   773
                // ValueName: \"\";
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   774
                // ValueData: \"\"\"{app}\\MYPROG.EXE\"\" \"\"%1\"\"\"\n"
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   775
                registryEntries.append("Root: HKCR; Subkey: \"")
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   776
                        .append(entryName)
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   777
                        .append("\\shell\\open\\command\"; ValueType: " +
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   778
                        "string; ValueName: \"\"; ValueData: \"\"\"{app}\\")
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   779
                        .append(APP_NAME.fetchFrom(p))
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   780
                        .append("\"\" \"\"%1\"\"\"\r\n");
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   781
            } else {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   782
                registryEntries.append(
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   783
                        "Root: HKCU; Subkey: \"Software\\Classes\\")
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   784
                        .append(entryName)
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   785
                        .append("\\shell\\open\\command\"; ValueType: " +
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   786
                        "string; ValueName: \"\"; ValueData: \"\"\"{app}\\")
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   787
                        .append(APP_NAME.fetchFrom(p))
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   788
                        .append("\"\" \"\"%1\"\"\"\r\n");
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   789
            }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   790
        }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   791
        if (registryEntries.length() > 0) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   792
            data.put("FILE_ASSOCIATIONS",
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   793
                    "ChangesAssociations=yes\r\n\r\n[Registry]\r\n" +
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   794
                    registryEntries.toString());
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   795
        } else {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   796
            data.put("FILE_ASSOCIATIONS", "");
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   797
        }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   798
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   799
        // TODO - alternate template for JRE installer
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   800
        String iss = Arguments.CREATE_JRE_INSTALLER.fetchFrom(p) ?
56947
5a03c4524b90 JDK-8211857: Support "exe" format for create-jre-installers
herrick
parents: 56941
diff changeset
   801
                DEFAULT_JRE_EXE_TEMPLATE : DEFAULT_EXE_PROJECT_TEMPLATE;
56941
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   802
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   803
        Writer w = new BufferedWriter(new FileWriter(
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   804
                getConfig_ExeProjectFile(p)));
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   805
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   806
        String content = preprocessTextResource(
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   807
                WinAppBundler.WIN_BUNDLER_PREFIX +
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   808
                getConfig_ExeProjectFile(p).getName(),
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   809
                getString("resource.inno-setup-project-file"),
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   810
                iss, data, VERBOSE.fetchFrom(p),
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   811
                DROP_IN_RESOURCES_ROOT.fetchFrom(p));
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   812
        w.write(content);
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   813
        w.close();
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   814
        return true;
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   815
    }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   816
57011
7df1e4bf870a 8213162: Association description in Inno Setup cannot contain double quotes
herrick
parents: 56989
diff changeset
   817
    private final static String removeQuotes(String s) {
7df1e4bf870a 8213162: Association description in Inno Setup cannot contain double quotes
herrick
parents: 56989
diff changeset
   818
        if (s.length() > 2 && s.startsWith("\"") && s.endsWith("\"")) {
7df1e4bf870a 8213162: Association description in Inno Setup cannot contain double quotes
herrick
parents: 56989
diff changeset
   819
            // special case for '"XXX"' return 'XXX' not '-XXX-'
7df1e4bf870a 8213162: Association description in Inno Setup cannot contain double quotes
herrick
parents: 56989
diff changeset
   820
            // note '"' and '""' are excluded from this special case
7df1e4bf870a 8213162: Association description in Inno Setup cannot contain double quotes
herrick
parents: 56989
diff changeset
   821
            s = s.substring(1, s.length() - 1);
7df1e4bf870a 8213162: Association description in Inno Setup cannot contain double quotes
herrick
parents: 56989
diff changeset
   822
        }
7df1e4bf870a 8213162: Association description in Inno Setup cannot contain double quotes
herrick
parents: 56989
diff changeset
   823
        // if there interior double quotes replace them with '-'
7df1e4bf870a 8213162: Association description in Inno Setup cannot contain double quotes
herrick
parents: 56989
diff changeset
   824
        return s.replaceAll("\"", "-");
7df1e4bf870a 8213162: Association description in Inno Setup cannot contain double quotes
herrick
parents: 56989
diff changeset
   825
    }
7df1e4bf870a 8213162: Association description in Inno Setup cannot contain double quotes
herrick
parents: 56989
diff changeset
   826
        
56941
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   827
    private final static String DEFAULT_INNO_SETUP_ICON =
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   828
            "icon_inno_setup.bmp";
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   829
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   830
    private boolean prepareProjectConfig(Map<String, ? super Object> p)
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   831
            throws IOException {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   832
        prepareMainProjectFile(p);
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   833
56982
e094d5483bd6 8212048: Cleanup source code and fix issues discussed in preliminary review
herrick
parents: 56947
diff changeset
   834
        // prepare installer icon
56941
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   835
        File iconTarget = getConfig_SmallInnoSetupIcon(p);
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   836
        fetchResource(WinAppBundler.WIN_BUNDLER_PREFIX + iconTarget.getName(),
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   837
                getString("resource.setup-icon"),
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   838
                DEFAULT_INNO_SETUP_ICON,
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   839
                iconTarget,
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   840
                VERBOSE.fetchFrom(p),
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   841
                DROP_IN_RESOURCES_ROOT.fetchFrom(p));
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   842
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   843
        fetchResource(WinAppBundler.WIN_BUNDLER_PREFIX +
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   844
                getConfig_Script(p).getName(),
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   845
                getString("resource.post-install-script"),
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   846
                (String) null,
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   847
                getConfig_Script(p),
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   848
                VERBOSE.fetchFrom(p),
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   849
                DROP_IN_RESOURCES_ROOT.fetchFrom(p));
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   850
        return true;
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   851
    }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   852
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   853
    private File getConfig_SmallInnoSetupIcon(
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   854
            Map<String, ? super Object> p) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   855
        return new File(EXE_IMAGE_DIR.fetchFrom(p),
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   856
                APP_NAME.fetchFrom(p) + "-setup-icon.bmp");
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
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   859
    private File getConfig_ExeProjectFile(Map<String, ? super Object> p) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   860
        return new File(EXE_IMAGE_DIR.fetchFrom(p),
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   861
                APP_NAME.fetchFrom(p) + ".iss");
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   862
    }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   863
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
    private File buildEXE(Map<String, ? super Object> p, File outdir)
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   866
             throws IOException {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   867
        Log.verbose(MessageFormat.format(
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   868
             getString("message.outputting-to-location"),
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   869
             outdir.getAbsolutePath()));
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   870
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   871
        outdir.mkdirs();
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   872
56982
e094d5483bd6 8212048: Cleanup source code and fix issues discussed in preliminary review
herrick
parents: 56947
diff changeset
   873
        // run Inno Setup
56941
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   874
        ProcessBuilder pb = new ProcessBuilder(
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   875
                TOOL_INNO_SETUP_COMPILER_EXECUTABLE.fetchFrom(p),
56982
e094d5483bd6 8212048: Cleanup source code and fix issues discussed in preliminary review
herrick
parents: 56947
diff changeset
   876
                "/q",    // turn off inno setup output
56941
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   877
                "/o"+outdir.getAbsolutePath(),
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   878
                getConfig_ExeProjectFile(p).getAbsolutePath());
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   879
        pb = pb.directory(EXE_IMAGE_DIR.fetchFrom(p));
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   880
        IOUtils.exec(pb, VERBOSE.fetchFrom(p));
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   881
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   882
        Log.info(MessageFormat.format(
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   883
                getString("message.output-location"),
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   884
                outdir.getAbsolutePath()));
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   885
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   886
        // 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
   887
        // not the best solution, but it is the most reliable
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   888
        File result = null;
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   889
        long lastModified = 0;
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   890
        File[] list = outdir.listFiles();
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   891
        if (list != null) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   892
            for (File f : list) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   893
                if (f.getName().endsWith(".exe") &&
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   894
                        f.lastModified() > lastModified) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   895
                    result = f;
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   896
                    lastModified = f.lastModified();
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   897
                }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   898
            }
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
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   901
        return result;
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   902
    }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   903
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   904
   public static void ensureByMutationFileIsRTF(File f) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   905
        if (f == null || !f.isFile()) return;
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   906
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   907
        try {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   908
            boolean existingLicenseIsRTF = false;
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
            try (FileInputStream fin = new FileInputStream(f)) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   911
                byte[] firstBits = new byte[7];
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   912
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   913
                if (fin.read(firstBits) == firstBits.length) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   914
                    String header = new String(firstBits);
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   915
                    existingLicenseIsRTF = "{\\rtf1\\".equals(header);
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   916
                }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   917
            }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   918
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   919
            if (!existingLicenseIsRTF) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   920
                List<String> oldLicense = Files.readAllLines(f.toPath());
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   921
                try (Writer w = Files.newBufferedWriter(
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   922
                        f.toPath(), Charset.forName("Windows-1252"))) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   923
                    w.write("{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang1033"
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   924
                            + "{\\fonttbl{\\f0\\fnil\\fcharset0 Arial;}}\n"
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   925
                            + "\\viewkind4\\uc1\\pard\\sa200\\sl276"
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   926
                            + "\\slmult1\\lang9\\fs20 ");
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   927
                    oldLicense.forEach(l -> {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   928
                        try {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   929
                            for (char c : l.toCharArray()) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   930
                                if (c < 0x10) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   931
                                    w.write("\\'0");
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   932
                                    w.write(Integer.toHexString(c));
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   933
                                } else if (c > 0xff) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   934
                                    w.write("\\ud");
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   935
                                    w.write(Integer.toString(c));
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   936
                                    w.write("?");
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   937
                                } else if ((c < 0x20) || (c >= 0x80) ||
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   938
                                        (c == 0x5C) || (c == 0x7B) ||
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   939
                                        (c == 0x7D)) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   940
                                    w.write("\\'");
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   941
                                    w.write(Integer.toHexString(c));
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   942
                                } else {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   943
                                    w.write(c);
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   944
                                }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   945
                            }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   946
                            if (l.length() < 1) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   947
                                w.write("\\par");
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   948
                            } else {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   949
                                w.write(" ");
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   950
                            }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   951
                            w.write("\r\n");
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   952
                        } catch (IOException e) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   953
                            Log.verbose(e);
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
                    w.write("}\r\n");
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   957
                }
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
        } catch (IOException e) {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   960
            Log.verbose(e);
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   961
        }
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
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   964
    private static String getString(String key)
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   965
            throws MissingResourceException {
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   966
        return I18N.getString(key);
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   967
    }
20568f1e1aa7 JDK-8211282: Support creation of 'exe' installers on Windows.
herrick
parents:
diff changeset
   968
}