Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JDK-8269387: jpackage --add-launcher should have option to not create shortcuts for additional launchers #4730

Closed
wants to merge 7 commits into from
Expand Up @@ -56,6 +56,7 @@
import static jdk.jpackage.internal.StandardBundlerParam.FILE_ASSOCIATIONS;
import static jdk.jpackage.internal.StandardBundlerParam.ICON;
import static jdk.jpackage.internal.StandardBundlerParam.PREDEFINED_APP_IMAGE;
import static jdk.jpackage.internal.StandardBundlerParam.SHORTCUT_HINT;;

/**
* Helper to create files for desktop integration.
Expand All @@ -82,7 +83,7 @@ private DesktopIntegration(PlatformPackage thePackage,
// Need desktop and icon files if one of conditions is met:
// - there are file associations configured
// - user explicitely requested to create a shortcut
boolean withDesktopFile = !associations.isEmpty() || SHORTCUT_HINT.fetchFrom(params);
boolean withDesktopFile = !associations.isEmpty() || LINUX_SHORTCUT_HINT.fetchFrom(params);

var curIconResource = LinuxAppImageBuilder.createIconResource(DEFAULT_ICON,
ICON_PNG, params, mainParams);
Expand Down Expand Up @@ -138,30 +139,34 @@ private DesktopIntegration(PlatformPackage thePackage,
// Read launchers information from predefine app image
if (launchers.isEmpty() &&
PREDEFINED_APP_IMAGE.fetchFrom(params) != null) {
List<AppImageFile.LauncherInfo> launchers = AppImageFile.getLaunchers(
List<AppImageFile.LauncherInfo> launcherInfos =
AppImageFile.getLaunchers(
PREDEFINED_APP_IMAGE.fetchFrom(params), params);
if (!launchers.isEmpty()) {
launchers.remove(0); // Remove main launcher
if (!launcherInfos.isEmpty()) {
launcherInfos.remove(0); // Remove main launcher
}
for (var launcher : launchers) {
for (var launcherInfo : launcherInfos) {
Map<String, ? super Object> launcherParams = new HashMap<>();
Arguments.putUnlessNull(launcherParams, CLIOptions.NAME.getId(),
launcher.getName());
launcherParams = AddLauncherArguments.merge(params, launcherParams,
ICON.getID(), ICON_PNG.getID(), ADD_LAUNCHERS.getID(),
FILE_ASSOCIATIONS.getID(), PREDEFINED_APP_IMAGE.getID());
if (launcher.isShortcut()) {
launcherInfo.getName());
launcherParams = AddLauncherArguments.merge(params,
launcherParams, ICON.getID(), ICON_PNG.getID(),
ADD_LAUNCHERS.getID(), FILE_ASSOCIATIONS.getID(),
PREDEFINED_APP_IMAGE.getID());
if (launcherInfo.isShortcut()) {
nestedIntegrations.add(new DesktopIntegration(thePackage,
launcherParams, params));
}
}
} else {
for (var launcherParams : launchers) {
launcherParams = AddLauncherArguments.merge(params, launcherParams,
ICON.getID(), ICON_PNG.getID(), ADD_LAUNCHERS.getID(),
FILE_ASSOCIATIONS.getID());
nestedIntegrations.add(new DesktopIntegration(thePackage,
launcherParams, params));
launcherParams = AddLauncherArguments.merge(params,
launcherParams, ICON.getID(), ICON_PNG.getID(),
ADD_LAUNCHERS.getID(), FILE_ASSOCIATIONS.getID());
if (SHORTCUT_HINT.fetchFrom(launcherParams)) {
nestedIntegrations.add(new DesktopIntegration(thePackage,
launcherParams, params));
}
}
}
}
Expand Down Expand Up @@ -569,7 +574,7 @@ private static class LinuxFileAssociation {
(s, p) -> s
);

private static final StandardBundlerParam<Boolean> SHORTCUT_HINT =
private static final StandardBundlerParam<Boolean> LINUX_SHORTCUT_HINT =
new StandardBundlerParam<>(
Arguments.CLIOptions.LINUX_SHORTCUT_HINT.getId(),
Boolean.class,
Expand Down
Expand Up @@ -81,12 +81,14 @@ public AdditionalLauncher addRawProperties(
return this;
}

public AdditionalLauncher setShortcuts(boolean menu, boolean desktop) {
public AdditionalLauncher setShortcuts(boolean menu, boolean shortcut) {
withMenuShortcut = menu;
withShortcut = shortcut;
if (TKit.isLinux()) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd move add addRawProperties() calls to initialize() method. This will prevent multiple addRawProperties() calls for "linux-shortcut" and "win-shortcut" properties in case setShortcuts() method is called multiple times.

addRawProperties(Map.entry("linux-shortcut", "" + menu));
addRawProperties(Map.entry("linux-shortcut", "" + shortcut));
} else if (TKit.isWindows()) {
addRawProperties(Map.entry("win-menu", "" + menu));
addRawProperties(Map.entry("win-shortcut", "" + desktop));
addRawProperties(Map.entry("win-shortcut", "" + shortcut));
}
return this;
}
Expand Down Expand Up @@ -188,15 +190,15 @@ private void verifyIcon(JPackageCommand cmd) throws IOException {
() -> iconInResourceDir(cmd, name));
while (effectiveIcon != NO_ICON) {
if (effectiveIcon != null) {
withLinuxDesktopFile = true;
withLinuxDesktopFile = Boolean.FALSE != withShortcut;
verifier.setExpectedIcon(effectiveIcon);
break;
}

Path customMainLauncherIcon = cmd.getArgumentValue("--icon",
() -> iconInResourceDir(cmd, null), Path::of);
if (customMainLauncherIcon != null) {
withLinuxDesktopFile = true;
withLinuxDesktopFile = Boolean.FALSE != withShortcut;
verifier.setExpectedIcon(customMainLauncherIcon);
break;
}
Expand All @@ -207,8 +209,8 @@ private void verifyIcon(JPackageCommand cmd) throws IOException {

if (TKit.isLinux() && !cmd.isImagePackageType()) {
if (effectiveIcon != NO_ICON && !withLinuxDesktopFile) {
withLinuxDesktopFile = Stream.of("--linux-shortcut").anyMatch(
cmd::hasArgument);
withLinuxDesktopFile = (Boolean.FALSE != withShortcut) &&
Stream.of("--linux-shortcut").anyMatch(cmd::hasArgument);
verifier.setExpectedDefaultIcon();
}
Path desktopFile = LinuxHelper.getDesktopFile(cmd, name);
Expand All @@ -222,8 +224,21 @@ private void verifyIcon(JPackageCommand cmd) throws IOException {
verifier.applyTo(cmd);
}

private void verifyShortcuts(JPackageCommand cmd) throws IOException {
if (TKit.isLinux() && !cmd.isImagePackageType()
&& withShortcut != null) {
Path desktopFile = LinuxHelper.getDesktopFile(cmd, name);
if (withShortcut) {
TKit.assertFileExists(desktopFile);
} else {
TKit.assertPathExists(desktopFile, false);
}
}
}

private void verify(JPackageCommand cmd) throws IOException {
verifyIcon(cmd);
verifyShortcuts(cmd);

Path launcherPath = cmd.appLauncherPath(name);

Expand All @@ -250,6 +265,8 @@ private void verify(JPackageCommand cmd) throws IOException {
private final String name;
private final List<Map.Entry<String, String>> rawProperties;
private BiConsumer<Path, List<Map.Entry<String, String>>> createFileHandler;
private Boolean withMenuShortcut;
private Boolean withShortcut;

private final static Path NO_ICON = Path.of("");
}