src/jdk.jpackage/linux/classes/jdk/jpackage/internal/LinuxAppImageBuilder.java
author herrick
Wed, 13 Mar 2019 13:37:26 -0400
branchJDK-8200758-branch
changeset 57264 2624a38ca35a
parent 57263 86e75b8f99c4
child 57392 46d4b0aa4542
permissions -rw-r--r--
Typo
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
57038
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
     1
/*
57106
ea870b9ce89a 8216492: Update copyright of all new jpackage fils to 2019
kcr
parents: 57091
diff changeset
     2
 * Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
57038
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
     4
 *
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    10
 *
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    15
 * accompanied this code).
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    16
 *
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    20
 *
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    23
 * questions.
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    24
 */
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    25
57039
98d3963b0b7b 8214051: rename jpackager tool to jpackage
herrick
parents: 57038
diff changeset
    26
package jdk.jpackage.internal;
57038
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    27
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    28
import java.io.File;
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    29
import java.io.FileInputStream;
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    30
import java.io.FileOutputStream;
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    31
import java.io.IOException;
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    32
import java.io.InputStream;
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    33
import java.io.OutputStream;
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    34
import java.io.OutputStreamWriter;
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    35
import java.io.UncheckedIOException;
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    36
import java.io.Writer;
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    37
import java.nio.file.Files;
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    38
import java.nio.file.Path;
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    39
import java.nio.file.attribute.PosixFilePermission;
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    40
import java.text.MessageFormat;
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    41
import java.util.HashMap;
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    42
import java.util.List;
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    43
import java.util.Map;
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    44
import java.util.Objects;
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    45
import java.util.ResourceBundle;
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    46
import java.util.Set;
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    47
57039
98d3963b0b7b 8214051: rename jpackager tool to jpackage
herrick
parents: 57038
diff changeset
    48
