src/jdk.jpackage/share/classes/jdk/jpackage/internal/StandardBundlerParam.java
author herrick
Thu, 06 Jun 2019 19:14:02 -0400
branchJDK-8200758-branch
changeset 57391 970f28090a06
parent 57389 cce526c681dc
child 57392 46d4b0aa4542
permissions -rw-r--r--
8223334: Additional cleanup in jpackage tool Reviewed-by: 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) 2014, 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
 */
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    25
57039
98d3963b0b7b 8214051: rename jpackager tool to jpackage
herrick
parents: 57038
diff changeset
    26
package jdk.jpackage.internal;
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    27
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    28
import java.io.File;
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.io.StringReader;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    31
import java.nio.file.Files;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    32
import java.nio.file.Path;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    33
import java.nio.file.Paths;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    34
import java.text.MessageFormat;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    35
import java.util.ArrayList;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    36
import java.util.Arrays;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    37
import java.util.Collections;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    38
import java.util.Date;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    39
import java.util.HashMap;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    40
import java.util.HashSet;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    41
import java.util.LinkedHashSet;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    42
import java.util.List;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    43
import java.util.Map;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    44
import java.util.Optional;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    45
import java.util.Properties;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    46
import java.util.ResourceBundle;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    47
import java.util.Set;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    48
import java.util.HashSet;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    49
import java.util.function.BiFunction;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    50
import java.util.function.Function;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    51
import java.util.jar.Attributes;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    52
import java.util.jar.JarFile;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    53
import java.util.jar.Manifest;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    54
import java.util.regex.Pattern;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    55
import java.util.stream.Collectors;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    56
56994
b4aca2dbe2b5 8212537: Create method and class description comments for main functionality
herrick
parents: 56989
diff changeset
    57
/**
57256
d7c27451f759 8219678: CLI changes in jpackage
herrick
parents: 57255
diff changeset
    58
 * StandardBundlerParam
56994
b4aca2dbe2b5 8212537: Create method and class description comments for main functionality
herrick
parents: 56989
diff changeset
    59
 *
b4aca2dbe2b5 8212537: Create method and class description comments for main functionality
herrick
parents: 56989
diff changeset
    60
 * A parameter to a bundler.
b4aca2dbe2b5 8212537: Create method and class description comments for main functionality
herrick
parents: 56989
diff changeset
    61
 *
b4aca2dbe2b5 8212537: Create method and class description comments for main functionality
herrick
parents: 56989
diff changeset
    62
 * Also contains static definitions of all of the common bundler parameters.
b4aca2dbe2b5 8212537: Create method and class description comments for main functionality
herrick
parents: 56989
diff changeset
    63
 * (additional platform specific and mode specific bundler parameters
b4aca2dbe2b5 8212537: Create method and class description comments for main functionality
herrick
parents: 56989
diff changeset
    64
 * are defined in each of the specific bundlers)
b4aca2dbe2b5 8212537: Create method and class description comments for main functionality
herrick
parents: 56989
diff changeset
    65
 *
b4aca2dbe2b5 8212537: Create method and class description comments for main functionality
herrick
parents: 56989
diff changeset
    66
 * Also contains static methods that operate on maps of parameters.
b4aca2dbe2b5 8212537: Create method and class description comments for main functionality
herrick
parents: 56989
diff changeset
    67
 */
57067
9c17d779808e 8213425: Analyze output from Source code scanner and fix where needed.
herrick
parents: 57059
diff changeset
    68
