src/jdk.jpackage/share/classes/jdk/jpackage/internal/Arguments.java
author herrick
Wed, 06 Feb 2019 09:10:12 -0500
branchJDK-8200758-branch
changeset 57151 38d0b67617e3
parent 57150 fa68c2ab636d
child 57192 3d6a21f41c10
permissions -rw-r--r--
8217317: Create jpackage native library for windows Submitten-by: almatvee Reviewed-by: herrick, ihse
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
     1
/*
57106
ea870b9ce89a 8216492: Update copyright of all new jpackage fils to 2019
kcr
parents: 57103
diff changeset
     2
 * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
     4
 *
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    10
 *
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    15
 * accompanied this code).
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    16
 *
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    20
 *
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    23
 * questions.
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    24
 */
57039
98d3963b0b7b 8214051: rename jpackager tool to jpackage
herrick
parents: 57038
diff changeset
    25
package jdk.jpackage.internal;
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    26
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    27
import java.io.File;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    28
import java.io.FileInputStream;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    29
import java.io.IOException;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    30
import java.nio.file.Files;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    31
import java.nio.file.Path;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    32
import java.text.MessageFormat;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    33
import java.util.ArrayList;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    34
import java.util.Arrays;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    35
import java.util.Collection;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    36
import java.util.EnumSet;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    37
import java.util.HashMap;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    38
import java.util.HashSet;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    39
import java.util.List;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    40
import java.util.Map;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    41
import java.util.Set;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    42
import java.util.Properties;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    43
import java.util.ResourceBundle;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    44
import java.util.jar.Attributes;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    45
import java.util.jar.JarFile;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    46
import java.util.jar.Manifest;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    47
import java.util.stream.Stream;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    48
import java.util.regex.Matcher;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    49
import java.util.regex.Pattern;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    50
56994
b4aca2dbe2b5 8212537: Create method and class description comments for main functionality
herrick
parents: 56989
diff changeset
    51
/**
b4aca2dbe2b5 8212537: Create method and class description comments for main functionality
herrick
parents: 56989
diff changeset
    52
 * Arguments
b4aca2dbe2b5 8212537: Create method and class description comments for main functionality
herrick
parents: 56989
diff changeset
    53
 *
b4aca2dbe2b5 8212537: Create method and class description comments for main functionality
herrick
parents: 56989
diff changeset
    54
 * This class encapsulates and processes the command line arguments,
57039
98d3963b0b7b 8214051: rename jpackager tool to jpackage
herrick
parents: 57038
diff changeset
    55
 * in effect, implementing all the work of jpackage tool.
56994
b4aca2dbe2b5 8212537: Create method and class description comments for main functionality
herrick
parents: 56989
diff changeset
    56
 *
b4aca2dbe2b5 8212537: Create method and class description comments for main functionality
herrick
parents: 56989
diff changeset
    57
 * The primary entry point, processArguments():
b4aca2dbe2b5 8212537: Create method and class description comments for main functionality
herrick
parents: 56989
diff changeset
    58
 * Processes and validates command line arguments, constructing DeployParams.
b4aca2dbe2b5 8212537: Create method and class description comments for main functionality
herrick
parents: 56989
diff changeset
    59
 * Validates the DeployParams, and generate the BundleParams.
b4aca2dbe2b5 8212537: Create method and class description comments for main functionality
herrick
parents: 56989
diff changeset
    60
 * Generates List of Bundlers from BundleParams valid for this platform.
b4aca2dbe2b5 8212537: Create method and class description comments for main functionality
herrick
parents: 56989
diff changeset
    61
 * Executes each Bundler in the list.
b4aca2dbe2b5 8212537: Create method and class description comments for main functionality
herrick
parents: 56989
diff changeset
    62
 */
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    63
public class Arguments {
56869
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56836
diff changeset
    64
    private static final ResourceBundle I18N = ResourceBundle.getBundle(
57059
9bb2a4dc3af7 8214143: Reduce Resource files
herrick
parents: 57039
diff changeset
    65
            "jdk.jpackage.internal.resources.MainResources");
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    66
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    67
    private static final String IMAGE_MODE = "image";
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    68
    private static final String INSTALLER_MODE = "installer";
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    69
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    70
    private static final String FA_EXTENSIONS = "extension";
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    71
    private static final String FA_CONTENT_TYPE = "mime-type";
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    72
    private static final String FA_DESCRIPTION = "description";
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    73
    private static final String FA_ICON = "icon";
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    74
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    75
    public static final BundlerParamInfo<Boolean> CREATE_IMAGE =
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    76
            new StandardBundlerParam<>(
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    77
                    I18N.getString("param.create-image.name"),
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    78
                    I18N.getString("param.create-image.description"),
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    79
                    IMAGE_MODE,
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    80
                    Boolean.class,
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    81
                    p -> Boolean.FALSE,
56869
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56836
diff changeset
    82
                    (s, p) -> (s == null || "null".equalsIgnoreCase(s)) ?
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56836
diff changeset
    83
                            true : Boolean.valueOf(s));
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    84
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    85
    public static final BundlerParamInfo<Boolean> CREATE_INSTALLER =
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    86
            new StandardBundlerParam<>(
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    87
                    I18N.getString("param.create-installer.name"),
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    88
                    I18N.getString("param.create-installer.description"),
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    89
                    INSTALLER_MODE,
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    90
                    Boolean.class,
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    91
                    p -> Boolean.FALSE,
56869
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56836
diff changeset
    92
                    (s, p) -> (s == null || "null".equalsIgnoreCase(s)) ?
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56836
diff changeset
    93
                            true : Boolean.valueOf(s));
56957
2f01969ed7cb 8211299: Output of System.out is not printed to CMD on Windows
herrick
parents: 56933
diff changeset
    94
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    95
    // regexp for parsing args (for example, for secondary launchers)
56869
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56836
diff changeset
    96
    private static Pattern pattern = Pattern.compile(
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56836
diff changeset
    97
          "(?:(?:([\"'])(?:\\\\\\1|.)*?(?:\\1|$))|(?:\\\\[\"'\\s]|[^\\s]))++");
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    98
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    99
    private DeployParams deployParams = null;
56994
b4aca2dbe2b5 8212537: Create method and class description comments for main functionality
herrick
parents: 56989
diff changeset
   100
    private BundlerType bundleType = null;
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   101
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   102
    private int pos = 0;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   103
    private List<String> argList = null;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   104
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   105
    private List<CLIOptions> allOptions = null;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   106
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   107
    private ArrayList<String> files = null;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   108
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   109
    private String input = null;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   110
    private String output = null;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   111
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   112
    private boolean hasMainJar = false;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   113
    private boolean hasMainClass = false;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   114
    private boolean hasMainModule = false;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   115
    private boolean hasTargetFormat = false;
56882
0ec8559f599a 8210439: Unable to create an installer from a previously created app image on Windows
herrick
parents: 56869
diff changeset
   116
    private boolean hasAppImage = false;
57151
38d0b67617e3 8217317: Create jpackage native library for windows
herrick
parents: 57150
diff changeset
   117
    public boolean userProvidedBuildRoot = false;
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   118
57108
f1c13cb0e713 8217269: jpackage Makefile improvments
herrick
parents: 57106
diff changeset
   119
    private String buildRoot = null;
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   120
    private String mainJarPath = null;
56957
2f01969ed7cb 8211299: Output of System.out is not printed to CMD on Windows
herrick
parents: 56933
diff changeset
   121
57150
fa68c2ab636d 8217894: jpackage CLI syntax changes
herrick
parents: 57140
diff changeset
   122
    private static boolean runtimeInstaller = false;
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   123
57039
98d3963b0b7b 8214051: rename jpackager tool to jpackage
herrick
parents: 57038
diff changeset
   124
    private List<jdk.jpackage.internal.Bundler> platformBundlers = null;
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   125
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   126
    private List<SecondaryLauncherArguments> secondaryLaunchers = null;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   127
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   128
    private static Map<String, CLIOptions> argIds = new HashMap<>();
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   129
    private static Map<String, CLIOptions> argShortIds = new HashMap<>();
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   130
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   131
    {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   132
        // init maps for parsing arguments
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   133
        EnumSet<CLIOptions> options = EnumSet.allOf(CLIOptions.class);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   134
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   135
        options.forEach(option -> {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   136
            argIds.put(option.getIdWithPrefix(), option);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   137
            if (option.getShortIdWithPrefix() != null) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   138
                argShortIds.put(option.getShortIdWithPrefix(), option);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   139
            }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   140
        });
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   141
    }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   142
