src/jdk.jpackage/linux/classes/jdk/jpackage/internal/LinuxPackageBundler.java
author herrick
Mon, 30 Sep 2019 19:33:13 -0400
branchJDK-8200758-branch
changeset 58417 67ffaf3a2b75
parent 58416 f09bf58c1f17
child 58434 b00cbf427368
permissions -rw-r--r--
8231280: Linux packages produced by jpackage should have correct dependencies Submitted-by: asemenyuk Reviewed-by: herrick
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
58301
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
     1
/*
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
     2
 * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
     4
 *
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
    10
 *
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
    15
 * accompanied this code).
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
    16
 *
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
    20
 *
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
    23
 * questions.
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
    24
 */
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
    25
package jdk.jpackage.internal;
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
    26
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
    27
import java.awt.image.BufferedImage;
58417
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
    28
import java.io.*;
58301
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
    29
import java.nio.file.Files;
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
    30
import java.nio.file.Path;
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
    31
import java.text.MessageFormat;
58417
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
    32
import java.util.*;
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
    33
import java.util.function.Predicate;
58301
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
    34
import java.util.stream.Collectors;
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
    35
import java.util.stream.Stream;
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
    36
import javax.imageio.ImageIO;
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
    37
import javax.xml.stream.XMLOutputFactory;
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
    38
import javax.xml.stream.XMLStreamException;
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
    39
import javax.xml.stream.XMLStreamWriter;
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
    40
import static jdk.jpackage.internal.LinuxAppBundler.LINUX_INSTALL_DIR;
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
    41
import static jdk.jpackage.internal.LinuxAppBundler.LINUX_PACKAGE_DEPENDENCIES;
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
    42
import static jdk.jpackage.internal.LinuxAppImageBuilder.DEFAULT_ICON;
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
    43
import static jdk.jpackage.internal.LinuxAppImageBuilder.ICON_PNG;
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
    44
import static jdk.jpackage.internal.StandardBundlerParam.*;
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
    45
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
    46
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
    47