class StandardBundlerParam<T> extends BundlerParamInfo<T> {
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    69
56869
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56835
diff changeset
    70
    private static final ResourceBundle I18N = ResourceBundle.getBundle(
57059
9bb2a4dc3af7 8214143: Reduce Resource files
herrick
parents: 57039
diff changeset
    71
            "jdk.jpackage.internal.resources.MainResources");
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    72
    private static final String JAVABASEJMOD = "java.base.jmod";
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    73
57256
d7c27451f759 8219678: CLI changes in jpackage
herrick
parents: 57255
diff changeset
    74
    StandardBundlerParam(String id, Class<T> valueType,
56869
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56835
diff changeset
    75
            Function<Map<String, ? super Object>, T> defaultValueFunction,
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56835
diff changeset
    76
            BiFunction<String, Map<String, ? super Object>, T> stringConverter)
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56835
diff changeset
    77
    {
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    78
        this.id = id;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    79
        this.valueType = valueType;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    80
        this.defaultValueFunction = defaultValueFunction;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    81
        this.stringConverter = stringConverter;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    82
    }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    83
57067
9c17d779808e 8213425: Analyze output from Source code scanner and fix where needed.
herrick
parents: 57059
diff changeset
    84
    static final StandardBundlerParam<RelativeFileSet> APP_RESOURCES =
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    85
            new StandardBundlerParam<>(
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    86
                    BundleParams.PARAM_APP_RESOURCES,
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    87
                    RelativeFileSet.class,
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    88
                    null, // no default.  Required parameter
56869
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56835
diff changeset
    89
                    null  // no string translation,
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56835
diff changeset
    90
                          // tool must provide complex type
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    91
            );
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    92
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    93
    @SuppressWarnings("unchecked")
57067
9c17d779808e 8213425: Analyze output from Source code scanner and fix where needed.
herrick
parents: 57059
diff changeset
    94
    static final
56869
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56835
diff changeset
    95
            StandardBundlerParam<List<RelativeFileSet>> APP_RESOURCES_LIST =
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    96
            new StandardBundlerParam<>(
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    97
                    BundleParams.PARAM_APP_RESOURCES + "List",
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    98
                    (Class<List<RelativeFileSet>>) (Object) List.class,
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    99
                    // Default is appResources, as a single item list
56869
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56835
diff changeset
   100
                    p -> new ArrayList<>(Collections.singletonList(
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56835
diff changeset
   101
                            APP_RESOURCES.fetchFrom(p))),
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   102
                    StandardBundlerParam::createAppResourcesListFromString
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   103
            );
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   104
57067
9c17d779808e 8213425: Analyze output from Source code scanner and fix where needed.
herrick
parents: 57059
diff changeset
   105
    static final StandardBundlerParam<String> SOURCE_DIR =
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   106
            new StandardBundlerParam<>(
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   107
                    Arguments.CLIOptions.INPUT.getId(),
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   108
                    String.class,
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   109
                    p -> null,
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   110
                    (s, p) -> {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   111
                        String value = String.valueOf(s);
56869
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56835
diff changeset
   112
                        if (value.charAt(value.length() - 1) ==
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56835
diff changeset
   113
                                File.separatorChar) {
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   114
                            return value.substring(0, value.length() - 1);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   115
                        }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   116
                        else {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   117
                            return value;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   118
                        }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   119
                    }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   120
            );
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   121
56869
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56835
diff changeset
   122
    // note that each bundler is likely to replace this one with
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56835
diff changeset
   123
    // their own converter
57067
9c17d779808e 8213425: Analyze output from Source code scanner and fix where needed.
herrick
parents: 57059
diff changeset
   124
    static final StandardBundlerParam<RelativeFileSet> MAIN_JAR =
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   125
            new StandardBundlerParam<>(
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   126
                    Arguments.CLIOptions.MAIN_JAR.getId(),
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   127
                    RelativeFileSet.class,
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   128
                    params -> {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   129
                        extractMainClassInfoFromAppResources(params);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   130
                        return (RelativeFileSet) params.get("mainJar");
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   131
                    },
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   132
                    (s, p) -> getMainJar(s, p)
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   133
            );
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   134
56989
0f19096663d1 8212625: Remove --echo-mode and related code
herrick
parents: 56982
diff changeset
   135
    // TODO: test CLASSPATH jar manifest Attributet
57067
9c17d779808e 8213425: Analyze output from Source code scanner and fix where needed.
herrick
parents: 57059
diff changeset
   136
    static final StandardBundlerParam<String> CLASSPATH =
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   137
            new StandardBundlerParam<>(
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   138
                    "classpath",
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   139
                    String.class,
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   140
                    params -> {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   141
                        extractMainClassInfoFromAppResources(params);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   142
                        String cp = (String) params.get("classpath");
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   143
                        return cp == null ? "" : cp;
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
                    (s, p) -> s.replace(File.pathSeparator, " ")
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   146
            );
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   147
57067
9c17d779808e 8213425: Analyze output from Source code scanner and fix where needed.
herrick
parents: 57059
diff changeset
   148
    static final StandardBundlerParam<String> MAIN_CLASS =
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   149
            new StandardBundlerParam<>(
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   150
                    Arguments.CLIOptions.APPCLASS.getId(),
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   151
                    String.class,
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   152
                    params -> {
57256
d7c27451f759 8219678: CLI changes in jpackage
herrick
parents: 57255
diff changeset
   153
                        if (isRuntimeInstaller(params)) {
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   154
                            return null;
56989
0f19096663d1 8212625: Remove --echo-mode and related code
herrick
parents: 56982
diff changeset
   155
                        }
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   156
                        extractMainClassInfoFromAppResources(params);
56869
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56835
diff changeset
   157
                        String s = (String) params.get(
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56835
diff changeset
   158
                                BundleParams.PARAM_APPLICATION_CLASS);
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   159
                        if (s == null) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   160
                            s = JLinkBundlerHelper.getMainClass(params);
57389
cce526c681dc 8222901: different behavior when --name option not used
herrick
parents: 57323
diff changeset
   161
                            if (s.length() == 0) {
cce526c681dc 8222901: different behavior when --name option not used
herrick
parents: 57323
diff changeset
   162
                                s = null;
cce526c681dc 8222901: different behavior when --name option not used
herrick
parents: 57323
diff changeset
   163
                            }
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   164
                        }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   165
                        return s;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   166
                    },
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   167
                    (s, p) -> s
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   168
            );
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   169
57314
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents: 57291
diff changeset
   170
    static final StandardBundlerParam<File> PREDEFINED_RUNTIME_IMAGE =
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents: 57291
diff changeset
   171
            new StandardBundlerParam<>(
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents: 57291
diff changeset
   172
                    Arguments.CLIOptions.PREDEFINED_RUNTIME_IMAGE.getId(),
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents: 57291
diff changeset
   173
                    File.class,
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents: 57291
diff changeset
   174
                    params -> null,
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents: 57291
diff changeset
   175
                    (s, p) -> new File(s)
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents: 57291
diff changeset
   176
            );
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents: 57291
diff changeset
   177
57067
9c17d779808e 8213425: Analyze output from Source code scanner and fix where needed.
herrick
parents: 57059
diff changeset
   178
    static final StandardBundlerParam<String> APP_NAME =
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   179
            new StandardBundlerParam<>(
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   180
                    Arguments.CLIOptions.NAME.getId(),
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   181
                    String.class,
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   182
                    params -> {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   183
                        String s = MAIN_CLASS.fetchFrom(params);
57314
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents: 57291
diff changeset
   184
                        if (s != null) {
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents: 57291
diff changeset
   185
                            int idx = s.lastIndexOf(".");
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents: 57291
diff changeset
   186
                            if (idx >= 0) {
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents: 57291
diff changeset
   187
                                return s.substring(idx+1);
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents: 57291
diff changeset
   188
                            }
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents: 57291
diff changeset
   189
                            return s;
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents: 57291
diff changeset
   190
                        } else if (isRuntimeInstaller(params)) {
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents: 57291
diff changeset
   191
                            File f = PREDEFINED_RUNTIME_IMAGE.fetchFrom(params);
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents: 57291
diff changeset
   192
                            if (f != null) {
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents: 57291
diff changeset
   193
                                return f.getName();
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents: 57291
diff changeset
   194
                            }
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   195
                        }
57314
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents: 57291
diff changeset
   196
                        return null;
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   197
                    },
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   198
                    (s, p) -> s
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   199
            );
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   200
57067
9c17d779808e 8213425: Analyze output from Source code scanner and fix where needed.
herrick
parents: 57059
diff changeset
   201
    static final StandardBundlerParam<File> ICON =
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   202
            new StandardBundlerParam<>(
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   203
                    Arguments.CLIOptions.ICON.getId(),
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   204
                    File.class,
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   205
                    params -> null,
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   206
                    (s, p) -> new File(s)
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   207
            );
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   208
57067
9c17d779808e 8213425: Analyze output from Source code scanner and fix where needed.
herrick
parents: 57059
diff changeset
   209
    static final StandardBundlerParam<String> VENDOR =
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   210
            new StandardBundlerParam<>(
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   211
                    Arguments.CLIOptions.VENDOR.getId(),
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   212
                    String.class,
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   213
                    params -> I18N.getString("param.vendor.default"),
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   214
                    (s, p) -> s
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
57067
9c17d779808e 8213425: Analyze output from Source code scanner and fix where needed.
herrick
parents: 57059
diff changeset
   217
    static final StandardBundlerParam<String> DESCRIPTION =
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   218
            new StandardBundlerParam<>(
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   219
                    Arguments.CLIOptions.DESCRIPTION.getId(),
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   220
                    String.class,
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   221
                    params -> params.containsKey(APP_NAME.getID())
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   222
                            ? APP_NAME.fetchFrom(params)
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   223
                            : I18N.getString("param.description.default"),
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   224
                    (s, p) -> s
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
57067
9c17d779808e 8213425: Analyze output from Source code scanner and fix where needed.
herrick
parents: 57059
diff changeset
   227
    static final StandardBundlerParam<String> COPYRIGHT =
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   228
            new StandardBundlerParam<>(
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   229
                    Arguments.CLIOptions.COPYRIGHT.getId(),
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   230
                    String.class,
56869
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56835
diff changeset
   231
                    params -> MessageFormat.format(I18N.getString(
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56835
diff changeset
   232
                            "param.copyright.default"), new Date()),
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   233
                    (s, p) -> s
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   234
            );
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   235
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   236
    @SuppressWarnings("unchecked")
57067
9c17d779808e 8213425: Analyze output from Source code scanner and fix where needed.
herrick
parents: 57059
diff changeset
   237
    static final StandardBundlerParam<List<String>> ARGUMENTS =
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   238
            new StandardBundlerParam<>(
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   239
                    Arguments.CLIOptions.ARGUMENTS.getId(),
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   240
                    (Class<List<String>>) (Object) List.class,
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   241
                    params -> Collections.emptyList(),
57391
970f28090a06 8223334: Additional cleanup in jpackage tool
herrick
parents: 57389
diff changeset
   242
                    (s, p) -> null
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   243
            );
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   244
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   245
    @SuppressWarnings("unchecked")
57316
2891b3ae222d 8221641: Follow up code clean up for JDK-8221582
herrick
parents: 57314
diff changeset
   246
    static final StandardBundlerParam<List<String>> JAVA_OPTIONS =
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   247
            new StandardBundlerParam<>(
57291
f2d429260ad4 8221582: Rename jvm-args option to java-options
herrick
parents: 57256
diff changeset
   248
                    Arguments.CLIOptions.JAVA_OPTIONS.getId(),
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   249
                    (Class<List<String>>) (Object) List.class,
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   250
                    params -> Collections.emptyList(),
56835
43caa6ff671a 8207022: jpackager saves VM args incorrectly if --jvm-args contains white spaces
herrick
parents: 56829
diff changeset
   251
                    (s, p) -> Arrays.asList(s.split("\n\n"))
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   252
            );
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   253
56869
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56835
diff changeset
   254
    // note that each bundler is likely to replace this one with
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56835
diff changeset
   255
    // their own converter
57067
9c17d779808e 8213425: Analyze output from Source code scanner and fix where needed.
herrick
parents: 57059
diff changeset
   256
    static final StandardBundlerParam<String> VERSION =
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   257
            new StandardBundlerParam<>(
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   258
                    Arguments.CLIOptions.VERSION.getId(),
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   259
                    String.class,
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   260
                    params -> I18N.getString("param.version.default"),
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   261
                    (s, p) -> s
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
    @SuppressWarnings("unchecked")
57080
bd4ce7f9ea2c 8214495: Change behavior of --license-file
herrick
parents: 57078
diff changeset
   265
    public static final StandardBundlerParam<String> LICENSE_FILE =
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   266
            new StandardBundlerParam<>(
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   267
                    Arguments.CLIOptions.LICENSE_FILE.getId(),
57080
bd4ce7f9ea2c 8214495: Change behavior of --license-file
herrick
parents: 57078
diff changeset
   268
                    String.class,
bd4ce7f9ea2c 8214495: Change behavior of --license-file
herrick
parents: 57078
diff changeset
   269
                    params -> null,
bd4ce7f9ea2c 8214495: Change behavior of --license-file
herrick
parents: 57078
diff changeset
   270
                    (s, p) -> s
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   271
            );
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   272
57256
d7c27451f759 8219678: CLI changes in jpackage
herrick
parents: 57255
diff changeset
   273
    static final StandardBundlerParam<File> TEMP_ROOT =
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   274
            new StandardBundlerParam<>(
57256
d7c27451f759 8219678: CLI changes in jpackage
herrick
parents: 57255
diff changeset
   275
                    Arguments.CLIOptions.TEMP_ROOT.getId(),
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   276
                    File.class,
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   277
                    params -> {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   278
                        try {
56869
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56835
diff changeset
   279
                            return Files.createTempDirectory(
57039
98d3963b0b7b 8214051: rename jpackager tool to jpackage
herrick
parents: 57038
diff changeset
   280
                                    "jdk.jpackage").toFile();
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   281
                        } catch (IOException ioe) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   282
                            return null;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   283
                        }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   284
                    },
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   285
                    (s, p) -> new File(s)
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   286
            );
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   287
57103
fe6bf39ac415 8216373: temporary build-root left behind when using secondary launcher(s)
herrick
parents: 57099
diff changeset
   288
    public static final StandardBundlerParam<File> CONFIG_ROOT =
fe6bf39ac415 8216373: temporary build-root left behind when using secondary launcher(s)
herrick
parents: 57099
diff changeset
   289
            new StandardBundlerParam<>(
fe6bf39ac415 8216373: temporary build-root left behind when using secondary launcher(s)
herrick
parents: 57099
diff changeset
   290
                "configRoot",
fe6bf39ac415 8216373: temporary build-root left behind when using secondary launcher(s)
herrick
parents: 57099
diff changeset
   291
                File.class,
fe6bf39ac415 8216373: temporary build-root left behind when using secondary launcher(s)
herrick
parents: 57099
diff changeset
   292
                params -> {
fe6bf39ac415 8216373: temporary build-root left behind when using secondary launcher(s)
herrick
parents: 57099
diff changeset
   293
                    File root =
57256
d7c27451f759 8219678: CLI changes in jpackage
herrick
parents: 57255
diff changeset
   294
                            new File(TEMP_ROOT.fetchFrom(params), "config");
57103
fe6bf39ac415 8216373: temporary build-root left behind when using secondary launcher(s)
herrick
parents: 57099
diff changeset
   295
                    root.mkdirs();
fe6bf39ac415 8216373: temporary build-root left behind when using secondary launcher(s)
herrick
parents: 57099
diff changeset
   296
                    return root;
fe6bf39ac415 8216373: temporary build-root left behind when using secondary launcher(s)
herrick
parents: 57099
diff changeset
   297
                },
fe6bf39ac415 8216373: temporary build-root left behind when using secondary launcher(s)
herrick
parents: 57099
diff changeset
   298
                (s, p) -> null
fe6bf39ac415 8216373: temporary build-root left behind when using secondary launcher(s)
herrick
parents: 57099
diff changeset
   299
            );
fe6bf39ac415 8216373: temporary build-root left behind when using secondary launcher(s)
herrick
parents: 57099
diff changeset
   300
57067
9c17d779808e 8213425: Analyze output from Source code scanner and fix where needed.
herrick
parents: 57059
diff changeset
   301
    static final StandardBundlerParam<String> IDENTIFIER =
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   302
            new StandardBundlerParam<>(
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   303
                    Arguments.CLIOptions.IDENTIFIER.getId(),
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   304
                    String.class,
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   305
                    params -> {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   306
                        String s = MAIN_CLASS.fetchFrom(params);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   307
                        if (s == null) return null;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   308
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   309
                        int idx = s.lastIndexOf(".");
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   310
                        if (idx >= 1) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   311
                            return s.substring(0, idx);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   312
                        }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   313
                        return s;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   314
                    },
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   315
                    (s, p) -> s
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   316
            );
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   317
57067
9c17d779808e 8213425: Analyze output from Source code scanner and fix where needed.
herrick
parents: 57059
diff changeset
   318
    static final StandardBundlerParam<Boolean> VERBOSE  =
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   319
            new StandardBundlerParam<>(
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   320
                    Arguments.CLIOptions.VERBOSE.getId(),
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   321
                    Boolean.class,
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   322
                    params -> false,
56869
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56835
diff changeset
   323
                    // valueOf(null) is false, and we actually do want null
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56835
diff changeset
   324
                    (s, p) -> (s == null || "null".equalsIgnoreCase(s)) ?
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56835
diff changeset
   325
                            true : Boolean.valueOf(s)
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   326
            );
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   327
57091
06bc4bd64599 8215515: Add a command line option to override internal resources.
herrick
parents: 57080
diff changeset
   328
    static final StandardBundlerParam<File> RESOURCE_DIR =
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   329
            new StandardBundlerParam<>(
57091
06bc4bd64599 8215515: Add a command line option to override internal resources.
herrick
parents: 57080
diff changeset
   330
                    Arguments.CLIOptions.RESOURCE_DIR.getId(),
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   331
                    File.class,
57091
06bc4bd64599 8215515: Add a command line option to override internal resources.
herrick
parents: 57080
diff changeset
   332
                    params -> null,
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   333
                    (s, p) -> new File(s)
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   334
            );
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   335
57067
9c17d779808e 8213425: Analyze output from Source code scanner and fix where needed.
herrick
parents: 57059
diff changeset
   336
    static final BundlerParamInfo<String> INSTALL_DIR =
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   337
            new StandardBundlerParam<>(
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   338
                    Arguments.CLIOptions.INSTALL_DIR.getId(),
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   339
                    String.class,
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   340
                     params -> null,
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   341
                    (s, p) -> s
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   342
    );
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   343
57067
9c17d779808e 8213425: Analyze output from Source code scanner and fix where needed.
herrick
parents: 57059
diff changeset
   344
    static final StandardBundlerParam<File> PREDEFINED_APP_IMAGE =
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   345
            new StandardBundlerParam<>(
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   346
            Arguments.CLIOptions.PREDEFINED_APP_IMAGE.getId(),
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   347
            File.class,
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   348
            params -> null,
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   349
            (s, p) -> new File(s));
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
    @SuppressWarnings("unchecked")
57256
d7c27451f759 8219678: CLI changes in jpackage
herrick
parents: 57255
diff changeset
   352
    static final StandardBundlerParam<List<Map<String, ? super Object>>> ADD_LAUNCHERS =
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   353
            new StandardBundlerParam<>(
57256
d7c27451f759 8219678: CLI changes in jpackage
herrick
parents: 57255
diff changeset
   354
                    Arguments.CLIOptions.ADD_LAUNCHER.getId(),
56869
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56835
diff changeset
   355
                    (Class<List<Map<String, ? super Object>>>) (Object)
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56835
diff changeset
   356
                            List.class,
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   357
                    params -> new ArrayList<>(1),
56869
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56835
diff changeset
   358
                    // valueOf(null) is false, and we actually do want null
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   359
                    (s, p) -> null
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
    @SuppressWarnings("unchecked")
57067
9c17d779808e 8213425: Analyze output from Source code scanner and fix where needed.
herrick
parents: 57059
diff changeset
   363
    static final StandardBundlerParam
56869
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56835
diff changeset
   364
            <List<Map<String, ? super Object>>> FILE_ASSOCIATIONS =
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   365
            new StandardBundlerParam<>(
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   366
                    Arguments.CLIOptions.FILE_ASSOCIATIONS.getId(),
56869
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56835
diff changeset
   367
                    (Class<List<Map<String, ? super Object>>>) (Object)
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56835
diff changeset
   368
                            List.class,
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   369
                    params -> new ArrayList<>(1),
56869
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56835
diff changeset
   370
                    // valueOf(null) is false, and we actually do want null
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   371
                    (s, p) -> null
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
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   374
    @SuppressWarnings("unchecked")
57067
9c17d779808e 8213425: Analyze output from Source code scanner and fix where needed.
herrick
parents: 57059
diff changeset
   375
    static final StandardBundlerParam<List<String>> FA_EXTENSIONS =
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   376
            new StandardBundlerParam<>(
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   377
                    "fileAssociation.extension",
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   378
                    (Class<List<String>>) (Object) List.class,
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   379
                    params -> null, // null means not matched to an extension
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   380
                    (s, p) -> Arrays.asList(s.split("(,|\\s)+"))
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
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   383
    @SuppressWarnings("unchecked")
57067
9c17d779808e 8213425: Analyze output from Source code scanner and fix where needed.
herrick
parents: 57059
diff changeset
   384
    static final StandardBundlerParam<List<String>> FA_CONTENT_TYPE =
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   385
            new StandardBundlerParam<>(
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   386
                    "fileAssociation.contentType",
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   387
                    (Class<List<String>>) (Object) List.class,
56869
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56835
diff changeset
   388
                    params -> null,
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56835
diff changeset
   389
                            // null means not matched to a content/mime type
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   390
                    (s, p) -> Arrays.asList(s.split("(,|\\s)+"))
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   391
            );
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   392
57067
9c17d779808e 8213425: Analyze output from Source code scanner and fix where needed.
herrick
parents: 57059
diff changeset
   393
    static final StandardBundlerParam<String> FA_DESCRIPTION =
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   394
            new StandardBundlerParam<>(
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   395
                    "fileAssociation.description",
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   396
                    String.class,
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   397
                    params -> APP_NAME.fetchFrom(params) + " File",
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   398
                    null
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
57067
9c17d779808e 8213425: Analyze output from Source code scanner and fix where needed.
herrick
parents: 57059
diff changeset
   401
    static final StandardBundlerParam<File> FA_ICON =
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   402
            new StandardBundlerParam<>(
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   403
                    "fileAssociation.icon",
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   404
                    File.class,
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   405
                    ICON::fetchFrom,
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   406
                    (s, p) -> new File(s)
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   407
            );
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
    @SuppressWarnings("unchecked")
57067
9c17d779808e 8213425: Analyze output from Source code scanner and fix where needed.
herrick
parents: 57059
diff changeset
   410
    static final BundlerParamInfo<List<Path>> MODULE_PATH =
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   411
            new StandardBundlerParam<>(
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   412
                    Arguments.CLIOptions.MODULE_PATH.getId(),
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   413
                    (Class<List<Path>>) (Object)List.class,
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   414
                    p -> { return getDefaultModulePath(); },
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   415
                    (s, p) -> {
56869
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56835
diff changeset
   416
                        List<Path> modulePath = Arrays.asList(s
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56835
diff changeset
   417
                                .split(File.pathSeparator)).stream()
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56835
diff changeset
   418
                                .map(ss -> new File(ss).toPath())
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56835
diff changeset
   419
                                .collect(Collectors.toList());
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   420
                        Path javaBasePath = null;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   421
                        if (modulePath != null) {
56869
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56835
diff changeset
   422
                            javaBasePath = JLinkBundlerHelper
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56835
diff changeset
   423
                                    .findPathOfModule(modulePath, JAVABASEJMOD);
57015
5d2008115309 JDK-8213244: Fix all warnings in jpackager java code
herrick
parents: 56994
diff changeset
   424
                        } else {
5d2008115309 JDK-8213244: Fix all warnings in jpackager java code
herrick
parents: 56994
diff changeset
   425
                            modulePath = new ArrayList<Path>();
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   426
                        }
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
                        // Add the default JDK module path to the module path.
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   429
                        if (javaBasePath == null) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   430
                            List<Path> jdkModulePath = getDefaultModulePath();
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   431
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   432
                            if (jdkModulePath != null) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   433
                                modulePath.addAll(jdkModulePath);
56869
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56835
diff changeset
   434
                                javaBasePath =
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56835
diff changeset
   435
                                        JLinkBundlerHelper.findPathOfModule(
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56835
diff changeset
   436
                                        modulePath, JAVABASEJMOD);
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   437
                            }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   438
                        }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   439
56869
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56835
diff changeset
   440
                        if (javaBasePath == null ||
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56835
diff changeset
   441
                                !Files.exists(javaBasePath)) {
57020
a828547f7e50 8213394: Stop using Log.info() except for expected output.
herrick
parents: 57017
diff changeset
   442
                            Log.error(String.format(I18N.getString(
a828547f7e50 8213394: Stop using Log.info() except for expected output.
herrick
parents: 57017
diff changeset
   443
                                    "warning.no.jdk.modules.found")));
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   444
                        }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   445
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   446
                        return modulePath;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   447
                    });
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   448
57067
9c17d779808e 8213425: Analyze output from Source code scanner and fix where needed.
herrick
parents: 57059
diff changeset
   449
    static final BundlerParamInfo<String> MODULE =
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   450
            new StandardBundlerParam<>(
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   451
                    Arguments.CLIOptions.MODULE.getId(),
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   452
                    String.class,
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   453
                    p -> null,
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   454
                    (s, p) -> {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   455
                        return String.valueOf(s);
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
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   458
    @SuppressWarnings("unchecked")
57067
9c17d779808e 8213425: Analyze output from Source code scanner and fix where needed.
herrick
parents: 57059
diff changeset
   459
    static final BundlerParamInfo<Set<String>> ADD_MODULES =
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   460
            new StandardBundlerParam<>(
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   461
                    Arguments.CLIOptions.ADD_MODULES.getId(),
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   462
                    (Class<Set<String>>) (Object) Set.class,
57015
5d2008115309 JDK-8213244: Fix all warnings in jpackager java code
herrick
parents: 56994
diff changeset
   463
                    p -> new LinkedHashSet<String>(),
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   464
                    (s, p) -> new LinkedHashSet<>(Arrays.asList(s.split(",")))
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
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   467
    @SuppressWarnings("unchecked")
57067
9c17d779808e 8213425: Analyze output from Source code scanner and fix where needed.
herrick
parents: 57059
diff changeset
   468
    static final BundlerParamInfo<Set<String>> LIMIT_MODULES =
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   469
            new StandardBundlerParam<>(
57150
fa68c2ab636d 8217894: jpackage CLI syntax changes
herrick
parents: 57119
diff changeset
   470
                    "limit-modules",
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   471
                    (Class<Set<String>>) (Object) Set.class,
57015
5d2008115309 JDK-8213244: Fix all warnings in jpackager java code
herrick
parents: 56994
diff changeset
   472
                    p -> new LinkedHashSet<String>(),
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   473
                    (s, p) -> new LinkedHashSet<>(Arrays.asList(s.split(",")))
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   474
            );
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   475
57256
d7c27451f759 8219678: CLI changes in jpackage
herrick
parents: 57255
diff changeset
   476
    static boolean isRuntimeInstaller(Map<String, ? super Object> p) {
d7c27451f759 8219678: CLI changes in jpackage
herrick
parents: 57255
diff changeset
   477
        if (p.containsKey(MODULE.getID()) ||
d7c27451f759 8219678: CLI changes in jpackage
herrick
parents: 57255
diff changeset
   478
                p.containsKey(MAIN_JAR.getID()) ||
d7c27451f759 8219678: CLI changes in jpackage
herrick
parents: 57255
diff changeset
   479
                p.containsKey(PREDEFINED_APP_IMAGE.getID())) {
d7c27451f759 8219678: CLI changes in jpackage
herrick
parents: 57255
diff changeset
   480
            return false; // we are building or are given an application
d7c27451f759 8219678: CLI changes in jpackage
herrick
parents: 57255
diff changeset
   481
        }
d7c27451f759 8219678: CLI changes in jpackage
herrick
parents: 57255
diff changeset
   482
        // runtime installer requires --runtime-image, if this is false
d7c27451f759 8219678: CLI changes in jpackage
herrick
parents: 57255
diff changeset
   483
        // here then we should have thrown error validating args.
d7c27451f759 8219678: CLI changes in jpackage
herrick
parents: 57255
diff changeset
   484
        return p.containsKey(PREDEFINED_RUNTIME_IMAGE.getID());
d7c27451f759 8219678: CLI changes in jpackage
herrick
parents: 57255
diff changeset
   485
    }
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   486
57067
9c17d779808e 8213425: Analyze output from Source code scanner and fix where needed.
herrick
parents: 57059
diff changeset
   487
    static File getPredefinedAppImage(Map<String, ? super Object> p) {
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   488
        File applicationImage = null;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   489
        if (PREDEFINED_APP_IMAGE.fetchFrom(p) != null) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   490
            applicationImage = PREDEFINED_APP_IMAGE.fetchFrom(p);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   491
            Log.debug("Using App Image from " + applicationImage);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   492
            if (!applicationImage.exists()) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   493
                throw new RuntimeException(
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   494
                        MessageFormat.format(I18N.getString(
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   495
                                "message.app-image-dir-does-not-exist"),
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   496
                                PREDEFINED_APP_IMAGE.getID(),
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   497
                                applicationImage.toString()));
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   498
            }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   499
        }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   500
        return applicationImage;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   501
    }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   502
57067
9c17d779808e 8213425: Analyze output from Source code scanner and fix where needed.
herrick
parents: 57059
diff changeset
   503
    static void copyPredefinedRuntimeImage(
56869
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56835
diff changeset
   504
            Map<String, ? super Object> p,
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56835
diff changeset
   505
            AbstractAppImageBuilder appBuilder)
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56835
diff changeset
   506
            throws IOException , ConfigException {
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   507
        File image = PREDEFINED_RUNTIME_IMAGE.fetchFrom(p);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   508
        if (!image.exists()) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   509
            throw new ConfigException(
56869
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56835
diff changeset
   510
                    MessageFormat.format(I18N.getString(
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56835
diff changeset
   511
                    "message.runtime-image-dir-does-not-exist"),
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56835
diff changeset
   512
                    PREDEFINED_RUNTIME_IMAGE.getID(),
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56835
diff changeset
   513
                    image.toString()),
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56835
diff changeset
   514
                    MessageFormat.format(I18N.getString(
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56835
diff changeset
   515
                    "message.runtime-image-dir-does-not-exist.advice"),
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56835
diff changeset
   516
                    PREDEFINED_RUNTIME_IMAGE.getID()));
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   517
        }
57077
8f9cf6ad59f0 8213962: JPackageCreateImageRuntimeModuleTest fails
herrick
parents: 57067
diff changeset
   518
        // copy whole runtime, need to skip jmods and src.zip
8f9cf6ad59f0 8213962: JPackageCreateImageRuntimeModuleTest fails
herrick
parents: 57067
diff changeset
   519
        final List<String> excludes = Arrays.asList("jmods", "src.zip");
8f9cf6ad59f0 8213962: JPackageCreateImageRuntimeModuleTest fails
herrick
parents: 57067
diff changeset
   520
        IOUtils.copyRecursive(image.toPath(), appBuilder.getRoot(), excludes);
8f9cf6ad59f0 8213962: JPackageCreateImageRuntimeModuleTest fails
herrick
parents: 57067
diff changeset
   521
8f9cf6ad59f0 8213962: JPackageCreateImageRuntimeModuleTest fails
herrick
parents: 57067
diff changeset
   522
        // if module-path given - copy modules to appDir/mods
8f9cf6ad59f0 8213962: JPackageCreateImageRuntimeModuleTest fails
herrick
parents: 57067
diff changeset
   523
        List<Path> modulePath =
8f9cf6ad59f0 8213962: JPackageCreateImageRuntimeModuleTest fails
herrick
parents: 57067
diff changeset
   524
                StandardBundlerParam.MODULE_PATH.fetchFrom(p);
8f9cf6ad59f0 8213962: JPackageCreateImageRuntimeModuleTest fails
herrick
parents: 57067
diff changeset
   525
        List<Path> defaultModulePath = getDefaultModulePath();
8f9cf6ad59f0 8213962: JPackageCreateImageRuntimeModuleTest fails
herrick
parents: 57067
diff changeset
   526
        Path dest = appBuilder.getAppModsDir();
57108
f1c13cb0e713 8217269: jpackage Makefile improvments
herrick
parents: 57106
diff changeset
   527
57077
8f9cf6ad59f0 8213962: JPackageCreateImageRuntimeModuleTest fails
herrick
parents: 57067
diff changeset
   528
        if (dest != null) {
8f9cf6ad59f0 8213962: JPackageCreateImageRuntimeModuleTest fails
herrick
parents: 57067
diff changeset
   529
            for (Path mp : modulePath) {
8f9cf6ad59f0 8213962: JPackageCreateImageRuntimeModuleTest fails
herrick
parents: 57067
diff changeset
   530
                if (!defaultModulePath.contains(mp)) {
8f9cf6ad59f0 8213962: JPackageCreateImageRuntimeModuleTest fails
herrick
parents: 57067
diff changeset
   531
                    Files.createDirectories(dest);
8f9cf6ad59f0 8213962: JPackageCreateImageRuntimeModuleTest fails
herrick
parents: 57067
diff changeset
   532
                    IOUtils.copyRecursive(mp, dest);
8f9cf6ad59f0 8213962: JPackageCreateImageRuntimeModuleTest fails
herrick
parents: 57067
diff changeset
   533
                }
8f9cf6ad59f0 8213962: JPackageCreateImageRuntimeModuleTest fails
herrick
parents: 57067
diff changeset
   534
            }
8f9cf6ad59f0 8213962: JPackageCreateImageRuntimeModuleTest fails
herrick
parents: 57067
diff changeset
   535
        }
8f9cf6ad59f0 8213962: JPackageCreateImageRuntimeModuleTest fails
herrick
parents: 57067
diff changeset
   536
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   537
        appBuilder.prepareApplicationFiles();
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   538
    }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   539
57067
9c17d779808e 8213425: Analyze output from Source code scanner and fix where needed.
herrick
parents: 57059
diff changeset
   540
    static void extractMainClassInfoFromAppResources(
56869
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56835
diff changeset
   541
            Map<String, ? super Object> params) {
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   542
        boolean hasMainClass = params.containsKey(MAIN_CLASS.getID());
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   543
        boolean hasMainJar = params.containsKey(MAIN_JAR.getID());
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   544
        boolean hasMainJarClassPath = params.containsKey(CLASSPATH.getID());
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   545
        boolean hasModule = params.containsKey(MODULE.getID());
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   546
56869
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56835
diff changeset
   547
        if (hasMainClass && hasMainJar && hasMainJarClassPath || hasModule ||
57256
d7c27451f759 8219678: CLI changes in jpackage
herrick
parents: 57255
diff changeset
   548
                isRuntimeInstaller(params)) {
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   549
            return;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   550
        }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   551
56869
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56835
diff changeset
   552
        // it's a pair.
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56835
diff changeset
   553
        // The [0] is the srcdir [1] is the file relative to sourcedir
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   554
        List<String[]> filesToCheck = new ArrayList<>();
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   555
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   556
        if (hasMainJar) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   557
            RelativeFileSet rfs = MAIN_JAR.fetchFrom(params);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   558
            for (String s : rfs.getIncludedFiles()) {
56869
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56835
diff changeset
   559
                filesToCheck.add(
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56835
diff changeset
   560
                        new String[] {rfs.getBaseDirectory().toString(), s});
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   561
            }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   562
        } else if (hasMainJarClassPath) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   563
            for (String s : CLASSPATH.fetchFrom(params).split("\\s+")) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   564
                if (APP_RESOURCES.fetchFrom(params) != null) {
56869
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56835
diff changeset
   565
                    filesToCheck.add(
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56835
diff changeset
   566
                            new String[] {APP_RESOURCES.fetchFrom(params)
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56835
diff changeset
   567
                            .getBaseDirectory().toString(), s});
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   568
                }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   569
            }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   570
        } else {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   571
            List<RelativeFileSet> rfsl = APP_RESOURCES_LIST.fetchFrom(params);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   572
            if (rfsl == null || rfsl.isEmpty()) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   573
                return;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   574
            }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   575
            for (RelativeFileSet rfs : rfsl) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   576
                if (rfs == null) continue;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   577
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   578
                for (String s : rfs.getIncludedFiles()) {
56869
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56835
diff changeset
   579
                    filesToCheck.add(
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56835
diff changeset
   580
                            new String[]{rfs.getBaseDirectory().toString(), s});
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
            }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   583
        }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   584
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   585
        // presume the set iterates in-order
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   586
        for (String[] fnames : filesToCheck) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   587
            try {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   588
                // only sniff jars
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   589
                if (!fnames[1].toLowerCase().endsWith(".jar")) continue;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   590
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   591
                File file = new File(fnames[0], fnames[1]);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   592
                // that actually exist
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   593
                if (!file.exists()) continue;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   594
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   595
                try (JarFile jf = new JarFile(file)) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   596
                    Manifest m = jf.getManifest();
56869
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56835
diff changeset
   597
                    Attributes attrs = (m != null) ?
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56835
diff changeset
   598
                            m.getMainAttributes() : null;
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   599
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   600
                    if (attrs != null) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   601
                        if (!hasMainJar) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   602
                            if (fnames[0] == null) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   603
                                fnames[0] = file.getParentFile().toString();
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   604
                            }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   605
                            params.put(MAIN_JAR.getID(), new RelativeFileSet(
56869
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56835
diff changeset
   606
                                    new File(fnames[0]),
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56835
diff changeset
   607
                                    new LinkedHashSet<>(Collections
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56835
diff changeset
   608
                                    .singletonList(file))));
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   609
                        }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   610
                        if (!hasMainJarClassPath) {
56869
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56835
diff changeset
   611
                            String cp =
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56835
diff changeset
   612
                                    attrs.getValue(Attributes.Name.CLASS_PATH);
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56835
diff changeset
   613
                            params.put(CLASSPATH.getID(),
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56835
diff changeset
   614
                                    cp == null ? "" : cp);
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   615
                        }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   616
                        break;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   617
                    }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   618
                }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   619
            } catch (IOException ignore) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   620
                ignore.printStackTrace();
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   621
            }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   622
        }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   623
    }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   624
