src/jdk.jpackage/share/classes/jdk/jpackage/internal/AbstractImageBundler.java
author herrick
Fri, 05 Apr 2019 11:24:44 -0400
branchJDK-8200758-branch
changeset 57307 4948a1944cf9
parent 57256 d7c27451f759
child 57389 cce526c681dc
permissions -rw-r--r--
8221777: CLI changes from jpackage EA5 feedback Reviewed-by: kbr, 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: 57059
diff changeset
     2
 * Copyright (c) 2015, 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: 57021
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.text.MessageFormat;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    29
import java.util.Map;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    30
import java.util.ResourceBundle;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    31
import java.util.regex.Matcher;
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    32
import java.util.regex.Pattern;
57021
441c020bf626 8213324:jpackager deletes existing app directory without warning
herrick
parents: 57017
diff changeset
    33
import java.io.File;
441c020bf626 8213324:jpackager deletes existing app directory without warning
herrick
parents: 57017
diff changeset
    34
import java.io.IOException;
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    35
57039
98d3963b0b7b 8214051: rename jpackager tool to jpackage
herrick
parents: 57021
diff changeset
    36
import static jdk.jpackage.internal.StandardBundlerParam.*;
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    37
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    38
/**
56994
b4aca2dbe2b5 8212537: Create method and class description comments for main functionality
herrick
parents: 56982
diff changeset
    39
 * AbstractImageBundler
b4aca2dbe2b5 8212537: Create method and class description comments for main functionality
herrick
parents: 56982
diff changeset
    40
 *
b4aca2dbe2b5 8212537: Create method and class description comments for main functionality
herrick
parents: 56982
diff changeset
    41
 * This is the base class for each of the Application Image Bundlers.
b4aca2dbe2b5 8212537: Create method and class description comments for main functionality
herrick
parents: 56982
diff changeset
    42
 *
b4aca2dbe2b5 8212537: Create method and class description comments for main functionality
herrick
parents: 56982
diff changeset
    43
 * It contains methods and parameters common to all Image Bundlers.
b4aca2dbe2b5 8212537: Create method and class description comments for main functionality
herrick
parents: 56982
diff changeset
    44
 *
57307
4948a1944cf9 8221777: CLI changes from jpackage EA5 feedback
herrick
parents: 57256
diff changeset
    45
 * Application Image Bundlers are created in "create-app-image" mode,
56994
b4aca2dbe2b5 8212537: Create method and class description comments for main functionality
herrick
parents: 56982
diff changeset
    46
 * or as an intermeadiate step in "create-installer" mode.
b4aca2dbe2b5 8212537: Create method and class description comments for main functionality
herrick
parents: 56982
diff changeset
    47
 *
b4aca2dbe2b5 8212537: Create method and class description comments for main functionality
herrick
parents: 56982
diff changeset
    48
 * The concrete implementations are in the platform specific Bundlers.
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    49
 */
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    50
public abstract class AbstractImageBundler extends AbstractBundler {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    51
56982
e094d5483bd6 8212048: Cleanup source code and fix issues discussed in preliminary review
herrick
parents: 56933
diff changeset
    52
    private final static String JAVA_VERSION_SPEC =
e094d5483bd6 8212048: Cleanup source code and fix issues discussed in preliminary review
herrick
parents: 56933
diff changeset
    53
        "java version \"((\\d+).(\\d+).(\\d+).(\\d+))(-(.*))?(\\+[^\"]*)?\"";
e094d5483bd6 8212048: Cleanup source code and fix issues discussed in preliminary review
herrick
parents: 56933
diff changeset
    54
56869
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56821
diff changeset
    55
    private static final ResourceBundle I18N = ResourceBundle.getBundle(
57059
9bb2a4dc3af7 8214143: Reduce Resource files
herrick
parents: 57039
diff changeset
    56
            "jdk.jpackage.internal.resources.MainResources");
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    57
56869
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56821
diff changeset
    58
    public void imageBundleValidation(Map<String, ? super Object> p)
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56821
diff changeset
    59
             throws ConfigException {
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    60
        StandardBundlerParam.validateMainClassInfoFromAppResources(p);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    61
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    62
    }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    63
56869
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56821
diff changeset
    64
    public static void extractFlagsFromVersion(
41e17fe9fbeb 8208522: removed unreferenced class and minor formatting of java source
herrick
parents: 56821
diff changeset
    65
            Map<String, ? super Object> params, String versionOutput) {
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    66
        Pattern bitArchPattern = Pattern.compile("(\\d*)[- ]?[bB]it");
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    67
        Matcher matcher = bitArchPattern.matcher(versionOutput);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    68
        if (matcher.find()) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    69
            params.put(".runtime.bit-arch", matcher.group(1));
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    70
        } else {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    71
            // presume 32 bit on no match
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    72
            params.put(".runtime.bit-arch", "32");
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    73
        }
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    74
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    75
        Pattern oldVersionMatcher = Pattern.compile(
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    76
                "java version \"((\\d+.(\\d+).\\d+)(_(\\d+)))?(-(.*))?\"");
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    77
        matcher = oldVersionMatcher.matcher(versionOutput);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    78
        if (matcher.find()) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    79
            params.put(".runtime.version", matcher.group(1));
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    80
            params.put(".runtime.version.release", matcher.group(2));
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    81
            params.put(".runtime.version.major", matcher.group(3));
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    82
            params.put(".runtime.version.update", matcher.group(5));
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    83
            params.put(".runtime.version.minor", matcher.group(5));
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    84
            params.put(".runtime.version.security", matcher.group(5));
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    85
            params.put(".runtime.version.patch", "0");
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    86
            params.put(".runtime.version.modifiers", matcher.group(7));
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    87
        } else {
56982
e094d5483bd6 8212048: Cleanup source code and fix issues discussed in preliminary review
herrick
parents: 56933
diff changeset
    88
            Pattern newVersionMatcher = Pattern.compile(JAVA_VERSION_SPEC);
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    89
            matcher = newVersionMatcher.matcher(versionOutput);
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    90
            if (matcher.find()) {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    91
                params.put(".runtime.version", matcher.group(1));
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    92
                params.put(".runtime.version.release", matcher.group(1));
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    93
                params.put(".runtime.version.major", matcher.group(2));
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    94
                params.put(".runtime.version.update", matcher.group(3));
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    95
                params.put(".runtime.version.minor", matcher.group(3));
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    96
                params.put(".runtime.version.security", matcher.group(4));
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    97
                params.put(".runtime.version.patch", matcher.group(5));
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    98
                params.put(".runtime.version.modifiers", matcher.group(7));
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
    99
            } else {
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   100
                params.put(".runtime.version", "");
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   101
                params.put(".runtime.version.release", "");
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   102
                params.put(".runtime.version.major", "");
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   103
                params.put(".runtime.version.update", "");
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   104
                params.put(".runtime.version.minor", "");
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   105
                params.put(".runtime.version.security", "");
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   106
                params.put(".runtime.version.patch", "");
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   107
                params.put(".runtime.version.modifiers", "");
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
    }
57021
441c020bf626 8213324:jpackager deletes existing app directory without warning
herrick
parents: 57017
diff changeset
   111
441c020bf626 8213324:jpackager deletes existing app directory without warning
herrick
parents: 57017
diff changeset
   112
    protected File createRoot(Map<String, ? super Object> p,
57256
d7c27451f759 8219678: CLI changes in jpackage
herrick
parents: 57213
diff changeset
   113
            File outputDirectory, boolean dependentTask, String name)
d7c27451f759 8219678: CLI changes in jpackage
herrick
parents: 57213
diff changeset
   114
            throws PackagerException {
57021
441c020bf626 8213324:jpackager deletes existing app directory without warning
herrick
parents: 57017
diff changeset
   115
        if (!outputDirectory.isDirectory() && !outputDirectory.mkdirs()) {
441c020bf626 8213324:jpackager deletes existing app directory without warning
herrick
parents: 57017
diff changeset
   116
            throw new RuntimeException(MessageFormat.format(
441c020bf626 8213324:jpackager deletes existing app directory without warning
herrick
parents: 57017
diff changeset
   117
                    I18N.getString("error.cannot-create-output-dir"),
441c020bf626 8213324:jpackager deletes existing app directory without warning
herrick
parents: 57017
diff changeset
   118
                    outputDirectory.getAbsolutePath()));
441c020bf626 8213324:jpackager deletes existing app directory without warning
herrick
parents: 57017
diff changeset
   119
        }
441c020bf626 8213324:jpackager deletes existing app directory without warning
herrick
parents: 57017
diff changeset
   120
        if (!outputDirectory.canWrite()) {
441c020bf626 8213324:jpackager deletes existing app directory without warning
herrick
parents: 57017
diff changeset
   121
            throw new RuntimeException(MessageFormat.format(
441c020bf626 8213324:jpackager deletes existing app directory without warning
herrick
parents: 57017
diff changeset
   122
                    I18N.getString("error.cannot-write-to-output-dir"),
441c020bf626 8213324:jpackager deletes existing app directory without warning
herrick
parents: 57017
diff changeset
   123
                    outputDirectory.getAbsolutePath()));
441c020bf626 8213324:jpackager deletes existing app directory without warning
herrick
parents: 57017
diff changeset
   124
        }
441c020bf626 8213324:jpackager deletes existing app directory without warning
herrick
parents: 57017
diff changeset
   125
        if (!dependentTask) {
441c020bf626 8213324:jpackager deletes existing app directory without warning
herrick
parents: 57017
diff changeset
   126
            Log.verbose(MessageFormat.format(
441c020bf626 8213324:jpackager deletes existing app directory without warning
herrick
parents: 57017
diff changeset
   127
                    I18N.getString("message.creating-app-bundle"),
441c020bf626 8213324:jpackager deletes existing app directory without warning
herrick
parents: 57017
diff changeset
   128
                    name, outputDirectory.getAbsolutePath()));
441c020bf626 8213324:jpackager deletes existing app directory without warning
herrick
parents: 57017
diff changeset
   129
        }
441c020bf626 8213324:jpackager deletes existing app directory without warning
herrick
parents: 57017
diff changeset
   130
441c020bf626 8213324:jpackager deletes existing app directory without warning
herrick
parents: 57017
diff changeset
   131
        // Create directory structure
441c020bf626 8213324:jpackager deletes existing app directory without warning
herrick
parents: 57017
diff changeset
   132
        File rootDirectory = new File(outputDirectory, name);
441c020bf626 8213324:jpackager deletes existing app directory without warning
herrick
parents: 57017
diff changeset
   133
441c020bf626 8213324:jpackager deletes existing app directory without warning
herrick
parents: 57017
diff changeset
   134
        if (rootDirectory.exists()) {
57256
d7c27451f759 8219678: CLI changes in jpackage
herrick
parents: 57213
diff changeset
   135
            throw new PackagerException("error.root-exists",
d7c27451f759 8219678: CLI changes in jpackage
herrick
parents: 57213
diff changeset
   136
                    rootDirectory.getAbsolutePath());
57021
441c020bf626 8213324:jpackager deletes existing app directory without warning
herrick
parents: 57017
diff changeset
   137
        }
57256
d7c27451f759 8219678: CLI changes in jpackage
herrick
parents: 57213
diff changeset
   138
57021
441c020bf626 8213324:jpackager deletes existing app directory without warning
herrick
parents: 57017
diff changeset
   139
        rootDirectory.mkdirs();
441c020bf626 8213324:jpackager deletes existing app directory without warning
herrick
parents: 57017
diff changeset
   140
441c020bf626 8213324:jpackager deletes existing app directory without warning
herrick
parents: 57017
diff changeset
   141
        return rootDirectory;
441c020bf626 8213324:jpackager deletes existing app directory without warning
herrick
parents: 57017
diff changeset
   142
    }
441c020bf626 8213324:jpackager deletes existing app directory without warning
herrick
parents: 57017
diff changeset
   143
56821
565d54ca1f41 8206005: Move prototype jpackager from closed sandbox to open sandbox
herrick
parents:
diff changeset
   144
}