src/jdk.jpackage/linux/classes/jdk/jpackage/internal/LinuxPackageBundler.java
author herrick
Wed, 23 Oct 2019 10:37:54 -0400
branchJDK-8200758-branch
changeset 58762 0fe62353385b
parent 58647 2c43b89b1679
child 58791 fca9cb5f4953
permissions -rw-r--r--
8232281: jpackage is not always reporting an error when no main class specified Reviewed-by: asemenyuk, asemenuk
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
58417
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
    27
import java.io.*;
58435
788704ff2559 fix bad merge
herrick
parents: 58434
diff changeset
    28
import java.nio.file.InvalidPathException;
58301
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
    29
import java.nio.file.Path;
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
    30
import java.text.MessageFormat;
58417
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
    31
import java.util.*;
58762
0fe62353385b 8232281: jpackage is not always reporting an error when no main class specified
herrick
parents: 58647
diff changeset
    32
import java.util.function.Function;
58417
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;
58647
2c43b89b1679 8231862: Decouple DesktopIntegration and LinuxPackageBundler classes
herrick
parents: 58607
diff changeset
    36
import static jdk.jpackage.internal.DesktopIntegration.*;
58301
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
    37
import static jdk.jpackage.internal.LinuxAppBundler.LINUX_INSTALL_DIR;
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
    38
import static jdk.jpackage.internal.LinuxAppBundler.LINUX_PACKAGE_DEPENDENCIES;
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
    39
import static jdk.jpackage.internal.StandardBundlerParam.*;
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
    40
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
    41
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
    42
abstract class LinuxPackageBundler extends AbstractBundler {
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
    43
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
    44
    LinuxPackageBundler(BundlerParamInfo<String> packageName) {
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
    45
        this.packageName = packageName;
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
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
    48
    @Override
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
    49
    final public boolean validate(Map<String, ? super Object> params)
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
    50
            throws ConfigException {
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
    51
58417
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
    52
        // run basic validation to ensure requirements are met
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
    53
        // 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
    54
        APP_BUNDLER.fetchFrom(params).validate(params);
58301
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
    55
58434
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58417
diff changeset
    56
        validateInstallDir(LINUX_INSTALL_DIR.fetchFrom(params));
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58417
diff changeset
    57
58417
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
    58
        validateFileAssociations(FILE_ASSOCIATIONS.fetchFrom(params));
58301
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
    59
58417
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
    60
        // 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
    61
        // throw an exception if invalid
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
    62
        packageName.getStringConverter().apply(packageName.fetchFrom(params),
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
    63
            params);
58301
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
    64
58417
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
    65
        for (var validator: getToolValidators(params)) {
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
    66
            ConfigException ex = validator.validate();
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
    67
            if (ex != null) {
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
    68
                throw ex;
58301
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
    69
            }
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
    70
        }
58417
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
    71
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
    72
        withFindNeededPackages = LibProvidersLookup.supported();
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
    73
        if (!withFindNeededPackages) {
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
    74
            final String advice;
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
    75
            if ("deb".equals(getID())) {
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
    76
                advice = "message.deb-ldd-not-available.advice";
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
    77
            } else {
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
    78
                advice = "message.rpm-ldd-not-available.advice";
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
    79
            }
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
    80
            // 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
    81
            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
    82
                    "message.ldd-not-available"), I18N.getString(advice)));
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
    83
        }
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
    84
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
    85
        // Packaging specific validation
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
    86
        doValidate(params);
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
    87
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
    88
        return true;
