|
| 1 | +/* |
| 2 | + * Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved. |
| 3 | + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 4 | + * |
| 5 | + * This code is free software; you can redistribute it and/or modify it |
| 6 | + * under the terms of the GNU General Public License version 2 only, as |
| 7 | + * published by the Free Software Foundation. Oracle designates this |
| 8 | + * particular file as subject to the "Classpath" exception as provided |
| 9 | + * by Oracle in the LICENSE file that accompanied this code. |
| 10 | + * |
| 11 | + * This code is distributed in the hope that it will be useful, but WITHOUT |
| 12 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 13 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 14 | + * version 2 for more details (a copy is included in the LICENSE file that |
| 15 | + * accompanied this code). |
| 16 | + * |
| 17 | + * You should have received a copy of the GNU General Public License version |
| 18 | + * 2 along with this work; if not, write to the Free Software Foundation, |
| 19 | + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
| 20 | + * |
| 21 | + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
| 22 | + * or visit www.oracle.com if you need additional information or have any |
| 23 | + * questions. |
| 24 | + */ |
| 25 | +package jdk.jpackage.internal; |
| 26 | + |
| 27 | +import static jdk.jpackage.internal.FromOptions.buildApplicationBuilder; |
| 28 | +import static jdk.jpackage.internal.FromOptions.createPackageBuilder; |
| 29 | +import static jdk.jpackage.internal.LinuxPackagingPipeline.APPLICATION_LAYOUT; |
| 30 | +import static jdk.jpackage.internal.cli.StandardOption.LINUX_APP_CATEGORY; |
| 31 | +import static jdk.jpackage.internal.cli.StandardOption.LINUX_DEB_MAINTAINER_EMAIL; |
| 32 | +import static jdk.jpackage.internal.cli.StandardOption.LINUX_MENU_GROUP; |
| 33 | +import static jdk.jpackage.internal.cli.StandardOption.LINUX_PACKAGE_DEPENDENCIES; |
| 34 | +import static jdk.jpackage.internal.cli.StandardOption.LINUX_PACKAGE_NAME; |
| 35 | +import static jdk.jpackage.internal.cli.StandardOption.LINUX_RELEASE; |
| 36 | +import static jdk.jpackage.internal.cli.StandardOption.LINUX_RPM_LICENSE_TYPE; |
| 37 | +import static jdk.jpackage.internal.cli.StandardOption.LINUX_SHORTCUT_HINT; |
| 38 | +import static jdk.jpackage.internal.model.StandardPackageType.LINUX_DEB; |
| 39 | +import static jdk.jpackage.internal.model.StandardPackageType.LINUX_RPM; |
| 40 | + |
| 41 | +import jdk.jpackage.internal.cli.Options; |
| 42 | +import jdk.jpackage.internal.model.Launcher; |
| 43 | +import jdk.jpackage.internal.model.LinuxApplication; |
| 44 | +import jdk.jpackage.internal.model.LinuxDebPackage; |
| 45 | +import jdk.jpackage.internal.model.LinuxLauncher; |
| 46 | +import jdk.jpackage.internal.model.LinuxLauncherMixin; |
| 47 | +import jdk.jpackage.internal.model.LinuxRpmPackage; |
| 48 | +import jdk.jpackage.internal.model.StandardPackageType; |
| 49 | + |
| 50 | +final class LinuxFromOptions { |
| 51 | + |
| 52 | + static LinuxApplication createLinuxApplication(Options options) { |
| 53 | + |
| 54 | + final var launcherFromOptions = new LauncherFromOptions().faWithDefaultDescription(); |
| 55 | + |
| 56 | + final var appBuilder = buildApplicationBuilder().create(options, launcherOptions -> { |
| 57 | + |
| 58 | + final var launcher = launcherFromOptions.create(launcherOptions); |
| 59 | + |
| 60 | + final var shortcut = LINUX_SHORTCUT_HINT.findIn(launcherOptions); |
| 61 | + |
| 62 | + return LinuxLauncher.create(launcher, new LinuxLauncherMixin.Stub(shortcut)); |
| 63 | + |
| 64 | + }, (LinuxLauncher linuxLauncher, Launcher launcher) -> { |
| 65 | + return LinuxLauncher.create(launcher, linuxLauncher); |
| 66 | + }, APPLICATION_LAYOUT); |
| 67 | + |
| 68 | + appBuilder.launchers().map(LinuxPackagingPipeline::normalizeShortcuts).ifPresent(appBuilder::launchers); |
| 69 | + |
| 70 | + return LinuxApplication.create(appBuilder.create()); |
| 71 | + } |
| 72 | + |
| 73 | + static LinuxRpmPackage createLinuxRpmPackage(Options options) { |
| 74 | + |
| 75 | + final var superPkgBuilder = createLinuxPackageBuilder(options, LINUX_RPM); |
| 76 | + |
| 77 | + final var pkgBuilder = new LinuxRpmPackageBuilder(superPkgBuilder); |
| 78 | + |
| 79 | + LINUX_RPM_LICENSE_TYPE.ifPresentIn(options, pkgBuilder::licenseType); |
| 80 | + |
| 81 | + return pkgBuilder.create(); |
| 82 | + } |
| 83 | + |
| 84 | + static LinuxDebPackage createLinuxDebPackage(Options options) { |
| 85 | + |
| 86 | + final var superPkgBuilder = createLinuxPackageBuilder(options, LINUX_DEB); |
| 87 | + |
| 88 | + final var pkgBuilder = new LinuxDebPackageBuilder(superPkgBuilder); |
| 89 | + |
| 90 | + LINUX_DEB_MAINTAINER_EMAIL.ifPresentIn(options, pkgBuilder::maintainerEmail); |
| 91 | + |
| 92 | + final var pkg = pkgBuilder.create(); |
| 93 | + |
| 94 | + // Show warning if license file is missing |
| 95 | + if (pkg.licenseFile().isEmpty()) { |
| 96 | + Log.verbose(I18N.getString("message.debs-like-licenses")); |
| 97 | + } |
| 98 | + |
| 99 | + return pkg; |
| 100 | + } |
| 101 | + |
| 102 | + private static LinuxPackageBuilder createLinuxPackageBuilder(Options options, StandardPackageType type) { |
| 103 | + |
| 104 | + final var app = createLinuxApplication(options); |
| 105 | + |
| 106 | + final var superPkgBuilder = createPackageBuilder(options, app, type); |
| 107 | + |
| 108 | + final var pkgBuilder = new LinuxPackageBuilder(superPkgBuilder); |
| 109 | + |
| 110 | + LINUX_PACKAGE_DEPENDENCIES.ifPresentIn(options, pkgBuilder::additionalDependencies); |
| 111 | + LINUX_APP_CATEGORY.ifPresentIn(options, pkgBuilder::category); |
| 112 | + LINUX_MENU_GROUP.ifPresentIn(options, pkgBuilder::menuGroupName); |
| 113 | + LINUX_RELEASE.ifPresentIn(options, pkgBuilder::release); |
| 114 | + LINUX_PACKAGE_NAME.ifPresentIn(options, pkgBuilder::literalName); |
| 115 | + |
| 116 | + return pkgBuilder; |
| 117 | + } |
| 118 | + |
| 119 | +} |
0 commit comments