57140
3dcb33ce7ced 8217751: jpackage messages and failures
herrick
parents: 57119
diff changeset
   143
    public Arguments(String[] args) throws PackagerException {
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   144
        initArgumentList(args);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   145
    }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   146
57067
9c17d779808e 8213425: Analyze output from Source code scanner and fix where needed.
herrick
parents: 57065
diff changeset
   147
    // CLIOptions is public for DeployParamsTest
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   148
    public enum CLIOptions {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   149
        CREATE_IMAGE(IMAGE_MODE, OptionCategories.MODE, () -> {
56994
b4aca2dbe2b5 8212537: Create method and class description comments for main functionality
herrick
parents: 56989
diff changeset
   150
            context().bundleType = BundlerType.IMAGE;
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   151
            context().deployParams.setTargetFormat("image");
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   152
            setOptionValue(IMAGE_MODE, true);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   153
        }),
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   154
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   155
        CREATE_INSTALLER(INSTALLER_MODE, OptionCategories.MODE, () -> {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   156
            setOptionValue(INSTALLER_MODE, true);
56994
b4aca2dbe2b5 8212537: Create method and class description comments for main functionality
herrick
parents: 56989
diff changeset
   157
            context().bundleType = BundlerType.INSTALLER;
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   158
            String format = "installer";
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   159
            context().deployParams.setTargetFormat(format);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   160
        }),
56957
2f01969ed7cb 8211299: Output of System.out is not printed to CMD on Windows
herrick
parents: 56933
diff changeset
   161
57150
fa68c2ab636d 8217894: jpackage CLI syntax changes
herrick
parents: 57140
diff changeset
   162
        RUNTIME_INSTALLER("runtime-installer",
fa68c2ab636d 8217894: jpackage CLI syntax changes
herrick
parents: 57140
diff changeset
   163
                OptionCategories.PROPERTY, () -> {
fa68c2ab636d 8217894: jpackage CLI syntax changes
herrick
parents: 57140
diff changeset
   164
            runtimeInstaller = true;
fa68c2ab636d 8217894: jpackage CLI syntax changes
herrick
parents: 57140
diff changeset
   165
            setOptionValue("runtime-installer", true);
fa68c2ab636d 8217894: jpackage CLI syntax changes
herrick
parents: 57140
diff changeset
   166
        }),
fa68c2ab636d 8217894: jpackage CLI syntax changes
herrick
parents: 57140
diff changeset
   167
fa68c2ab636d 8217894: jpackage CLI syntax changes
herrick
parents: 57140
diff changeset
   168
        INSTALLER_TYPE("installer-type", OptionCategories.PROPERTY, () -> {
fa68c2ab636d 8217894: jpackage CLI syntax changes
herrick
parents: 57140
diff changeset
   169
            String type = popArg();
fa68c2ab636d 8217894: jpackage CLI syntax changes
herrick
parents: 57140
diff changeset
   170
            context().deployParams.setTargetFormat(type);
fa68c2ab636d 8217894: jpackage CLI syntax changes
herrick
parents: 57140
diff changeset
   171
            context().hasTargetFormat = true;
fa68c2ab636d 8217894: jpackage CLI syntax changes
herrick
parents: 57140
diff changeset
   172
            setOptionValue("installer-type", type);
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   173
        }),
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   174
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   175
        INPUT ("input", "i", OptionCategories.PROPERTY, () -> {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   176
            context().input = popArg();
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   177
            setOptionValue("input", context().input);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   178
        }),
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   179
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   180
        OUTPUT ("output", "o", OptionCategories.PROPERTY, () -> {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   181
            context().output = popArg();
56994
b4aca2dbe2b5 8212537: Create method and class description comments for main functionality
herrick
parents: 56989
diff changeset
   182
            context().deployParams.setOutput(new File(context().output));
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   183
        }),
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   184
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   185
        DESCRIPTION ("description", "d", OptionCategories.PROPERTY),
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   186
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   187
        VENDOR ("vendor", OptionCategories.PROPERTY),
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   188
57150
fa68c2ab636d 8217894: jpackage CLI syntax changes
herrick
parents: 57140
diff changeset
   189
        APPCLASS ("main-class", "c", OptionCategories.PROPERTY, () -> {
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   190
            context().hasMainClass = true;
57150
fa68c2ab636d 8217894: jpackage CLI syntax changes
herrick
parents: 57140
diff changeset
   191
            setOptionValue("main-class", popArg());
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   192
        }),
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   193
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   194
        NAME ("name", "n", OptionCategories.PROPERTY),
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   195
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   196
        IDENTIFIER ("identifier", OptionCategories.PROPERTY),
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   197
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   198
        VERBOSE ("verbose", OptionCategories.PROPERTY, () -> {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   199
            setOptionValue("verbose", true);
56987
0d2ff0d6bb94 8211297: --verbose does not work with jpackager
herrick
parents: 56982
diff changeset
   200
            Log.setVerbose(true);
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   201
        }),
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   202
57150
fa68c2ab636d 8217894: jpackage CLI syntax changes
herrick
parents: 57140
diff changeset
   203
        OVERWRITE ("overwrite", OptionCategories.PROPERTY, () -> {
fa68c2ab636d 8217894: jpackage CLI syntax changes
herrick
parents: 57140
diff changeset
   204
            setOptionValue("overwrite", true);
57021
441c020bf626 8213324:jpackager deletes existing app directory without warning
herrick
parents: 57020
diff changeset
   205
        }),
441c020bf626 8213324:jpackager deletes existing app directory without warning
herrick
parents: 57020
diff changeset
   206
57091
06bc4bd64599 8215515: Add a command line option to override internal resources.
herrick
parents: 57071
diff changeset
   207
        RESOURCE_DIR("resource-dir",
06bc4bd64599 8215515: Add a command line option to override internal resources.
herrick
parents: 57071
diff changeset
   208
                OptionCategories.PROPERTY, () -> {
06bc4bd64599 8215515: Add a command line option to override internal resources.
herrick
parents: 57071
diff changeset
   209
            String resourceDir = popArg();
06bc4bd64599 8215515: Add a command line option to override internal resources.
herrick
parents: 57071
diff changeset
   210
            setOptionValue("resource-dir", resourceDir);
06bc4bd64599 8215515: Add a command line option to override internal resources.
herrick
parents: 57071
diff changeset
   211
        }),
57021
441c020bf626 8213324:jpackager deletes existing app directory without warning
herrick
parents: 57020
diff changeset
   212
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   213
        FILES ("files", "f", OptionCategories.PROPERTY, () -> {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   214
              context().files = new ArrayList<>();
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   215
              String files = popArg();
56869
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56836
diff changeset
   216
              context().files.addAll(
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56836
diff changeset
   217
                      Arrays.asList(files.split(File.pathSeparator)));
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   218
        }),
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   219
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   220
        ARGUMENTS ("arguments", "a", OptionCategories.PROPERTY, () -> {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   221
            List<String> arguments = getArgumentList(popArg());
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   222
            setOptionValue("arguments", arguments);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   223
        }),
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   224
56869
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56836
diff changeset
   225
        STRIP_NATIVE_COMMANDS ("strip-native-commands",
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56836
diff changeset
   226
                   OptionCategories.PROPERTY, () -> {
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   227
            setOptionValue("strip-native-commands", true);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   228
        }),
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   229
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   230
        ICON ("icon", OptionCategories.PROPERTY),
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   231
        CATEGORY ("category", OptionCategories.PROPERTY),
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   232
        COPYRIGHT ("copyright", OptionCategories.PROPERTY),
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   233
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   234
        LICENSE_FILE ("license-file", OptionCategories.PROPERTY),
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   235
57071
94e9270166f0 8213392: Enhance --help and --version
herrick
parents: 57067
diff changeset
   236
        VERSION ("app-version", OptionCategories.PROPERTY),
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   237
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   238
        JVM_ARGS ("jvm-args", OptionCategories.PROPERTY, () -> {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   239
            List<String> args = getArgumentList(popArg());
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   240
            args.forEach(a -> setOptionValue("jvm-args", a));
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   241
        }),
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   242
56869
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56836
diff changeset
   243
        FILE_ASSOCIATIONS ("file-associations",
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56836
diff changeset
   244
                OptionCategories.PROPERTY, () -> {
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   245
            Map<String, ? super Object> args = new HashMap<>();
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   246
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   247
            // load .properties file
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   248
            Map<String, String> initialMap = getPropertiesFromFile(popArg());
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   249
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   250
            String ext = initialMap.get(FA_EXTENSIONS);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   251
            if (ext != null) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   252
                args.put(StandardBundlerParam.FA_EXTENSIONS.getID(), ext);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   253
            }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   254
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   255
            String type = initialMap.get(FA_CONTENT_TYPE);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   256
            if (type != null) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   257
                args.put(StandardBundlerParam.FA_CONTENT_TYPE.getID(), type);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   258
            }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   259
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   260
            String desc = initialMap.get(FA_DESCRIPTION);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   261
            if (desc != null) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   262
                args.put(StandardBundlerParam.FA_DESCRIPTION.getID(), desc);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   263
            }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   264
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   265
            String icon = initialMap.get(FA_ICON);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   266
            if (icon != null) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   267
                args.put(StandardBundlerParam.FA_ICON.getID(), icon);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   268
            }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   269