abstract class LinuxPackageBundler extends AbstractBundler {
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
    48
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
    49
    private static final String DESKTOP_COMMANDS_INSTALL = "DESKTOP_COMMANDS_INSTALL";
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
    50
    private static final String DESKTOP_COMMANDS_UNINSTALL = "DESKTOP_COMMANDS_UNINSTALL";
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
    51
    private static final String UTILITY_SCRIPTS = "UTILITY_SCRIPTS";
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
    52
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
    53
    private static final BundlerParamInfo<LinuxAppBundler> APP_BUNDLER =
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
    54
        new StandardBundlerParam<>(
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
    55
                "linux.app.bundler",
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
    56
                LinuxAppBundler.class,
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
    57
                (params) -> new LinuxAppBundler(),
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
    58
                null
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
    59
        );
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
    60
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
    61
    private static final BundlerParamInfo<String> MENU_GROUP =
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
    62
        new StandardBundlerParam<>(
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
    63
                Arguments.CLIOptions.LINUX_MENU_GROUP.getId(),
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
    64
                String.class,
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
    65
                params -> I18N.getString("param.menu-group.default"),
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
    66
                (s, p) -> s
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
    67
        );
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
    68
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
    69
    private static final StandardBundlerParam<Boolean> SHORTCUT_HINT =
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
    70
        new StandardBundlerParam<>(
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
    71
                Arguments.CLIOptions.LINUX_SHORTCUT_HINT.getId(),
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
    72
                Boolean.class,
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
    73
                params -> false,
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
    74
                (s, p) -> (s == null || "null".equalsIgnoreCase(s))
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
    75
                        ? false : Boolean.valueOf(s)
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
    76
        );
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
    77
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
    78
    LinuxPackageBundler(BundlerParamInfo<String> packageName) {
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
    79
        this.packageName = packageName;
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
    80
    }
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
    81
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
    82
    private final BundlerParamInfo<String> packageName;
58417
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
    83
    private boolean withFindNeededPackages;
58301
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
    84
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
    85
    @Override
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
    86
    final public boolean validate(Map<String, ? super Object> params)
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
    87
            throws ConfigException {
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
    88
58417
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
    89
        // run basic validation to ensure requirements are met
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
    90
        // we are not interested in return code, only possible exception
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
    91
        APP_BUNDLER.fetchFrom(params).validate(params);
58301
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
    92
58417
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
    93
        validateFileAssociations(FILE_ASSOCIATIONS.fetchFrom(params));
58301
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
    94
58417
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
    95
        // If package name has some restrictions, the string converter will
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
    96
        // throw an exception if invalid
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
    97
        packageName.getStringConverter().apply(packageName.fetchFrom(params),
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
    98
            params);
58301
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
    99
58417
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   100
        for (var validator: getToolValidators(params)) {
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   101
            ConfigException ex = validator.validate();
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   102
            if (ex != null) {
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   103
                throw ex;
58301
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   104
            }
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   105
        }
58417
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   106
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   107
        withFindNeededPackages = LibProvidersLookup.supported();
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   108
        if (!withFindNeededPackages) {
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   109
            final String advice;
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   110
            if ("deb".equals(getID())) {
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   111
                advice = "message.deb-ldd-not-available.advice";
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   112
            } else {
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   113
                advice = "message.rpm-ldd-not-available.advice";
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   114
            }
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   115
            // Let user know package dependencies will not be generated.
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   116
            Log.error(String.format("%s\n%s", I18N.getString(
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   117
                    "message.ldd-not-available"), I18N.getString(advice)));
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   118
        }
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   119
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   120
        // Packaging specific validation
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   121
        doValidate(params);
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   122
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   123
        return true;
58301
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   124
    }
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   125
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   126
    @Override
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   127
    final public String getBundleType() {
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   128
        return "INSTALLER";
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   129
    }
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   130
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   131
    @Override
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   132
    final public File execute(Map<String, ? super Object> params,
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   133
            File outputParentDir) throws PackagerException {
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   134
        IOUtils.writableOutputDir(outputParentDir.toPath());
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   135
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   136
        PlatformPackage thePackage = createMetaPackage(params);
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   137
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   138
        try {
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   139
            File appImage = StandardBundlerParam.getPredefinedAppImage(params);
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   140
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   141
            // we either have an application image or need to build one
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   142
            if (appImage != null) {
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   143
                appImageLayout(params).resolveAt(appImage.toPath()).copy(
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   144
                        thePackage.sourceApplicationLayout());
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   145
            } else {
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   146
                appImage = APP_BUNDLER.fetchFrom(params).doBundle(params,
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   147
                        thePackage.sourceRoot().toFile(), true);
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   148
                ApplicationLayout srcAppLayout = appImageLayout(params).resolveAt(
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   149
                        appImage.toPath());
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   150
                if (appImage.equals(PREDEFINED_RUNTIME_IMAGE.fetchFrom(params))) {
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   151
                    // Application image points to run-time image.
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   152
                    // Copy it.
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   153
                    srcAppLayout.copy(thePackage.sourceApplicationLayout());
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   154
                } else {
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   155
                    // Application image is a newly created directory tree.
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   156
                    // Move it.
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   157
                    srcAppLayout.move(thePackage.sourceApplicationLayout());
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   158
                    if (appImage.exists()) {
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   159
                        // Empty app image directory might remain after all application
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   160
                        // directories have been moved.
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   161
                        appImage.delete();
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   162
                    }
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   163
                }
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   164
            }
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   165
58417
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   166
            if (!StandardBundlerParam.isRuntimeInstaller(params)) {
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   167
                desktopIntegration = new DesktopIntegration(thePackage, params);
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   168
            } else {
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   169
                desktopIntegration = null;
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   170
            }
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   171
58301
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   172
            Map<String, String> data = createDefaultReplacementData(params);
58417
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   173
            if (desktopIntegration != null) {
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   174
                data.putAll(desktopIntegration.create());
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   175
            } else {
58301
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   176
                Stream.of(DESKTOP_COMMANDS_INSTALL, DESKTOP_COMMANDS_UNINSTALL,
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   177
                        UTILITY_SCRIPTS).forEach(v -> data.put(v, ""));
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   178
            }
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   179
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   180
            data.putAll(createReplacementData(params));
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   181
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   182
            return buildPackageBundle(Collections.unmodifiableMap(data), params,
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   183
                    outputParentDir);
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   184
        } catch (IOException ex) {
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   185
            Log.verbose(ex);
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   186
            throw new PackagerException(ex);
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   187
        }
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   188
    }
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   189
58417
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   190
    private List<String> getListOfNeededPackages(
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   191
            Map<String, ? super Object> params) throws IOException {
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   192
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   193
        PlatformPackage thePackage = createMetaPackage(params);
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   194
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   195
        final List<String> xdgUtilsPackage;
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   196
        if (desktopIntegration != null) {
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   197
            xdgUtilsPackage = desktopIntegration.requiredPackages();
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   198
        } else {
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   199
            xdgUtilsPackage = Collections.emptyList();
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   200
        }
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   201
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   202
        final List<String> neededLibPackages;
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   203
        if (withFindNeededPackages) {
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   204
            LibProvidersLookup lookup = new LibProvidersLookup();
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   205
            initLibProvidersLookup(params, lookup);
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   206
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   207
            neededLibPackages = lookup.execute(thePackage.sourceRoot());
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   208
        } else {
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   209
            neededLibPackages = Collections.emptyList();
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   210
        }
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   211
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   212
        // Merge all package lists together.
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   213
        // Filter out empty names, sort and remove duplicates.
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   214
        List<String> result = Stream.of(xdgUtilsPackage, neededLibPackages).flatMap(
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   215
                List::stream).filter(Predicate.not(String::isEmpty)).sorted().distinct().collect(
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   216
                Collectors.toList());
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   217
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   218
        Log.verbose(String.format("Required packages: %s", result));
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   219
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   220
        return result;
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   221
    }
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   222
58301
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   223
    private Map<String, String> createDefaultReplacementData(
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   224
            Map<String, ? super Object> params) throws IOException {
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   225
        Map<String, String> data = new HashMap<>();
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   226
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   227
        data.put("APPLICATION_PACKAGE", createMetaPackage(params).name());
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   228
        data.put("APPLICATION_VENDOR", VENDOR.fetchFrom(params));
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   229
        data.put("APPLICATION_VERSION", VERSION.fetchFrom(params));
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   230
        data.put("APPLICATION_DESCRIPTION", DESCRIPTION.fetchFrom(params));
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   231
        data.put("APPLICATION_RELEASE", RELEASE.fetchFrom(params));
58417
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   232
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   233
        String defaultDeps = String.join(", ", getListOfNeededPackages(params));
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   234
        String customDeps = LINUX_PACKAGE_DEPENDENCIES.fetchFrom(params).strip();
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   235
        if (!customDeps.isEmpty() && !defaultDeps.isEmpty()) {
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   236
            customDeps = ", " + customDeps;
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   237
        }
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   238
        data.put("PACKAGE_DEFAULT_DEPENDENCIES", defaultDeps);
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   239
        data.put("PACKAGE_CUSTOM_DEPENDENCIES", customDeps);
58301
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   240
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   241
        return data;
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   242
    }
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   243
58417
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   244
    abstract protected void initLibProvidersLookup(
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   245
            Map<String, ? super Object> params,
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   246
            LibProvidersLookup libProvidersLookup);
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   247
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   248
    abstract protected List<ToolValidator> getToolValidators(
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   249
            Map<String, ? super Object> params);
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   250
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   251
    abstract protected void doValidate(Map<String, ? super Object> params)
58301
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   252
            throws ConfigException;
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   253
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   254
    abstract protected Map<String, String> createReplacementData(
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   255
            Map<String, ? super Object> params) throws IOException;
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   256
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   257
    abstract protected File buildPackageBundle(
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   258
            Map<String, String> replacementData,
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   259
            Map<String, ? super Object> params, File outputParentDir) throws
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   260
            PackagerException, IOException;
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   261
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   262
    final protected PlatformPackage createMetaPackage(
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   263
            Map<String, ? super Object> params) {
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   264
        return new PlatformPackage() {
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   265
            @Override
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   266
            public String name() {
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   267
                return packageName.fetchFrom(params);
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   268
            }
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   269
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   270
            @Override
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   271
            public Path sourceRoot() {
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   272
                return IMAGES_ROOT.fetchFrom(params).toPath().toAbsolutePath();
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   273
            }
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   274
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   275
            @Override
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   276
            public ApplicationLayout sourceApplicationLayout() {
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   277
                return appImageLayout(params).resolveAt(
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   278
                        applicationInstallDir(sourceRoot()));
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   279
            }
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   280
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   281
            @Override
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   282
            public ApplicationLayout installedApplicationLayout() {
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   283
                return appImageLayout(params).resolveAt(
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   284
                        applicationInstallDir(Path.of("/")));
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   285
            }
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   286
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   287
            private Path applicationInstallDir(Path root) {
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   288
                Path installDir = Path.of(LINUX_INSTALL_DIR.fetchFrom(params),
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   289
                        name());
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   290
                if (installDir.isAbsolute()) {
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   291
                    installDir = Path.of("." + installDir.toString()).normalize();
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   292
                }
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   293
                return root.resolve(installDir);
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   294
            }
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   295
        };
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   296
    }
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   297
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   298
    private ApplicationLayout appImageLayout(
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   299
            Map<String, ? super Object> params) {
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   300
        if (StandardBundlerParam.isRuntimeInstaller(params)) {
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   301
            return ApplicationLayout.javaRuntime();
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   302
        }
58416
f09bf58c1f17 8231605: Improve test helpers
herrick
parents: 58302
diff changeset
   303
        return ApplicationLayout.linuxAppImage();
58301
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   304
    }
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   305
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   306
    private static void validateFileAssociations(
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   307
            List<Map<String, ? super Object>> associations) throws
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   308
            ConfigException {
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   309
        // only one mime type per association, at least one file extention
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   310
        int assocIdx = 0;
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   311
        for (var assoc : associations) {
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   312
            ++assocIdx;
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   313
            List<String> mimes = FA_CONTENT_TYPE.fetchFrom(assoc);
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   314
            if (mimes == null || mimes.isEmpty()) {
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   315
                String msgKey = "error.no-content-types-for-file-association";
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   316
                throw new ConfigException(
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   317
                        MessageFormat.format(I18N.getString(msgKey), assocIdx),
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   318
                        I18N.getString(msgKey + ".advise"));
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   319
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   320
            }
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   321
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   322
            if (mimes.size() > 1) {
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   323
                String msgKey = "error.too-many-content-types-for-file-association";
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   324
                throw new ConfigException(
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   325
                        MessageFormat.format(I18N.getString(msgKey), assocIdx),
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   326
                        I18N.getString(msgKey + ".advise"));
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   327
            }
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   328
        }
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   329
    }
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   330
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   331
    /**
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   332
     * Helper to create files for desktop integration.
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   333
     */
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   334
    private class DesktopIntegration {
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   335
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   336
        DesktopIntegration(PlatformPackage thePackage,
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   337
                Map<String, ? super Object> params) {
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   338
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   339
            associations = FILE_ASSOCIATIONS.fetchFrom(params).stream().filter(
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   340
                    a -> {
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   341
                        if (a == null) {
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   342
                            return false;
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   343
                        }
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   344
                        List<String> mimes = FA_CONTENT_TYPE.fetchFrom(a);
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   345
                        return (mimes != null && !mimes.isEmpty());
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   346
                    }).collect(Collectors.toUnmodifiableList());
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   347
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   348
            launchers = ADD_LAUNCHERS.fetchFrom(params);
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   349
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   350
            this.thePackage = thePackage;
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   351
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   352
            customIconFile = ICON_PNG.fetchFrom(params);
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   353
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   354
            verbose = VERBOSE.fetchFrom(params);
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   355
            resourceDir = RESOURCE_DIR.fetchFrom(params);
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   356
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   357
            // XDG recommends to use vendor prefix in desktop file names as xdg
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   358
            // commands copy files to system directories.
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   359
            // Package name should be a good prefix.
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   360
            final String desktopFileName = String.format("%s-%s.desktop",
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   361
                        thePackage.name(), APP_NAME.fetchFrom(params));
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   362
            final String mimeInfoFileName = String.format("%s-%s-MimeInfo.xml",
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   363
                        thePackage.name(), APP_NAME.fetchFrom(params));
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   364
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   365
            mimeInfoFile = new DesktopFile(mimeInfoFileName);
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   366
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   367
            if (!associations.isEmpty() || SHORTCUT_HINT.fetchFrom(params) || customIconFile != null) {
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   368
                //
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   369
                // Create primary .desktop file if one of conditions is met:
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   370
                // - there are file associations configured
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   371
                // - user explicitely requested to create a shortcut
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   372
                // - custom icon specified
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   373
                //
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   374
                desktopFile = new DesktopFile(desktopFileName);
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   375
                iconFile = new DesktopFile(String.format("%s.png",
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   376
                        APP_NAME.fetchFrom(params)));
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   377
            } else {
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   378
                desktopFile = null;
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   379
                iconFile = null;
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   380
            }
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   381
58417
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   382
            desktopFileData = Collections.unmodifiableMap(
58301
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   383
                    createDataForDesktopFile(params));
58417
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   384
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   385
            nestedIntegrations = launchers.stream().map(
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   386
                    launcherParams -> new DesktopIntegration(thePackage,
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   387
                            launcherParams)).collect(Collectors.toList());
58301
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   388
        }
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   389
58417
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   390
        List<String> requiredPackages() {
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   391
            return Stream.of(List.of(this), nestedIntegrations).flatMap(
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   392
                    List::stream).map(DesktopIntegration::requiredPackagesSelf).flatMap(
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   393
                    List::stream).distinct().collect(Collectors.toList());
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   394
        }
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   395
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   396
        Map<String, String> create() throws IOException {
58301
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   397
            if (iconFile != null) {
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   398
                // Create application icon file.
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   399
                prepareSrcIconFile();
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   400
            }
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   401
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   402
            Map<String, String> data = new HashMap<>(desktopFileData);
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   403
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   404
            final ShellCommands shellCommands;
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   405
            if (desktopFile != null) {
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   406
                // Create application desktop description file.
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   407
                createDesktopFile(data);
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   408
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   409
                // Shell commands will be created only if desktop file
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   410
                // should be installed.
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   411
                shellCommands = new ShellCommands();
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   412
            } else {
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   413
                shellCommands = null;
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   414
            }
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   415
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   416
            if (!associations.isEmpty()) {
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   417
                // Create XML file with mime types corresponding to file associations.
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   418
                createFileAssociationsMimeInfoFile();
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   419
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   420
                shellCommands.setFileAssociations();
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   421
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   422
                // Create icon files corresponding to file associations
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   423
                Map<String, Path> mimeTypeWithIconFile = createFileAssociationIconFiles();
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   424
                mimeTypeWithIconFile.forEach((k, v) -> {
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   425
                    shellCommands.addIcon(k, v);
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   426
                });
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   427
            }
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   428
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   429
            // Create shell commands to install/uninstall integration with desktop of the app.
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   430
            if (shellCommands != null) {
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   431
                shellCommands.applyTo(data);
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   432
            }
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   433
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   434
            boolean needCleanupScripts = !associations.isEmpty();
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   435
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   436
            // Take care of additional launchers if there are any.
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   437
            // Process every additional launcher as the main application launcher.
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   438
            // Collect shell commands to install/uninstall integration with desktop
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   439
            // of the additional launchers and append them to the corresponding
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   440
            // commands of the main launcher.
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   441
            List<String> installShellCmds = new ArrayList<>(Arrays.asList(
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   442
                    data.get(DESKTOP_COMMANDS_INSTALL)));
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   443
            List<String> uninstallShellCmds = new ArrayList<>(Arrays.asList(
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   444
                    data.get(DESKTOP_COMMANDS_UNINSTALL)));
58417
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   445
            for (var integration: nestedIntegrations) {
58301
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   446
                if (!integration.associations.isEmpty()) {
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   447
                    needCleanupScripts = true;
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   448
                }
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   449
58417
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   450
                Map<String, String> launcherData = integration.create();
58301
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   451
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   452
                installShellCmds.add(launcherData.get(DESKTOP_COMMANDS_INSTALL));
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   453
                uninstallShellCmds.add(launcherData.get(
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   454
                        DESKTOP_COMMANDS_UNINSTALL));
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   455
            }
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   456
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   457
            data.put(DESKTOP_COMMANDS_INSTALL, stringifyShellCommands(
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   458
                    installShellCmds));
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   459
            data.put(DESKTOP_COMMANDS_UNINSTALL, stringifyShellCommands(
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   460
                    uninstallShellCmds));
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   461
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   462
            if (needCleanupScripts) {
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   463
                // Pull in utils.sh scrips library.
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   464
                try (InputStream is = getResourceAsStream("utils.sh");
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   465
                        InputStreamReader isr = new InputStreamReader(is);
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   466
                        BufferedReader reader = new BufferedReader(isr)) {
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   467
                    data.put(UTILITY_SCRIPTS, reader.lines().collect(
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   468
                            Collectors.joining(System.lineSeparator())));
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   469
                }
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   470
            } else {
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   471
                data.put(UTILITY_SCRIPTS, "");
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   472
            }
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   473
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   474
            return data;
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   475
        }
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   476
58417
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   477
        private List<String> requiredPackagesSelf() {
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   478
            if (desktopFile != null) {
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   479
                return List.of("xdg-utils");
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   480
            }
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   481
            return Collections.emptyList();
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   482
        }
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   483
58301
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   484
        private Map<String, String> createDataForDesktopFile(
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   485
                Map<String, ? super Object> params) {
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   486
            Map<String, String> data = new HashMap<>();
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   487
            data.put("APPLICATION_NAME", APP_NAME.fetchFrom(params));
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   488
            data.put("APPLICATION_DESCRIPTION", DESCRIPTION.fetchFrom(params));
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   489
            data.put("APPLICATION_ICON",
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   490
                    iconFile != null ? iconFile.installPath().toString() : null);
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   491
            data.put("DEPLOY_BUNDLE_CATEGORY", MENU_GROUP.fetchFrom(params));
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   492
            data.put("APPLICATION_LAUNCHER",
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   493
                    thePackage.installedApplicationLayout().launchersDirectory().resolve(
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   494
                            LinuxAppImageBuilder.getLauncherName(params)).toString());
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   495
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   496
            return data;
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   497
        }
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   498
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   499
        /**
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   500
         * Shell commands to integrate something with desktop.
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   501
         */
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   502
        private class ShellCommands {
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   503
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   504
            ShellCommands() {
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   505
                registerIconCmds = new ArrayList<>();
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   506
                unregisterIconCmds = new ArrayList<>();
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   507
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   508
                registerDesktopFileCmd = String.join(" ", "xdg-desktop-menu",
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   509
                        "install", desktopFile.installPath().toString());
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   510
                unregisterDesktopFileCmd = String.join(" ", "xdg-desktop-menu",
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   511
                        "uninstall", desktopFile.installPath().toString());
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   512
            }
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   513
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   514
            void setFileAssociations() {
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   515
                registerFileAssociationsCmd = String.join(" ", "xdg-mime",
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   516
                        "install",
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   517
                        mimeInfoFile.installPath().toString());
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   518
                unregisterFileAssociationsCmd = String.join(" ", "xdg-mime",
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   519
                        "uninstall", mimeInfoFile.installPath().toString());
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   520
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   521
                //
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   522
                // Add manual cleanup of system files to get rid of
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   523
                // the default mime type handlers.
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   524
                //
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   525
                // Even after mime type is unregisterd with `xdg-mime uninstall`
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   526
                // command and desktop file deleted with `xdg-desktop-menu uninstall`
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   527
                // command, records in
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   528
                // `/usr/share/applications/defaults.list` (Ubuntu 16) or
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   529
                // `/usr/local/share/applications/defaults.list` (OracleLinux 7)
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   530
                // files remain referencing deleted mime time and deleted
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   531
                // desktop file which makes `xdg-mime query default` output name
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   532
                // of non-existing desktop file.
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   533
                //
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   534
                String cleanUpCommand = String.join(" ",
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   535
                        "uninstall_default_mime_handler",
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   536
                        desktopFile.installPath().getFileName().toString(),
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   537
                        String.join(" ", getMimeTypeNamesFromFileAssociations()));
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   538
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   539
                unregisterFileAssociationsCmd = stringifyShellCommands(
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   540
                        unregisterFileAssociationsCmd, cleanUpCommand);
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   541
            }
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   542
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   543
            void addIcon(String mimeType, Path iconFile) {
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   544
                final int imgSize = getSquareSizeOfImage(iconFile.toFile());
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   545
                final String dashMime = mimeType.replace('/', '-');
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   546
                registerIconCmds.add(String.join(" ", "xdg-icon-resource",
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   547
                        "install", "--context", "mimetypes", "--size ",
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   548
                        Integer.toString(imgSize), iconFile.toString(), dashMime));
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   549
                unregisterIconCmds.add(String.join(" ", "xdg-icon-resource",
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   550
                        "uninstall", dashMime));
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   551
            }
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   552
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   553
            void applyTo(Map<String, String> data) {
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   554
                List<String> cmds = new ArrayList<>();
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   555
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   556
                cmds.add(registerDesktopFileCmd);
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   557
                cmds.add(registerFileAssociationsCmd);
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   558
                cmds.addAll(registerIconCmds);
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   559
                data.put(DESKTOP_COMMANDS_INSTALL, stringifyShellCommands(cmds));
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   560
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   561
                cmds.clear();
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   562
                cmds.add(unregisterDesktopFileCmd);
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   563
                cmds.add(unregisterFileAssociationsCmd);
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   564
                cmds.addAll(unregisterIconCmds);
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   565
                data.put(DESKTOP_COMMANDS_UNINSTALL, stringifyShellCommands(cmds));
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   566
            }
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   567
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   568
            private String registerDesktopFileCmd;
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   569
            private String unregisterDesktopFileCmd;
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   570
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   571
            private String registerFileAssociationsCmd;
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   572
            private String unregisterFileAssociationsCmd;
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   573
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   574
            private List<String> registerIconCmds;
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   575
            private List<String> unregisterIconCmds;
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   576
        }
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   577
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   578
        private final PlatformPackage thePackage;
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   579
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   580
        private final List<Map<String, ? super Object>> associations;
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   581
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   582
        private final List<Map<String, ? super Object>> launchers;
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   583
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   584
        /**
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   585
         * Desktop integration file. xml, icon, etc.
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   586
         * Resides somewhere in application installation tree.
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   587
         * Has two paths:
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   588
         *  - path where it should be placed at package build time;
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   589
         *  - path where it should be installed by package manager;
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   590
         */
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   591
        private class DesktopFile {
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   592
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   593
            DesktopFile(String fileName) {
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   594
                installPath = thePackage
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   595
                        .installedApplicationLayout()
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   596
                        .destktopIntegrationDirectory().resolve(fileName);
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   597
                srcPath = thePackage
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   598
                        .sourceApplicationLayout()
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   599
                        .destktopIntegrationDirectory().resolve(fileName);
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   600
            }
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   601
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   602
            private final Path installPath;
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   603
            private final Path srcPath;
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   604
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   605
            Path installPath() {
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   606
                return installPath;
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   607
            }
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   608
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   609
            Path srcPath() {
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   610
                return srcPath;
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   611
            }
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   612
        }
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   613
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   614
        private final boolean verbose;
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   615
        private final File resourceDir;
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   616
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   617
        private final DesktopFile mimeInfoFile;
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   618
        private final DesktopFile desktopFile;
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   619
        private final DesktopFile iconFile;
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   620
58417
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   621
        final private List<DesktopIntegration> nestedIntegrations;
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   622
58301
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   623
        private final Map<String, String> desktopFileData;
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   624
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   625
        /**
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   626
         * Path to icon file provided by user or null.
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   627
         */
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   628
        private final File customIconFile;
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   629
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   630
        private void appendFileAssociation(XMLStreamWriter xml,
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   631
                Map<String, ? super Object> assoc) throws XMLStreamException {
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   632
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   633
            xml.writeStartElement("mime-type");
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   634
            final String thisMime = FA_CONTENT_TYPE.fetchFrom(assoc).get(0);
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   635
            xml.writeAttribute("type", thisMime);
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   636
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   637
            final String description = FA_DESCRIPTION.fetchFrom(assoc);
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   638
            if (description != null && !description.isEmpty()) {
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   639
                xml.writeStartElement("comment");
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   640
                xml.writeCharacters(description);
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   641
                xml.writeEndElement();
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   642
            }
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   643
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   644
            final List<String> extensions = FA_EXTENSIONS.fetchFrom(assoc);
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   645
            if (extensions == null) {
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   646
                Log.error(I18N.getString(
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   647
                        "message.creating-association-with-null-extension"));
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   648
            } else {
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   649
                for (String ext : extensions) {
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   650
                    xml.writeStartElement("glob");
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   651
                    xml.writeAttribute("pattern", "*." + ext);
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   652
                    xml.writeEndElement();
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   653
                }
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   654
            }
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   655
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   656
            xml.writeEndElement();
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   657
        }
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   658
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   659
        private void createFileAssociationsMimeInfoFile() throws IOException {
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   660
            XMLOutputFactory xmlFactory = XMLOutputFactory.newInstance();
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   661
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   662
            try (Writer w = new BufferedWriter(new FileWriter(
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   663
                    mimeInfoFile.srcPath().toFile()))) {
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   664
                XMLStreamWriter xml = xmlFactory.createXMLStreamWriter(w);
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   665
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   666
                xml.writeStartDocument();
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   667
                xml.writeStartElement("mime-info");
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   668
                xml.writeNamespace("xmlns",
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   669
                        "http://www.freedesktop.org/standards/shared-mime-info");
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   670
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   671
                for (var assoc : associations) {
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   672
                    appendFileAssociation(xml, assoc);
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   673
                }
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   674
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   675
                xml.writeEndElement();
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   676
                xml.writeEndDocument();
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   677
                xml.flush();
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   678
                xml.close();
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   679
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   680
            } catch (XMLStreamException ex) {
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   681
                Log.verbose(ex);
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   682
                throw new IOException(ex);
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   683
            }
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   684
        }
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   685
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   686
        private Map<String, Path> createFileAssociationIconFiles() throws
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   687
                IOException {
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   688
            Map<String, Path> mimeTypeWithIconFile = new HashMap<>();
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   689
            for (var assoc : associations) {
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   690
                File customFaIcon = FA_ICON.fetchFrom(assoc);
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   691
                if (customFaIcon == null || !customFaIcon.exists() || getSquareSizeOfImage(
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   692
                        customFaIcon) == 0) {
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   693
                    continue;
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   694
                }
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   695
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   696
                String fname = iconFile.srcPath().getFileName().toString();
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   697
                if (fname.indexOf(".") > 0) {
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   698
                    fname = fname.substring(0, fname.lastIndexOf("."));
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   699
                }
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   700
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   701
                DesktopFile faIconFile = new DesktopFile(
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   702
                        fname + "_fa_" + customFaIcon.getName());
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   703
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   704
                IOUtils.copyFile(customFaIcon, faIconFile.srcPath().toFile());
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   705
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   706
                mimeTypeWithIconFile.put(FA_CONTENT_TYPE.fetchFrom(assoc).get(0),
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   707
                        faIconFile.installPath());
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   708
            }
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   709
            return mimeTypeWithIconFile;
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   710
        }
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   711
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   712
        private void createDesktopFile(Map<String, String> data) throws IOException {
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   713
            List<String> mimeTypes = getMimeTypeNamesFromFileAssociations();
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   714
            data.put("DESKTOP_MIMES", "MimeType=" + String.join(";", mimeTypes));
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   715
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   716
            // prepare desktop shortcut
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   717
            try (Writer w = Files.newBufferedWriter(desktopFile.srcPath())) {
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   718
                String content = preprocessTextResource(
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   719
                        desktopFile.srcPath().getFileName().toString(),
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   720
                        I18N.getString("resource.menu-shortcut-descriptor"),
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   721
                        "template.desktop",
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   722
                        data,
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   723
                        verbose,
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   724
                        resourceDir);
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   725
                w.write(content);
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   726
            }
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   727
        }
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   728
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   729
        private void prepareSrcIconFile() throws IOException {
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   730
            if (customIconFile == null || !customIconFile.exists()) {
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   731
                fetchResource(iconFile.srcPath().getFileName().toString(),
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   732
                        I18N.getString("resource.menu-icon"),
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   733
                        DEFAULT_ICON,
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   734
                        iconFile.srcPath().toFile(),
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   735
                        verbose,
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   736
                        resourceDir);
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   737
            } else {
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   738
                fetchResource(iconFile.srcPath().getFileName().toString(),
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   739
                        I18N.getString("resource.menu-icon"),
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   740
                        customIconFile,
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   741
                        iconFile.srcPath().toFile(),
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   742
                        verbose,
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   743
                        resourceDir);
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   744
            }
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   745
        }
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   746
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   747
        private List<String> getMimeTypeNamesFromFileAssociations() {
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   748
            return associations.stream().map(
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   749
                    a -> FA_CONTENT_TYPE.fetchFrom(a).get(0)).collect(
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   750
                            Collectors.toUnmodifiableList());
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   751
        }
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   752
    }
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   753
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   754
    private static int getSquareSizeOfImage(File f) {
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   755
        try {
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   756
            BufferedImage bi = ImageIO.read(f);
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   757
            if (bi.getWidth() == bi.getHeight()) {
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   758
                return bi.getWidth();
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   759
            }
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   760
        } catch (IOException e) {
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   761
            Log.verbose(e);
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   762
        }
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   763
        return 0;
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   764
    }
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   765
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   766
    private static String stringifyShellCommands(String ... commands) {
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   767
        return stringifyShellCommands(Arrays.asList(commands));
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   768
    }
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   769
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   770
    private static String stringifyShellCommands(List<String> commands) {
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   771
        return String.join(System.lineSeparator(), commands.stream().filter(
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   772
                s -> s != null && !s.isEmpty()).collect(Collectors.toList()));
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   773
    }
58417
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   774
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   775
    private DesktopIntegration desktopIntegration;
58301
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   776
}