changeset 58696:34869f56f4c5

8241713: Linux desktop shortcuts with spaces make postinst/prerm fail Reviewed-by: almatvee, herrick
author asemenyuk
date Sat, 04 Apr 2020 07:09:52 -0400
parents d2738e1be37a
children f810ecf73455
files src/jdk.incubator.jpackage/linux/classes/jdk/incubator/jpackage/internal/DesktopIntegration.java test/jdk/tools/jpackage/helpers/jdk/jpackage/test/LinuxHelper.java test/jdk/tools/jpackage/linux/ShortcutHintTest.java
diffstat 3 files changed, 17 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.incubator.jpackage/linux/classes/jdk/incubator/jpackage/internal/DesktopIntegration.java	Mon Apr 06 20:35:50 2020 +0200
+++ b/src/jdk.incubator.jpackage/linux/classes/jdk/incubator/jpackage/internal/DesktopIntegration.java	Sat Apr 04 07:09:52 2020 -0400
@@ -84,19 +84,21 @@
                 .setCategory(I18N.getString("resource.menu-shortcut-descriptor"))
                 .setPublicName(APP_NAME.fetchFrom(params) + ".desktop");
 
+        final String escapedAppFileName = APP_NAME.fetchFrom(params).replaceAll("\\s+", "_");
+
         // XDG recommends to use vendor prefix in desktop file names as xdg
         // commands copy files to system directories.
         // Package name should be a good prefix.
         final String desktopFileName = String.format("%s-%s.desktop",
-                    thePackage.name(), APP_NAME.fetchFrom(params));
+                    thePackage.name(), escapedAppFileName);
         final String mimeInfoFileName = String.format("%s-%s-MimeInfo.xml",
-                    thePackage.name(), APP_NAME.fetchFrom(params));
+                    thePackage.name(), escapedAppFileName);
 
         mimeInfoFile = new DesktopFile(mimeInfoFileName);
 
         if (withDesktopFile) {
             desktopFile = new DesktopFile(desktopFileName);
-            iconFile = new DesktopFile(APP_NAME.fetchFrom(params)
+            iconFile = new DesktopFile(escapedAppFileName
                     + IOUtils.getSuffix(Path.of(DEFAULT_ICON)));
 
             if (curIconResource == null) {
--- a/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/LinuxHelper.java	Mon Apr 06 20:35:50 2020 +0200
+++ b/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/LinuxHelper.java	Sat Apr 04 07:09:52 2020 -0400
@@ -50,7 +50,7 @@
         cmd.verifyIsOfType(PackageType.LINUX);
         String desktopFileName = String.format("%s-%s.desktop", getPackageName(
                 cmd), Optional.ofNullable(launcherName).orElseGet(
-                        () -> cmd.name()));
+                        () -> cmd.name()).replaceAll("\\s+", "_"));
         return cmd.appLayout().destktopIntegrationDirectory().resolve(
                 desktopFileName);
     }
--- a/test/jdk/tools/jpackage/linux/ShortcutHintTest.java	Mon Apr 06 20:35:50 2020 +0200
+++ b/test/jdk/tools/jpackage/linux/ShortcutHintTest.java	Sat Apr 04 07:09:52 2020 -0400
@@ -91,8 +91,16 @@
         return new PackageTest()
                 .forTypes(PackageType.LINUX)
                 .configureHelloApp()
-                .addBundleDesktopIntegrationVerifier(true);
-
+                .addBundleDesktopIntegrationVerifier(true)
+                .addInitializer(cmd -> {
+                    String defaultAppName = cmd.name();
+                    String appName = defaultAppName.replace(
+                            ShortcutHintTest.class.getSimpleName(),
+                            "Shortcut Hint  Test");
+                    cmd.setArgumentValue("--name", appName);
+                    cmd.addArguments("--linux-package-name",
+                            defaultAppName.toLowerCase());
+                });
     }
 
     /**
@@ -163,9 +171,7 @@
                     ));
         })
         .addInstallVerifier(cmd -> {
-            Path desktopFile = cmd.appLayout().destktopIntegrationDirectory().resolve(
-                    String.format("%s-%s.desktop",
-                            LinuxHelper.getPackageName(cmd), cmd.name()));
+            Path desktopFile = LinuxHelper.getDesktopFile(cmd);
             TKit.assertFileExists(desktopFile);
             TKit.assertTextStream(expectedVersionString)
                     .label(String.format("[%s] file", desktopFile))