src/jdk.jpackage/share/classes/jdk/jpackage/internal/DeployParams.java
author herrick
Thu, 06 Jun 2019 19:51:17 -0400
branchJDK-8200758-branch
changeset 57396 3944e4c2f779
parent 57391 970f28090a06
child 57414 6eda749d3117
permissions -rw-r--r--
8223586: remove jpackage dead code and other cleanup 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
57396
3944e4c2f779 8223586: remove jpackage dead code and other cleanup
herrick
parents: 57391
diff changeset
    55
    BundlerType bundleType = BundlerType.NONE;
3944e4c2f779 8223586: remove jpackage dead code and other cleanup
herrick
parents: 57391
diff changeset
    56
    String targetFormat = null; //means any
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    57
    String licenseType;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    58
    String copyright;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    59
    String version;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    60
    String applicationClass;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    61
57391
970f28090a06 8223334: Additional cleanup in jpackage tool
herrick
parents: 57324
diff changeset
    62
    // Java modules support
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    63
    String addModules = null;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    64
    String limitModules = null;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    65
    String module = null;
56902
6972c0e75e23 8210367: invalid --app-image arg causes exception runnning light.exe in windows
herrick
parents: 56888
diff changeset
    66
56994
b4aca2dbe2b5 8212537: Create method and class description comments for main functionality
herrick
parents: 56987
diff changeset
    67
    File outdir = null;
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    68
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: 56848
diff changeset
    70
    // list of jvm args
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56848
diff changeset
    71
    // (in theory string can contain spaces and need to be escaped
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    72
    List<String> jvmargs = new LinkedList<>();
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
    // raw arguments to the bundler
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    75
    Map<String, ? super Object> bundlerArguments = new LinkedHashMap<>();
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    76
57067
9c17d779808e 8213425: Analyze output from Source code scanner and fix where needed.
herrick
parents: 57062
diff changeset
    77
    void setLicenseType(String licenseType) {
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    78
        this.licenseType = licenseType;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    79
    }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    80
57067
9c17d779808e 8213425: Analyze output from Source code scanner and fix where needed.
herrick
parents: 57062
diff changeset
    81
    void setCopyright(String copyright) {
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    82
        this.copyright = copyright;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    83
    }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    84
57067
9c17d779808e 8213425: Analyze output from Source code scanner and fix where needed.
herrick
parents: 57062
diff changeset
    85
    void setVersion(String version) {
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    86
        this.version = version;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    87
    }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    88
57067
9c17d779808e 8213425: Analyze output from Source code scanner and fix where needed.
herrick
parents: 57062
diff changeset
    89
    void addJvmArg(String v) {
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    90
        jvmargs.add(v);
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
57067
9c17d779808e 8213425: Analyze output from Source code scanner and fix where needed.
herrick
parents: 57062
diff changeset
    93
    void addAddModule(String value) {
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    94
        if (addModules == null) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    95
            addModules = value;
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
        else {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    98
            addModules += "," + value;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    99
        }
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
57067
9c17d779808e 8213425: Analyze output from Source code scanner and fix where needed.
herrick
parents: 57062
diff changeset
   102
    void addLimitModule(String value) {
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   103
        if (limitModules == null) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   104
            limitModules = value;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   105
        }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   106
        else {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   107
            limitModules += "," + value;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   108
        }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   109
    }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   110
57067
9c17d779808e 8213425: Analyze output from Source code scanner and fix where needed.
herrick
parents: 57062
diff changeset
   111
    void setModule(String value) {
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   112
        this.module = value;
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
57067
9c17d779808e 8213425: Analyze output from Source code scanner and fix where needed.
herrick
parents: 57062
diff changeset
   115
    void setApplicationClass(String applicationClass) {
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   116
        this.applicationClass = applicationClass;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   117
    }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   118
57067
9c17d779808e 8213425: Analyze output from Source code scanner and fix where needed.
herrick
parents: 57062
diff changeset
   119
    File getOutput() {
56994
b4aca2dbe2b5 8212537: Create method and class description comments for main functionality
herrick
parents: 56987
diff changeset
   120
        return outdir;
b4aca2dbe2b5 8212537: Create method and class description comments for main functionality
herrick
parents: 56987
diff changeset
   121
    }
b4aca2dbe2b5 8212537: Create method and class description comments for main functionality
herrick
parents: 56987
diff changeset
   122
b4aca2dbe2b5 8212537: Create method and class description comments for main functionality
herrick
parents: 56987
diff changeset
   123
    public void setOutput(File output) {
b4aca2dbe2b5 8212537: Create method and class description comments for main functionality
herrick
parents: 56987
diff changeset
   124
        outdir = output;
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   125
    }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   126
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   127
    static class Template {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   128
        File in;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   129
        File out;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   130
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   131
        Template(File in, File out) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   132
            this.in = in;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   133
            this.out = out;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   134
        }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   135
    }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   136
56869
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56848
diff changeset
   137
    // we need to expand as in some cases
57039
98d3963b0b7b 8214051: rename jpackager tool to jpackage
herrick
parents: 57038
diff changeset
   138
    // (most notably jpackage)
56869
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56848
diff changeset
   139
    // 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
   140
    // everything in the given folder
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   141
    // (IOUtils.copyfiles() have recursive behavior)
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   142
    List<File> expandFileset(File root) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   143
        List<File> files = new LinkedList<>();
56982
e094d5483bd6 8212048: Cleanup source code and fix issues discussed in preliminary review
herrick
parents: 56933
diff changeset
   144
        if (!Files.isSymbolicLink(root.toPath())) {
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   145
            if (root.isDirectory()) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   146
                File[] children = root.listFiles();
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   147
                if (children != null) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   148
                    for (File f : children) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   149
                        files.addAll(expandFileset(f));
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   150
                    }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   151
                }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   152
            } else {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   153
                files.add(root);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   154
            }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   155
        }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   156
        return files;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   157
    }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   158
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   159
    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
   160
        addResource(baseDir, new File(baseDir, path));
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   161
    }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   162
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   163
    public void addResource(File baseDir, File file) {
56869
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56848
diff changeset
   164
        // normalize initial file
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   165
        // to strip things like "." in the path
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   166
        // or it can confuse symlink detection logic
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   167
        file = file.getAbsoluteFile();
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
        if (baseDir == null) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   170
            baseDir = file.getParentFile();
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   171
        }