56836
40abf95122b0 8207143: jpackager fails to parse file associations
herrick
parents: 56821
diff changeset
   270
            ArrayList<Map<String, ? super Object>> associationList =
40abf95122b0 8207143: jpackager fails to parse file associations
herrick
parents: 56821
diff changeset
   271
                new ArrayList<Map<String, ? super Object>>();
40abf95122b0 8207143: jpackager fails to parse file associations
herrick
parents: 56821
diff changeset
   272
40abf95122b0 8207143: jpackager fails to parse file associations
herrick
parents: 56821
diff changeset
   273
            associationList.add(args);
40abf95122b0 8207143: jpackager fails to parse file associations
herrick
parents: 56821
diff changeset
   274
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   275
            // check that we really add _another_ value to the list
56836
40abf95122b0 8207143: jpackager fails to parse file associations
herrick
parents: 56821
diff changeset
   276
            setOptionValue("file-associations", associationList);
40abf95122b0 8207143: jpackager fails to parse file associations
herrick
parents: 56821
diff changeset
   277
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   278
        }),
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   279
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   280
        SECONDARY_LAUNCHER ("secondary-launcher",
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   281
                    OptionCategories.PROPERTY, () -> {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   282
            context().secondaryLaunchers.add(
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   283
                new SecondaryLauncherArguments(popArg()));
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   284
        }),
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   285
57096
d06bec27f8c9 8215903: modify behavior of retaining temporary output dir
herrick
parents: 57091
diff changeset
   286
        BUILD_ROOT ("build-root", OptionCategories.PROPERTY, () -> {
d06bec27f8c9 8215903: modify behavior of retaining temporary output dir
herrick
parents: 57091
diff changeset
   287
            context().buildRoot = popArg();
57151
38d0b67617e3 8217317: Create jpackage native library for windows
herrick
parents: 57150
diff changeset
   288
            context().userProvidedBuildRoot = true;
57096
d06bec27f8c9 8215903: modify behavior of retaining temporary output dir
herrick
parents: 57091
diff changeset
   289
            setOptionValue("build-root", context().buildRoot);
d06bec27f8c9 8215903: modify behavior of retaining temporary output dir
herrick
parents: 57091
diff changeset
   290
        }),
56957
2f01969ed7cb 8211299: Output of System.out is not printed to CMD on Windows
herrick
parents: 56933
diff changeset
   291
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   292
        INSTALL_DIR ("install-dir", OptionCategories.PROPERTY),
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   293
56882
0ec8559f599a 8210439: Unable to create an installer from a previously created app image on Windows
herrick
parents: 56869
diff changeset
   294
        PREDEFINED_APP_IMAGE ("app-image", OptionCategories.PROPERTY, ()-> {
0ec8559f599a 8210439: Unable to create an installer from a previously created app image on Windows
herrick
parents: 56869
diff changeset
   295
            setOptionValue("app-image", popArg());
0ec8559f599a 8210439: Unable to create an installer from a previously created app image on Windows
herrick
parents: 56869
diff changeset
   296
            context().hasAppImage = true;
0ec8559f599a 8210439: Unable to create an installer from a previously created app image on Windows
herrick
parents: 56869
diff changeset
   297
        }),
56957
2f01969ed7cb 8211299: Output of System.out is not printed to CMD on Windows
herrick
parents: 56933
diff changeset
   298
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   299
        PREDEFINED_RUNTIME_IMAGE ("runtime-image", OptionCategories.PROPERTY),
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   300
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   301
        MAIN_JAR ("main-jar", "j", OptionCategories.PROPERTY, () -> {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   302
            context().mainJarPath = popArg();
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   303
            context().hasMainJar = true;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   304
            setOptionValue("main-jar", context().mainJarPath);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   305
        }),
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   306
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   307
        MODULE ("module", "m", OptionCategories.MODULAR, () -> {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   308
            context().hasMainModule = true;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   309
            setOptionValue("module", popArg());
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   310
        }),
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   311
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   312
        ADD_MODULES ("add-modules", OptionCategories.MODULAR),
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   313
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   314
        MODULE_PATH ("module-path", "p", OptionCategories.MODULAR),
56957
2f01969ed7cb 8211299: Output of System.out is not printed to CMD on Windows
herrick
parents: 56933
diff changeset
   315
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   316
        MAC_SIGN ("mac-sign", "s", OptionCategories.PLATFORM_MAC, () -> {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   317
            setOptionValue("mac-sign", true);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   318
        }),
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   319
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   320
        MAC_BUNDLE_NAME ("mac-bundle-name", OptionCategories.PLATFORM_MAC),
56957
2f01969ed7cb 8211299: Output of System.out is not printed to CMD on Windows
herrick
parents: 56933
diff changeset
   321
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   322
        MAC_BUNDLE_IDENTIFIER("mac-bundle-identifier",
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   323
                    OptionCategories.PLATFORM_MAC),
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   324
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   325
        MAC_APP_STORE_CATEGORY ("mac-app-store-category",
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   326
                    OptionCategories.PLATFORM_MAC),
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   327
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   328
        MAC_BUNDLE_SIGNING_PREFIX ("mac-bundle-signing-prefix",
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   329
                    OptionCategories.PLATFORM_MAC),
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   330
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   331
        MAC_SIGNING_KEY_NAME ("mac-signing-key-user-name",
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   332
                    OptionCategories.PLATFORM_MAC),
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   333
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   334
        MAC_SIGNING_KEYCHAIN ("mac-signing-keychain",
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   335
                    OptionCategories.PLATFORM_MAC),
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   336
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   337
        MAC_APP_STORE_ENTITLEMENTS ("mac-app-store-entitlements",
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   338
                    OptionCategories.PLATFORM_MAC),
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   339
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   340
        WIN_MENU_HINT ("win-menu", OptionCategories.PLATFORM_WIN, () -> {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   341
            setOptionValue("win-menu", true);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   342
        }),
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   343
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   344
        WIN_MENU_GROUP ("win-menu-group", OptionCategories.PLATFORM_WIN),
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   345
56869
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56836
diff changeset
   346
        WIN_SHORTCUT_HINT ("win-shortcut",
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56836
diff changeset
   347
                OptionCategories.PLATFORM_WIN, () -> {
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   348
            setOptionValue("win-shortcut", true);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   349
        }),
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   350
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   351
        WIN_PER_USER_INSTALLATION ("win-per-user-install",
56869
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56836
diff changeset
   352
                OptionCategories.PLATFORM_WIN, () -> {
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   353
            setOptionValue("win-per-user-install", false);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   354
        }),
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   355
56869
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56836
diff changeset
   356
        WIN_DIR_CHOOSER ("win-dir-chooser",
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56836
diff changeset
   357
                OptionCategories.PLATFORM_WIN, () -> {
56957
2f01969ed7cb 8211299: Output of System.out is not printed to CMD on Windows
herrick
parents: 56933
diff changeset
   358
            setOptionValue("win-dir-chooser", true);
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   359
        }),
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   360
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   361
        WIN_REGISTRY_NAME ("win-registry-name", OptionCategories.PLATFORM_WIN),
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   362
57062
044e7a644ee3 8214575: Exe installers will install application to already existing instalation
herrick
parents: 57060
diff changeset
   363
        WIN_UPGRADE_UUID ("win-upgrade-uuid",
56869
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56836
diff changeset
   364
                OptionCategories.PLATFORM_WIN),
