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