src/jdk.jpackage/share/classes/jdk/jpackage/internal/Arguments.java
author herrick
Tue, 24 Sep 2019 13:57:28 -0400
branchJDK-8200758-branch
changeset 58304 7a61351edad2
parent 58301 e0efb29609bd
child 58415 73f8e557549a
permissions -rw-r--r--
8231282 : Revisit --linux-deb-copyright option Submitted-by: asemenyuk Reviewed-by: herrick, almatvee
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;
58147
45a9084fe981 8230521: rename --output/-o option and add default value (".")
herrick
parents: 58116
diff changeset
    32
import java.nio.file.Paths;
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    33
import java.text.MessageFormat;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    34
import java.util.ArrayList;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    35
import java.util.Arrays;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    36
import java.util.Collection;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    37
import java.util.EnumSet;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    38
import java.util.HashMap;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    39
import java.util.HashSet;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    40
import java.util.List;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    41
import java.util.Map;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    42
import java.util.Set;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    43
import java.util.Properties;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    44
import java.util.ResourceBundle;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    45
import java.util.jar.Attributes;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    46
import java.util.jar.JarFile;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    47
import java.util.jar.Manifest;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    48
import java.util.stream.Stream;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    49
import java.util.regex.Matcher;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    50
import java.util.regex.Pattern;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    51
56994
b4aca2dbe2b5 8212537: Create method and class description comments for main functionality
herrick
parents: 56989
diff changeset
    52