56957
2f01969ed7cb 8211299: Output of System.out is not printed to CMD on Windows
herrick
parents: 56933
diff changeset
   365
2f01969ed7cb 8211299: Output of System.out is not printed to CMD on Windows
herrick
parents: 56933
diff changeset
   366
        WIN_CONSOLE_HINT ("win-console", OptionCategories.PLATFORM_WIN, () -> {
2f01969ed7cb 8211299: Output of System.out is not printed to CMD on Windows
herrick
parents: 56933
diff changeset
   367
            setOptionValue("win-console", true);
2f01969ed7cb 8211299: Output of System.out is not printed to CMD on Windows
herrick
parents: 56933
diff changeset
   368
        }),
2f01969ed7cb 8211299: Output of System.out is not printed to CMD on Windows
herrick
parents: 56933
diff changeset
   369
56869
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56836
diff changeset
   370
        LINUX_BUNDLE_NAME ("linux-bundle-name",
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56836
diff changeset
   371
                OptionCategories.PLATFORM_LINUX),
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   372
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   373
        LINUX_DEB_MAINTAINER ("linux-deb-maintainer",
56869
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56836
diff changeset
   374
                OptionCategories.PLATFORM_LINUX),
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   375
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   376
        LINUX_RPM_LICENSE_TYPE ("linux-rpm-license-type",
56869
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56836
diff changeset
   377
                OptionCategories.PLATFORM_LINUX),
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   378
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   379
        LINUX_PACKAGE_DEPENDENCIES ("linux-package-deps",
56869
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56836
diff changeset
   380
                OptionCategories.PLATFORM_LINUX);
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   381
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   382
        private final String id;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   383
        private final String shortId;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   384
        private final OptionCategories category;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   385
        private final ArgAction action;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   386
        private static Arguments argContext;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   387
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   388
        private CLIOptions(String id, OptionCategories category) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   389
            this(id, null, category, null);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   390
        }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   391
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   392
        private CLIOptions(String id, String shortId,
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   393
                           OptionCategories category) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   394
            this(id, shortId, category, null);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   395
        }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   396
56869
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56836
diff changeset
   397
        private CLIOptions(String id,
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56836
diff changeset
   398
                OptionCategories category, ArgAction action) {
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   399
            this(id, null, category, action);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   400
        }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   401
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   402
        private CLIOptions(String id, String shortId,
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   403
                           OptionCategories category, ArgAction action) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   404
            this.id = id;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   405
            this.shortId = shortId;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   406
            this.action = action;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   407
            this.category = category;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   408
        }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   409
57067
9c17d779808e 8213425: Analyze output from Source code scanner and fix where needed.
herrick
parents: 57065
diff changeset
   410
        static void setContext(Arguments context) {
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   411
            argContext = context;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   412
        }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   413
57151
38d0b67617e3 8217317: Create jpackage native library for windows
herrick
parents: 57150
diff changeset
   414
        public static Arguments context() {
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   415
            if (argContext != null) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   416
                return argContext;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   417
            } else {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   418
                throw new RuntimeException("Argument context is not set.");
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   419
            }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   420
        }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   421
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   422
        public String getId() {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   423
            return this.id;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   424
        }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   425
57067
9c17d779808e 8213425: Analyze output from Source code scanner and fix where needed.
herrick
parents: 57065
diff changeset
   426
        String getIdWithPrefix() {
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   427
            String prefix = isMode() ? "create-" : "--";
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   428
            return prefix + this.id;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   429
        }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   430
57067
9c17d779808e 8213425: Analyze output from Source code scanner and fix where needed.
herrick
parents: 57065
diff changeset
   431
        String getShortIdWithPrefix() {
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   432
            return this.shortId == null ? null : "-" + this.shortId;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   433
        }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   434
57067
9c17d779808e 8213425: Analyze output from Source code scanner and fix where needed.
herrick
parents: 57065
diff changeset
   435
        void execute() {
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   436
            if (action != null) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   437
                action.execute();
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   438
            } else {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   439
                defaultAction();
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   440
            }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   441
        }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   442
57067
9c17d779808e 8213425: Analyze output from Source code scanner and fix where needed.
herrick
parents: 57065
diff changeset
   443
        boolean isMode() {
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   444
            return category == OptionCategories.MODE;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   445
        }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   446
57067
9c17d779808e 8213425: Analyze output from Source code scanner and fix where needed.
herrick
parents: 57065
diff changeset
   447
        OptionCategories getCategory() {
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   448
            return category;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   449
        }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   450
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   451
        private void defaultAction() {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   452
            context().deployParams.addBundleArgument(id, popArg());
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   453
        }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   454
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   455
        private static void setOptionValue(String option, Object value) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   456
            context().deployParams.addBundleArgument(option, value);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   457
        }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   458
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   459
        private static String popArg() {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   460
            nextArg();
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   461
            return (context().pos >= context().argList.size()) ?
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   462
                            "" : context().argList.get(context().pos);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   463
        }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   464
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   465
        private static String getArg() {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   466
            return (context().pos >= context().argList.size()) ?
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   467
                        "" : context().argList.get(context().pos);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   468
        }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   469
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   470
        private static void nextArg() {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   471
            context().pos++;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   472
        }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   473
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   474
        private static void prevArg() {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   475
            context().pos--;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   476
        }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   477
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   478
        private static boolean hasNextArg() {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   479
            return context().pos < context().argList.size();
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   480
        }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   481
    }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   482
57067
9c17d779808e 8213425: Analyze output from Source code scanner and fix where needed.
herrick
parents: 57065
diff changeset
   483
    enum OptionCategories {
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   484
        MODE,
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   485
        MODULAR,
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   486
        PROPERTY,
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   487
        PLATFORM_MAC,
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   488
        PLATFORM_WIN,
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   489
        PLATFORM_LINUX;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   490
    }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   491
