From 0d8b5188bb4315be3c63898a2ce4e68dd2bd4481 Mon Sep 17 00:00:00 2001 From: Alexey Semenyuk Date: Fri, 14 Nov 2025 01:07:05 +0000 Subject: [PATCH] 8364560: The default value of --linux-menu-group option is invalid 8356574: Test --linux-menu-group option Reviewed-by: almatvee --- .../internal/LinuxPackageBuilder.java | 10 ++++---- .../internal/model/LinuxPackageMixin.java | 15 +++++++++++- .../resources/LinuxResources.properties | 1 - .../jdk/jpackage/test/LinuxHelper.java | 3 ++- .../jpackage/linux/ShortcutHintTest.java | 24 +++++++++++++++---- 5 files changed, 41 insertions(+), 12 deletions(-) diff --git a/src/jdk.jpackage/linux/classes/jdk/jpackage/internal/LinuxPackageBuilder.java b/src/jdk.jpackage/linux/classes/jdk/jpackage/internal/LinuxPackageBuilder.java index cc00d7816f5..4cfb8a26c8f 100644 --- a/src/jdk.jpackage/linux/classes/jdk/jpackage/internal/LinuxPackageBuilder.java +++ b/src/jdk.jpackage/linux/classes/jdk/jpackage/internal/LinuxPackageBuilder.java @@ -84,9 +84,9 @@ final class LinuxPackageBuilder { private LinuxPackage create(Package pkg) throws ConfigException { return LinuxPackage.create(pkg, new LinuxPackageMixin.Stub( Optional.ofNullable(menuGroupName).orElseGet(DEFAULTS::menuGroupName), - Optional.ofNullable(category), + category(), Optional.ofNullable(additionalDependencies), - Optional.ofNullable(release), + release(), pkg.asStandardPackageType().map(LinuxPackageArch::getValue).orElseThrow())); } @@ -192,7 +192,7 @@ final class LinuxPackageBuilder { private final PackageBuilder pkgBuilder; - private static final Defaults DEFAULTS = new Defaults(I18N.getString( - "param.menu-group.default")); - + // Should be one of https://specifications.freedesktop.org/menu/latest/category-registry.html#main-category-registry + // The category is an ID, not a localizable string + private static final Defaults DEFAULTS = new Defaults("Utility"); } diff --git a/src/jdk.jpackage/linux/classes/jdk/jpackage/internal/model/LinuxPackageMixin.java b/src/jdk.jpackage/linux/classes/jdk/jpackage/internal/model/LinuxPackageMixin.java index 5bcf57194f6..056e3b89527 100644 --- a/src/jdk.jpackage/linux/classes/jdk/jpackage/internal/model/LinuxPackageMixin.java +++ b/src/jdk.jpackage/linux/classes/jdk/jpackage/internal/model/LinuxPackageMixin.java @@ -34,6 +34,12 @@ public interface LinuxPackageMixin { /** * Gets the name of the start menu group where to create shortcuts for * application launchers of this package. + *

+ * It sets the value of the "Categories" property in .desktop files of the + * package. + *

+ * Should be one of the values from https://specifications.freedesktop.org/menu/latest/category-registry.html * * @return the name of the start menu group where to create shortcuts for * application launchers of this package @@ -44,6 +50,13 @@ public interface LinuxPackageMixin { /** * Gets the category of this package. + *

+ * For RPM packages this is the value of the optional "Group" property. + *

+ * For DEB packages this is the value of the mandatory "Section" property. + * The + * present list of recognized values. * * @return the category of this package */ @@ -62,7 +75,7 @@ public interface LinuxPackageMixin { * Gets the release of this package. Returns an empty {@link Optional} instance * if this package doesn't have a release. *

- * For RPM packages, this is the value of a "Release" property in spec file. RPM + * For RPM packages, this is the value of the "Release" property in spec file. RPM * packages always have a release. *

* For DEB packages, this is an optional {@code debian_revision} component of a diff --git a/src/jdk.jpackage/linux/classes/jdk/jpackage/internal/resources/LinuxResources.properties b/src/jdk.jpackage/linux/classes/jdk/jpackage/internal/resources/LinuxResources.properties index fbc83ba2e10..a732d02c7d1 100644 --- a/src/jdk.jpackage/linux/classes/jdk/jpackage/internal/resources/LinuxResources.properties +++ b/src/jdk.jpackage/linux/classes/jdk/jpackage/internal/resources/LinuxResources.properties @@ -28,7 +28,6 @@ deb.bundler.name=DEB Bundle rpm.bundler.name=RPM Bundle param.license-type.default=Unknown -param.menu-group.default=Unknown resource.deb-control-file=DEB control file resource.deb-preinstall-script=DEB preinstall script diff --git a/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/LinuxHelper.java b/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/LinuxHelper.java index 25358e8ecdc..e795f7c9760 100644 --- a/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/LinuxHelper.java +++ b/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/LinuxHelper.java @@ -564,7 +564,8 @@ public final class LinuxHelper { for (var e : List.of( Map.entry("Type", "Application"), Map.entry("Terminal", "false"), - Map.entry("Comment", launcherDescription) + Map.entry("Comment", launcherDescription), + Map.entry("Categories", Optional.ofNullable(cmd.getArgumentValue("--linux-menu-group")).orElse("Utility")) )) { String key = e.getKey(); TKit.assertEquals(e.getValue(), data.find(key).orElseThrow(), String.format( diff --git a/test/jdk/tools/jpackage/linux/ShortcutHintTest.java b/test/jdk/tools/jpackage/linux/ShortcutHintTest.java index 8d373cb2b86..2591d1d393a 100644 --- a/test/jdk/tools/jpackage/linux/ShortcutHintTest.java +++ b/test/jdk/tools/jpackage/linux/ShortcutHintTest.java @@ -26,13 +26,15 @@ import java.nio.file.Files; import java.nio.file.Path; import java.util.List; import jdk.jpackage.test.AdditionalLauncher; +import jdk.jpackage.test.Annotations.Parameter; +import jdk.jpackage.test.Annotations.Test; import jdk.jpackage.test.FileAssociations; -import jdk.jpackage.test.PackageType; -import jdk.jpackage.test.PackageTest; -import jdk.jpackage.test.TKit; import jdk.jpackage.test.JPackageCommand; import jdk.jpackage.test.LinuxHelper; -import jdk.jpackage.test.Annotations.Test; +import jdk.jpackage.test.PackageTest; +import jdk.jpackage.test.PackageType; +import jdk.jpackage.test.RunnablePackageTest.Action; +import jdk.jpackage.test.TKit; /** * Test --linux-shortcut parameter. Output of the test should be @@ -179,4 +181,18 @@ public class ShortcutHintTest { .apply(Files.readAllLines(desktopFile)); }).run(); } + + /** + * Test "--linux-menu-group" option. + * + * @param menuGroup value of "--linux-menu-group" option + */ + @Test + // Values from https://specifications.freedesktop.org/menu/latest/category-registry.html#main-category-registry + @Parameter("Development") + public static void testMenuGroup(String menuGroup) { + createTest().addInitializer(JPackageCommand::setFakeRuntime).addInitializer(cmd -> { + cmd.addArgument("--linux-shortcut").setArgumentValue("--linux-menu-group", menuGroup); + }).run(Action.CREATE_AND_UNPACK); + } }