57067
9c17d779808e 8213425: Analyze output from Source code scanner and fix where needed.
herrick
parents: 57059
diff changeset
   625
    static void validateMainClassInfoFromAppResources(
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   626
            Map<String, ? super Object> params) throws ConfigException {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   627
        boolean hasMainClass = params.containsKey(MAIN_CLASS.getID());
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   628
        boolean hasMainJar = params.containsKey(MAIN_JAR.getID());
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   629
        boolean hasMainJarClassPath = params.containsKey(CLASSPATH.getID());
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   630
        boolean hasModule = params.containsKey(MODULE.getID());
56882
0ec8559f599a 8210439: Unable to create an installer from a previously created app image on Windows
herrick
parents: 56869
diff changeset
   631
        boolean hasAppImage = params.containsKey(PREDEFINED_APP_IMAGE.getID());
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   632
56869
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56835
diff changeset
   633
        if (hasMainClass && hasMainJar && hasMainJarClassPath ||
57256
d7c27451f759 8219678: CLI changes in jpackage
herrick
parents: 57255
diff changeset
   634
               hasModule || hasAppImage || isRuntimeInstaller(params)) {
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   635
            return;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   636
        }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   637
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   638
        extractMainClassInfoFromAppResources(params);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   639
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   640
        if (!params.containsKey(MAIN_CLASS.getID())) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   641
            if (hasMainJar) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   642
                throw new ConfigException(
56869
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56835
diff changeset
   643
                        MessageFormat.format(I18N.getString(
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56835
diff changeset
   644
                        "error.no-main-class-with-main-jar"),
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56835
diff changeset
   645
                        MAIN_JAR.fetchFrom(params)),
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56835
diff changeset
   646
                        MessageFormat.format(I18N.getString(
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56835
diff changeset
   647
                        "error.no-main-class-with-main-jar.advice"),
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56835
diff changeset
   648
                        MAIN_JAR.fetchFrom(params)));
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   649
            } else {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   650
                throw new ConfigException(
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   651
                        I18N.getString("error.no-main-class"),
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   652
                        I18N.getString("error.no-main-class.advice"));
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   653
            }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   654
        }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   655
    }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   656