57140
3dcb33ce7ced 8217751: jpackage messages and failures
herrick
parents: 57119
diff changeset
   492
    private void initArgumentList(String[] args) throws PackagerException {
57060
5103d6d2e796 8213385: jpackager Command-Line Argument File.
herrick
parents: 57059
diff changeset
   493
        argList = new ArrayList<String>(args.length);
5103d6d2e796 8213385: jpackager Command-Line Argument File.
herrick
parents: 57059
diff changeset
   494
        for (String arg : args) {
5103d6d2e796 8213385: jpackager Command-Line Argument File.
herrick
parents: 57059
diff changeset
   495
            if (arg.startsWith("@")) {
5103d6d2e796 8213385: jpackager Command-Line Argument File.
herrick
parents: 57059
diff changeset
   496
                if (arg.length() > 1) {
5103d6d2e796 8213385: jpackager Command-Line Argument File.
herrick
parents: 57059
diff changeset
   497
                    String filename = arg.substring(1);
5103d6d2e796 8213385: jpackager Command-Line Argument File.
herrick
parents: 57059
diff changeset
   498
                    argList.addAll(extractArgList(filename));
5103d6d2e796 8213385: jpackager Command-Line Argument File.
herrick
parents: 57059
diff changeset
   499
                } else {
57140
3dcb33ce7ced 8217751: jpackage messages and failures
herrick
parents: 57119
diff changeset
   500
                    throw new PackagerException("ERR_InvalidOption", arg);
57060
5103d6d2e796 8213385: jpackager Command-Line Argument File.
herrick
parents: 57059
diff changeset
   501
                }
5103d6d2e796 8213385: jpackager Command-Line Argument File.
herrick
parents: 57059
diff changeset
   502
            } else {
5103d6d2e796 8213385: jpackager Command-Line Argument File.
herrick
parents: 57059
diff changeset
   503
                argList.add(arg);
5103d6d2e796 8213385: jpackager Command-Line Argument File.
herrick
parents: 57059
diff changeset
   504
            }
5103d6d2e796 8213385: jpackager Command-Line Argument File.
herrick
parents: 57059
diff changeset
   505
        }
5103d6d2e796 8213385: jpackager Command-Line Argument File.
herrick
parents: 57059
diff changeset
   506
        Log.debug ("\nJPackage argument list: \n" + argList + "\n");
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   507
        pos = 0;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   508
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   509
        deployParams = new DeployParams();
56994
b4aca2dbe2b5 8212537: Create method and class description comments for main functionality
herrick
parents: 56989
diff changeset
   510
        bundleType = BundlerType.NONE;
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   511
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   512
        allOptions = new ArrayList<>();
56957
2f01969ed7cb 8211299: Output of System.out is not printed to CMD on Windows
herrick
parents: 56933
diff changeset
   513
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   514
        secondaryLaunchers = new ArrayList<>();
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   515
    }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   516
57060
5103d6d2e796 8213385: jpackager Command-Line Argument File.
herrick
parents: 57059
diff changeset
   517
    private List<String> extractArgList(String filename) {
5103d6d2e796 8213385: jpackager Command-Line Argument File.
herrick
parents: 57059
diff changeset
   518
        List<String> args = new ArrayList<String>();
5103d6d2e796 8213385: jpackager Command-Line Argument File.
herrick
parents: 57059
diff changeset
   519
        try {
5103d6d2e796 8213385: jpackager Command-Line Argument File.
herrick
parents: 57059
diff changeset
   520
            File f = new File(filename);
5103d6d2e796 8213385: jpackager Command-Line Argument File.
herrick
parents: 57059
diff changeset
   521
            if (f.exists()) {
5103d6d2e796 8213385: jpackager Command-Line Argument File.
herrick
parents: 57059
diff changeset
   522
                List<String> lines = Files.readAllLines(f.toPath());
5103d6d2e796 8213385: jpackager Command-Line Argument File.
herrick
parents: 57059
diff changeset
   523
                for (String line : lines) {
5103d6d2e796 8213385: jpackager Command-Line Argument File.
herrick
parents: 57059
diff changeset
   524
                    String [] qsplit;
5103d6d2e796 8213385: jpackager Command-Line Argument File.
herrick
parents: 57059
diff changeset
   525
                    String quote = "\"";
5103d6d2e796 8213385: jpackager Command-Line Argument File.
herrick
parents: 57059
diff changeset
   526
                    if (line.contains("\"")) {
5103d6d2e796 8213385: jpackager Command-Line Argument File.
herrick
parents: 57059
diff changeset
   527
                        qsplit = line.split("\"");
5103d6d2e796 8213385: jpackager Command-Line Argument File.
herrick
parents: 57059
diff changeset
   528
                    } else {
5103d6d2e796 8213385: jpackager Command-Line Argument File.
herrick
parents: 57059
diff changeset
   529
                        qsplit = line.split("\'");
5103d6d2e796 8213385: jpackager Command-Line Argument File.
herrick
parents: 57059
diff changeset
   530
                        quote = "\'";
5103d6d2e796 8213385: jpackager Command-Line Argument File.
herrick
parents: 57059
diff changeset
   531
                    }
5103d6d2e796 8213385: jpackager Command-Line Argument File.
herrick
parents: 57059
diff changeset
   532
                    for (int i=0; i<qsplit.length; i++) {
5103d6d2e796 8213385: jpackager Command-Line Argument File.
herrick
parents: 57059
diff changeset
   533
                        // every other qsplit of line is a quoted string
5103d6d2e796 8213385: jpackager Command-Line Argument File.
herrick
parents: 57059
diff changeset
   534
                        if ((i & 1) == 0) {
5103d6d2e796 8213385: jpackager Command-Line Argument File.
herrick
parents: 57059
diff changeset
   535
                            // non-quoted string - split by whitespace
5103d6d2e796 8213385: jpackager Command-Line Argument File.
herrick
parents: 57059
diff changeset
   536
                            String [] newargs = qsplit[i].split("\\s");
5103d6d2e796 8213385: jpackager Command-Line Argument File.
herrick
parents: 57059
diff changeset
   537
                            for (String newarg : newargs) {
5103d6d2e796 8213385: jpackager Command-Line Argument File.
herrick
parents: 57059
diff changeset
   538
                                args.add(newarg);
5103d6d2e796 8213385: jpackager Command-Line Argument File.
herrick
parents: 57059
diff changeset
   539
                            }
5103d6d2e796 8213385: jpackager Command-Line Argument File.
herrick
parents: 57059
diff changeset
   540
                        } else {
5103d6d2e796 8213385: jpackager Command-Line Argument File.
herrick
parents: 57059
diff changeset
   541
                            // quoted string - don't split by whitespace
5103d6d2e796 8213385: jpackager Command-Line Argument File.
herrick
parents: 57059
diff changeset
   542
                            args.add(qsplit[i]);
5103d6d2e796 8213385: jpackager Command-Line Argument File.
herrick
parents: 57059
diff changeset
   543
                        }
5103d6d2e796 8213385: jpackager Command-Line Argument File.
herrick
parents: 57059
diff changeset
   544
                    }
57108
f1c13cb0e713 8217269: jpackage Makefile improvments
herrick
parents: 57106
diff changeset
   545
                }
57060
5103d6d2e796 8213385: jpackager Command-Line Argument File.
herrick
parents: 57059
diff changeset
   546
            } else {
57150
fa68c2ab636d 8217894: jpackage CLI syntax changes
herrick
parents: 57140
diff changeset
   547
                Log.info(MessageFormat.format(I18N.getString(
fa68c2ab636d 8217894: jpackage CLI syntax changes
herrick
parents: 57140
diff changeset
   548
                        "warning.missing.arg.file"), f));
57060
5103d6d2e796 8213385: jpackager Command-Line Argument File.
herrick
parents: 57059
diff changeset
   549
            }
5103d6d2e796 8213385: jpackager Command-Line Argument File.
herrick
parents: 57059
diff changeset
   550
        } catch (IOException ioe) {
5103d6d2e796 8213385: jpackager Command-Line Argument File.
herrick
parents: 57059
diff changeset
   551
            Log.verbose(ioe.getMessage());
5103d6d2e796 8213385: jpackager Command-Line Argument File.
herrick
parents: 57059
diff changeset
   552
            Log.verbose(ioe);
5103d6d2e796 8213385: jpackager Command-Line Argument File.
herrick
parents: 57059
diff changeset
   553
        }
5103d6d2e796 8213385: jpackager Command-Line Argument File.
herrick
parents: 57059
diff changeset
   554
        return args;
5103d6d2e796 8213385: jpackager Command-Line Argument File.
herrick
parents: 57059
diff changeset
   555
    }
5103d6d2e796 8213385: jpackager Command-Line Argument File.
herrick
parents: 57059
diff changeset
   556
