src/jdk.jpackage/share/classes/jdk/jpackage/internal/DeployParams.java
author herrick
Tue, 10 Sep 2019 14:57:03 -0400
branchJDK-8200758-branch
changeset 58114 42df7de58e39
parent 57450 82c78b40b39d
child 58115 4a27283b542d
permissions -rw-r--r--
8230519: jpackage "--package-type" values and default Reviewed-by: asemenyuk, 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: 57099
diff changeset
     2
 * Copyright (c) 2011, 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;
56982
e094d5483bd6 8212048: Cleanup source code and fix issues discussed in preliminary review
herrick
parents: 56933
diff changeset
    29
import java.nio.file.Files;
57119
b3dda8d77d8a 8217331: Problems when space in application name
herrick
parents: 57106
diff changeset
    30
import java.nio.file.Path;
b3dda8d77d8a 8217331: Problems when space in application name
herrick
parents: 57106
diff changeset
    31
import java.nio.file.InvalidPathException;
57080
bd4ce7f9ea2c 8214495: Change behavior of --license-file
herrick
parents: 57078
diff changeset
    32
import java.text.MessageFormat;
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    33
import java.util.ArrayList;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    34
import java.util.Arrays;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    35
import java.util.Collection;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    36
import java.util.LinkedHashMap;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    37
import java.util.LinkedHashSet;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    38
import java.util.LinkedList;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    39
import java.util.List;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    40
import java.util.Map;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    41
import java.util.Set;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    42
import java.util.TreeMap;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    43
import java.util.TreeSet;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    44
56994
b4aca2dbe2b5 8212537: Create method and class description comments for main functionality
herrick
parents: 56987
diff changeset
    45
/**
b4aca2dbe2b5 8212537: Create method and class description comments for main functionality
herrick
parents: 56987
diff changeset
    46
 * DeployParams
b4aca2dbe2b5 8212537: Create method and class description comments for main functionality
herrick
parents: 56987
diff changeset
    47
 *
b4aca2dbe2b5 8212537: Create method and class description comments for main functionality
herrick
parents: 56987
diff changeset
    48
 * This class is generated and used in Arguments.processArguments() as
b4aca2dbe2b5 8212537: Create method and class description comments for main functionality
herrick
parents: 56987
diff changeset
    49
 * intermediate step in generating the BundleParams and ultimately the Bundles
b4aca2dbe2b5 8212537: Create method and class description comments for main functionality
herrick
parents: 56987
diff changeset
    50
 */
b4aca2dbe2b5 8212537: Create method and class description comments for main functionality
herrick
parents: 56987
diff changeset
    51
public class DeployParams {
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    52
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    53
    final List<RelativeFileSet> resources = new ArrayList<>();
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    54
58114
42df7de58e39 8230519: jpackage "--package-type" values and default
herrick
parents: 57450
diff changeset
    55
    String targetFormat = null; // means default type for this platform
56902
6972c0e75e23 8210367: invalid --app-image arg causes exception runnning light.exe in windows
herrick
parents: 56888
diff changeset
    56
56994
b4aca2dbe2b5 8212537: Create method and class description comments for main functionality
herrick
parents: 56987
diff changeset
    57
    File outdir = null;
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    58
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    59
    // raw arguments to the bundler
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    60
    Map<String, ? super Object> bundlerArguments = new LinkedHashMap<>();
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    61
56994
b4aca2dbe2b5 8212537: Create method and class description comments for main functionality
herrick
parents: 56987
diff changeset
    62
    public void setOutput(File output) {
b4aca2dbe2b5 8212537: Create method and class description comments for main functionality
herrick
parents: 56987
diff changeset
    63
        outdir = output;
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    64
    }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    65
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    66
    static class Template {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    67
        File in;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    68
        File out;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    69
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    70
        Template(File in, File out) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    71
            this.in = in;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    72
            this.out = out;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    73
        }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    74
    }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    75
56869
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56848
diff changeset
    76
    // we need to expand as in some cases
57039
98d3963b0b7b 8214051: rename jpackager tool to jpackage
herrick
parents: 57038
diff changeset
    77
    // (most notably jpackage)
56869
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56848
diff changeset
    78
    // we may get "." as filename and assumption is we include
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    79
    // everything in the given folder
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    80
    // (IOUtils.copyfiles() have recursive behavior)
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    81
    List<File> expandFileset(File root) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    82
        List<File> files = new LinkedList<>();