import static jdk.jpackage.internal.StandardBundlerParam.*;
57038
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    49
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    50
public class LinuxAppImageBuilder extends AbstractAppImageBuilder {
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    51
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    52
    private static final ResourceBundle I18N = ResourceBundle.getBundle(
57059
9bb2a4dc3af7 8214143: Reduce Resource files
herrick
parents: 57039
diff changeset
    53
        "jdk.jpackage.internal.resources.LinuxResources");
57038
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    54
57064
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents: 57059
diff changeset
    55
    private static final String LIBRARY_NAME = "libapplauncher.so";
57038
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    56
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    57
    private final Path root;
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    58
    private final Path appDir;
57077
8f9cf6ad59f0 8213962: JPackageCreateImageRuntimeModuleTest fails
herrick
parents: 57070
diff changeset
    59
    private final Path appModsDir;
57038
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    60
    private final Path runtimeDir;
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    61
    private final Path resourcesDir;
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    62
    private final Path mdir;
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    63
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    64
    private final Map<String, ? super Object> params;
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    65
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    66
    public static final BundlerParamInfo<File> ICON_PNG =
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    67
            new StandardBundlerParam<>(
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    68
            "icon.png",
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    69
            File.class,
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    70
            params -> {
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    71
                File f = ICON.fetchFrom(params);
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    72
                if (f != null && !f.getName().toLowerCase().endsWith(".png")) {
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    73
                    Log.error(MessageFormat.format(I18N.getString(
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    74
                            "message.icon-not-png"), f));
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    75
                    return null;
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    76
                }
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    77
                return f;
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    78
            },
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    79
            (s, p) -> new File(s));
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    80
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    81
    public LinuxAppImageBuilder(Map<String, Object> config, Path imageOutDir)
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    82
            throws IOException {
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    83
        super(config,
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    84
                imageOutDir.resolve(APP_NAME.fetchFrom(config) + "/runtime"));
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    85
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    86
        Objects.requireNonNull(imageOutDir);
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    87
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    88
        this.root = imageOutDir.resolve(APP_NAME.fetchFrom(config));
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    89
        this.appDir = root.resolve("app");
57077
8f9cf6ad59f0 8213962: JPackageCreateImageRuntimeModuleTest fails
herrick
parents: 57070
diff changeset
    90
        this.appModsDir = appDir.resolve("mods");
57038
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    91
        this.runtimeDir = root.resolve("runtime");
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    92
        this.resourcesDir = root.resolve("resources");
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    93
        this.mdir = runtimeDir.resolve("lib");
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    94
        this.params = new HashMap<>();
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    95
        config.entrySet().stream().forEach(e -> params.put(
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    96
                e.getKey().toString(), e.getValue()));
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    97
        Files.createDirectories(appDir);
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    98
        Files.createDirectories(runtimeDir);
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
    99
        Files.createDirectories(resourcesDir);
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   100
    }
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   101
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   102
    public LinuxAppImageBuilder(String appName, Path imageOutDir)
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   103
            throws IOException {
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   104
        super(null, imageOutDir.resolve(appName));
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   105
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   106
        Objects.requireNonNull(imageOutDir);
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   107
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   108
        this.root = imageOutDir.resolve(appName);
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   109
        this.appDir = null;
57077
8f9cf6ad59f0 8213962: JPackageCreateImageRuntimeModuleTest fails
herrick
parents: 57070
diff changeset
   110
        this.appModsDir = null;
57038
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   111
        this.runtimeDir = null;
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   112
        this.resourcesDir = null;
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   113
        this.mdir = null;
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   114
        this.params = new HashMap<>();
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   115
    }
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   116
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   117
    private Path destFile(String dir, String filename) {
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   118
        return runtimeDir.resolve(dir).resolve(filename);
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   119
    }
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   120
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   121
    private void writeEntry(InputStream in, Path dstFile) throws IOException {
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   122
        Files.createDirectories(dstFile.getParent());
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   123
        Files.copy(in, dstFile);
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   124
    }
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   125
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   126
    private void writeSymEntry(Path dstFile, Path target) throws IOException {
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   127
        Files.createDirectories(dstFile.getParent());
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   128
        Files.createLink(dstFile, target);
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   129
    }
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   130
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   131
    /**
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   132
     * chmod ugo+x file
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   133
     */
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   134
    private void setExecutable(Path file) {
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   135
        try {
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   136
            Set<PosixFilePermission> perms =
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   137
                    Files.getPosixFilePermissions(file);
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   138
            perms.add(PosixFilePermission.OWNER_EXECUTE);
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   139
            perms.add(PosixFilePermission.GROUP_EXECUTE);
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   140
            perms.add(PosixFilePermission.OTHERS_EXECUTE);
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   141
            Files.setPosixFilePermissions(file, perms);
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   142
        } catch (IOException ioe) {
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   143
            throw new UncheckedIOException(ioe);
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   144
        }
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   145
    }
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   146
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   147
    private static void createUtf8File(File file, String content)
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   148
            throws IOException {
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   149
        try (OutputStream fout = new FileOutputStream(file);
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   150
            Writer output = new OutputStreamWriter(fout, "UTF-8")) {
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   151
            output.write(content);
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   152
        }
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   153
    }
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   154
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   155
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   156
    // it is static for the sake of sharing with "installer" bundlers
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   157
    // that may skip calls to validate/bundle in this class!
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   158
    public static File getRootDir(File outDir, Map<String, ? super Object> p) {
57119
b3dda8d77d8a 8217331: Problems when space in application name
herrick
parents: 57106
diff changeset
   159
        return new File(outDir, APP_NAME.fetchFrom(p));
57038
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   160
    }
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   161
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   162
    public static String getLauncherName(Map<String, ? super Object> p) {
57119
b3dda8d77d8a 8217331: Problems when space in application name
herrick
parents: 57106
diff changeset
   163
        return APP_NAME.fetchFrom(p);
57038
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   164
    }
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   165
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   166
    public static String getLauncherCfgName(Map<String, ? super Object> p) {
57119
b3dda8d77d8a 8217331: Problems when space in application name
herrick
parents: 57106
diff changeset
   167
        return "app/" + APP_NAME.fetchFrom(p) + ".cfg";
57038
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   168
    }
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   169
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   170
    @Override
57077
8f9cf6ad59f0 8213962: JPackageCreateImageRuntimeModuleTest fails
herrick
parents: 57070
diff changeset
   171
    public Path getAppDir() {
8f9cf6ad59f0 8213962: JPackageCreateImageRuntimeModuleTest fails
herrick
parents: 57070
diff changeset
   172
        return appDir;
8f9cf6ad59f0 8213962: JPackageCreateImageRuntimeModuleTest fails
herrick
parents: 57070
diff changeset
   173
    }
8f9cf6ad59f0 8213962: JPackageCreateImageRuntimeModuleTest fails
herrick
parents: 57070
diff changeset
   174
8f9cf6ad59f0 8213962: JPackageCreateImageRuntimeModuleTest fails
herrick
parents: 57070
diff changeset
   175
    @Override
8f9cf6ad59f0 8213962: JPackageCreateImageRuntimeModuleTest fails
herrick
parents: 57070
diff changeset
   176
    public Path getAppModsDir() {
8f9cf6ad59f0 8213962: JPackageCreateImageRuntimeModuleTest fails
herrick
parents: 57070
diff changeset
   177
        return appModsDir;
8f9cf6ad59f0 8213962: JPackageCreateImageRuntimeModuleTest fails
herrick
parents: 57070
diff changeset
   178
    }
8f9cf6ad59f0 8213962: JPackageCreateImageRuntimeModuleTest fails
herrick
parents: 57070
diff changeset
   179
8f9cf6ad59f0 8213962: JPackageCreateImageRuntimeModuleTest fails
herrick
parents: 57070
diff changeset
   180
    @Override
57038
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   181
    public void prepareApplicationFiles() throws IOException {
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   182
        Map<String, ? super Object> originalParams = new HashMap<>(params);
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   183
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   184
        // create the primary launcher
57263
86e75b8f99c4 Merge error from JDK-8220505
herrick
parents: 57259
diff changeset
   185
        createLauncherForEntryPoint(params);
57038
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   186
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   187
        // Copy library to the launcher folder
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   188
        try (InputStream is_lib = getResourceAsStream(LIBRARY_NAME)) {
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   189
            writeEntry(is_lib, root.resolve(LIBRARY_NAME));
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   190
        }
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   191
57256
d7c27451f759 8219678: CLI changes in jpackage
herrick
parents: 57119
diff changeset
   192
        // create the additional launchers, if any
57038
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   193
        List<Map<String, ? super Object>> entryPoints
57256
d7c27451f759 8219678: CLI changes in jpackage
herrick
parents: 57119
diff changeset
   194
                = StandardBundlerParam.ADD_LAUNCHERS.fetchFrom(params);
57038
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   195
        for (Map<String, ? super Object> entryPoint : entryPoints) {
57259
a84c657c713d 8171959: add-launcher is not working when normal jar is used for first launcher and module is used for second launcher
herrick
parents: 57256
diff changeset
   196
            createLauncherForEntryPoint(
a84c657c713d 8171959: add-launcher is not working when normal jar is used for first launcher and module is used for second launcher
herrick
parents: 57256
diff changeset
   197
                    AddLauncherArguments.merge(originalParams, entryPoint));
57038
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   198
        }
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   199
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   200
        // Copy class path entries to Java folder
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   201
        copyApplication();
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   202
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   203
        // Copy icon to Resources folder
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   204
        copyIcon();
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   205
    }
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   206
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   207
    @Override
57070
42783e8e73de 8212164: resolve jre.list and jre.module.list
herrick
parents: 57067
diff changeset
   208
    public void prepareJreFiles() throws IOException {}
57038
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   209
57264
herrick
parents: 57263
diff changeset
   210
    private void createLauncherForEntryPoint(Map<String, ? super Object> p)
57263
86e75b8f99c4 Merge error from JDK-8220505
herrick
parents: 57259
diff changeset
   211
            throws IOException {
57038
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   212
        // Copy executable to Linux folder
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   213
        Path executableFile = root.resolve(getLauncherName(p));
57064
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents: 57059
diff changeset
   214
        try (InputStream is_launcher =
a7fdadf67a92 8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents: 57059
diff changeset
   215
                getResourceAsStream("jpackageapplauncher")) {
57038
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   216
            writeEntry(is_launcher, executableFile);
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   217
        }
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   218
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   219
        executableFile.toFile().setExecutable(true, false);
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   220
        executableFile.toFile().setWritable(true, true);
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   221
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   222
        writeCfgFile(p, root.resolve(getLauncherCfgName(p)).toFile(),
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   223
                "$APPDIR/runtime");
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   224
    }
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   225
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   226
    private void copyIcon() throws IOException {
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   227
        File icon = ICON_PNG.fetchFrom(params);
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   228
        if (icon != null) {
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   229
            File iconTarget = new File(resourcesDir.toFile(),
57119
b3dda8d77d8a 8217331: Problems when space in application name
herrick
parents: 57106
diff changeset
   230
                    APP_NAME.fetchFrom(params) + ".png");
57038
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   231
            IOUtils.copyFile(icon, iconTarget);
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   232
        }
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   233
    }
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   234
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   235
    private void copyApplication() throws IOException {
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   236
        for (RelativeFileSet appResources :
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   237
                APP_RESOURCES_LIST.fetchFrom(params)) {
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   238
            if (appResources == null) {
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   239
                throw new RuntimeException("Null app resources?");
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   240
            }
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   241
            File srcdir = appResources.getBaseDirectory();
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   242
            for (String fname : appResources.getIncludedFiles()) {
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   243
                copyEntry(appDir, srcdir, fname);
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   244
            }
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   245
        }
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   246
    }
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   247
b0f09e7c4680 8213963: Flatten out jpackager packages and resources
herrick
parents:
diff changeset
   248
}