56869
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56835
diff changeset
   657
    private static List<RelativeFileSet>
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56835
diff changeset
   658
            createAppResourcesListFromString(String s,
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56835
diff changeset
   659
            Map<String, ? super Object> objectObjectMap) {
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   660
        List<RelativeFileSet> result = new ArrayList<>();
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   661
        for (String path : s.split("[:;]")) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   662
            File f = new File(path);
56869
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56835
diff changeset
   663
            if (f.getName().equals("*") || path.endsWith("/") ||
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56835
diff changeset
   664
                    path.endsWith("\\")) {
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   665
                if (f.getName().equals("*")) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   666
                    f = f.getParentFile();
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   667
                }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   668
                Set<File> theFiles = new HashSet<>();
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   669
                try {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   670
                    Files.walk(f.toPath())
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   671
                            .filter(Files::isRegularFile)
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   672
                            .forEach(p -> theFiles.add(p.toFile()));
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   673
                } catch (IOException e) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   674
                    e.printStackTrace();
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   675
                }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   676
                result.add(new RelativeFileSet(f, theFiles));
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   677
            } else {
56869
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56835
diff changeset
   678
                result.add(new RelativeFileSet(f.getParentFile(),
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56835
diff changeset
   679
                        Collections.singleton(f)));
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   680
            }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   681
        }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   682
        return result;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   683
    }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   684