5103d6d2e796 8213385: jpackager Command-Line Argument File.
herrick
parents: 57059
diff changeset
   557
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   558
    public boolean processArguments() throws Exception {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   559
        try {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   560
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   561
            // init context of arguments
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   562
            CLIOptions.setContext(this);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   563
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   564
            // parse cmd line
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   565
            String arg;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   566
            CLIOptions option;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   567
            for (; CLIOptions.hasNextArg(); CLIOptions.nextArg()) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   568
                arg = CLIOptions.getArg();
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   569
                if ((option = toCLIOption(arg)) != null) {
57060
5103d6d2e796 8213385: jpackager Command-Line Argument File.
herrick
parents: 57059
diff changeset
   570
                    // found a CLI option
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   571
                    allOptions.add(option);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   572
                    option.execute();
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   573
                } else {
57140
3dcb33ce7ced 8217751: jpackage messages and failures
herrick
parents: 57119
diff changeset
   574
                    throw new PackagerException("ERR_InvalidOption", arg);
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   575
                }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   576
            }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   577
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   578
            if (allOptions.isEmpty() || !allOptions.get(0).isMode()) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   579
                // first argument should always be a mode.
57150
fa68c2ab636d 8217894: jpackage CLI syntax changes
herrick
parents: 57140
diff changeset
   580
                throw new PackagerException("ERR_MissingMode");
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   581
            }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   582
57150
fa68c2ab636d 8217894: jpackage CLI syntax changes
herrick
parents: 57140
diff changeset
   583
            if (hasMainJar && !hasMainClass) {
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   584
                // try to get main-class from manifest
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   585
                String mainClass = getMainClassFromManifest();
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   586
                if (mainClass != null) {
56869
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56836
diff changeset
   587
                    CLIOptions.setOptionValue(
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56836
diff changeset
   588
                            CLIOptions.APPCLASS.getId(), mainClass);
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   589
                }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   590
            }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   591
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   592
            // display warning for arguments that are not supported
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   593
            // for current configuration.
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   594
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   595
            validateArguments();
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   596
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   597
            addResources(deployParams, input, files);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   598
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   599
            deployParams.setBundleType(bundleType);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   600
56869
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56836
diff changeset
   601
            List<Map<String, ? super Object>> launchersAsMap =
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56836
diff changeset
   602
                    new ArrayList<>();
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   603
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   604
            for (SecondaryLauncherArguments sl : secondaryLaunchers) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   605
                launchersAsMap.add(sl.getLauncherMap());
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   606
            }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   607
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   608
            deployParams.addBundleArgument(
56869
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56836
diff changeset
   609
                    StandardBundlerParam.SECONDARY_LAUNCHERS.getID(),
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56836
diff changeset
   610
                    launchersAsMap);
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   611
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   612
            // at this point deployParams should be already configured
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   613
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   614
            deployParams.validate();
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   615
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   616
            BundleParams bp = deployParams.getBundleParams();
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   617
56958
8880b21d458d 8208578: Need to improve error handling of mandatory arguments
herrick
parents: 56957
diff changeset
   618
            // validate name(s)
8880b21d458d 8208578: Need to improve error handling of mandatory arguments
herrick
parents: 56957
diff changeset
   619
            ArrayList<String> usedNames = new ArrayList<String>();
8880b21d458d 8208578: Need to improve error handling of mandatory arguments
herrick
parents: 56957
diff changeset
   620
            usedNames.add(bp.getName()); // add main app name
8880b21d458d 8208578: Need to improve error handling of mandatory arguments
herrick
parents: 56957
diff changeset
   621
8880b21d458d 8208578: Need to improve error handling of mandatory arguments
herrick
parents: 56957
diff changeset
   622
            for (SecondaryLauncherArguments sl : secondaryLaunchers) {
8880b21d458d 8208578: Need to improve error handling of mandatory arguments
herrick
parents: 56957
diff changeset
   623
                Map<String, ? super Object> slMap = sl.getLauncherMap();
56987
0d2ff0d6bb94 8211297: --verbose does not work with jpackager
herrick
parents: 56982
diff changeset
   624
                String slName =
56958
8880b21d458d 8208578: Need to improve error handling of mandatory arguments
herrick
parents: 56957
diff changeset
   625
                        (String) slMap.get(Arguments.CLIOptions.NAME.getId());
8880b21d458d 8208578: Need to improve error handling of mandatory arguments
herrick
parents: 56957
diff changeset
   626
                if (slName == null) {
8880b21d458d 8208578: Need to improve error handling of mandatory arguments
herrick
parents: 56957
diff changeset
   627
                    throw new PackagerException("ERR_NoSecondaryLauncherName");
57119
b3dda8d77d8a 8217331: Problems when space in application name
herrick
parents: 57108
diff changeset
   628
                }
b3dda8d77d8a 8217331: Problems when space in application name
herrick
parents: 57108
diff changeset
   629
                // same rules apply to secondary launcher names as app name
b3dda8d77d8a 8217331: Problems when space in application name
herrick
parents: 57108
diff changeset
   630
                DeployParams.validateName(slName, false);
b3dda8d77d8a 8217331: Problems when space in application name
herrick
parents: 57108
diff changeset
   631
                for (String usedName : usedNames) {
b3dda8d77d8a 8217331: Problems when space in application name
herrick
parents: 57108
diff changeset
   632
                    if (slName.equals(usedName)) {
b3dda8d77d8a 8217331: Problems when space in application name
herrick
parents: 57108
diff changeset
   633
                        throw new PackagerException("ERR_NoUniqueName");
56958
8880b21d458d 8208578: Need to improve error handling of mandatory arguments
herrick
parents: 56957
diff changeset
   634
                    }
8880b21d458d 8208578: Need to improve error handling of mandatory arguments
herrick
parents: 56957
diff changeset
   635
                }
8880b21d458d 8208578: Need to improve error handling of mandatory arguments
herrick
parents: 56957
diff changeset
   636
                usedNames.add(slName);
8880b21d458d 8208578: Need to improve error handling of mandatory arguments
herrick
parents: 56957
diff changeset
   637
            }
57150
fa68c2ab636d 8217894: jpackage CLI syntax changes
herrick
parents: 57140
diff changeset
   638
            if (runtimeInstaller && bp.getName() == null) {
56958
8880b21d458d 8208578: Need to improve error handling of mandatory arguments
herrick
parents: 56957
diff changeset
   639
                throw new PackagerException("ERR_NoJreInstallerName");
8880b21d458d 8208578: Need to improve error handling of mandatory arguments
herrick
parents: 56957
diff changeset
   640
            }
8880b21d458d 8208578: Need to improve error handling of mandatory arguments
herrick
parents: 56957
diff changeset
   641
57062
044e7a644ee3 8214575: Exe installers will install application to already existing instalation
herrick
parents: 57060
diff changeset
   642
            return generateBundle(bp.getBundleParamsAsMap());
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   643
        } catch (Exception e) {
56987
0d2ff0d6bb94 8211297: --verbose does not work with jpackager
herrick
parents: 56982
diff changeset
   644
            if (Log.isVerbose()) {
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   645
                throw e;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   646
            } else {
57022
81021f910bc2 8213333: Fix issues found in jpackager with automated tests
herrick
parents: 57021
diff changeset
   647
                Log.error(e.getMessage());
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   648
                if (e.getCause() != null && e.getCause() != e) {
57022
81021f910bc2 8213333: Fix issues found in jpackager with automated tests
herrick
parents: 57021
diff changeset
   649
                    Log.error(e.getCause().getMessage());
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   650
                }
57022
81021f910bc2 8213333: Fix issues found in jpackager with automated tests
herrick
parents: 57021
diff changeset
   651
                return false;
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   652
            }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   653
        }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   654
    }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   655
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   656
    private void validateArguments() {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   657
        CLIOptions mode = allOptions.get(0);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   658
        for (CLIOptions option : allOptions) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   659
            if(!ValidOptions.checkIfSupported(mode, option)) {
57140
3dcb33ce7ced 8217751: jpackage messages and failures
herrick
parents: 57119
diff changeset
   660
                Log.info(MessageFormat.format(I18N.getString(
3dcb33ce7ced 8217751: jpackage messages and failures
herrick
parents: 57119
diff changeset
   661
                        "warning.unsupported.option"), option.getId(), mode));
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   662
            }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   663
        }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   664
    }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   665