56869
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56848
diff changeset
   172
        resources.add(new RelativeFileSet(
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56848
diff changeset
   173
                baseDir, new LinkedHashSet<>(expandFileset(file))));
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   174
    }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   175
57097
6e5eb7855fe2 8215900: Without --files args, only jars in the top level of --input are added to class-path
herrick
parents: 57096
diff changeset
   176
    void setClasspath() {
6e5eb7855fe2 8215900: Without --files args, only jars in the top level of --input are added to class-path
herrick
parents: 57096
diff changeset
   177
        String classpath = "";
6e5eb7855fe2 8215900: Without --files args, only jars in the top level of --input are added to class-path
herrick
parents: 57096
diff changeset
   178
        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
   179
             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
   180
                 if (file.endsWith(".jar")) {
6e5eb7855fe2 8215900: Without --files args, only jars in the top level of --input are added to class-path
herrick
parents: 57096
diff changeset
   181
                     classpath += file + File.pathSeparator;
6e5eb7855fe2 8215900: Without --files args, only jars in the top level of --input are added to class-path
herrick
parents: 57096
diff changeset
   182
                 }
6e5eb7855fe2 8215900: Without --files args, only jars in the top level of --input are added to class-path
herrick
parents: 57096
diff changeset
   183
             }
6e5eb7855fe2 8215900: Without --files args, only jars in the top level of --input are added to class-path
herrick
parents: 57096
diff changeset
   184
        }
6e5eb7855fe2 8215900: Without --files args, only jars in the top level of --input are added to class-path
herrick
parents: 57096
diff changeset
   185
        addBundleArgument(
6e5eb7855fe2 8215900: Without --files args, only jars in the top level of --input are added to class-path
herrick
parents: 57096
diff changeset
   186
                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
   187
    }
6e5eb7855fe2 8215900: Without --files args, only jars in the top level of --input are added to class-path
herrick
parents: 57096
diff changeset
   188
57119
b3dda8d77d8a 8217331: Problems when space in application name
herrick
parents: 57106
diff changeset
   189
    static void validateName(String s, boolean forApp)