56982
e094d5483bd6 8212048: Cleanup source code and fix issues discussed in preliminary review
herrick
parents: 56933
diff changeset
    83
        if (!Files.isSymbolicLink(root.toPath())) {
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    84
            if (root.isDirectory()) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    85
                File[] children = root.listFiles();
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    86
                if (children != null) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    87
                    for (File f : children) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    88
                        files.addAll(expandFileset(f));
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    89
                    }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    90
                }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    91
            } else {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    92
                files.add(root);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    93
            }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    94
        }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    95
        return files;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    96
    }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    97
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    98
    public void addResource(File baseDir, String path) {
57276
eac9018748b3 8220804: Help message for @ argfile option is printed in the wrong place
herrick
parents: 57256
diff changeset
    99
        addResource(baseDir, new File(baseDir, path));
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   100
    }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   101
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   102
    public void addResource(File baseDir, File file) {
56869
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56848
diff changeset
   103
        // normalize initial file
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   104
        // to strip things like "." in the path
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   105
        // or it can confuse symlink detection logic
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   106
        file = file.getAbsoluteFile();
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   107
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   108
        if (baseDir == null) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   109
            baseDir = file.getParentFile();
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   110
        }
56869
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56848
diff changeset
   111
        resources.add(new RelativeFileSet(
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56848
diff changeset
   112
                baseDir, new LinkedHashSet<>(expandFileset(file))));
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   113
    }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   114
57450
82c78b40b39d 8227058: Regressions related to no longer setting user.dir
herrick
parents: 57438
diff changeset
   115
    void setClasspath(String mainJarPath) {
82c78b40b39d 8227058: Regressions related to no longer setting user.dir
herrick
parents: 57438
diff changeset
   116
        String classpath;
82c78b40b39d 8227058: Regressions related to no longer setting user.dir
herrick
parents: 57438
diff changeset
   117
        // we want main jar first on the classpath
82c78b40b39d 8227058: Regressions related to no longer setting user.dir
herrick
parents: 57438
diff changeset
   118
        if (mainJarPath != null) {
82c78b40b39d 8227058: Regressions related to no longer setting user.dir
herrick
parents: 57438
diff changeset
   119
            classpath = mainJarPath + File.pathSeparator;
82c78b40b39d 8227058: Regressions related to no longer setting user.dir
herrick
parents: 57438
diff changeset
   120
        } else {
82c78b40b39d 8227058: Regressions related to no longer setting user.dir
herrick
parents: 57438
diff changeset
   121
            classpath = "";
82c78b40b39d 8227058: Regressions related to no longer setting user.dir
herrick
parents: 57438
diff changeset
   122
        }
57097
6e5eb7855fe2 8215900: Without --files args, only jars in the top level of --input are added to class-path
herrick
parents: 57096
diff changeset
   123
        for (RelativeFileSet resource : resources) {
6e5eb7855fe2 8215900: Without --files args, only jars in the top level of --input are added to class-path
herrick
parents: 57096
diff changeset
   124
             for (String file : resource.getIncludedFiles()) {
6e5eb7855fe2 8215900: Without --files args, only jars in the top level of --input are added to class-path
herrick
parents: 57096
diff changeset
   125
                 if (file.endsWith(".jar")) {
57450
82c78b40b39d 8227058: Regressions related to no longer setting user.dir
herrick
parents: 57438
diff changeset
   126
                     if (!file.equals(mainJarPath)) {
82c78b40b39d 8227058: Regressions related to no longer setting user.dir
herrick
parents: 57438
diff changeset
   127
                         classpath += file + File.pathSeparator;
82c78b40b39d 8227058: Regressions related to no longer setting user.dir
herrick
parents: 57438
diff changeset
   128
                     }
57097
6e5eb7855fe2 8215900: Without --files args, only jars in the top level of --input are added to class-path
herrick
parents: 57096
diff changeset
   129
                 }
6e5eb7855fe2 8215900: Without --files args, only jars in the top level of --input are added to class-path
herrick
parents: 57096
diff changeset
   130
             }
6e5eb7855fe2 8215900: Without --files args, only jars in the top level of --input are added to class-path
herrick
parents: 57096
diff changeset
   131
        }
6e5eb7855fe2 8215900: Without --files args, only jars in the top level of --input are added to class-path
herrick
parents: 57096
diff changeset
   132
        addBundleArgument(
6e5eb7855fe2 8215900: Without --files args, only jars in the top level of --input are added to class-path
herrick
parents: 57096
diff changeset
   133
                StandardBundlerParam.CLASSPATH.getID(), classpath);
6e5eb7855fe2 8215900: Without --files args, only jars in the top level of --input are added to class-path
herrick
parents: 57096
diff changeset
   134
    }
6e5eb7855fe2 8215900: Without --files args, only jars in the top level of --input are added to class-path
herrick
parents: 57096
diff changeset
   135
57119
b3dda8d77d8a 8217331: Problems when space in application name
herrick
parents: 57106
diff changeset
   136
    static void validateName(String s, boolean forApp)