/**
b4aca2dbe2b5 8212537: Create method and class description comments for main functionality
herrick
parents: 56989
diff changeset
    53
 * Arguments
b4aca2dbe2b5 8212537: Create method and class description comments for main functionality
herrick
parents: 56989
diff changeset
    54
 *
b4aca2dbe2b5 8212537: Create method and class description comments for main functionality
herrick
parents: 56989
diff changeset
    55
 * This class encapsulates and processes the command line arguments,
57039
98d3963b0b7b 8214051: rename jpackager tool to jpackage
herrick
parents: 57038
diff changeset
    56
 * 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
    57
 *
b4aca2dbe2b5 8212537: Create method and class description comments for main functionality
herrick
parents: 56989
diff changeset
    58
 * The primary entry point, processArguments():
b4aca2dbe2b5 8212537: Create method and class description comments for main functionality
herrick
parents: 56989
diff changeset
    59
 * Processes and validates command line arguments, constructing DeployParams.
b4aca2dbe2b5 8212537: Create method and class description comments for main functionality
herrick
parents: 56989
diff changeset
    60
 * Validates the DeployParams, and generate the BundleParams.
b4aca2dbe2b5 8212537: Create method and class description comments for main functionality
herrick
parents: 56989
diff changeset
    61
 * 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
    62
 * Executes each Bundler in the list.
b4aca2dbe2b5 8212537: Create method and class description comments for main functionality
herrick
parents: 56989
diff changeset
    63
 */
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    64
public class Arguments {
56869
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56836
diff changeset
    65
    private static final ResourceBundle I18N = ResourceBundle.getBundle(
57059
9bb2a4dc3af7 8214143: Reduce Resource files
herrick
parents: 57039
diff changeset
    66
            "jdk.jpackage.internal.resources.MainResources");
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    67
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    68
    private static final String FA_EXTENSIONS = "extension";
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    69
    private static final String FA_CONTENT_TYPE = "mime-type";
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    70
    private static final String FA_DESCRIPTION = "description";
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    71
    private static final String FA_ICON = "icon";
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    72
57256
d7c27451f759 8219678: CLI changes in jpackage
herrick
parents: 57214
diff changeset
    73
    // regexp for parsing args (for example, for additional launchers)
56869
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56836
diff changeset
    74
    private static Pattern pattern = Pattern.compile(
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56836
diff changeset
    75
          "(?:(?:([\"'])(?:\\\\\\1|.)*?(?:\\1|$))|(?:\\\\[\"'\\s]|[^\\s]))++");
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    76
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    77
    private DeployParams deployParams = null;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    78
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    79
    private int pos = 0;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    80
    private List<String> argList = null;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    81
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    82
    private List<CLIOptions> allOptions = null;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    83
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    84
    private String input = null;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    85
    private String output = null;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    86
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    87
    private boolean hasMainJar = false;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    88
    private boolean hasMainClass = false;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    89
    private boolean hasMainModule = false;
57151
38d0b67617e3 8217317: Create jpackage native library for windows
herrick
parents: 57150
diff changeset
    90
    public boolean userProvidedBuildRoot = false;
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    91
57108
f1c13cb0e713 8217269: jpackage Makefile improvments
herrick
parents: 57106
diff changeset
    92
    private String buildRoot = null;
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    93
    private String mainJarPath = null;
56957
2f01969ed7cb 8211299: Output of System.out is not printed to CMD on Windows
herrick
parents: 56933
diff changeset
    94
57150
fa68c2ab636d 8217894: jpackage CLI syntax changes
herrick
parents: 57140
diff changeset
    95
    private static boolean runtimeInstaller = false;
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    96
57256
d7c27451f759 8219678: CLI changes in jpackage
herrick
parents: 57214
diff changeset
    97
    private List<AddLauncherArguments> addLaunchers = null;
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 static Map<String, CLIOptions> argIds = new HashMap<>();
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   100
    private static Map<String, CLIOptions> argShortIds = new HashMap<>();
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   101
57276
eac9018748b3 8220804: Help message for @ argfile option is printed in the wrong place
herrick
parents: 57261
diff changeset
   102
    static {
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   103
        // init maps for parsing arguments
57276
eac9018748b3 8220804: Help message for @ argfile option is printed in the wrong place
herrick
parents: 57261
diff changeset
   104
        (EnumSet.allOf(CLIOptions.class)).forEach(option -> {
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   105
            argIds.put(option.getIdWithPrefix(), option);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   106
            if (option.getShortIdWithPrefix() != null) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   107
                argShortIds.put(option.getShortIdWithPrefix(), option);
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
        });
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   110
    }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   111
57391
970f28090a06 8223334: Additional cleanup in jpackage tool
herrick
parents: 57330
diff changeset
   112
    public Arguments(String[] args) {
57276
eac9018748b3 8220804: Help message for @ argfile option is printed in the wrong place
herrick
parents: 57261
diff changeset
   113
        argList = new ArrayList<String>(args.length);
eac9018748b3 8220804: Help message for @ argfile option is printed in the wrong place
herrick
parents: 57261
diff changeset
   114
        for (String arg : args) {
eac9018748b3 8220804: Help message for @ argfile option is printed in the wrong place
herrick
parents: 57261
diff changeset
   115
            argList.add(arg);
eac9018748b3 8220804: Help message for @ argfile option is printed in the wrong place
herrick
parents: 57261
diff changeset
   116
        }
57776
783db59cd8d3 8224594: Simplify jpackage Logging
herrick
parents: 57741
diff changeset
   117
        Log.verbose ("\njpackage argument list: \n" + argList + "\n");
57276
eac9018748b3 8220804: Help message for @ argfile option is printed in the wrong place
herrick
parents: 57261
diff changeset
   118
        pos = 0;
eac9018748b3 8220804: Help message for @ argfile option is printed in the wrong place
herrick
parents: 57261
diff changeset
   119
eac9018748b3 8220804: Help message for @ argfile option is printed in the wrong place
herrick
parents: 57261
diff changeset
   120
        deployParams = new DeployParams();
57414
6eda749d3117 8225428: CLI change to remove "mode", rename to "package", and build only one target
herrick
parents: 57392
diff changeset
   121
57276
eac9018748b3 8220804: Help message for @ argfile option is printed in the wrong place
herrick
parents: 57261
diff changeset
   122
        allOptions = new ArrayList<>();
eac9018748b3 8220804: Help message for @ argfile option is printed in the wrong place
herrick
parents: 57261
diff changeset
   123
eac9018748b3 8220804: Help message for @ argfile option is printed in the wrong place
herrick
parents: 57261
diff changeset
   124
        addLaunchers = new ArrayList<>();
58147
45a9084fe981 8230521: rename --output/-o option and add default value (".")
herrick
parents: 58116
diff changeset
   125
45a9084fe981 8230521: rename --output/-o option and add default value (".")
herrick
parents: 58116
diff changeset
   126
        output = Paths.get("").toAbsolutePath().toString();
45a9084fe981 8230521: rename --output/-o option and add default value (".")
herrick
parents: 58116
diff changeset
   127
        deployParams.setOutput(new File(output));
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   128
    }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   129
57067
9c17d779808e 8213425: Analyze output from Source code scanner and fix where needed.
herrick
parents: 57065
diff changeset
   130
    // CLIOptions is public for DeployParamsTest
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   131
    public enum CLIOptions {
57414
6eda749d3117 8225428: CLI change to remove "mode", rename to "package", and build only one target
herrick
parents: 57392
diff changeset
   132
        PACKAGE_TYPE("package-type", OptionCategories.PROPERTY, () -> {
58114
42df7de58e39 8230519: jpackage "--package-type" values and default
herrick
parents: 57909
diff changeset
   133
            context().deployParams.setTargetFormat(popArg());
56821
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
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   136
        INPUT ("input", "i", OptionCategories.PROPERTY, () -> {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   137
            context().input = popArg();
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   138
            setOptionValue("input", context().input);
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
58147
45a9084fe981 8230521: rename --output/-o option and add default value (".")
herrick
parents: 58116
diff changeset
   141
        OUTPUT ("dest", "d", OptionCategories.PROPERTY, () -> {
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   142
            context().output = popArg();
56994
b4aca2dbe2b5 8212537: Create method and class description comments for main functionality
herrick
parents: 56989
diff changeset
   143
            context().deployParams.setOutput(new File(context().output));
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   144
        }),
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   145
58147
45a9084fe981 8230521: rename --output/-o option and add default value (".")
herrick
parents: 58116
diff changeset
   146
        DESCRIPTION ("description", OptionCategories.PROPERTY),
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   147
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   148
        VENDOR ("vendor", OptionCategories.PROPERTY),
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   149
57256
d7c27451f759 8219678: CLI changes in jpackage
herrick
parents: 57214
diff changeset
   150
        APPCLASS ("main-class", OptionCategories.PROPERTY, () -> {
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   151
            context().hasMainClass = true;
57150
fa68c2ab636d 8217894: jpackage CLI syntax changes
herrick
parents: 57140
diff changeset
   152
            setOptionValue("main-class", popArg());
56821
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
        NAME ("name", "n", OptionCategories.PROPERTY),
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   156
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   157
        IDENTIFIER ("identifier", OptionCategories.PROPERTY),
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   158
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   159
        VERBOSE ("verbose", OptionCategories.PROPERTY, () -> {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   160
            setOptionValue("verbose", true);
57776
783db59cd8d3 8224594: Simplify jpackage Logging
herrick
parents: 57741
diff changeset
   161
            Log.setVerbose();
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   162
        }),
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   163
57091
06bc4bd64599 8215515: Add a command line option to override internal resources.
herrick
parents: 57071
diff changeset
   164
        RESOURCE_DIR("resource-dir",
06bc4bd64599 8215515: Add a command line option to override internal resources.
herrick
parents: 57071
diff changeset
   165
                OptionCategories.PROPERTY, () -> {
06bc4bd64599 8215515: Add a command line option to override internal resources.
herrick
parents: 57071
diff changeset
   166
            String resourceDir = popArg();
06bc4bd64599 8215515: Add a command line option to override internal resources.
herrick
parents: 57071
diff changeset
   167
            setOptionValue("resource-dir", resourceDir);
06bc4bd64599 8215515: Add a command line option to override internal resources.
herrick
parents: 57071
diff changeset
   168
        }),
57021
441c020bf626 8213324:jpackager deletes existing app directory without warning
herrick
parents: 57020
diff changeset
   169
57256
d7c27451f759 8219678: CLI changes in jpackage
herrick
parents: 57214
diff changeset
   170
        ARGUMENTS ("arguments", OptionCategories.PROPERTY, () -> {
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   171
            List<String> arguments = getArgumentList(popArg());
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   172
            setOptionValue("arguments", arguments);
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
57256
d7c27451f759 8219678: CLI changes in jpackage
herrick
parents: 57214
diff changeset
   175
        ICON ("icon", OptionCategories.PROPERTY),
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   176
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   177
        COPYRIGHT ("copyright", OptionCategories.PROPERTY),
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
        LICENSE_FILE ("license-file", OptionCategories.PROPERTY),
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   180
57071
94e9270166f0 8213392: Enhance --help and --version
herrick
parents: 57067
diff changeset
   181
        VERSION ("app-version", OptionCategories.PROPERTY),
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   182
57741
38856ef4a19c 8229138: Add --linux-app-release option for DEB and RPM packages
herrick
parents: 57450
diff changeset
   183
        RELEASE ("linux-app-release", OptionCategories.PROPERTY),
38856ef4a19c 8229138: Add --linux-app-release option for DEB and RPM packages
herrick
parents: 57450
diff changeset
   184
57291
f2d429260ad4 8221582: Rename jvm-args option to java-options
herrick
parents: 57276
diff changeset
   185
        JAVA_OPTIONS ("java-options", OptionCategories.PROPERTY, () -> {
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   186
            List<String> args = getArgumentList(popArg());
57291
f2d429260ad4 8221582: Rename jvm-args option to java-options
herrick
parents: 57276
diff changeset
   187
            args.forEach(a -> setOptionValue("java-options", a));
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   188
        }),
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   189
56869
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56836
diff changeset
   190
        FILE_ASSOCIATIONS ("file-associations",
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56836
diff changeset
   191
                OptionCategories.PROPERTY, () -> {
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   192
            Map<String, ? super Object> args = new HashMap<>();
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
            // load .properties file
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   195
            Map<String, String> initialMap = getPropertiesFromFile(popArg());
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   196
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   197
            String ext = initialMap.get(FA_EXTENSIONS);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   198
            if (ext != null) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   199
                args.put(StandardBundlerParam.FA_EXTENSIONS.getID(), ext);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   200
            }
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
            String type = initialMap.get(FA_CONTENT_TYPE);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   203
            if (type != null) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   204
                args.put(StandardBundlerParam.FA_CONTENT_TYPE.getID(), type);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   205
            }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   206
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   207
            String desc = initialMap.get(FA_DESCRIPTION);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   208
            if (desc != null) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   209
                args.put(StandardBundlerParam.FA_DESCRIPTION.getID(), desc);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   210
            }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   211
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   212
            String icon = initialMap.get(FA_ICON);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   213
            if (icon != null) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   214
                args.put(StandardBundlerParam.FA_ICON.getID(), icon);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   215
            }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   216
56836
40abf95122b0 8207143: jpackager fails to parse file associations
herrick
parents: 56821
diff changeset
   217
            ArrayList<Map<String, ? super Object>> associationList =
40abf95122b0 8207143: jpackager fails to parse file associations
herrick
parents: 56821
diff changeset
   218
                new ArrayList<Map<String, ? super Object>>();
40abf95122b0 8207143: jpackager fails to parse file associations
herrick
parents: 56821
diff changeset
   219
40abf95122b0 8207143: jpackager fails to parse file associations
herrick
parents: 56821
diff changeset
   220
            associationList.add(args);
40abf95122b0 8207143: jpackager fails to parse file associations
herrick
parents: 56821
diff changeset
   221
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   222
            // check that we really add _another_ value to the list
56836
40abf95122b0 8207143: jpackager fails to parse file associations
herrick
parents: 56821
diff changeset
   223
            setOptionValue("file-associations", associationList);
40abf95122b0 8207143: jpackager fails to parse file associations
herrick
parents: 56821
diff changeset
   224
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   225
        }),
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   226
57256
d7c27451f759 8219678: CLI changes in jpackage
herrick
parents: 57214
diff changeset
   227
        ADD_LAUNCHER ("add-launcher",
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   228
                    OptionCategories.PROPERTY, () -> {
57330
a30edd277572 8222733: Modify jpackage option --add-launcher synta
herrick
parents: 57314
diff changeset
   229
            String spec = popArg();
a30edd277572 8222733: Modify jpackage option --add-launcher synta
herrick
parents: 57314
diff changeset
   230
            String name = null;
a30edd277572 8222733: Modify jpackage option --add-launcher synta
herrick
parents: 57314
diff changeset
   231
            String filename = spec;
a30edd277572 8222733: Modify jpackage option --add-launcher synta
herrick
parents: 57314
diff changeset
   232
            if (spec.contains("=")) {
a30edd277572 8222733: Modify jpackage option --add-launcher synta
herrick
parents: 57314
diff changeset
   233
                String[] values = spec.split("=", 2);
a30edd277572 8222733: Modify jpackage option --add-launcher synta
herrick
parents: 57314
diff changeset
   234
                name = values[0];
a30edd277572 8222733: Modify jpackage option --add-launcher synta
herrick
parents: 57314
diff changeset
   235
                filename = values[1];
a30edd277572 8222733: Modify jpackage option --add-launcher synta
herrick
parents: 57314
diff changeset
   236
            }
57256
d7c27451f759 8219678: CLI changes in jpackage
herrick
parents: 57214
diff changeset
   237
            context().addLaunchers.add(
57330
a30edd277572 8222733: Modify jpackage option --add-launcher synta
herrick
parents: 57314
diff changeset
   238
                new AddLauncherArguments(name, filename));
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   239
        }),
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   240
58115
4a27283b542d /home/aherrick/comment
herrick
parents: 58114
diff changeset
   241
        TEMP_ROOT ("temp", OptionCategories.PROPERTY, () -> {
57096
d06bec27f8c9 8215903: modify behavior of retaining temporary output dir
herrick
parents: 57091
diff changeset
   242
            context().buildRoot = popArg();
57151
38d0b67617e3 8217317: Create jpackage native library for windows
herrick
parents: 57150
diff changeset
   243
            context().userProvidedBuildRoot = true;
58115
4a27283b542d /home/aherrick/comment
herrick
parents: 58114
diff changeset
   244
            setOptionValue("temp", context().buildRoot);
57096
d06bec27f8c9 8215903: modify behavior of retaining temporary output dir
herrick
parents: 57091
diff changeset
   245
        }),
56957
2f01969ed7cb 8211299: Output of System.out is not printed to CMD on Windows
herrick
parents: 56933
diff changeset
   246
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   247
        INSTALL_DIR ("install-dir", OptionCategories.PROPERTY),
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   248
57392
46d4b0aa4542 8223241: jpackage cleanup from code review
herrick
parents: 57391
diff changeset
   249
        PREDEFINED_APP_IMAGE ("app-image", OptionCategories.PROPERTY),
56957
2f01969ed7cb 8211299: Output of System.out is not printed to CMD on Windows
herrick
parents: 56933
diff changeset
   250
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   251
        PREDEFINED_RUNTIME_IMAGE ("runtime-image", OptionCategories.PROPERTY),
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   252
57256
d7c27451f759 8219678: CLI changes in jpackage
herrick
parents: 57214
diff changeset
   253
        MAIN_JAR ("main-jar",  OptionCategories.PROPERTY, () -> {
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   254
            context().mainJarPath = popArg();
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   255
            context().hasMainJar = true;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   256
            setOptionValue("main-jar", context().mainJarPath);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   257
        }),
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
        MODULE ("module", "m", OptionCategories.MODULAR, () -> {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   260
            context().hasMainModule = true;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   261
            setOptionValue("module", popArg());
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   262
        }),
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
        ADD_MODULES ("add-modules", OptionCategories.MODULAR),
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   265
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   266
        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
   267
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   268
        MAC_SIGN ("mac-sign", "s", OptionCategories.PLATFORM_MAC, () -> {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   269
            setOptionValue("mac-sign", true);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   270
        }),
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   271
58115
4a27283b542d /home/aherrick/comment
herrick
parents: 58114
diff changeset
   272
        MAC_BUNDLE_NAME ("mac-package-name", OptionCategories.PLATFORM_MAC),
56957
2f01969ed7cb 8211299: Output of System.out is not printed to CMD on Windows
herrick
parents: 56933
diff changeset
   273
58115
4a27283b542d /home/aherrick/comment
herrick
parents: 58114
diff changeset
   274
        MAC_BUNDLE_IDENTIFIER("mac-package-identifier",
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   275
                    OptionCategories.PLATFORM_MAC),
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   276
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   277
        MAC_APP_STORE_CATEGORY ("mac-app-store-category",
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   278
                    OptionCategories.PLATFORM_MAC),
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   279
58115
4a27283b542d /home/aherrick/comment
herrick
parents: 58114
diff changeset
   280
        MAC_BUNDLE_SIGNING_PREFIX ("mac-package-signing-prefix",
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   281
                    OptionCategories.PLATFORM_MAC),
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   282
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   283
        MAC_SIGNING_KEY_NAME ("mac-signing-key-user-name",
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   284
                    OptionCategories.PLATFORM_MAC),
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   285
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   286
        MAC_SIGNING_KEYCHAIN ("mac-signing-keychain",
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   287
                    OptionCategories.PLATFORM_MAC),
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   288
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   289
        MAC_APP_STORE_ENTITLEMENTS ("mac-app-store-entitlements",
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   290
                    OptionCategories.PLATFORM_MAC),
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   291
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   292
        WIN_MENU_HINT ("win-menu", OptionCategories.PLATFORM_WIN, () -> {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   293
            setOptionValue("win-menu", true);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   294
        }),
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   295
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   296
        WIN_MENU_GROUP ("win-menu-group", OptionCategories.PLATFORM_WIN),
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   297
56869
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56836
diff changeset
   298
        WIN_SHORTCUT_HINT ("win-shortcut",
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56836
diff changeset
   299
                OptionCategories.PLATFORM_WIN, () -> {
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   300
            setOptionValue("win-shortcut", true);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   301
        }),
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   302
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   303
        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
   304
                OptionCategories.PLATFORM_WIN, () -> {
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   305
            setOptionValue("win-per-user-install", false);
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
56869
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56836
diff changeset
   308
        WIN_DIR_CHOOSER ("win-dir-chooser",
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56836
diff changeset
   309
                OptionCategories.PLATFORM_WIN, () -> {
56957
2f01969ed7cb 8211299: Output of System.out is not printed to CMD on Windows
herrick
parents: 56933
diff changeset
   310
            setOptionValue("win-dir-chooser", true);
56821
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
57062
044e7a644ee3 8214575: Exe installers will install application to already existing instalation
herrick
parents: 57060
diff changeset
   313
        WIN_UPGRADE_UUID ("win-upgrade-uuid",
56869
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56836
diff changeset
   314
                OptionCategories.PLATFORM_WIN),
56957
2f01969ed7cb 8211299: Output of System.out is not printed to CMD on Windows
herrick
parents: 56933
diff changeset
   315
2f01969ed7cb 8211299: Output of System.out is not printed to CMD on Windows
herrick
parents: 56933
diff changeset
   316
        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
   317
            setOptionValue("win-console", true);
2f01969ed7cb 8211299: Output of System.out is not printed to CMD on Windows
herrick
parents: 56933
diff changeset
   318
        }),
2f01969ed7cb 8211299: Output of System.out is not printed to CMD on Windows
herrick
parents: 56933
diff changeset
   319
58115
4a27283b542d /home/aherrick/comment
herrick
parents: 58114
diff changeset
   320
        LINUX_BUNDLE_NAME ("linux-package-name",
56869
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56836
diff changeset
   321
                OptionCategories.PLATFORM_LINUX),
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   322
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   323
        LINUX_DEB_MAINTAINER ("linux-deb-maintainer",
56869
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56836
diff changeset
   324
                OptionCategories.PLATFORM_LINUX),
57909
c7de06ed4b54 8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents: 57807
diff changeset
   325
57790
1ea531646100 8213941: Debian linux problems in JavaPackager
herrick
parents: 57776
diff changeset
   326
        LINUX_CATEGORY ("linux-app-category",
1ea531646100 8213941: Debian linux problems in JavaPackager
herrick
parents: 57776
diff changeset
   327
                OptionCategories.PLATFORM_LINUX),
1ea531646100 8213941: Debian linux problems in JavaPackager
herrick
parents: 57776
diff changeset
   328
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   329
        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
   330
                OptionCategories.PLATFORM_LINUX),
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   331
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   332
        LINUX_PACKAGE_DEPENDENCIES ("linux-package-deps",
57256
d7c27451f759 8219678: CLI changes in jpackage
herrick
parents: 57214
diff changeset
   333
                OptionCategories.PLATFORM_LINUX),
d7c27451f759 8219678: CLI changes in jpackage
herrick
parents: 57214
diff changeset
   334
58116
93b8c1305de2 8229779: Shortcut creation policy
herrick
parents: 58115
diff changeset
   335
        LINUX_SHORTCUT_HINT ("linux-shortcut",
93b8c1305de2 8229779: Shortcut creation policy
herrick
parents: 58115
diff changeset
   336
                OptionCategories.PLATFORM_LINUX, () -> {
93b8c1305de2 8229779: Shortcut creation policy
herrick
parents: 58115
diff changeset
   337
            setOptionValue("linux-shortcut", true);
93b8c1305de2 8229779: Shortcut creation policy
herrick
parents: 58115
diff changeset
   338
        }),
93b8c1305de2 8229779: Shortcut creation policy
herrick
parents: 58115
diff changeset
   339
57256
d7c27451f759 8219678: CLI changes in jpackage
herrick
parents: 57214
diff changeset
   340
        LINUX_MENU_GROUP ("linux-menu-group", OptionCategories.PLATFORM_LINUX);
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   341
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   342
        private final String id;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   343
        private final String shortId;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   344
        private final OptionCategories category;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   345
        private final ArgAction action;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   346
        private static Arguments argContext;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   347
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   348
        private CLIOptions(String id, OptionCategories category) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   349
            this(id, null, category, null);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   350
        }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   351
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   352
        private CLIOptions(String id, String shortId,
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   353
                           OptionCategories category) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   354
            this(id, shortId, category, null);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   355
        }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   356
56869
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56836
diff changeset
   357
        private CLIOptions(String id,
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56836
diff changeset
   358
                OptionCategories category, ArgAction action) {
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   359
            this(id, null, category, action);
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
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   362
        private CLIOptions(String id, String shortId,
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   363
                           OptionCategories category, ArgAction action) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   364
            this.id = id;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   365
            this.shortId = shortId;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   366
            this.action = action;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   367
            this.category = category;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   368
        }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   369
57067
9c17d779808e 8213425: Analyze output from Source code scanner and fix where needed.
herrick
parents: 57065
diff changeset
   370
        static void setContext(Arguments context) {
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   371
            argContext = context;
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
57151
38d0b67617e3 8217317: Create jpackage native library for windows
herrick
parents: 57150
diff changeset
   374
        public static Arguments context() {
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   375
            if (argContext != null) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   376
                return argContext;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   377
            } else {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   378
                throw new RuntimeException("Argument context is not set.");
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   379
            }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   380
        }
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
        public String getId() {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   383
            return this.id;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   384
        }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   385
57067
9c17d779808e 8213425: Analyze output from Source code scanner and fix where needed.
herrick
parents: 57065
diff changeset
   386
        String getIdWithPrefix() {
57438
4a31db8d42bd 8226599: use code coverage results to remove dead code
herrick
parents: 57421
diff changeset
   387
            return "--" + this.id;
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   388
        }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   389
57067
9c17d779808e 8213425: Analyze output from Source code scanner and fix where needed.
herrick
parents: 57065
diff changeset
   390
        String getShortIdWithPrefix() {
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   391
            return this.shortId == null ? null : "-" + this.shortId;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   392
        }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   393
57067
9c17d779808e 8213425: Analyze output from Source code scanner and fix where needed.
herrick
parents: 57065
diff changeset
   394
        void execute() {
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   395
            if (action != null) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   396
                action.execute();
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   397
            } else {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   398
                defaultAction();
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   399
            }
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 void defaultAction() {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   403
            context().deployParams.addBundleArgument(id, popArg());
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   404
        }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   405
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   406
        private static void setOptionValue(String option, Object value) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   407
            context().deployParams.addBundleArgument(option, value);
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
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   410
        private static String popArg() {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   411
            nextArg();
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   412
            return (context().pos >= context().argList.size()) ?
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   413
                            "" : context().argList.get(context().pos);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   414
        }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   415
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   416
        private static String getArg() {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   417
            return (context().pos >= context().argList.size()) ?
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   418
                        "" : context().argList.get(context().pos);
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
        private static void nextArg() {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   422
            context().pos++;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   423
        }
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
        private static boolean hasNextArg() {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   426
            return context().pos < context().argList.size();
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   427
        }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   428
    }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   429
57067
9c17d779808e 8213425: Analyze output from Source code scanner and fix where needed.
herrick
parents: 57065
diff changeset
   430
    enum OptionCategories {
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   431
        MODULAR,
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   432
        PROPERTY,
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   433
        PLATFORM_MAC,
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   434
        PLATFORM_WIN,
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   435
        PLATFORM_LINUX;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   436
    }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   437
57391
970f28090a06 8223334: Additional cleanup in jpackage tool
herrick
parents: 57330
diff changeset
   438
    public boolean processArguments() {
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   439
        try {
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
            // init context of arguments
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   442
            CLIOptions.setContext(this);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   443
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   444
            // parse cmd line
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   445
            String arg;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   446
            CLIOptions option;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   447
            for (; CLIOptions.hasNextArg(); CLIOptions.nextArg()) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   448
                arg = CLIOptions.getArg();
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   449
                if ((option = toCLIOption(arg)) != null) {
57060
5103d6d2e796 8213385: jpackager Command-Line Argument File.
herrick
parents: 57059
diff changeset
   450
                    // found a CLI option
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   451
                    allOptions.add(option);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   452
                    option.execute();
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   453
                } else {
57140
3dcb33ce7ced 8217751: jpackage messages and failures
herrick
parents: 57119
diff changeset
   454
                    throw new PackagerException("ERR_InvalidOption", arg);
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   455
                }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   456
            }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   457
57150
fa68c2ab636d 8217894: jpackage CLI syntax changes
herrick
parents: 57140
diff changeset
   458
            if (hasMainJar && !hasMainClass) {
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   459
                // try to get main-class from manifest
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   460
                String mainClass = getMainClassFromManifest();
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   461
                if (mainClass != null) {
56869
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56836
diff changeset
   462
                    CLIOptions.setOptionValue(
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56836
diff changeset
   463
                            CLIOptions.APPCLASS.getId(), mainClass);
56821
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
            }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   466
57414
6eda749d3117 8225428: CLI change to remove "mode", rename to "package", and build only one target
herrick
parents: 57392
diff changeset
   467
            // display error for arguments that are not supported
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   468
            // for current configuration.
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
            validateArguments();
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   471
57450
82c78b40b39d 8227058: Regressions related to no longer setting user.dir
herrick
parents: 57438
diff changeset
   472
            addResources(deployParams, input, mainJarPath);
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   473
56869
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56836
diff changeset
   474
            List<Map<String, ? super Object>> launchersAsMap =
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56836
diff changeset
   475
                    new ArrayList<>();
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   476
57256
d7c27451f759 8219678: CLI changes in jpackage
herrick
parents: 57214
diff changeset
   477
            for (AddLauncherArguments sl : addLaunchers) {
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   478
                launchersAsMap.add(sl.getLauncherMap());
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   479
            }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   480
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   481
            deployParams.addBundleArgument(
57256
d7c27451f759 8219678: CLI changes in jpackage
herrick
parents: 57214
diff changeset
   482
                    StandardBundlerParam.ADD_LAUNCHERS.getID(),
56869
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56836
diff changeset
   483
                    launchersAsMap);
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   484
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   485
            // at this point deployParams should be already configured
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   486
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   487
            deployParams.validate();
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   488
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   489
            BundleParams bp = deployParams.getBundleParams();
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   490
56958
8880b21d458d 8208578: Need to improve error handling of mandatory arguments
herrick
parents: 56957
diff changeset
   491
            // validate name(s)
8880b21d458d 8208578: Need to improve error handling of mandatory arguments
herrick
parents: 56957
diff changeset
   492
            ArrayList<String> usedNames = new ArrayList<String>();
8880b21d458d 8208578: Need to improve error handling of mandatory arguments
herrick
parents: 56957
diff changeset
   493
            usedNames.add(bp.getName()); // add main app name
8880b21d458d 8208578: Need to improve error handling of mandatory arguments
herrick
parents: 56957
diff changeset
   494
57256
d7c27451f759 8219678: CLI changes in jpackage
herrick
parents: 57214
diff changeset
   495
            for (AddLauncherArguments sl : addLaunchers) {
56958
8880b21d458d 8208578: Need to improve error handling of mandatory arguments
herrick
parents: 56957
diff changeset
   496
                Map<String, ? super Object> slMap = sl.getLauncherMap();
56987
0d2ff0d6bb94 8211297: --verbose does not work with jpackager
herrick
parents: 56982
diff changeset
   497
                String slName =
56958
8880b21d458d 8208578: Need to improve error handling of mandatory arguments
herrick
parents: 56957
diff changeset
   498
                        (String) slMap.get(Arguments.CLIOptions.NAME.getId());
8880b21d458d 8208578: Need to improve error handling of mandatory arguments
herrick
parents: 56957
diff changeset
   499
                if (slName == null) {
57256
d7c27451f759 8219678: CLI changes in jpackage
herrick
parents: 57214
diff changeset
   500
                    throw new PackagerException("ERR_NoAddLauncherName");
57119
b3dda8d77d8a 8217331: Problems when space in application name
herrick
parents: 57108
diff changeset
   501
                }
57256
d7c27451f759 8219678: CLI changes in jpackage
herrick
parents: 57214
diff changeset
   502
                // same rules apply to additional launcher names as app name
57119
b3dda8d77d8a 8217331: Problems when space in application name
herrick
parents: 57108
diff changeset
   503
                DeployParams.validateName(slName, false);
b3dda8d77d8a 8217331: Problems when space in application name
herrick
parents: 57108
diff changeset
   504
                for (String usedName : usedNames) {
b3dda8d77d8a 8217331: Problems when space in application name
herrick
parents: 57108
diff changeset
   505
                    if (slName.equals(usedName)) {
b3dda8d77d8a 8217331: Problems when space in application name
herrick
parents: 57108
diff changeset
   506
                        throw new PackagerException("ERR_NoUniqueName");
56958
8880b21d458d 8208578: Need to improve error handling of mandatory arguments
herrick
parents: 56957
diff changeset
   507
                    }
8880b21d458d 8208578: Need to improve error handling of mandatory arguments
herrick
parents: 56957
diff changeset
   508
                }
8880b21d458d 8208578: Need to improve error handling of mandatory arguments
herrick
parents: 56957
diff changeset
   509
                usedNames.add(slName);
8880b21d458d 8208578: Need to improve error handling of mandatory arguments
herrick
parents: 56957
diff changeset
   510
            }
57150
fa68c2ab636d 8217894: jpackage CLI syntax changes
herrick
parents: 57140
diff changeset
   511
            if (runtimeInstaller && bp.getName() == null) {
56958
8880b21d458d 8208578: Need to improve error handling of mandatory arguments
herrick
parents: 56957
diff changeset
   512
                throw new PackagerException("ERR_NoJreInstallerName");
8880b21d458d 8208578: Need to improve error handling of mandatory arguments
herrick
parents: 56957
diff changeset
   513
            }
8880b21d458d 8208578: Need to improve error handling of mandatory arguments
herrick
parents: 56957
diff changeset
   514
57414
6eda749d3117 8225428: CLI change to remove "mode", rename to "package", and build only one target
herrick
parents: 57392
diff changeset
   515
            generateBundle(bp.getBundleParamsAsMap());
6eda749d3117 8225428: CLI change to remove "mode", rename to "package", and build only one target
herrick
parents: 57392
diff changeset
   516
            return true;
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   517
        } catch (Exception e) {
56987
0d2ff0d6bb94 8211297: --verbose does not work with jpackager
herrick
parents: 56982
diff changeset
   518
            if (Log.isVerbose()) {
57391
970f28090a06 8223334: Additional cleanup in jpackage tool
herrick
parents: 57330
diff changeset
   519
                Log.verbose(e);
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   520
            } else {
57261
13b6672477df 8220505: Allow building available installers when --installer-type not specified
herrick
parents: 57256
diff changeset
   521
                String msg1 = e.getMessage();
13b6672477df 8220505: Allow building available installers when --installer-type not specified
herrick
parents: 57256
diff changeset
   522
                Log.error(msg1);
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   523
                if (e.getCause() != null && e.getCause() != e) {
57261
13b6672477df 8220505: Allow building available installers when --installer-type not specified
herrick
parents: 57256
diff changeset
   524
                    String msg2 = e.getCause().getMessage();
58301
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents: 58147
diff changeset
   525
                    if (msg2 != null && !msg1.contains(msg2)) {
57261
13b6672477df 8220505: Allow building available installers when --installer-type not specified
herrick
parents: 57256
diff changeset
   526
                        Log.error(msg2);
13b6672477df 8220505: Allow building available installers when --installer-type not specified
herrick
parents: 57256
diff changeset
   527
                    }
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   528
                }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   529
            }
57391
970f28090a06 8223334: Additional cleanup in jpackage tool
herrick
parents: 57330
diff changeset
   530
            return false;
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   531
        }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   532
    }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   533
57256
d7c27451f759 8219678: CLI changes in jpackage
herrick
parents: 57214
diff changeset
   534
    private void validateArguments() throws PackagerException {
58114
42df7de58e39 8230519: jpackage "--package-type" values and default
herrick
parents: 57909
diff changeset
   535
        String type = deployParams.getTargetFormat();
42df7de58e39 8230519: jpackage "--package-type" values and default
herrick
parents: 57909
diff changeset
   536
        String ptype = (type != null) ? type : "default";
42df7de58e39 8230519: jpackage "--package-type" values and default
herrick
parents: 57909
diff changeset
   537
        boolean imageOnly = deployParams.isTargetAppImage();
57256
d7c27451f759 8219678: CLI changes in jpackage
herrick
parents: 57214
diff changeset
   538
        boolean hasAppImage = allOptions.contains(
d7c27451f759 8219678: CLI changes in jpackage
herrick
parents: 57214
diff changeset
   539
                CLIOptions.PREDEFINED_APP_IMAGE);
d7c27451f759 8219678: CLI changes in jpackage
herrick
parents: 57214
diff changeset
   540
        boolean hasRuntime = allOptions.contains(
d7c27451f759 8219678: CLI changes in jpackage
herrick
parents: 57214
diff changeset
   541
                CLIOptions.PREDEFINED_RUNTIME_IMAGE);
d7c27451f759 8219678: CLI changes in jpackage
herrick
parents: 57214
diff changeset
   542
        boolean installerOnly = !imageOnly && hasAppImage;
57414
6eda749d3117 8225428: CLI change to remove "mode", rename to "package", and build only one target
herrick
parents: 57392
diff changeset
   543
        runtimeInstaller = !imageOnly && hasRuntime && !hasAppImage &&
57256
d7c27451f759 8219678: CLI changes in jpackage
herrick
parents: 57214
diff changeset
   544
                !hasMainModule && !hasMainJar;
d7c27451f759 8219678: CLI changes in jpackage
herrick
parents: 57214
diff changeset
   545
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   546
        for (CLIOptions option : allOptions) {
57256
d7c27451f759 8219678: CLI changes in jpackage
herrick
parents: 57214
diff changeset
   547
            if (!ValidOptions.checkIfSupported(option)) {
d7c27451f759 8219678: CLI changes in jpackage
herrick
parents: 57214
diff changeset
   548
                // includes option valid only on different platform
d7c27451f759 8219678: CLI changes in jpackage
herrick
parents: 57214
diff changeset
   549
                throw new PackagerException("ERR_UnsupportedOption",
d7c27451f759 8219678: CLI changes in jpackage
herrick
parents: 57214
diff changeset
   550
                        option.getIdWithPrefix());
d7c27451f759 8219678: CLI changes in jpackage
herrick
parents: 57214
diff changeset
   551
            }
d7c27451f759 8219678: CLI changes in jpackage
herrick
parents: 57214
diff changeset
   552
            if (imageOnly) {
d7c27451f759 8219678: CLI changes in jpackage
herrick
parents: 57214
diff changeset
   553
                if (!ValidOptions.checkIfImageSupported(option)) {
57414
6eda749d3117 8225428: CLI change to remove "mode", rename to "package", and build only one target
herrick
parents: 57392
diff changeset
   554
                    throw new PackagerException("ERR_InvalidTypeOption",
58114
42df7de58e39 8230519: jpackage "--package-type" values and default
herrick
parents: 57909
diff changeset
   555
                        option.getIdWithPrefix(), type);
57192
3d6a21f41c10 8217802: Invalid Option warning message.
herrick
parents: 57151
diff changeset
   556
                }
57414
6eda749d3117 8225428: CLI change to remove "mode", rename to "package", and build only one target
herrick
parents: 57392
diff changeset
   557
            } else if (installerOnly || runtimeInstaller) {
57256
d7c27451f759 8219678: CLI changes in jpackage
herrick
parents: 57214
diff changeset
   558
                if (!ValidOptions.checkIfInstallerSupported(option)) {
57414
6eda749d3117 8225428: CLI change to remove "mode", rename to "package", and build only one target
herrick
parents: 57392
diff changeset
   559
                    if (runtimeInstaller) {
6eda749d3117 8225428: CLI change to remove "mode", rename to "package", and build only one target
herrick
parents: 57392
diff changeset
   560
                        throw new PackagerException("ERR_NoInstallerEntryPoint",
6eda749d3117 8225428: CLI change to remove "mode", rename to "package", and build only one target
herrick
parents: 57392
diff changeset
   561
                            option.getIdWithPrefix());
6eda749d3117 8225428: CLI change to remove "mode", rename to "package", and build only one target
herrick
parents: 57392
diff changeset
   562
                    } else {
6eda749d3117 8225428: CLI change to remove "mode", rename to "package", and build only one target
herrick
parents: 57392
diff changeset
   563
                        throw new PackagerException("ERR_InvalidTypeOption",
6eda749d3117 8225428: CLI change to remove "mode", rename to "package", and build only one target
herrick
parents: 57392
diff changeset
   564
                            option.getIdWithPrefix(), ptype);
6eda749d3117 8225428: CLI change to remove "mode", rename to "package", and build only one target
herrick
parents: 57392
diff changeset
   565
                   }
57256
d7c27451f759 8219678: CLI changes in jpackage
herrick
parents: 57214
diff changeset
   566
                }
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   567
            }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   568
        }
57256
d7c27451f759 8219678: CLI changes in jpackage
herrick
parents: 57214
diff changeset
   569
        if (installerOnly && hasRuntime) {
d7c27451f759 8219678: CLI changes in jpackage
herrick
parents: 57214
diff changeset
   570
            // note --runtime-image is only for image or runtime installer.
57414
6eda749d3117 8225428: CLI change to remove "mode", rename to "package", and build only one target
herrick
parents: 57392
diff changeset
   571
            throw new PackagerException("ERR_InvalidTypeOption",
6eda749d3117 8225428: CLI change to remove "mode", rename to "package", and build only one target
herrick
parents: 57392
diff changeset
   572
                    CLIOptions.PREDEFINED_RUNTIME_IMAGE.getIdWithPrefix(),
6eda749d3117 8225428: CLI change to remove "mode", rename to "package", and build only one target
herrick
parents: 57392
diff changeset
   573
                    ptype);
57256
d7c27451f759 8219678: CLI changes in jpackage
herrick
parents: 57214
diff changeset
   574
        }
d7c27451f759 8219678: CLI changes in jpackage
herrick
parents: 57214
diff changeset
   575
        if (hasMainJar && hasMainModule) {
d7c27451f759 8219678: CLI changes in jpackage
herrick
parents: 57214
diff changeset
   576
            throw new PackagerException("ERR_BothMainJarAndModule");
d7c27451f759 8219678: CLI changes in jpackage
herrick
parents: 57214
diff changeset
   577
        }
d7c27451f759 8219678: CLI changes in jpackage
herrick
parents: 57214
diff changeset
   578
        if (imageOnly && !hasMainJar && !hasMainModule) {
d7c27451f759 8219678: CLI changes in jpackage
herrick
parents: 57214
diff changeset
   579
            throw new PackagerException("ERR_NoEntryPoint");
d7c27451f759 8219678: CLI changes in jpackage
herrick
parents: 57214
diff changeset
   580
        }
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
57414
6eda749d3117 8225428: CLI change to remove "mode", rename to "package", and build only one target
herrick
parents: 57392
diff changeset
   583
    private jdk.jpackage.internal.Bundler getPlatformBundler() {
58114
42df7de58e39 8230519: jpackage "--package-type" values and default
herrick
parents: 57909
diff changeset
   584
        boolean appImage = deployParams.isTargetAppImage();
42df7de58e39 8230519: jpackage "--package-type" values and default
herrick
parents: 57909
diff changeset
   585
        String type = deployParams.getTargetFormat();
42df7de58e39 8230519: jpackage "--package-type" values and default
herrick
parents: 57909
diff changeset
   586
        String bundleType = (appImage ?  "IMAGE" : "INSTALLER");
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   587
57039
98d3963b0b7b 8214051: rename jpackager tool to jpackage
herrick
parents: 57038
diff changeset
   588
        for (jdk.jpackage.internal.Bundler bundler :
57414
6eda749d3117 8225428: CLI change to remove "mode", rename to "package", and build only one target
herrick
parents: 57392
diff changeset
   589
                Bundlers.createBundlersInstance().getBundlers(bundleType)) {
58114
42df7de58e39 8230519: jpackage "--package-type" values and default
herrick
parents: 57909
diff changeset
   590
            if (type == null) {
42df7de58e39 8230519: jpackage "--package-type" values and default
herrick
parents: 57909
diff changeset
   591
                 if (bundler.isDefault()
42df7de58e39 8230519: jpackage "--package-type" values and default
herrick
parents: 57909
diff changeset
   592
                         && bundler.supported(runtimeInstaller)) {
42df7de58e39 8230519: jpackage "--package-type" values and default
herrick
parents: 57909
diff changeset
   593
                     return bundler;
42df7de58e39 8230519: jpackage "--package-type" values and default
herrick
parents: 57909
diff changeset
   594
                 }
42df7de58e39 8230519: jpackage "--package-type" values and default
herrick
parents: 57909
diff changeset
   595
            } else {
42df7de58e39 8230519: jpackage "--package-type" values and default
herrick
parents: 57909
diff changeset
   596
                 if ((appImage || type.equalsIgnoreCase(bundler.getID()))
42df7de58e39 8230519: jpackage "--package-type" values and default
herrick
parents: 57909
diff changeset
   597
                         && bundler.supported(runtimeInstaller)) {
57414
6eda749d3117 8225428: CLI change to remove "mode", rename to "package", and build only one target
herrick
parents: 57392
diff changeset
   598
                     return bundler;
6eda749d3117 8225428: CLI change to remove "mode", rename to "package", and build only one target
herrick
parents: 57392
diff changeset
   599
                 }
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   600
            }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   601
        }
57414
6eda749d3117 8225428: CLI change to remove "mode", rename to "package", and build only one target
herrick
parents: 57392
diff changeset
   602
        return null;
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
57414
6eda749d3117 8225428: CLI change to remove "mode", rename to "package", and build only one target
herrick
parents: 57392
diff changeset
   605
    private void generateBundle(Map<String,? super Object> params)
56869
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56836
diff changeset
   606
            throws PackagerException {
57103
fe6bf39ac415 8216373: temporary build-root left behind when using secondary launcher(s)
herrick
parents: 57099
diff changeset
   607
57062
044e7a644ee3 8214575: Exe installers will install application to already existing instalation
herrick
parents: 57060
diff changeset
   608
        boolean bundleCreated = false;
57103
fe6bf39ac415 8216373: temporary build-root left behind when using secondary launcher(s)
herrick
parents: 57099
diff changeset
   609
58115
4a27283b542d /home/aherrick/comment
herrick
parents: 58114
diff changeset
   610
        // the temp dir needs to be fetched from the params early,
57103
fe6bf39ac415 8216373: temporary build-root left behind when using secondary launcher(s)
herrick
parents: 57099
diff changeset
   611
        // to prevent each copy of the params (such as may be used for
58115
4a27283b542d /home/aherrick/comment
herrick
parents: 58114
diff changeset
   612
        // additional launchers) from generating a separate temp dir when
57103
fe6bf39ac415 8216373: temporary build-root left behind when using secondary launcher(s)
herrick
parents: 57099
diff changeset
   613
        // 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
   614
        // 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
   615
        // clean these extra (and unneeded) temp directories.
57256
d7c27451f759 8219678: CLI changes in jpackage
herrick
parents: 57214
diff changeset
   616
        StandardBundlerParam.TEMP_ROOT.fetchFrom(params);
57414
6eda749d3117 8225428: CLI change to remove "mode", rename to "package", and build only one target
herrick
parents: 57392
diff changeset
   617
6eda749d3117 8225428: CLI change to remove "mode", rename to "package", and build only one target
herrick
parents: 57392
diff changeset
   618
        // determine what bundler to run
6eda749d3117 8225428: CLI change to remove "mode", rename to "package", and build only one target
herrick
parents: 57392
diff changeset
   619
        jdk.jpackage.internal.Bundler bundler = getPlatformBundler();
6eda749d3117 8225428: CLI change to remove "mode", rename to "package", and build only one target
herrick
parents: 57392
diff changeset
   620
6eda749d3117 8225428: CLI change to remove "mode", rename to "package", and build only one target
herrick
parents: 57392
diff changeset
   621
        if (bundler == null) {
57256
d7c27451f759 8219678: CLI changes in jpackage
herrick
parents: 57214
diff changeset
   622
            throw new PackagerException("ERR_InvalidInstallerType",
57414
6eda749d3117 8225428: CLI change to remove "mode", rename to "package", and build only one target
herrick
parents: 57392
diff changeset
   623
                      deployParams.getTargetFormat());
57256
d7c27451f759 8219678: CLI changes in jpackage
herrick
parents: 57214
diff changeset
   624
        }
57414
6eda749d3117 8225428: CLI change to remove "mode", rename to "package", and build only one target
herrick
parents: 57392
diff changeset
   625
6eda749d3117 8225428: CLI change to remove "mode", rename to "package", and build only one target
herrick
parents: 57392
diff changeset
   626
        Map<String, ? super Object> localParams = new HashMap<>(params);
6eda749d3117 8225428: CLI change to remove "mode", rename to "package", and build only one target
herrick
parents: 57392
diff changeset
   627
        try {
6eda749d3117 8225428: CLI change to remove "mode", rename to "package", and build only one target
herrick
parents: 57392
diff changeset
   628
            bundler.validate(localParams);
6eda749d3117 8225428: CLI change to remove "mode", rename to "package", and build only one target
herrick
parents: 57392
diff changeset
   629
            File result = bundler.execute(localParams, deployParams.outdir);
6eda749d3117 8225428: CLI change to remove "mode", rename to "package", and build only one target
herrick
parents: 57392
diff changeset
   630
            if (result == null) {
6eda749d3117 8225428: CLI change to remove "mode", rename to "package", and build only one target
herrick
parents: 57392
diff changeset
   631
                throw new PackagerException("MSG_BundlerFailed",
6eda749d3117 8225428: CLI change to remove "mode", rename to "package", and build only one target
herrick
parents: 57392
diff changeset
   632
                        bundler.getID(), bundler.getName());
6eda749d3117 8225428: CLI change to remove "mode", rename to "package", and build only one target
herrick
parents: 57392
diff changeset
   633
            }
6eda749d3117 8225428: CLI change to remove "mode", rename to "package", and build only one target
herrick
parents: 57392
diff changeset
   634
            Log.verbose(MessageFormat.format(
6eda749d3117 8225428: CLI change to remove "mode", rename to "package", and build only one target
herrick
parents: 57392
diff changeset
   635
                    I18N.getString("message.bundle-created"),
6eda749d3117 8225428: CLI change to remove "mode", rename to "package", and build only one target
herrick
parents: 57392
diff changeset
   636
                    bundler.getName()));
6eda749d3117 8225428: CLI change to remove "mode", rename to "package", and build only one target
herrick
parents: 57392
diff changeset
   637
        } catch (ConfigException e) {
57776
783db59cd8d3 8224594: Simplify jpackage Logging
herrick
parents: 57741
diff changeset
   638
            Log.verbose(e);
57414
6eda749d3117 8225428: CLI change to remove "mode", rename to "package", and build only one target
herrick
parents: 57392
diff changeset
   639
            if (e.getAdvice() != null)  {
6eda749d3117 8225428: CLI change to remove "mode", rename to "package", and build only one target
herrick
parents: 57392
diff changeset
   640
                throw new PackagerException(e, "MSG_BundlerConfigException",
6eda749d3117 8225428: CLI change to remove "mode", rename to "package", and build only one target
herrick
parents: 57392
diff changeset
   641
                        bundler.getName(), e.getMessage(), e.getAdvice());
6eda749d3117 8225428: CLI change to remove "mode", rename to "package", and build only one target
herrick
parents: 57392
diff changeset
   642
            } else {
6eda749d3117 8225428: CLI change to remove "mode", rename to "package", and build only one target
herrick
parents: 57392
diff changeset
   643
                throw new PackagerException(e,
6eda749d3117 8225428: CLI change to remove "mode", rename to "package", and build only one target
herrick
parents: 57392
diff changeset
   644
                       "MSG_BundlerConfigExceptionNoAdvice",
6eda749d3117 8225428: CLI change to remove "mode", rename to "package", and build only one target
herrick
parents: 57392
diff changeset
   645
                        bundler.getName(), e.getMessage());
6eda749d3117 8225428: CLI change to remove "mode", rename to "package", and build only one target
herrick
parents: 57392
diff changeset
   646
            }
6eda749d3117 8225428: CLI change to remove "mode", rename to "package", and build only one target
herrick
parents: 57392
diff changeset
   647
        } catch (RuntimeException re) {
57776
783db59cd8d3 8224594: Simplify jpackage Logging
herrick
parents: 57741
diff changeset
   648
            Log.verbose(re);
57414
6eda749d3117 8225428: CLI change to remove "mode", rename to "package", and build only one target
herrick
parents: 57392
diff changeset
   649
            throw new PackagerException(re, "MSG_BundlerRuntimeException",
6eda749d3117 8225428: CLI change to remove "mode", rename to "package", and build only one target
herrick
parents: 57392
diff changeset
   650
                    bundler.getName(), re.toString());
6eda749d3117 8225428: CLI change to remove "mode", rename to "package", and build only one target
herrick
parents: 57392
diff changeset
   651
        } finally {
6eda749d3117 8225428: CLI change to remove "mode", rename to "package", and build only one target
herrick
parents: 57392
diff changeset
   652
            if (userProvidedBuildRoot) {
57261
13b6672477df 8220505: Allow building available installers when --installer-type not specified
herrick
parents: 57256
diff changeset
   653
                Log.verbose(MessageFormat.format(
57414
6eda749d3117 8225428: CLI change to remove "mode", rename to "package", and build only one target
herrick
parents: 57392
diff changeset
   654
                        I18N.getString("message.debug-working-directory"),
6eda749d3117 8225428: CLI change to remove "mode", rename to "package", and build only one target
herrick
parents: 57392
diff changeset
   655
                        (new File(buildRoot)).getAbsolutePath()));
57421
0410ee319681 8226532: cleanup is not called when jpackage command fails.
herrick
parents: 57414
diff changeset
   656
            } else {
0410ee319681 8226532: cleanup is not called when jpackage command fails.
herrick
parents: 57414
diff changeset
   657
                // always clean up the temporary directory created
58115
4a27283b542d /home/aherrick/comment
herrick
parents: 58114
diff changeset
   658
                // when --temp option not used.
57421
0410ee319681 8226532: cleanup is not called when jpackage command fails.
herrick
parents: 57414
diff changeset
   659
                bundler.cleanup(localParams);
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   660
            }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   661
        }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   662
    }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   663
56994
b4aca2dbe2b5 8212537: Create method and class description comments for main functionality
herrick
parents: 56989
diff changeset
   664
    private void addResources(DeployParams deployParams,
57450
82c78b40b39d 8227058: Regressions related to no longer setting user.dir
herrick
parents: 57438
diff changeset
   665
            String inputdir, String mainJar) throws PackagerException {
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   666
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   667
        if (inputdir == null || inputdir.isEmpty()) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   668
            return;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   669
        }
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
        File baseDir = new File(inputdir);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   672
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   673
        if (!baseDir.isDirectory()) {
57314
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents: 57307
diff changeset
   674
            throw new PackagerException("ERR_InputNotDirectory", inputdir);
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents: 57307
diff changeset
   675
        }
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents: 57307
diff changeset
   676
        if (!baseDir.canRead()) {
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents: 57307
diff changeset
   677
            throw new PackagerException("ERR_CannotReadInputDir", inputdir);
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   678
        }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   679
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   680
        List<String> fileNames;
57307
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents: 57291
diff changeset
   681
        fileNames = new ArrayList<>();
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents: 57291
diff changeset
   682
        try (Stream<Path> files = Files.list(baseDir.toPath())) {
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents: 57291
diff changeset
   683
            files.forEach(file -> fileNames.add(
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents: 57291
diff changeset
   684
                    file.getFileName().toString()));
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents: 57291
diff changeset
   685
        } catch (IOException e) {
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents: 57291
diff changeset
   686
            Log.error("Unable to add resources: " + e.getMessage());
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   687
        }
56994
b4aca2dbe2b5 8212537: Create method and class description comments for main functionality
herrick
parents: 56989
diff changeset
   688
        fileNames.forEach(file -> deployParams.addResource(baseDir, file));
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   689
57450
82c78b40b39d 8227058: Regressions related to no longer setting user.dir
herrick
parents: 57438
diff changeset
   690
        deployParams.setClasspath(mainJar);
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   691
    }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   692
57067
9c17d779808e 8213425: Analyze output from Source code scanner and fix where needed.
herrick
parents: 57065
diff changeset
   693
    static CLIOptions toCLIOption(String arg) {
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   694
        CLIOptions option;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   695
        if ((option = argIds.get(arg)) == null) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   696
            option = argShortIds.get(arg);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   697
        }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   698
        return option;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   699
    }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   700
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   701
    static Map<String, String> getPropertiesFromFile(String filename) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   702
        Map<String, String> map = new HashMap<>();
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   703
        // load properties file
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   704
        File file = new File(filename);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   705
        Properties properties = new Properties();
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   706
        try (FileInputStream in = new FileInputStream(file)) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   707
            properties.load(in);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   708
        } catch (IOException e) {
57020
a828547f7e50 8213394: Stop using Log.info() except for expected output.
herrick
parents: 57017
diff changeset
   709
            Log.error("Exception: " + e.getMessage());
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   710
        }
56957
2f01969ed7cb 8211299: Output of System.out is not printed to CMD on Windows
herrick
parents: 56933
diff changeset
   711
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   712
        for (final String name: properties.stringPropertyNames()) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   713
            map.put(name, properties.getProperty(name));
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   714
        }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   715
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   716
        return map;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   717
    }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   718
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   719
    static List<String> getArgumentList(String inputString) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   720
        List<String> list = new ArrayList<>();
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   721
        if (inputString == null || inputString.isEmpty()) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   722
             return list;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   723
        }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   724
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   725
        // 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
   726
        // strings are delimited by whitespace unless surrounded by
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   727
        // 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
   728
        Matcher m = pattern.matcher(inputString);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   729
        while (m.find()) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   730
            String s = inputString.substring(m.start(), m.end()).trim();
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   731
            // 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
   732
            // whitespace only strings. The regex preserves quotes and escaped
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   733
            // 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
   734
            if (!s.isEmpty()) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   735
                list.add(unquoteIfNeeded(s));
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   736
            }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   737
        }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   738
        return list;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   739
    }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   740
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   741
    private static String unquoteIfNeeded(String in) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   742
        if (in == null) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   743
            return null;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   744
        }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   745
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   746
        if (in.isEmpty()) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   747
            return "";
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   748
        }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   749
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   750
        // Use code points to preserve non-ASCII chars
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   751
        StringBuilder sb = new StringBuilder();
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   752
        int codeLen = in.codePointCount(0, in.length());
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   753
        int quoteChar = -1;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   754
        for (int i = 0; i < codeLen; i++) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   755
            int code = in.codePointAt(i);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   756
            if (code == '"' || code == '\'') {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   757
                // If quote is escaped make sure to copy it
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   758
                if (i > 0 && in.codePointAt(i - 1) == '\\') {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   759
                    sb.deleteCharAt(sb.length() - 1);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   760
                    sb.appendCodePoint(code);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   761
                    continue;
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
                if (quoteChar != -1) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   764
                    if (code == quoteChar) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   765
                        // close quote, skip char
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   766
                        quoteChar = -1;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   767
                    } else {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   768
                        sb.appendCodePoint(code);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   769
                    }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   770
                } else {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   771
                    // opening quote, skip char
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   772
                    quoteChar = code;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   773
                }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   774
            } else {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   775
                sb.appendCodePoint(code);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   776
            }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   777
        }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   778
        return sb.toString();
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   779
    }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   780
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   781
    private String getMainClassFromManifest() {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   782
        if (mainJarPath == null ||
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   783
            input == null ) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   784
            return null;
56957
2f01969ed7cb 8211299: Output of System.out is not printed to CMD on Windows
herrick
parents: 56933
diff changeset
   785
        }
2f01969ed7cb 8211299: Output of System.out is not printed to CMD on Windows
herrick
parents: 56933
diff changeset
   786
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   787
        JarFile jf;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   788
        try {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   789
            File file = new File(input, mainJarPath);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   790
            if (!file.exists()) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   791
                return null;
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
            jf = new JarFile(file);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   794
            Manifest m = jf.getManifest();
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   795
            Attributes attrs = (m != null) ? m.getMainAttributes() : null;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   796
            if (attrs != null) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   797
                return attrs.getValue(Attributes.Name.MAIN_CLASS);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   798
            }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   799
        } catch (IOException ignore) {}
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   800
        return null;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   801
    }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   802
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   803
}