b3dda8d77d8a 8217331: Problems when space in application name
herrick
parents: 57106
diff changeset
   190
            throws PackagerException {
57255
f686bda3b831 8215574: Investigate and document usage of --category, --copyright, --vendor and --description
herrick
parents: 57218
diff changeset
   191
57119
b3dda8d77d8a 8217331: Problems when space in application name
herrick
parents: 57106
diff changeset
   192
        String exceptionKey = forApp ?
b3dda8d77d8a 8217331: Problems when space in application name
herrick
parents: 57106
diff changeset
   193
            "ERR_InvalidAppName" : "ERR_InvalidSLName";
57255
f686bda3b831 8215574: Investigate and document usage of --category, --copyright, --vendor and --description
herrick
parents: 57218
diff changeset
   194
57119
b3dda8d77d8a 8217331: Problems when space in application name
herrick
parents: 57106
diff changeset
   195
        if (s == null) {
b3dda8d77d8a 8217331: Problems when space in application name
herrick
parents: 57106
diff changeset
   196
            if (forApp) {
b3dda8d77d8a 8217331: Problems when space in application name
herrick
parents: 57106
diff changeset
   197
                return;
b3dda8d77d8a 8217331: Problems when space in application name
herrick
parents: 57106
diff changeset
   198
            } else {
b3dda8d77d8a 8217331: Problems when space in application name
herrick
parents: 57106
diff changeset
   199
                throw new PackagerException(exceptionKey, s);
b3dda8d77d8a 8217331: Problems when space in application name
herrick
parents: 57106
diff changeset
   200
            }
56985
5e6ced665587 8211285: Better app validation
herrick
parents: 56982
diff changeset
   201
        }
57119
b3dda8d77d8a 8217331: Problems when space in application name
herrick
parents: 57106
diff changeset
   202
        if (s.length() == 0 || s.charAt(s.length() - 1) == '\\') {
b3dda8d77d8a 8217331: Problems when space in application name
herrick
parents: 57106
diff changeset
   203
            throw new PackagerException(exceptionKey, s);
b3dda8d77d8a 8217331: Problems when space in application name
herrick
parents: 57106
diff changeset
   204
        }
b3dda8d77d8a 8217331: Problems when space in application name
herrick
parents: 57106
diff changeset
   205
        try {
b3dda8d77d8a 8217331: Problems when space in application name
herrick
parents: 57106
diff changeset
   206
            // name must be valid path element for this file system
b3dda8d77d8a 8217331: Problems when space in application name
herrick
parents: 57106
diff changeset
   207
            Path p = (new File(s)).toPath();
b3dda8d77d8a 8217331: Problems when space in application name
herrick
parents: 57106
diff changeset
   208
            // and it must be a single name element in a path
b3dda8d77d8a 8217331: Problems when space in application name
herrick
parents: 57106
diff changeset
   209
            if (p.getNameCount() != 1) {
b3dda8d77d8a 8217331: Problems when space in application name
herrick
parents: 57106
diff changeset
   210
                throw new PackagerException(exceptionKey, s);
b3dda8d77d8a 8217331: Problems when space in application name
herrick
parents: 57106
diff changeset
   211
            }
b3dda8d77d8a 8217331: Problems when space in application name
herrick
parents: 57106
diff changeset
   212
        } catch (InvalidPathException ipe) {
b3dda8d77d8a 8217331: Problems when space in application name
herrick
parents: 57106
diff changeset
   213
            throw new PackagerException(ipe, exceptionKey, s);
56985
5e6ced665587 8211285: Better app validation
herrick
parents: 56982
diff changeset
   214
        }
5e6ced665587 8211285: Better app validation
herrick
parents: 56982
diff changeset
   215
5e6ced665587 8211285: Better app validation
herrick
parents: 56982
diff changeset
   216
        for (int i = 0; i < s.length(); i++) {
5e6ced665587 8211285: Better app validation
herrick
parents: 56982
diff changeset
   217
            char a = s.charAt(i);
5e6ced665587 8211285: Better app validation
herrick
parents: 56982
diff changeset
   218
            // 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
   219
            // check if it is acceptable extended ASCII or unicode character.
57119
b3dda8d77d8a 8217331: Problems when space in application name
herrick
parents: 57106
diff changeset
   220
            if (a < ' ' || a > '~') {
57096
d06bec27f8c9 8215903: modify behavior of retaining temporary output dir
herrick
parents: 57080
diff changeset
   221
                // Accept anything else including special chars like copyright
56985
5e6ced665587 8211285: Better app validation
herrick
parents: 56982
diff changeset
   222
                // symbols. Note: space will be included by ASCII check above,
57119
b3dda8d77d8a 8217331: Problems when space in application name
herrick
parents: 57106
diff changeset
   223
                // but other whitespace like tabs or new line will be rejected.
b3dda8d77d8a 8217331: Problems when space in application name
herrick
parents: 57106
diff changeset
   224
                if (Character.isISOControl(a)  ||
b3dda8d77d8a 8217331: Problems when space in application name
herrick
parents: 57106
diff changeset
   225
                        Character.isWhitespace(a)) {
b3dda8d77d8a 8217331: Problems when space in application name
herrick
parents: 57106
diff changeset
   226
                    throw new PackagerException(exceptionKey, s);
56985
5e6ced665587 8211285: Better app validation
herrick
parents: 56982
diff changeset
   227
                }
57119
b3dda8d77d8a 8217331: Problems when space in application name
herrick
parents: 57106
diff changeset
   228
            } else if (a == '"' || a == '%') {
b3dda8d77d8a 8217331: Problems when space in application name
herrick
parents: 57106
diff changeset
   229
                throw new PackagerException(exceptionKey, s);
56985
5e6ced665587 8211285: Better app validation
herrick
parents: 56982
diff changeset
   230
            }
5e6ced665587 8211285: Better app validation
herrick
parents: 56982
diff changeset
   231
        }
5e6ced665587 8211285: Better app validation
herrick
parents: 56982
diff changeset
   232
    }
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   233
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   234
    public void validate() throws PackagerException {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   235
        if (outdir == null) {
56848
f8a7c83f31f1 JDK-8208456: [packager] Remove some unused Strings
herrick
parents: 56836
diff changeset
   236
            throw new PackagerException("ERR_MissingArgument", "--output");
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   237
        }
56888
628a283daa6c 8210505: Unable to create an installer from an app-image on linux
herrick
parents: 56882
diff changeset
   238
628a283daa6c 8210505: Unable to create an installer from an app-image on linux
herrick
parents: 56882
diff changeset
   239
        boolean hasModule = (bundlerArguments.get(
628a283daa6c 8210505: Unable to create an installer from an app-image on linux
herrick
parents: 56882
diff changeset
   240
                Arguments.CLIOptions.MODULE.getId()) != null);
57256
d7c27451f759 8219678: CLI changes in jpackage
herrick
parents: 57255
diff changeset
   241
        boolean hasAppImage = (bundlerArguments.get(
56888
628a283daa6c 8210505: Unable to create an installer from an app-image on linux
herrick
parents: 56882
diff changeset
   242
                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
   243
        boolean hasClass = (bundlerArguments.get(
628a283daa6c 8210505: Unable to create an installer from an app-image on linux
herrick
parents: 56882
diff changeset
   244
                Arguments.CLIOptions.APPCLASS.getId()) != null);
628a283daa6c 8210505: Unable to create an installer from an app-image on linux
herrick
parents: 56882
diff changeset
   245
        boolean hasMain = (bundlerArguments.get(
628a283daa6c 8210505: Unable to create an installer from an app-image on linux
herrick
parents: 56882
diff changeset
   246
                Arguments.CLIOptions.MAIN_JAR.getId()) != null);
57030
902f4c4fba42 8214021: Create additional automated tests for jpackager
herrick
parents: 57022
diff changeset
   247
        boolean hasRuntimeImage = (bundlerArguments.get(
902f4c4fba42 8214021: Create additional automated tests for jpackager
herrick
parents: 57022
diff changeset
   248
                Arguments.CLIOptions.PREDEFINED_RUNTIME_IMAGE.getId()) != null);
902f4c4fba42 8214021: Create additional automated tests for jpackager
herrick
parents: 57022
diff changeset
   249
        boolean hasInput = (bundlerArguments.get(
902f4c4fba42 8214021: Create additional automated tests for jpackager
herrick
parents: 57022
diff changeset
   250
                Arguments.CLIOptions.INPUT.getId()) != null);
902f4c4fba42 8214021: Create additional automated tests for jpackager
herrick
parents: 57022
diff changeset
   251
        boolean hasModulePath = (bundlerArguments.get(
902f4c4fba42 8214021: Create additional automated tests for jpackager
herrick
parents: 57022
diff changeset
   252
                Arguments.CLIOptions.MODULE_PATH.getId()) != null);
57256
d7c27451f759 8219678: CLI changes in jpackage
herrick
parents: 57255
diff changeset
   253
        boolean runtimeInstaller = (BundlerType.INSTALLER == getBundleType()) &&
d7c27451f759 8219678: CLI changes in jpackage
herrick
parents: 57255
diff changeset
   254
                !hasAppImage && !hasModule && !hasMain && hasRuntimeImage;
57030
902f4c4fba42 8214021: Create additional automated tests for jpackager
herrick
parents: 57022
diff changeset
   255
902f4c4fba42 8214021: Create additional automated tests for jpackager
herrick
parents: 57022
diff changeset
   256
        if (getBundleType() == BundlerType.IMAGE) {
902f4c4fba42 8214021: Create additional automated tests for jpackager
herrick
parents: 57022
diff changeset
   257
            // Module application requires --runtime-image or --module-path
902f4c4fba42 8214021: Create additional automated tests for jpackager
herrick
parents: 57022
diff changeset
   258
            if (hasModule) {
902f4c4fba42 8214021: Create additional automated tests for jpackager
herrick
parents: 57022
diff changeset
   259
                if (!hasModulePath && !hasRuntimeImage) {
902f4c4fba42 8214021: Create additional automated tests for jpackager
herrick
parents: 57022
diff changeset
   260
                    throw new PackagerException("ERR_MissingArgument",
902f4c4fba42 8214021: Create additional automated tests for jpackager
herrick
parents: 57022
diff changeset
   261
                            "--runtime-image or --module-path");
902f4c4fba42 8214021: Create additional automated tests for jpackager
herrick
parents: 57022
diff changeset
   262
                }
902f4c4fba42 8214021: Create additional automated tests for jpackager
herrick
parents: 57022
diff changeset
   263
            } else {
902f4c4fba42 8214021: Create additional automated tests for jpackager
herrick
parents: 57022
diff changeset
   264
                if (!hasInput) {
57096
d06bec27f8c9 8215903: modify behavior of retaining temporary output dir
herrick
parents: 57080
diff changeset
   265
                    throw new PackagerException(
d06bec27f8c9 8215903: modify behavior of retaining temporary output dir
herrick
parents: 57080
diff changeset
   266
                           "ERR_MissingArgument", "--input");
57030
902f4c4fba42 8214021: Create additional automated tests for jpackager
herrick
parents: 57022
diff changeset
   267
                }
902f4c4fba42 8214021: Create additional automated tests for jpackager
herrick
parents: 57022
diff changeset
   268
            }
902f4c4fba42 8214021: Create additional automated tests for jpackager
herrick
parents: 57022
diff changeset
   269
        } else if (getBundleType() == BundlerType.INSTALLER) {
57150
fa68c2ab636d 8217894: jpackage CLI syntax changes
herrick
parents: 57119
diff changeset
   270
            if (!runtimeInstaller) {
57030
902f4c4fba42 8214021: Create additional automated tests for jpackager
herrick
parents: 57022
diff changeset
   271
                if (hasModule) {
902f4c4fba42 8214021: Create additional automated tests for jpackager
herrick
parents: 57022
diff changeset
   272
                    if (!hasModulePath && !hasRuntimeImage && !hasAppImage) {
902f4c4fba42 8214021: Create additional automated tests for jpackager
herrick
parents: 57022
diff changeset
   273
                        throw new PackagerException("ERR_MissingArgument",
902f4c4fba42 8214021: Create additional automated tests for jpackager
herrick
parents: 57022
diff changeset
   274
                            "--runtime-image, --module-path or --app-image");
902f4c4fba42 8214021: Create additional automated tests for jpackager
herrick
parents: 57022
diff changeset
   275
                    }
902f4c4fba42 8214021: Create additional automated tests for jpackager
herrick
parents: 57022
diff changeset
   276
                } else {
902f4c4fba42 8214021: Create additional automated tests for jpackager
herrick
parents: 57022
diff changeset
   277
                    if (!hasInput && !hasAppImage) {
57096
d06bec27f8c9 8215903: modify behavior of retaining temporary output dir
herrick
parents: 57080
diff changeset
   278
                        throw new PackagerException("ERR_MissingArgument",
d06bec27f8c9 8215903: modify behavior of retaining temporary output dir
herrick
parents: 57080
diff changeset
   279
                                "--input or --app-image");
57030
902f4c4fba42 8214021: Create additional automated tests for jpackager
herrick
parents: 57022
diff changeset
   280
                    }
902f4c4fba42 8214021: Create additional automated tests for jpackager
herrick
parents: 57022
diff changeset
   281
                }
902f4c4fba42 8214021: Create additional automated tests for jpackager
herrick
parents: 57022
diff changeset
   282
            }
902f4c4fba42 8214021: Create additional automated tests for jpackager
herrick
parents: 57022
diff changeset
   283
        }
56888
628a283daa6c 8210505: Unable to create an installer from an app-image on linux
herrick
parents: 56882
diff changeset
   284
628a283daa6c 8210505: Unable to create an installer from an app-image on linux
herrick
parents: 56882
diff changeset
   285
        // 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
   286
        // then we need some resources and a main class
57256
d7c27451f759 8219678: CLI changes in jpackage
herrick
parents: 57255
diff changeset
   287
        if (!hasModule && !hasAppImage && !runtimeInstaller) {
56888
628a283daa6c 8210505: Unable to create an installer from an app-image on linux
herrick
parents: 56882
diff changeset
   288
            if (resources.isEmpty()) {
628a283daa6c 8210505: Unable to create an installer from an app-image on linux
herrick
parents: 56882
diff changeset
   289
                throw new PackagerException("ERR_MissingAppResources");
628a283daa6c 8210505: Unable to create an installer from an app-image on linux
herrick
parents: 56882
diff changeset
   290
            }
628a283daa6c 8210505: Unable to create an installer from an app-image on linux
herrick
parents: 56882
diff changeset
   291
            if (!hasMain) {
56982
e094d5483bd6 8212048: Cleanup source code and fix issues discussed in preliminary review
herrick
parents: 56933
diff changeset
   292
                throw new PackagerException("ERR_MissingArgument",
e094d5483bd6 8212048: Cleanup source code and fix issues discussed in preliminary review
herrick
parents: 56933
diff changeset
   293
                        "--main-jar");
56888
628a283daa6c 8210505: Unable to create an installer from an app-image on linux
herrick
parents: 56882
diff changeset
   294
            }
628a283daa6c 8210505: Unable to create an installer from an app-image on linux
herrick
parents: 56882
diff changeset
   295
        }
56902
6972c0e75e23 8210367: invalid --app-image arg causes exception runnning light.exe in windows
herrick
parents: 56888
diff changeset
   296
57096
d06bec27f8c9 8215903: modify behavior of retaining temporary output dir
herrick
parents: 57080
diff changeset
   297
        String name = (String)bundlerArguments.get(
d06bec27f8c9 8215903: modify behavior of retaining temporary output dir
herrick
parents: 57080
diff changeset
   298
                Arguments.CLIOptions.NAME.getId());
57119
b3dda8d77d8a 8217331: Problems when space in application name
herrick
parents: 57106
diff changeset
   299
        validateName(name, true);
56985
5e6ced665587 8211285: Better app validation
herrick
parents: 56982
diff changeset
   300
56902
6972c0e75e23 8210367: invalid --app-image arg causes exception runnning light.exe in windows
herrick
parents: 56888
diff changeset
   301
        // Validate app image if set
56982
e094d5483bd6 8212048: Cleanup source code and fix issues discussed in preliminary review
herrick
parents: 56933
diff changeset
   302
        String appImage = (String)bundlerArguments.get(
e094d5483bd6 8212048: Cleanup source code and fix issues discussed in preliminary review
herrick
parents: 56933
diff changeset
   303
                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
   304
        if (appImage != null) {
6972c0e75e23 8210367: invalid --app-image arg causes exception runnning light.exe in windows
herrick
parents: 56888
diff changeset
   305
            File appImageDir = new File(appImage);
57218
8018ecf829bc 8217902: jpackage fails with --app-image option on mac
herrick
parents: 57150
diff changeset
   306
            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
   307
                throw new PackagerException("ERR_AppImageNotExist", appImage);
6972c0e75e23 8210367: invalid --app-image arg causes exception runnning light.exe in windows
herrick
parents: 56888
diff changeset
   308
            }
6972c0e75e23 8210367: invalid --app-image arg causes exception runnning light.exe in windows
herrick
parents: 56888
diff changeset
   309
        }
57080
bd4ce7f9ea2c 8214495: Change behavior of --license-file
herrick
parents: 57078
diff changeset
   310
57256
d7c27451f759 8219678: CLI changes in jpackage
herrick
parents: 57255
diff changeset
   311
        // Validate temp-root
57096
d06bec27f8c9 8215903: modify behavior of retaining temporary output dir
herrick
parents: 57080
diff changeset
   312
        String root = (String)bundlerArguments.get(
57256
d7c27451f759 8219678: CLI changes in jpackage
herrick
parents: 57255
diff changeset
   313
                Arguments.CLIOptions.TEMP_ROOT.getId());
57096
d06bec27f8c9 8215903: modify behavior of retaining temporary output dir
herrick
parents: 57080
diff changeset
   314
        if (root != null) {
d06bec27f8c9 8215903: modify behavior of retaining temporary output dir
herrick
parents: 57080
diff changeset
   315
            String [] contents = (new File(root)).list();
d06bec27f8c9 8215903: modify behavior of retaining temporary output dir
herrick
parents: 57080
diff changeset
   316
d06bec27f8c9 8215903: modify behavior of retaining temporary output dir
herrick
parents: 57080
diff changeset
   317
            if (contents != null && contents.length > 0) {
d06bec27f8c9 8215903: modify behavior of retaining temporary output dir
herrick
parents: 57080
diff changeset
   318
                throw new PackagerException("ERR_BuildRootInvalid", root);
d06bec27f8c9 8215903: modify behavior of retaining temporary output dir
herrick
parents: 57080
diff changeset
   319
            }
d06bec27f8c9 8215903: modify behavior of retaining temporary output dir
herrick
parents: 57080
diff changeset
   320
        }
d06bec27f8c9 8215903: modify behavior of retaining temporary output dir
herrick
parents: 57080
diff changeset
   321
57080
bd4ce7f9ea2c 8214495: Change behavior of --license-file
herrick
parents: 57078
diff changeset
   322
        // Validate license file if set
bd4ce7f9ea2c 8214495: Change behavior of --license-file
herrick
parents: 57078
diff changeset
   323
        String license = (String)bundlerArguments.get(
bd4ce7f9ea2c 8214495: Change behavior of --license-file
herrick
parents: 57078
diff changeset
   324
                Arguments.CLIOptions.LICENSE_FILE.getId());
bd4ce7f9ea2c 8214495: Change behavior of --license-file
herrick
parents: 57078
diff changeset
   325
        if (license != null) {
bd4ce7f9ea2c 8214495: Change behavior of --license-file
herrick
parents: 57078
diff changeset
   326
            File licenseFile = new File(license);
bd4ce7f9ea2c 8214495: Change behavior of --license-file
herrick
parents: 57078
diff changeset
   327
            if (!licenseFile.exists()) {
bd4ce7f9ea2c 8214495: Change behavior of --license-file
herrick
parents: 57078
diff changeset
   328
                throw new PackagerException("ERR_LicenseFileNotExit");
bd4ce7f9ea2c 8214495: Change behavior of --license-file
herrick
parents: 57078
diff changeset
   329
            }
bd4ce7f9ea2c 8214495: Change behavior of --license-file
herrick
parents: 57078
diff changeset
   330
        }
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   331
    }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   332
57067
9c17d779808e 8213425: Analyze output from Source code scanner and fix where needed.
herrick
parents: 57062
diff changeset
   333
    boolean validateForBundle() {
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   334
        boolean result = false;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   335
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   336
        // Success
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   337
        if (((applicationClass != null && !applicationClass.isEmpty()) ||
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   338
            (module != null && !module.isEmpty()))) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   339
            result = true;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   340
        }
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
        return result;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   343
    }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   344
57067
9c17d779808e 8213425: Analyze output from Source code scanner and fix where needed.
herrick
parents: 57062
diff changeset
   345
    void setBundleType(BundlerType type) {
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   346
        bundleType = type;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   347
    }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   348
57067
9c17d779808e 8213425: Analyze output from Source code scanner and fix where needed.
herrick
parents: 57062
diff changeset
   349
    BundlerType getBundleType() {
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   350
        return bundleType;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   351
    }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   352
57067
9c17d779808e 8213425: Analyze output from Source code scanner and fix where needed.
herrick
parents: 57062
diff changeset
   353
    void setTargetFormat(String t) {
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   354
        targetFormat = t;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   355
    }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   356
57067
9c17d779808e 8213425: Analyze output from Source code scanner and fix where needed.
herrick
parents: 57062
diff changeset
   357
    String getTargetFormat() {
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   358
        return targetFormat;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   359
    }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   360
57396
3944e4c2f779 8223586: remove jpackage dead code and other cleanup
herrick
parents: 57391
diff changeset
   361
    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
   362
            StandardBundlerParam.JAVA_OPTIONS.getID(),
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   363
            StandardBundlerParam.ARGUMENTS.getID(),
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   364
            StandardBundlerParam.MODULE_PATH.getID(),
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   365
            StandardBundlerParam.ADD_MODULES.getID(),
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   366
            StandardBundlerParam.LIMIT_MODULES.getID(),
56982
e094d5483bd6 8212048: Cleanup source code and fix issues discussed in preliminary review
herrick
parents: 56933
diff changeset
   367
            StandardBundlerParam.FILE_ASSOCIATIONS.getID()
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   368
    ));
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   369
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   370
    @SuppressWarnings("unchecked")
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   371
    public void addBundleArgument(String key, Object value) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   372
        // special hack for multi-line arguments