b3dda8d77d8a 8217331: Problems when space in application name
herrick
parents: 57106
diff changeset
   137
            throws PackagerException {
57255
f686bda3b831 8215574: Investigate and document usage of --category, --copyright, --vendor and --description
herrick
parents: 57218
diff changeset
   138
57119
b3dda8d77d8a 8217331: Problems when space in application name
herrick
parents: 57106
diff changeset
   139
        String exceptionKey = forApp ?
b3dda8d77d8a 8217331: Problems when space in application name
herrick
parents: 57106
diff changeset
   140
            "ERR_InvalidAppName" : "ERR_InvalidSLName";
57255
f686bda3b831 8215574: Investigate and document usage of --category, --copyright, --vendor and --description
herrick
parents: 57218
diff changeset
   141
57119
b3dda8d77d8a 8217331: Problems when space in application name
herrick
parents: 57106
diff changeset
   142
        if (s == null) {
b3dda8d77d8a 8217331: Problems when space in application name
herrick
parents: 57106
diff changeset
   143
            if (forApp) {
b3dda8d77d8a 8217331: Problems when space in application name
herrick
parents: 57106
diff changeset
   144
                return;
b3dda8d77d8a 8217331: Problems when space in application name
herrick
parents: 57106
diff changeset
   145
            } else {
b3dda8d77d8a 8217331: Problems when space in application name
herrick
parents: 57106
diff changeset
   146
                throw new PackagerException(exceptionKey, s);
b3dda8d77d8a 8217331: Problems when space in application name
herrick
parents: 57106
diff changeset
   147
            }
56985
5e6ced665587 8211285: Better app validation
herrick
parents: 56982
diff changeset
   148
        }
57119
b3dda8d77d8a 8217331: Problems when space in application name
herrick
parents: 57106
diff changeset
   149
        if (s.length() == 0 || s.charAt(s.length() - 1) == '\\') {
b3dda8d77d8a 8217331: Problems when space in application name
herrick
parents: 57106
diff changeset
   150
            throw new PackagerException(exceptionKey, s);
b3dda8d77d8a 8217331: Problems when space in application name
herrick
parents: 57106
diff changeset
   151
        }
b3dda8d77d8a 8217331: Problems when space in application name
herrick
parents: 57106
diff changeset
   152
        try {
b3dda8d77d8a 8217331: Problems when space in application name
herrick
parents: 57106
diff changeset
   153
            // name must be valid path element for this file system
b3dda8d77d8a 8217331: Problems when space in application name
herrick
parents: 57106
diff changeset
   154
            Path p = (new File(s)).toPath();
b3dda8d77d8a 8217331: Problems when space in application name
herrick
parents: 57106
diff changeset
   155
            // and it must be a single name element in a path
b3dda8d77d8a 8217331: Problems when space in application name
herrick
parents: 57106
diff changeset
   156
            if (p.getNameCount() != 1) {
b3dda8d77d8a 8217331: Problems when space in application name
herrick
parents: 57106
diff changeset
   157
                throw new PackagerException(exceptionKey, s);
b3dda8d77d8a 8217331: Problems when space in application name
herrick
parents: 57106
diff changeset
   158
            }
b3dda8d77d8a 8217331: Problems when space in application name
herrick
parents: 57106
diff changeset
   159
        } catch (InvalidPathException ipe) {
b3dda8d77d8a 8217331: Problems when space in application name
herrick
parents: 57106
diff changeset
   160
            throw new PackagerException(ipe, exceptionKey, s);
56985
5e6ced665587 8211285: Better app validation
herrick
parents: 56982
diff changeset
   161
        }
5e6ced665587 8211285: Better app validation
herrick
parents: 56982
diff changeset
   162
5e6ced665587 8211285: Better app validation
herrick
parents: 56982
diff changeset
   163
        for (int i = 0; i < s.length(); i++) {
5e6ced665587 8211285: Better app validation
herrick
parents: 56982
diff changeset
   164
            char a = s.charAt(i);
5e6ced665587 8211285: Better app validation
herrick
parents: 56982
diff changeset
   165
            // We check for ASCII codes first which we accept. If check fails,
57096
d06bec27f8c9 8215903: modify behavior of retaining temporary output dir
herrick
parents: 57080
diff changeset
   166
            // check if it is acceptable extended ASCII or unicode character.
57119
b3dda8d77d8a 8217331: Problems when space in application name
herrick
parents: 57106
diff changeset
   167
            if (a < ' ' || a > '~') {
57096
d06bec27f8c9 8215903: modify behavior of retaining temporary output dir
herrick
parents: 57080
diff changeset
   168
                // Accept anything else including special chars like copyright
56985
5e6ced665587 8211285: Better app validation
herrick
parents: 56982
diff changeset
   169
                // symbols. Note: space will be included by ASCII check above,
57119
b3dda8d77d8a 8217331: Problems when space in application name
herrick
parents: 57106
diff changeset
   170
                // but other whitespace like tabs or new line will be rejected.
b3dda8d77d8a 8217331: Problems when space in application name
herrick
parents: 57106
diff changeset
   171
                if (Character.isISOControl(a)  ||
b3dda8d77d8a 8217331: Problems when space in application name
herrick
parents: 57106
diff changeset
   172
                        Character.isWhitespace(a)) {
b3dda8d77d8a 8217331: Problems when space in application name
herrick
parents: 57106
diff changeset
   173
                    throw new PackagerException(exceptionKey, s);
56985
5e6ced665587 8211285: Better app validation
herrick
parents: 56982
diff changeset
   174
                }
57119
b3dda8d77d8a 8217331: Problems when space in application name
herrick
parents: 57106
diff changeset
   175
            } else if (a == '"' || a == '%') {
b3dda8d77d8a 8217331: Problems when space in application name
herrick
parents: 57106
diff changeset
   176
                throw new PackagerException(exceptionKey, s);
56985
5e6ced665587 8211285: Better app validation
herrick
parents: 56982
diff changeset
   177
            }
5e6ced665587 8211285: Better app validation
herrick
parents: 56982
diff changeset
   178
        }
5e6ced665587 8211285: Better app validation
herrick
parents: 56982
diff changeset
   179
    }
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   180
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   181
    public void validate() throws PackagerException {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   182
        if (outdir == null) {
56848
f8a7c83f31f1 JDK-8208456: [packager] Remove some unused Strings
herrick
parents: 56836
diff changeset
   183
            throw new PackagerException("ERR_MissingArgument", "--output");
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   184
        }
56888
628a283daa6c 8210505: Unable to create an installer from an app-image on linux
herrick
parents: 56882
diff changeset
   185
628a283daa6c 8210505: Unable to create an installer from an app-image on linux
herrick
parents: 56882
diff changeset
   186
        boolean hasModule = (bundlerArguments.get(
628a283daa6c 8210505: Unable to create an installer from an app-image on linux
herrick
parents: 56882
diff changeset
   187
                Arguments.CLIOptions.MODULE.getId()) != null);
57256
d7c27451f759 8219678: CLI changes in jpackage
herrick
parents: 57255
diff changeset
   188
        boolean hasAppImage = (bundlerArguments.get(
56888
628a283daa6c 8210505: Unable to create an installer from an app-image on linux
herrick
parents: 56882
diff changeset
   189
                Arguments.CLIOptions.PREDEFINED_APP_IMAGE.getId()) != null);
628a283daa6c 8210505: Unable to create an installer from an app-image on linux
herrick
parents: 56882
diff changeset
   190
        boolean hasClass = (bundlerArguments.get(
628a283daa6c 8210505: Unable to create an installer from an app-image on linux
herrick
parents: 56882
diff changeset
   191
                Arguments.CLIOptions.APPCLASS.getId()) != null);
628a283daa6c 8210505: Unable to create an installer from an app-image on linux
herrick
parents: 56882
diff changeset
   192
        boolean hasMain = (bundlerArguments.get(
628a283daa6c 8210505: Unable to create an installer from an app-image on linux
herrick
parents: 56882
diff changeset
   193
                Arguments.CLIOptions.MAIN_JAR.getId()) != null);
57030
902f4c4fba42 8214021: Create additional automated tests for jpackager
herrick
parents: 57022
diff changeset
   194
        boolean hasRuntimeImage = (bundlerArguments.get(
902f4c4fba42 8214021: Create additional automated tests for jpackager
herrick
parents: 57022
diff changeset
   195
                Arguments.CLIOptions.PREDEFINED_RUNTIME_IMAGE.getId()) != null);
902f4c4fba42 8214021: Create additional automated tests for jpackager
herrick
parents: 57022
diff changeset
   196
        boolean hasInput = (bundlerArguments.get(
902f4c4fba42 8214021: Create additional automated tests for jpackager
herrick
parents: 57022
diff changeset
   197
                Arguments.CLIOptions.INPUT.getId()) != null);
902f4c4fba42 8214021: Create additional automated tests for jpackager
herrick
parents: 57022
diff changeset
   198
        boolean hasModulePath = (bundlerArguments.get(
902f4c4fba42 8214021: Create additional automated tests for jpackager
herrick
parents: 57022
diff changeset
   199
                Arguments.CLIOptions.MODULE_PATH.getId()) != null);
58114
42df7de58e39 8230519: jpackage "--package-type" values and default
herrick
parents: 57450
diff changeset
   200
        boolean runtimeInstaller = !isTargetAppImage() &&
57256
d7c27451f759 8219678: CLI changes in jpackage
herrick
parents: 57255
diff changeset
   201
                !hasAppImage && !hasModule && !hasMain && hasRuntimeImage;
57030
902f4c4fba42 8214021: Create additional automated tests for jpackager
herrick
parents: 57022
diff changeset
   202
58114
42df7de58e39 8230519: jpackage "--package-type" values and default
herrick
parents: 57450
diff changeset
   203
        if (isTargetAppImage()) {
57030
902f4c4fba42 8214021: Create additional automated tests for jpackager
herrick
parents: 57022
diff changeset
   204
            // Module application requires --runtime-image or --module-path
902f4c4fba42 8214021: Create additional automated tests for jpackager
herrick
parents: 57022
diff changeset
   205
            if (hasModule) {
902f4c4fba42 8214021: Create additional automated tests for jpackager
herrick
parents: 57022
diff changeset
   206
                if (!hasModulePath && !hasRuntimeImage) {
902f4c4fba42 8214021: Create additional automated tests for jpackager
herrick
parents: 57022
diff changeset
   207
                    throw new PackagerException("ERR_MissingArgument",
902f4c4fba42 8214021: Create additional automated tests for jpackager
herrick
parents: 57022
diff changeset
   208
                            "--runtime-image or --module-path");
902f4c4fba42 8214021: Create additional automated tests for jpackager
herrick
parents: 57022
diff changeset
   209
                }
902f4c4fba42 8214021: Create additional automated tests for jpackager
herrick
parents: 57022
diff changeset
   210
            } else {
902f4c4fba42 8214021: Create additional automated tests for jpackager
herrick
parents: 57022
diff changeset
   211
                if (!hasInput) {
57096
d06bec27f8c9 8215903: modify behavior of retaining temporary output dir
herrick
parents: 57080
diff changeset
   212
                    throw new PackagerException(
d06bec27f8c9 8215903: modify behavior of retaining temporary output dir
herrick
parents: 57080
diff changeset
   213
                           "ERR_MissingArgument", "--input");
57030
902f4c4fba42 8214021: Create additional automated tests for jpackager
herrick
parents: 57022
diff changeset
   214
                }
902f4c4fba42 8214021: Create additional automated tests for jpackager
herrick
parents: 57022
diff changeset
   215
            }
57414
6eda749d3117 8225428: CLI change to remove "mode", rename to "package", and build only one target
herrick
parents: 57396
diff changeset
   216
        } else {
57150
fa68c2ab636d 8217894: jpackage CLI syntax changes
herrick
parents: 57119
diff changeset
   217
            if (!runtimeInstaller) {
57030
902f4c4fba42 8214021: Create additional automated tests for jpackager
herrick
parents: 57022
diff changeset
   218
                if (hasModule) {
902f4c4fba42 8214021: Create additional automated tests for jpackager
herrick
parents: 57022
diff changeset
   219
                    if (!hasModulePath && !hasRuntimeImage && !hasAppImage) {
902f4c4fba42 8214021: Create additional automated tests for jpackager
herrick
parents: 57022
diff changeset
   220
                        throw new PackagerException("ERR_MissingArgument",
902f4c4fba42 8214021: Create additional automated tests for jpackager
herrick
parents: 57022
diff changeset
   221
                            "--runtime-image, --module-path or --app-image");
902f4c4fba42 8214021: Create additional automated tests for jpackager
herrick
parents: 57022
diff changeset
   222
                    }
902f4c4fba42 8214021: Create additional automated tests for jpackager
herrick
parents: 57022
diff changeset
   223
                } else {
902f4c4fba42 8214021: Create additional automated tests for jpackager
herrick
parents: 57022
diff changeset
   224
                    if (!hasInput && !hasAppImage) {
57096
d06bec27f8c9 8215903: modify behavior of retaining temporary output dir
herrick
parents: 57080
diff changeset
   225
                        throw new PackagerException("ERR_MissingArgument",
d06bec27f8c9 8215903: modify behavior of retaining temporary output dir
herrick
parents: 57080
diff changeset
   226
                                "--input or --app-image");
57030
902f4c4fba42 8214021: Create additional automated tests for jpackager
herrick
parents: 57022
diff changeset
   227
                    }
902f4c4fba42 8214021: Create additional automated tests for jpackager
herrick
parents: 57022
diff changeset
   228
                }
902f4c4fba42 8214021: Create additional automated tests for jpackager
herrick
parents: 57022
diff changeset
   229
            }
902f4c4fba42 8214021: Create additional automated tests for jpackager
herrick
parents: 57022
diff changeset
   230
        }
56888
628a283daa6c 8210505: Unable to create an installer from an app-image on linux
herrick
parents: 56882
diff changeset
   231
628a283daa6c 8210505: Unable to create an installer from an app-image on linux
herrick
parents: 56882
diff changeset
   232
        // if bundling non-modular image, or installer without app-image
628a283daa6c 8210505: Unable to create an installer from an app-image on linux
herrick
parents: 56882
diff changeset
   233
        // then we need some resources and a main class
57256
d7c27451f759 8219678: CLI changes in jpackage
herrick
parents: 57255
diff changeset
   234
        if (!hasModule && !hasAppImage && !runtimeInstaller) {
56888
628a283daa6c 8210505: Unable to create an installer from an app-image on linux
herrick
parents: 56882
diff changeset
   235
            if (resources.isEmpty()) {
628a283daa6c 8210505: Unable to create an installer from an app-image on linux
herrick
parents: 56882
diff changeset
   236
                throw new PackagerException("ERR_MissingAppResources");
628a283daa6c 8210505: Unable to create an installer from an app-image on linux
herrick
parents: 56882
diff changeset
   237
            }
628a283daa6c 8210505: Unable to create an installer from an app-image on linux
herrick
parents: 56882
diff changeset
   238
            if (!hasMain) {
56982
e094d5483bd6 8212048: Cleanup source code and fix issues discussed in preliminary review
herrick
parents: 56933
diff changeset
   239
                throw new PackagerException("ERR_MissingArgument",
e094d5483bd6 8212048: Cleanup source code and fix issues discussed in preliminary review
herrick
parents: 56933
diff changeset
   240
                        "--main-jar");
56888
628a283daa6c 8210505: Unable to create an installer from an app-image on linux
herrick
parents: 56882
diff changeset
   241
            }
628a283daa6c 8210505: Unable to create an installer from an app-image on linux
herrick
parents: 56882
diff changeset
   242
        }
56902
6972c0e75e23 8210367: invalid --app-image arg causes exception runnning light.exe in windows
herrick
parents: 56888
diff changeset
   243
57096
d06bec27f8c9 8215903: modify behavior of retaining temporary output dir
herrick
parents: 57080
diff changeset
   244
        String name = (String)bundlerArguments.get(
d06bec27f8c9 8215903: modify behavior of retaining temporary output dir
herrick
parents: 57080
diff changeset
   245
                Arguments.CLIOptions.NAME.getId());
57119
b3dda8d77d8a 8217331: Problems when space in application name
herrick
parents: 57106
diff changeset
   246
        validateName(name, true);
56985
5e6ced665587 8211285: Better app validation
herrick
parents: 56982
diff changeset
   247
56902
6972c0e75e23 8210367: invalid --app-image arg causes exception runnning light.exe in windows
herrick
parents: 56888
diff changeset
   248
        // Validate app image if set
56982
e094d5483bd6 8212048: Cleanup source code and fix issues discussed in preliminary review
herrick
parents: 56933
diff changeset
   249
        String appImage = (String)bundlerArguments.get(
e094d5483bd6 8212048: Cleanup source code and fix issues discussed in preliminary review
herrick
parents: 56933
diff changeset
   250
                Arguments.CLIOptions.PREDEFINED_APP_IMAGE.getId());
56902
6972c0e75e23 8210367: invalid --app-image arg causes exception runnning light.exe in windows
herrick
parents: 56888
diff changeset
   251
        if (appImage != null) {
6972c0e75e23 8210367: invalid --app-image arg causes exception runnning light.exe in windows
herrick
parents: 56888
diff changeset
   252
            File appImageDir = new File(appImage);
57218
8018ecf829bc 8217902: jpackage fails with --app-image option on mac
herrick
parents: 57150
diff changeset
   253
            if (!appImageDir.exists() || appImageDir.list().length == 0) {
56902
6972c0e75e23 8210367: invalid --app-image arg causes exception runnning light.exe in windows
herrick
parents: 56888
diff changeset
   254
                throw new PackagerException("ERR_AppImageNotExist", appImage);
6972c0e75e23 8210367: invalid --app-image arg causes exception runnning light.exe in windows
herrick
parents: 56888
diff changeset
   255
            }
6972c0e75e23 8210367: invalid --app-image arg causes exception runnning light.exe in windows
herrick
parents: 56888
diff changeset
   256
        }
57080
bd4ce7f9ea2c 8214495: Change behavior of --license-file
herrick
parents: 57078
diff changeset
   257
57256
d7c27451f759 8219678: CLI changes in jpackage
herrick
parents: 57255
diff changeset
   258
        // Validate temp-root
57096
d06bec27f8c9 8215903: modify behavior of retaining temporary output dir
herrick
parents: 57080
diff changeset
   259
        String root = (String)bundlerArguments.get(
57256
d7c27451f759 8219678: CLI changes in jpackage
herrick
parents: 57255
diff changeset
   260
                Arguments.CLIOptions.TEMP_ROOT.getId());
57096
d06bec27f8c9 8215903: modify behavior of retaining temporary output dir
herrick
parents: 57080
diff changeset
   261
        if (root != null) {
d06bec27f8c9 8215903: modify behavior of retaining temporary output dir
herrick
parents: 57080
diff changeset
   262
            String [] contents = (new File(root)).list();
d06bec27f8c9 8215903: modify behavior of retaining temporary output dir
herrick
parents: 57080
diff changeset
   263
d06bec27f8c9 8215903: modify behavior of retaining temporary output dir
herrick
parents: 57080
diff changeset
   264
            if (contents != null && contents.length > 0) {
d06bec27f8c9 8215903: modify behavior of retaining temporary output dir
herrick
parents: 57080
diff changeset
   265
                throw new PackagerException("ERR_BuildRootInvalid", root);
d06bec27f8c9 8215903: modify behavior of retaining temporary output dir
herrick
parents: 57080
diff changeset
   266
            }
d06bec27f8c9 8215903: modify behavior of retaining temporary output dir
herrick
parents: 57080
diff changeset
   267
        }
d06bec27f8c9 8215903: modify behavior of retaining temporary output dir
herrick
parents: 57080
diff changeset
   268
57080
bd4ce7f9ea2c 8214495: Change behavior of --license-file
herrick
parents: 57078
diff changeset
   269
        // Validate license file if set
bd4ce7f9ea2c 8214495: Change behavior of --license-file
herrick
parents: 57078
diff changeset
   270
        String license = (String)bundlerArguments.get(
bd4ce7f9ea2c 8214495: Change behavior of --license-file
herrick
parents: 57078
diff changeset
   271
                Arguments.CLIOptions.LICENSE_FILE.getId());
bd4ce7f9ea2c 8214495: Change behavior of --license-file
herrick
parents: 57078
diff changeset
   272
        if (license != null) {
bd4ce7f9ea2c 8214495: Change behavior of --license-file
herrick
parents: 57078
diff changeset
   273
            File licenseFile = new File(license);
bd4ce7f9ea2c 8214495: Change behavior of --license-file
herrick
parents: 57078
diff changeset
   274
            if (!licenseFile.exists()) {
bd4ce7f9ea2c 8214495: Change behavior of --license-file
herrick
parents: 57078
diff changeset
   275
                throw new PackagerException("ERR_LicenseFileNotExit");
bd4ce7f9ea2c 8214495: Change behavior of --license-file
herrick
parents: 57078
diff changeset
   276
            }
bd4ce7f9ea2c 8214495: Change behavior of --license-file
herrick
parents: 57078
diff changeset
   277
        }
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   278
    }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   279