57039
98d3963b0b7b 8214051: rename jpackager tool to jpackage
herrick
parents: 57038
diff changeset
   666
    private List<jdk.jpackage.internal.Bundler> getPlatformBundlers() {
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   667
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   668
        if (platformBundlers != null) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   669
            return platformBundlers;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   670
        }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   671
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   672
        platformBundlers = new ArrayList<>();
57039
98d3963b0b7b 8214051: rename jpackager tool to jpackage
herrick
parents: 57038
diff changeset
   673
        for (jdk.jpackage.internal.Bundler bundler :
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   674
                Bundlers.createBundlersInstance().getBundlers(
56869
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56836
diff changeset
   675
                        bundleType.toString())) {
56957
2f01969ed7cb 8211299: Output of System.out is not printed to CMD on Windows
herrick
parents: 56933
diff changeset
   676
            if (hasTargetFormat && deployParams.getTargetFormat() != null &&
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   677
                    !deployParams.getTargetFormat().equalsIgnoreCase(
56869
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56836
diff changeset
   678
                    bundler.getID())) {
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   679
                continue;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   680
            }
57150
fa68c2ab636d 8217894: jpackage CLI syntax changes
herrick
parents: 57140
diff changeset
   681
            if (bundler.supported(runtimeInstaller)) {
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   682
                 platformBundlers.add(bundler);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   683
            }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   684
        }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   685
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   686
        return platformBundlers;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   687
    }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   688
57062
044e7a644ee3 8214575: Exe installers will install application to already existing instalation
herrick
parents: 57060
diff changeset
   689
    private boolean generateBundle(Map<String,? super Object> params)
56869
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56836
diff changeset
   690
            throws PackagerException {
57103
fe6bf39ac415 8216373: temporary build-root left behind when using secondary launcher(s)
herrick
parents: 57099
diff changeset
   691
57062
044e7a644ee3 8214575: Exe installers will install application to already existing instalation
herrick
parents: 57060
diff changeset
   692
        boolean bundleCreated = false;
57103
fe6bf39ac415 8216373: temporary build-root left behind when using secondary launcher(s)
herrick
parents: 57099
diff changeset
   693
fe6bf39ac415 8216373: temporary build-root left behind when using secondary launcher(s)
herrick
parents: 57099
diff changeset
   694
        // the build-root needs to be fetched from the params early,
fe6bf39ac415 8216373: temporary build-root left behind when using secondary launcher(s)
herrick
parents: 57099
diff changeset
   695
        // to prevent each copy of the params (such as may be used for
fe6bf39ac415 8216373: temporary build-root left behind when using secondary launcher(s)
herrick
parents: 57099
diff changeset
   696
        // secondary launchers) from generating a separate build-root when
fe6bf39ac415 8216373: temporary build-root left behind when using secondary launcher(s)
herrick
parents: 57099
diff changeset
   697
        // the default is used (the default is a new temp directory)
fe6bf39ac415 8216373: temporary build-root left behind when using secondary launcher(s)
herrick
parents: 57099
diff changeset
   698
        // The bundler.cleanup() below would not otherwise be able to
fe6bf39ac415 8216373: temporary build-root left behind when using secondary launcher(s)
herrick
parents: 57099
diff changeset
   699
        // clean these extra (and unneeded) temp directories.
fe6bf39ac415 8216373: temporary build-root left behind when using secondary launcher(s)
herrick
parents: 57099
diff changeset
   700
        StandardBundlerParam.BUILD_ROOT.fetchFrom(params);
57062
044e7a644ee3 8214575: Exe installers will install application to already existing instalation
herrick
parents: 57060
diff changeset
   701
57039
98d3963b0b7b 8214051: rename jpackager tool to jpackage
herrick
parents: 57038
diff changeset
   702
        for (jdk.jpackage.internal.Bundler bundler : getPlatformBundlers()) {
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   703
            Map<String, ? super Object> localParams = new HashMap<>(params);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   704
            try {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   705
                if (bundler.validate(localParams)) {
56869
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56836
diff changeset
   706
                    File result =
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56836
diff changeset
   707
                            bundler.execute(localParams, deployParams.outdir);
57151
38d0b67617e3 8217317: Create jpackage native library for windows
herrick
parents: 57150
diff changeset
   708
                    if (!userProvidedBuildRoot) {
57096
d06bec27f8c9 8215903: modify behavior of retaining temporary output dir
herrick
parents: 57091
diff changeset
   709
                        bundler.cleanup(localParams);
d06bec27f8c9 8215903: modify behavior of retaining temporary output dir
herrick
parents: 57091
diff changeset
   710
                    }
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   711
                    if (result == null) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   712
                        throw new PackagerException("MSG_BundlerFailed",
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   713
                                bundler.getID(), bundler.getName());
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   714
                    }
57096
d06bec27f8c9 8215903: modify behavior of retaining temporary output dir
herrick
parents: 57091
diff changeset
   715
                    bundleCreated = true; // at least one bundle was created
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   716
                }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   717
            } catch (UnsupportedPlatformException e) {
57140
3dcb33ce7ced 8217751: jpackage messages and failures
herrick
parents: 57119
diff changeset
   718
                throw new PackagerException(e,
3dcb33ce7ced 8217751: jpackage messages and failures
herrick
parents: 57119
diff changeset
   719
                        "MSG_BundlerPlatformException",
3dcb33ce7ced 8217751: jpackage messages and failures
herrick
parents: 57119
diff changeset
   720
                        bundler.getName());
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   721
            } catch (ConfigException e) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   722
                Log.debug(e);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   723
                if (e.getAdvice() != null) {
57140
3dcb33ce7ced 8217751: jpackage messages and failures
herrick
parents: 57119
diff changeset
   724
                    throw new PackagerException(e,
3dcb33ce7ced 8217751: jpackage messages and failures
herrick
parents: 57119
diff changeset
   725
                            "MSG_BundlerConfigException",
3dcb33ce7ced 8217751: jpackage messages and failures
herrick
parents: 57119
diff changeset
   726
                            bundler.getName(), e.getMessage(), e.getAdvice());
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   727
                } else {
57140
3dcb33ce7ced 8217751: jpackage messages and failures
herrick
parents: 57119
diff changeset
   728
                    throw new PackagerException(e,
3dcb33ce7ced 8217751: jpackage messages and failures
herrick
parents: 57119
diff changeset
   729
                           "MSG_BundlerConfigExceptionNoAdvice",
3dcb33ce7ced 8217751: jpackage messages and failures
herrick
parents: 57119
diff changeset
   730
                            bundler.getName(), e.getMessage());
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   731
                }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   732
            } catch (RuntimeException re) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   733
                Log.debug(re);
57140
3dcb33ce7ced 8217751: jpackage messages and failures
herrick
parents: 57119
diff changeset
   734
                throw new PackagerException(re, "MSG_BundlerRuntimeException",
3dcb33ce7ced 8217751: jpackage messages and failures
herrick
parents: 57119
diff changeset
   735
                        bundler.getName(), re.toString());
57096
d06bec27f8c9 8215903: modify behavior of retaining temporary output dir
herrick
parents: 57091
diff changeset
   736
            } finally {
57151
38d0b67617e3 8217317: Create jpackage native library for windows
herrick
parents: 57150
diff changeset
   737
                if (userProvidedBuildRoot) {
57096
d06bec27f8c9 8215903: modify behavior of retaining temporary output dir
herrick
parents: 57091
diff changeset
   738
                    Log.verbose(MessageFormat.format(
d06bec27f8c9 8215903: modify behavior of retaining temporary output dir
herrick
parents: 57091
diff changeset
   739
                            I18N.getString("message.debug-working-directory"),
d06bec27f8c9 8215903: modify behavior of retaining temporary output dir
herrick
parents: 57091
diff changeset
   740
                            (new File(buildRoot)).getAbsolutePath()));
d06bec27f8c9 8215903: modify behavior of retaining temporary output dir
herrick
parents: 57091
diff changeset
   741
                }
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   742
            }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   743
        }