58301
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
    89
    }
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
    90
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
    91
    @Override
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
    92
    final public String getBundleType() {
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
    93
        return "INSTALLER";
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
    94
    }
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
    95
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
    96
    @Override
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
    97
    final public File execute(Map<String, ? super Object> params,
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
    98
            File outputParentDir) throws PackagerException {
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
    99
        IOUtils.writableOutputDir(outputParentDir.toPath());
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   100
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   101
        PlatformPackage thePackage = createMetaPackage(params);
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   102
58762
0fe62353385b 8232281: jpackage is not always reporting an error when no main class specified
herrick
parents: 58647
diff changeset
   103
        Function<File, ApplicationLayout> initAppImageLayout = imageRoot -> {
0fe62353385b 8232281: jpackage is not always reporting an error when no main class specified
herrick
parents: 58647
diff changeset
   104
            ApplicationLayout layout = appImageLayout(params);
0fe62353385b 8232281: jpackage is not always reporting an error when no main class specified
herrick
parents: 58647
diff changeset
   105
            layout.pathGroup().setPath(new Object(),
0fe62353385b 8232281: jpackage is not always reporting an error when no main class specified
herrick
parents: 58647
diff changeset
   106
                    AppImageFile.getPathInAppImage(Path.of("")));
0fe62353385b 8232281: jpackage is not always reporting an error when no main class specified
herrick
parents: 58647
diff changeset
   107
            return layout.resolveAt(imageRoot.toPath());
0fe62353385b 8232281: jpackage is not always reporting an error when no main class specified
herrick
parents: 58647
diff changeset
   108
        };
0fe62353385b 8232281: jpackage is not always reporting an error when no main class specified
herrick
parents: 58647
diff changeset
   109
58301
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   110
        try {
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   111
            File appImage = StandardBundlerParam.getPredefinedAppImage(params);
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   112
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   113
            // we either have an application image or need to build one
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   114
            if (appImage != null) {
58762
0fe62353385b 8232281: jpackage is not always reporting an error when no main class specified
herrick
parents: 58647
diff changeset
   115
                initAppImageLayout.apply(appImage).copy(
58301
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   116
                        thePackage.sourceApplicationLayout());
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   117
            } else {
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   118
                appImage = APP_BUNDLER.fetchFrom(params).doBundle(params,
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   119
                        thePackage.sourceRoot().toFile(), true);
58762
0fe62353385b 8232281: jpackage is not always reporting an error when no main class specified
herrick
parents: 58647
diff changeset
   120
                ApplicationLayout srcAppLayout = initAppImageLayout.apply(
0fe62353385b 8232281: jpackage is not always reporting an error when no main class specified
herrick
parents: 58647
diff changeset
   121
                        appImage);
58301
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   122
                if (appImage.equals(PREDEFINED_RUNTIME_IMAGE.fetchFrom(params))) {
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   123
                    // Application image points to run-time image.
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   124
                    // Copy it.
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   125
                    srcAppLayout.copy(thePackage.sourceApplicationLayout());
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   126
                } else {
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   127
                    // Application image is a newly created directory tree.
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   128
                    // Move it.
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   129
                    srcAppLayout.move(thePackage.sourceApplicationLayout());
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   130
                    if (appImage.exists()) {
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   131
                        // Empty app image directory might remain after all application
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   132
                        // directories have been moved.
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   133
                        appImage.delete();
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   134
                    }
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
            }
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   137
58417
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   138
            if (!StandardBundlerParam.isRuntimeInstaller(params)) {
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   139
                desktopIntegration = new DesktopIntegration(thePackage, params);
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   140
            } else {
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   141
                desktopIntegration = null;
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   142
            }
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   143
58301
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   144
            Map<String, String> data = createDefaultReplacementData(params);
58417
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   145
            if (desktopIntegration != null) {
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   146
                data.putAll(desktopIntegration.create());
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   147
            } else {
58301
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   148
                Stream.of(DESKTOP_COMMANDS_INSTALL, DESKTOP_COMMANDS_UNINSTALL,
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   149
                        UTILITY_SCRIPTS).forEach(v -> data.put(v, ""));
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   150
            }
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   151
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   152
            data.putAll(createReplacementData(params));
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   153
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   154
            return buildPackageBundle(Collections.unmodifiableMap(data), params,
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   155
                    outputParentDir);
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   156
        } catch (IOException ex) {
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   157
            Log.verbose(ex);
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   158
            throw new PackagerException(ex);
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   159
        }
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   160
    }
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   161
58417
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   162
    private List<String> getListOfNeededPackages(
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   163
            Map<String, ? super Object> params) throws IOException {
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   164
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   165
        PlatformPackage thePackage = createMetaPackage(params);
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   166
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   167
        final List<String> xdgUtilsPackage;
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   168
        if (desktopIntegration != null) {
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   169
            xdgUtilsPackage = desktopIntegration.requiredPackages();
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   170
        } else {
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   171
            xdgUtilsPackage = Collections.emptyList();
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   172
        }
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   173
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   174
        final List<String> neededLibPackages;
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   175
        if (withFindNeededPackages) {
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   176
            LibProvidersLookup lookup = new LibProvidersLookup();
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   177
            initLibProvidersLookup(params, lookup);
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   178
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   179
            neededLibPackages = lookup.execute(thePackage.sourceRoot());
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   180
        } else {
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   181
            neededLibPackages = Collections.emptyList();
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   182
        }
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   183
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   184
        // Merge all package lists together.
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   185
        // Filter out empty names, sort and remove duplicates.
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   186
        List<String> result = Stream.of(xdgUtilsPackage, neededLibPackages).flatMap(
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   187
                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
   188
                Collectors.toList());
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   189
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   190
        Log.verbose(String.format("Required packages: %s", result));
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   191
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   192
        return result;
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   193
    }
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   194
58301
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   195
    private Map<String, String> createDefaultReplacementData(
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   196
            Map<String, ? super Object> params) throws IOException {
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   197
        Map<String, String> data = new HashMap<>();
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   198
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   199
        data.put("APPLICATION_PACKAGE", createMetaPackage(params).name());
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   200
        data.put("APPLICATION_VENDOR", VENDOR.fetchFrom(params));
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   201
        data.put("APPLICATION_VERSION", VERSION.fetchFrom(params));
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   202
        data.put("APPLICATION_DESCRIPTION", DESCRIPTION.fetchFrom(params));
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   203
        data.put("APPLICATION_RELEASE", RELEASE.fetchFrom(params));
58417
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   204
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   205
        String defaultDeps = String.join(", ", getListOfNeededPackages(params));
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   206
        String customDeps = LINUX_PACKAGE_DEPENDENCIES.fetchFrom(params).strip();
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   207
        if (!customDeps.isEmpty() && !defaultDeps.isEmpty()) {
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   208
            customDeps = ", " + customDeps;
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   209
        }
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   210
        data.put("PACKAGE_DEFAULT_DEPENDENCIES", defaultDeps);
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   211
        data.put("PACKAGE_CUSTOM_DEPENDENCIES", customDeps);
58301
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   212
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   213
        return data;
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   214
    }
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   215
58417
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   216
    abstract protected void initLibProvidersLookup(
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   217
            Map<String, ? super Object> params,
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   218
            LibProvidersLookup libProvidersLookup);
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
    abstract protected List<ToolValidator> getToolValidators(
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   221
            Map<String, ? super Object> params);
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   222
67ffaf3a2b75 8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents: 58416
diff changeset
   223
    abstract protected void doValidate(Map<String, ? super Object> params)
58301
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   224
            throws ConfigException;
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   225
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   226
    abstract protected Map<String, String> createReplacementData(
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   227
            Map<String, ? super Object> params) throws IOException;
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   228
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   229
    abstract protected File buildPackageBundle(
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   230
            Map<String, String> replacementData,
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   231
            Map<String, ? super Object> params, File outputParentDir) throws
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   232
            PackagerException, IOException;
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   233
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   234
    final protected PlatformPackage createMetaPackage(
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   235
            Map<String, ? super Object> params) {
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   236
        return new PlatformPackage() {
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   237
            @Override
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   238
            public String name() {
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   239
                return packageName.fetchFrom(params);
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
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   242
            @Override
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   243
            public Path sourceRoot() {
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   244
                return IMAGES_ROOT.fetchFrom(params).toPath().toAbsolutePath();
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   245
            }
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   246
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   247
            @Override
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   248
            public ApplicationLayout sourceApplicationLayout() {
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   249
                return appImageLayout(params).resolveAt(
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   250
                        applicationInstallDir(sourceRoot()));
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   251
            }
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   252
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   253
            @Override
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   254
            public ApplicationLayout installedApplicationLayout() {
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   255
                return appImageLayout(params).resolveAt(
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   256
                        applicationInstallDir(Path.of("/")));
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   257
            }
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   258
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   259
            private Path applicationInstallDir(Path root) {
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   260
                Path installDir = Path.of(LINUX_INSTALL_DIR.fetchFrom(params),
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   261
                        name());
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   262
                if (installDir.isAbsolute()) {
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   263
                    installDir = Path.of("." + installDir.toString()).normalize();
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   264
                }
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   265
                return root.resolve(installDir);
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   266
            }
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   267
        };
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
    private ApplicationLayout appImageLayout(
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   271
            Map<String, ? super Object> params) {
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   272
        if (StandardBundlerParam.isRuntimeInstaller(params)) {
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   273
            return ApplicationLayout.javaRuntime();
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   274
        }
58416
f09bf58c1f17 8231605: Improve test helpers
herrick
parents: 58302
diff changeset
   275
        return ApplicationLayout.linuxAppImage();
58301
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   276
    }
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   277
58434
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58417
diff changeset
   278
    private static void validateInstallDir(String installDir) throws
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58417
diff changeset
   279
            ConfigException {
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58417
diff changeset
   280
        if (installDir.startsWith("/usr/") || installDir.equals("/usr")) {
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58417
diff changeset
   281
            throw new ConfigException(MessageFormat.format(I18N.getString(
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58417
diff changeset
   282
                    "error.unsupported-install-dir"), installDir), null);
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58417
diff changeset
   283
        }
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58417
diff changeset
   284
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58417
diff changeset
   285
        if (installDir.isEmpty()) {
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58417
diff changeset
   286
            throw new ConfigException(MessageFormat.format(I18N.getString(
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58417
diff changeset
   287
                    "error.invalid-install-dir"), "/"), null);
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58417
diff changeset
   288
        }
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58417
diff changeset
   289
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58417
diff changeset
   290
        boolean valid = false;
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58417
diff changeset
   291
        try {
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58417
diff changeset
   292
            final Path installDirPath = Path.of(installDir);
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58417
diff changeset
   293
            valid = installDirPath.isAbsolute();
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58417
diff changeset
   294
            if (valid && !installDirPath.normalize().toString().equals(
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58417
diff changeset
   295
                    installDirPath.toString())) {
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58417
diff changeset
   296
                // Don't allow '/opt/foo/..' or /opt/.
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58417
diff changeset
   297
                valid = false;
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58417
diff changeset
   298
            }
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58417
diff changeset
   299
        } catch (InvalidPathException ex) {
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58417
diff changeset
   300
        }
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58417
diff changeset
   301
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58417
diff changeset
   302
        if (!valid) {
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58417
diff changeset
   303
            throw new ConfigException(MessageFormat.format(I18N.getString(
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58417
diff changeset
   304
                    "error.invalid-install-dir"), installDir), null);
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58417
diff changeset
   305
        }
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58417
diff changeset
   306
    }
b00cbf427368 8231721 : jpackage --install-dir should reject system dirs on Linux
herrick
parents: 58417
diff changeset
   307
58301
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   308
    private static void validateFileAssociations(
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   309
            List<Map<String, ? super Object>> associations) throws
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   310
            ConfigException {
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   311
        // only one mime type per association, at least one file extention
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   312
        int assocIdx = 0;
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   313
        for (var assoc : associations) {
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   314
            ++assocIdx;
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   315
            List<String> mimes = FA_CONTENT_TYPE.fetchFrom(assoc);
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   316
            if (mimes == null || mimes.isEmpty()) {
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   317
                String msgKey = "error.no-content-types-for-file-association";
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   318
                throw new ConfigException(
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   319
                        MessageFormat.format(I18N.getString(msgKey), assocIdx),
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   320
                        I18N.getString(msgKey + ".advise"));
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
            }
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   323
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   324
            if (mimes.size() > 1) {
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   325
                String msgKey = "error.too-many-content-types-for-file-association";
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   326
                throw new ConfigException(
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   327
                        MessageFormat.format(I18N.getString(msgKey), assocIdx),
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   328
                        I18N.getString(msgKey + ".advise"));
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
58647
2c43b89b1679 8231862: Decouple DesktopIntegration and LinuxPackageBundler classes
herrick
parents: 58607
diff changeset
   333
    private final BundlerParamInfo<String> packageName;
2c43b89b1679 8231862: Decouple DesktopIntegration and LinuxPackageBundler classes
herrick
parents: 58607
diff changeset
   334
    private boolean withFindNeededPackages;
2c43b89b1679 8231862: Decouple DesktopIntegration and LinuxPackageBundler classes
herrick
parents: 58607
diff changeset
   335
    private DesktopIntegration desktopIntegration;
58301
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   336
58647
2c43b89b1679 8231862: Decouple DesktopIntegration and LinuxPackageBundler classes
herrick
parents: 58607
diff changeset
   337
    private static final BundlerParamInfo<LinuxAppBundler> APP_BUNDLER =
2c43b89b1679 8231862: Decouple DesktopIntegration and LinuxPackageBundler classes
herrick
parents: 58607
diff changeset
   338
        new StandardBundlerParam<>(
2c43b89b1679 8231862: Decouple DesktopIntegration and LinuxPackageBundler classes
herrick
parents: 58607
diff changeset
   339
                "linux.app.bundler",
2c43b89b1679 8231862: Decouple DesktopIntegration and LinuxPackageBundler classes
herrick
parents: 58607
diff changeset
   340
                LinuxAppBundler.class,
2c43b89b1679 8231862: Decouple DesktopIntegration and LinuxPackageBundler classes
herrick
parents: 58607
diff changeset
   341
                (params) -> new LinuxAppBundler(),
2c43b89b1679 8231862: Decouple DesktopIntegration and LinuxPackageBundler classes
herrick
parents: 58607
diff changeset
   342
                null
2c43b89b1679 8231862: Decouple DesktopIntegration and LinuxPackageBundler classes
herrick
parents: 58607
diff changeset
   343
        );
58301
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   344
e0efb29609bd 8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
diff changeset
   345
}