56836
40abf95122b0 8207143: jpackager fails to parse file associations
herrick
parents: 56821
diff changeset
   373
        if (multi_args.contains(key)) {
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   374
            Object existingValue = bundlerArguments.get(key);
56836
40abf95122b0 8207143: jpackager fails to parse file associations
herrick
parents: 56821
diff changeset
   375
            if (existingValue instanceof String && value instanceof String) {
57324
c1d3935fbb79 8222406: Multiple arguments for the same option - aggragation broken
herrick
parents: 57323
diff changeset
   376
                String delim = "\n\n";
c1d3935fbb79 8222406: Multiple arguments for the same option - aggragation broken
herrick
parents: 57323
diff changeset
   377
                if (key.equals(StandardBundlerParam.MODULE_PATH.getID())) {
c1d3935fbb79 8222406: Multiple arguments for the same option - aggragation broken
herrick
parents: 57323
diff changeset
   378
                    delim = File.pathSeparator;
c1d3935fbb79 8222406: Multiple arguments for the same option - aggragation broken
herrick
parents: 57323
diff changeset
   379
                } else if (key.equals(
c1d3935fbb79 8222406: Multiple arguments for the same option - aggragation broken
herrick
parents: 57323
diff changeset
   380
                        StandardBundlerParam.ADD_MODULES.getID())) {
c1d3935fbb79 8222406: Multiple arguments for the same option - aggragation broken
herrick
parents: 57323
diff changeset
   381
                    delim = ",";
c1d3935fbb79 8222406: Multiple arguments for the same option - aggragation broken
herrick
parents: 57323
diff changeset
   382
                }
c1d3935fbb79 8222406: Multiple arguments for the same option - aggragation broken
herrick
parents: 57323
diff changeset
   383
                bundlerArguments.put(key, existingValue + delim + value);
56836
40abf95122b0 8207143: jpackager fails to parse file associations
herrick
parents: 56821
diff changeset
   384
            } else if (existingValue instanceof List && value instanceof List) {
40abf95122b0 8207143: jpackager fails to parse file associations
herrick
parents: 56821
diff changeset
   385
                ((List)existingValue).addAll((List)value);
40abf95122b0 8207143: jpackager fails to parse file associations
herrick
parents: 56821
diff changeset
   386
            } else if (existingValue instanceof Map &&
40abf95122b0 8207143: jpackager fails to parse file associations
herrick
parents: 56821
diff changeset
   387
                value instanceof String && ((String)value).contains("=")) {
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   388
                String[] mapValues = ((String)value).split("=", 2);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   389
                ((Map)existingValue).put(mapValues[0], mapValues[1]);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   390
            } else {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   391
                bundlerArguments.put(key, value);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   392
            }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   393
        } else {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   394
            bundlerArguments.put(key, value);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   395
        }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   396
    }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   397