57067
9c17d779808e 8213425: Analyze output from Source code scanner and fix where needed.
herrick
parents: 57062
diff changeset
   280
    void setTargetFormat(String t) {
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   281
        targetFormat = t;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   282
    }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   283
57067
9c17d779808e 8213425: Analyze output from Source code scanner and fix where needed.
herrick
parents: 57062
diff changeset
   284
    String getTargetFormat() {
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   285
        return targetFormat;
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
58114
42df7de58e39 8230519: jpackage "--package-type" values and default
herrick
parents: 57450
diff changeset
   288
    boolean isTargetAppImage() {
42df7de58e39 8230519: jpackage "--package-type" values and default
herrick
parents: 57450
diff changeset
   289
        return ("app-image".equals(targetFormat));
42df7de58e39 8230519: jpackage "--package-type" values and default
herrick
parents: 57450
diff changeset
   290
    }
42df7de58e39 8230519: jpackage "--package-type" values and default
herrick
parents: 57450
diff changeset
   291
57396
3944e4c2f779 8223586: remove jpackage dead code and other cleanup
herrick
parents: 57391
diff changeset
   292
    private static final Set<String> multi_args = new TreeSet<>(Arrays.asList(
57316
2891b3ae222d 8221641: Follow up code clean up for JDK-8221582
herrick
parents: 57314
diff changeset
   293
            StandardBundlerParam.JAVA_OPTIONS.getID(),
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   294
            StandardBundlerParam.ARGUMENTS.getID(),
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   295
            StandardBundlerParam.MODULE_PATH.getID(),
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   296
            StandardBundlerParam.ADD_MODULES.getID(),
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   297
            StandardBundlerParam.LIMIT_MODULES.getID(),
56982
e094d5483bd6 8212048: Cleanup source code and fix issues discussed in preliminary review
herrick
parents: 56933
diff changeset
   298
            StandardBundlerParam.FILE_ASSOCIATIONS.getID()
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   299
    ));
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   300
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   301
    @SuppressWarnings("unchecked")
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   302
    public void addBundleArgument(String key, Object value) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   303
        // special hack for multi-line arguments
56836
40abf95122b0 8207143: jpackager fails to parse file associations
herrick
parents: 56821
diff changeset
   304
        if (multi_args.contains(key)) {
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   305
            Object existingValue = bundlerArguments.get(key);
56836
40abf95122b0 8207143: jpackager fails to parse file associations
herrick
parents: 56821
diff changeset
   306
            if (existingValue instanceof String && value instanceof String) {
57324
c1d3935fbb79 8222406: Multiple arguments for the same option - aggragation broken
herrick
parents: 57323
diff changeset
   307
                String delim = "\n\n";
c1d3935fbb79 8222406: Multiple arguments for the same option - aggragation broken
herrick
parents: 57323
diff changeset
   308
                if (key.equals(StandardBundlerParam.MODULE_PATH.getID())) {
c1d3935fbb79 8222406: Multiple arguments for the same option - aggragation broken
herrick
parents: 57323
diff changeset
   309
                    delim = File.pathSeparator;
c1d3935fbb79 8222406: Multiple arguments for the same option - aggragation broken
herrick
parents: 57323
diff changeset
   310
                } else if (key.equals(
c1d3935fbb79 8222406: Multiple arguments for the same option - aggragation broken
herrick
parents: 57323
diff changeset
   311
                        StandardBundlerParam.ADD_MODULES.getID())) {
c1d3935fbb79 8222406: Multiple arguments for the same option - aggragation broken
herrick
parents: 57323
diff changeset
   312
                    delim = ",";
c1d3935fbb79 8222406: Multiple arguments for the same option - aggragation broken
herrick
parents: 57323
diff changeset
   313
                }
c1d3935fbb79 8222406: Multiple arguments for the same option - aggragation broken
herrick
parents: 57323
diff changeset
   314
                bundlerArguments.put(key, existingValue + delim + value);
56836
40abf95122b0 8207143: jpackager fails to parse file associations
herrick
parents: 56821
diff changeset
   315
            } else if (existingValue instanceof List && value instanceof List) {
40abf95122b0 8207143: jpackager fails to parse file associations
herrick
parents: 56821
diff changeset
   316
                ((List)existingValue).addAll((List)value);
40abf95122b0 8207143: jpackager fails to parse file associations
herrick
parents: 56821
diff changeset
   317
            } else if (existingValue instanceof Map &&
40abf95122b0 8207143: jpackager fails to parse file associations
herrick
parents: 56821
diff changeset
   318
                value instanceof String && ((String)value).contains("=")) {
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   319
                String[] mapValues = ((String)value).split("=", 2);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   320
                ((Map)existingValue).put(mapValues[0], mapValues[1]);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   321
            } else {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   322
                bundlerArguments.put(key, value);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   323
            }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   324
        } else {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   325
            bundlerArguments.put(key, value);
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
    }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   328
57067
9c17d779808e 8213425: Analyze output from Source code scanner and fix where needed.
herrick
parents: 57062
diff changeset
   329
    BundleParams getBundleParams() {
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   330
        BundleParams bundleParams = new BundleParams();
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   331
57096
d06bec27f8c9 8215903: modify behavior of retaining temporary output dir
herrick
parents: 57080
diff changeset
   332
        // construct app resources relative to output folder!
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   333
        bundleParams.setAppResourcesList(resources);
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
        Map<String, String> unescapedHtmlParams = new TreeMap<>();
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   336
        Map<String, String> escapedHtmlParams = new TreeMap<>();
56902
6972c0e75e23 8210367: invalid --app-image arg causes exception runnning light.exe in windows
herrick
parents: 56888
diff changeset
   337
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   338
        // check for collisions
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   339
        TreeSet<String> keys = new TreeSet<>(bundlerArguments.keySet());
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   340
        keys.retainAll(bundleParams.getBundleParamsAsMap().keySet());
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   341
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   342
        if (!keys.isEmpty()) {
56869
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56848
diff changeset
   343
            throw new RuntimeException("Deploy Params and Bundler Arguments "
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56848
diff changeset
   344
                    + "overlap in the following values:" + keys.toString());
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   345
        }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   346
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   347
        bundleParams.addAllBundleParams(bundlerArguments);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   348
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   349
        return bundleParams;
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
56994
b4aca2dbe2b5 8212537: Create method and class description comments for main functionality
herrick
parents: 56987
diff changeset
   352
    @Override
b4aca2dbe2b5 8212537: Create method and class description comments for main functionality
herrick
parents: 56987
diff changeset
   353
    public String toString() {
57097
6e5eb7855fe2 8215900: Without --files args, only jars in the top level of --input are added to class-path
herrick
parents: 57096
diff changeset
   354
        return "DeployParams {" + "output: " + outdir
6e5eb7855fe2 8215900: Without --files args, only jars in the top level of --input are added to class-path
herrick
parents: 57096
diff changeset
   355
                + " resources: {" + resources + "}}";
56994
b4aca2dbe2b5 8212537: Create method and class description comments for main functionality
herrick
parents: 56987
diff changeset
   356
    }
b4aca2dbe2b5 8212537: Create method and class description comments for main functionality
herrick
parents: 56987
diff changeset
   357
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   358
}