56869
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56835
diff changeset
   685
    private static RelativeFileSet getMainJar(
57078
db003bfc5bf7 JDK-8215453: remove unused BundlerParams and fix misleading messages
herrick
parents: 57077
diff changeset
   686
            String mainJarValue, Map<String, ? super Object> params) {
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   687
        for (RelativeFileSet rfs : APP_RESOURCES_LIST.fetchFrom(params)) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   688
            File appResourcesRoot = rfs.getBaseDirectory();
57078
db003bfc5bf7 JDK-8215453: remove unused BundlerParams and fix misleading messages
herrick
parents: 57077
diff changeset
   689
            File mainJarFile = new File(appResourcesRoot, mainJarValue);
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   690
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   691
            if (mainJarFile.exists()) {
56869
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56835
diff changeset
   692
                return new RelativeFileSet(appResourcesRoot,
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56835
diff changeset
   693
                     new LinkedHashSet<>(Collections.singletonList(
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56835
diff changeset
   694
                     mainJarFile)));
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   695
            }
57078
db003bfc5bf7 JDK-8215453: remove unused BundlerParams and fix misleading messages
herrick
parents: 57077
diff changeset
   696
            mainJarFile = new File(mainJarValue);
db003bfc5bf7 JDK-8215453: remove unused BundlerParams and fix misleading messages
herrick
parents: 57077
diff changeset
   697
            if (mainJarFile.exists()) {
57314
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents: 57291
diff changeset
   698
                // absolute path for main-jar may fail is not legal
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents: 57291
diff changeset
   699
                // below contains explicit error message.
57078
db003bfc5bf7 JDK-8215453: remove unused BundlerParams and fix misleading messages
herrick
parents: 57077
diff changeset
   700
            } else {
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   701
                List<Path> modulePath = MODULE_PATH.fetchFrom(params);
57078
db003bfc5bf7 JDK-8215453: remove unused BundlerParams and fix misleading messages
herrick
parents: 57077
diff changeset
   702
                modulePath.removeAll(getDefaultModulePath());
db003bfc5bf7 JDK-8215453: remove unused BundlerParams and fix misleading messages
herrick
parents: 57077
diff changeset
   703
                if (!modulePath.isEmpty()) {
db003bfc5bf7 JDK-8215453: remove unused BundlerParams and fix misleading messages
herrick
parents: 57077
diff changeset
   704
                    Path modularJarPath = JLinkBundlerHelper.findPathOfModule(
db003bfc5bf7 JDK-8215453: remove unused BundlerParams and fix misleading messages
herrick
parents: 57077
diff changeset
   705
                            modulePath, mainJarValue);
db003bfc5bf7 JDK-8215453: remove unused BundlerParams and fix misleading messages
herrick
parents: 57077
diff changeset
   706
                    if (modularJarPath != null &&
db003bfc5bf7 JDK-8215453: remove unused BundlerParams and fix misleading messages
herrick
parents: 57077
diff changeset
   707
                            Files.exists(modularJarPath)) {
db003bfc5bf7 JDK-8215453: remove unused BundlerParams and fix misleading messages
herrick
parents: 57077
diff changeset
   708
                        return new RelativeFileSet(appResourcesRoot,
db003bfc5bf7 JDK-8215453: remove unused BundlerParams and fix misleading messages
herrick
parents: 57077
diff changeset
   709
                                new LinkedHashSet<>(Collections.singletonList(
db003bfc5bf7 JDK-8215453: remove unused BundlerParams and fix misleading messages
herrick
parents: 57077
diff changeset
   710
                                modularJarPath.toFile())));
db003bfc5bf7 JDK-8215453: remove unused BundlerParams and fix misleading messages
herrick
parents: 57077
diff changeset
   711
                    }
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   712
                }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   713
            }
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
        throw new IllegalArgumentException(
56869
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56835
diff changeset
   717
                new ConfigException(MessageFormat.format(I18N.getString(
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56835
diff changeset
   718
                        "error.main-jar-does-not-exist"),
57078
db003bfc5bf7 JDK-8215453: remove unused BundlerParams and fix misleading messages
herrick
parents: 57077
diff changeset
   719
                        mainJarValue), I18N.getString(
56869
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56835
diff changeset
   720
                        "error.main-jar-does-not-exist.advice")));
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   721
    }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   722
