Skip to content

Commit

Permalink
8241713: Linux desktop shortcuts with spaces make postinst/prerm fail
Browse files Browse the repository at this point in the history
Reviewed-by: almatvee, herrick
  • Loading branch information
Alexey Semenyuk committed Apr 4, 2020
1 parent c1016d5 commit 3aa216e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
Expand Up @@ -84,19 +84,21 @@ private DesktopIntegration(PlatformPackage thePackage,
.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) {
Expand Down
Expand Up @@ -50,7 +50,7 @@ public static Path getDesktopFile(JPackageCommand cmd, String launcherName) {
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);
}
Expand Down
16 changes: 11 additions & 5 deletions test/jdk/tools/jpackage/linux/ShortcutHintTest.java
Expand Up @@ -91,8 +91,16 @@ private static PackageTest createTest() {
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());
});
}

/**
Expand Down Expand Up @@ -163,9 +171,7 @@ public static void testDesktopFileFromResourceDir() throws IOException {
));
})
.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))
Expand Down

0 comments on commit 3aa216e

Please sign in to comment.