57067
9c17d779808e 8213425: Analyze output from Source code scanner and fix where needed.
herrick
parents: 57062
diff changeset
   398
    BundleParams getBundleParams() {
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   399
        BundleParams bundleParams = new BundleParams();
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   400
57096
d06bec27f8c9 8215903: modify behavior of retaining temporary output dir
herrick
parents: 57080
diff changeset
   401
        // construct app resources relative to output folder!
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   402
        bundleParams.setAppResourcesList(resources);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   403
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   404
        bundleParams.setApplicationClass(applicationClass);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   405
        bundleParams.setAppVersion(version);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   406
        bundleParams.setType(bundleType);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   407
        bundleParams.setBundleFormat(targetFormat);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   408
        bundleParams.setCopyright(copyright);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   409
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   410
        bundleParams.setJvmargs(jvmargs);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   411
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   412
        if (addModules != null && !addModules.isEmpty()) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   413
            bundleParams.setAddModules(addModules);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   414
        }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   415
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   416
        if (limitModules != null && !limitModules.isEmpty()) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   417
            bundleParams.setLimitModules(limitModules);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   418
        }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   419
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   420
        if (module != null && !module.isEmpty()) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   421
            bundleParams.setMainModule(module);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   422
        }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   423
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   424
        Map<String, String> unescapedHtmlParams = new TreeMap<>();
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   425
        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
   426
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   427
        // check for collisions
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   428
        TreeSet<String> keys = new TreeSet<>(bundlerArguments.keySet());
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   429
        keys.retainAll(bundleParams.getBundleParamsAsMap().keySet());
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   430
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   431
        if (!keys.isEmpty()) {
56869
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56848
diff changeset
   432
            throw new RuntimeException("Deploy Params and Bundler Arguments "
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56848
diff changeset
   433
                    + "overlap in the following values:" + keys.toString());
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   434
        }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   435
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   436
        bundleParams.addAllBundleParams(bundlerArguments);
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
        return bundleParams;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   439
    }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   440
57067
9c17d779808e 8213425: Analyze output from Source code scanner and fix where needed.
herrick
parents: 57062
diff changeset
   441
    Map<String, ? super Object> getBundlerArguments() {
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   442
        return this.bundlerArguments;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   443
    }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   444
56994
b4aca2dbe2b5 8212537: Create method and class description comments for main functionality
herrick
parents: 56987
diff changeset
   445
    @Override
b4aca2dbe2b5 8212537: Create method and class description comments for main functionality
herrick
parents: 56987
diff changeset
   446
    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
   447
        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
   448
                + " resources: {" + resources + "}}";
56994
b4aca2dbe2b5 8212537: Create method and class description comments for main functionality
herrick
parents: 56987
diff changeset
   449
    }
b4aca2dbe2b5 8212537: Create method and class description comments for main functionality
herrick
parents: 56987
diff changeset
   450
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   451
}