57062
044e7a644ee3 8214575: Exe installers will install application to already existing instalation
herrick
parents: 57060
diff changeset
   744
044e7a644ee3 8214575: Exe installers will install application to already existing instalation
herrick
parents: 57060
diff changeset
   745
        return bundleCreated;
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   746
    }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   747
56994
b4aca2dbe2b5 8212537: Create method and class description comments for main functionality
herrick
parents: 56989
diff changeset
   748
    private void addResources(DeployParams deployParams,
56869
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56836
diff changeset
   749
            String inputdir, List<String> inputfiles) {
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   750
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   751
        if (inputdir == null || inputdir.isEmpty()) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   752
            return;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   753
        }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   754
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   755
        File baseDir = new File(inputdir);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   756
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   757
        if (!baseDir.isDirectory()) {
57020
a828547f7e50 8213394: Stop using Log.info() except for expected output.
herrick
parents: 57017
diff changeset
   758
            Log.error(
57096
d06bec27f8c9 8215903: modify behavior of retaining temporary output dir
herrick
parents: 57091
diff changeset
   759
                    "Unable to add resources: \"--input\" is not a directory.");
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   760
            return;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   761
        }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   762
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   763
        List<String> fileNames;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   764
        if (inputfiles != null) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   765
            fileNames = inputfiles;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   766
        } else {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   767
            // "-files" is omitted, all files in input cdir (which
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   768
            // is a mandatory argument in this case) will be packaged.
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   769
            fileNames = new ArrayList<>();
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   770
            try (Stream<Path> files = Files.list(baseDir.toPath())) {
56869
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56836
diff changeset
   771
                files.forEach(file -> fileNames.add(
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56836
diff changeset
   772
                        file.getFileName().toString()));
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   773
            } catch (IOException e) {
57020
a828547f7e50 8213394: Stop using Log.info() except for expected output.
herrick
parents: 57017
diff changeset
   774
                Log.error("Unable to add resources: " + e.getMessage());
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   775
            }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   776
        }
56994
b4aca2dbe2b5 8212537: Create method and class description comments for main functionality
herrick
parents: 56989
diff changeset
   777
        fileNames.forEach(file -> deployParams.addResource(baseDir, file));
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   778
57097
6e5eb7855fe2 8215900: Without --files args, only jars in the top level of --input are added to class-path
herrick
parents: 57096
diff changeset
   779
        deployParams.setClasspath();
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   780
    }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   781
57067
9c17d779808e 8213425: Analyze output from Source code scanner and fix where needed.
herrick
parents: 57065
diff changeset
   782
    static boolean isCLIOption(String arg) {
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   783
        return toCLIOption(arg) != null;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   784
    }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   785
57067
9c17d779808e 8213425: Analyze output from Source code scanner and fix where needed.
herrick
parents: 57065
diff changeset
   786
    static CLIOptions toCLIOption(String arg) {
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   787
        CLIOptions option;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   788
        if ((option = argIds.get(arg)) == null) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   789
            option = argShortIds.get(arg);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   790
        }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   791
        return option;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   792
    }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   793
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   794
    static Map<String, String> getArgumentMap(String inputString) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   795
        Map<String, String> map = new HashMap<>();
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   796
        List<String> list = getArgumentList(inputString);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   797
        for (String pair : list) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   798
            int equals = pair.indexOf("=");
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   799
            if (equals != -1) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   800
                String key = pair.substring(0, equals);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   801
                String value = pair.substring(equals+1, pair.length());
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   802
                map.put(key, value);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   803
            }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   804
        }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   805
        return map;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   806
    }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   807
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   808
    static Map<String, String> getPropertiesFromFile(String filename) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   809
        Map<String, String> map = new HashMap<>();
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   810
        // load properties file
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   811
        File file = new File(filename);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   812
        Properties properties = new Properties();
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   813
        try (FileInputStream in = new FileInputStream(file)) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   814
            properties.load(in);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   815
        } catch (IOException e) {
57020
a828547f7e50 8213394: Stop using Log.info() except for expected output.
herrick
parents: 57017
diff changeset
   816
            Log.error("Exception: " + e.getMessage());
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   817
        }
56957
2f01969ed7cb 8211299: Output of System.out is not printed to CMD on Windows
herrick
parents: 56933
diff changeset
   818
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   819
        for (final String name: properties.stringPropertyNames()) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   820
            map.put(name, properties.getProperty(name));
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   821
        }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   822
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   823
        return map;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   824
    }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   825
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   826
    static List<String> getArgumentList(String inputString) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   827
        List<String> list = new ArrayList<>();
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   828
        if (inputString == null || inputString.isEmpty()) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   829
             return list;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   830
        }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   831
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   832
        // The "pattern" regexp attempts to abide to the rule that
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   833
        // strings are delimited by whitespace unless surrounded by
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   834
        // quotes, then it is anything (including spaces) in the quotes.
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   835
        Matcher m = pattern.matcher(inputString);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   836
        while (m.find()) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   837
            String s = inputString.substring(m.start(), m.end()).trim();
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   838
            // Ensure we do not have an empty string. trim() will take care of
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   839
            // whitespace only strings. The regex preserves quotes and escaped
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   840
            // chars so we need to clean them before adding to the List
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   841
            if (!s.isEmpty()) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   842
                list.add(unquoteIfNeeded(s));
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   843
            }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   844
        }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   845
        return list;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   846
    }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   847
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   848
    private static String unquoteIfNeeded(String in) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   849
        if (in == null) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   850
            return null;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   851
        }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   852
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   853
        if (in.isEmpty()) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   854
            return "";
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   855
        }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   856
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   857
        // Use code points to preserve non-ASCII chars
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   858
        StringBuilder sb = new StringBuilder();
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   859
        int codeLen = in.codePointCount(0, in.length());
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   860
        int quoteChar = -1;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   861
        for (int i = 0; i < codeLen; i++) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   862
            int code = in.codePointAt(i);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   863
            if (code == '"' || code == '\'') {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   864
                // If quote is escaped make sure to copy it
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   865
                if (i > 0 && in.codePointAt(i - 1) == '\\') {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   866
                    sb.deleteCharAt(sb.length() - 1);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   867
                    sb.appendCodePoint(code);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   868
                    continue;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   869
                }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   870
                if (quoteChar != -1) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   871
                    if (code == quoteChar) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   872
                        // close quote, skip char
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   873
                        quoteChar = -1;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   874
                    } else {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   875
                        sb.appendCodePoint(code);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   876
                    }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   877
                } else {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   878
                    // opening quote, skip char
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   879
                    quoteChar = code;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   880
                }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   881
            } else {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   882
                sb.appendCodePoint(code);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   883
            }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   884
        }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   885
        return sb.toString();
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   886
    }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   887
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   888
    private String getMainClassFromManifest() {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   889
        if (mainJarPath == null ||
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   890
            input == null ) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   891
            return null;
56957
2f01969ed7cb 8211299: Output of System.out is not printed to CMD on Windows
herrick
parents: 56933
diff changeset
   892
        }
2f01969ed7cb 8211299: Output of System.out is not printed to CMD on Windows
herrick
parents: 56933
diff changeset
   893
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   894
        JarFile jf;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   895
        try {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   896
            File file = new File(input, mainJarPath);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   897
            if (!file.exists()) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   898
                return null;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   899
            }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   900
            jf = new JarFile(file);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   901
            Manifest m = jf.getManifest();
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   902
            Attributes attrs = (m != null) ? m.getMainAttributes() : null;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   903
            if (attrs != null) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   904
                return attrs.getValue(Attributes.Name.MAIN_CLASS);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   905
            }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   906
        } catch (IOException ignore) {}
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   907
        return null;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   908
    }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   909
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   910
}