57067
9c17d779808e 8213425: Analyze output from Source code scanner and fix where needed.
herrick
parents: 57059
diff changeset
   723
    static List<Path> getDefaultModulePath() {
57015
5d2008115309 JDK-8213244: Fix all warnings in jpackager java code
herrick
parents: 56994
diff changeset
   724
        List<Path> result = new ArrayList<Path>();
56869
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56835
diff changeset
   725
        Path jdkModulePath = Paths.get(
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56835
diff changeset
   726
                System.getProperty("java.home"), "jmods").toAbsolutePath();
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   727
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   728
        if (jdkModulePath != null && Files.exists(jdkModulePath)) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   729
            result.add(jdkModulePath);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   730
        }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   731
        else {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   732
            // On a developer build the JDK Home isn't where we expect it
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   733
            // relative to the jmods directory. Do some extra
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   734
            // processing to find it.
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   735
            Map<String, String> env = System.getenv();
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
            if (env.containsKey("JDK_HOME")) {
56869
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56835
diff changeset
   738
                jdkModulePath = Paths.get(env.get("JDK_HOME"),
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56835
diff changeset
   739
                        ".." + File.separator + "images"
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56835
diff changeset
   740
                        + File.separator + "jmods").toAbsolutePath();
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   741
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   742
                if (jdkModulePath != null && Files.exists(jdkModulePath)) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   743
                    result.add(jdkModulePath);
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
        }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   747
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   748
        return result;
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
}