8279995: jpackage --add-launcher option should allow overriding description

Reviewed-by: asemenyuk
This commit is contained in:
Alexander Matveev 2022-02-25 20:49:59 +00:00
parent 441e48509c
commit fb8bf81842
7 changed files with 75 additions and 10 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -54,6 +54,7 @@ import static jdk.jpackage.internal.StandardBundlerParam.SHORTCUT_HINT;
* The add-launcher properties file may have any of:
*
* appVersion
* description
* module
* main-jar
* main-class
@ -111,6 +112,9 @@ class AddLauncherArguments {
Arguments.putUnlessNull(bundleParams, CLIOptions.VERSION.getId(),
getOptionValue(CLIOptions.VERSION));
Arguments.putUnlessNull(bundleParams, CLIOptions.DESCRIPTION.getId(),
getOptionValue(CLIOptions.DESCRIPTION));
Arguments.putUnlessNull(bundleParams, CLIOptions.RELEASE.getId(),
getOptionValue(CLIOptions.RELEASE));

View File

@ -1,5 +1,5 @@
#
# Copyright (c) 2017, 2021, Oracle and/or its affiliates. All rights reserved.
# Copyright (c) 2017, 2022, Oracle and/or its affiliates. All rights reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# This code is free software; you can redistribute it and/or modify it
@ -138,7 +138,7 @@ Generic Options:\n\
\ Name of launcher, and a path to a Properties file that contains\n\
\ a list of key, value pairs\n\
\ (absolute path or relative to the current directory)\n\
\ The keys "module", "main-jar", "main-class",\n\
\ The keys "module", "main-jar", "main-class", "description",\n\
\ "arguments", "java-options", "app-version", "icon",\n\
\ "win-console", "win-shortcut", "win-menu",\n\
\ "linux-app-category", and "linux-shortcut" can be used.\n\

View File

@ -1,5 +1,5 @@
#
# Copyright (c) 2017, 2021, Oracle and/or its affiliates. All rights reserved.
# Copyright (c) 2017, 2022, Oracle and/or its affiliates. All rights reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# This code is free software; you can redistribute it and/or modify it
@ -138,7 +138,7 @@ Generic Options:\n\
\ Name of launcher, and a path to a Properties file that contains\n\
\ a list of key, value pairs\n\
\ (absolute path or relative to the current directory)\n\
\ The keys "module", "main-jar", "main-class",\n\
\ The keys "module", "main-jar", "main-class", "description",\n\
\ "arguments", "java-options", "app-version", "icon",\n\
\ "win-console", "win-shortcut", "win-menu",\n\
\ "linux-app-category", and "linux-shortcut" can be used.\n\

View File

@ -1,5 +1,5 @@
#
# Copyright (c) 2017, 2021, Oracle and/or its affiliates. All rights reserved.
# Copyright (c) 2017, 2022, Oracle and/or its affiliates. All rights reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# This code is free software; you can redistribute it and/or modify it
@ -138,7 +138,7 @@ Generic Options:\n\
\ Name of launcher, and a path to a Properties file that contains\n\
\ a list of key, value pairs\n\
\ (absolute path or relative to the current directory)\n\
\ The keys "module", "main-jar", "main-class",\n\
\ The keys "module", "main-jar", "main-class", "description",\n\
\ "arguments", "java-options", "app-version", "icon",\n\
\ "win-console", "win-shortcut", "win-menu",\n\
\ "linux-app-category", and "linux-shortcut" can be used.\n\

View File

@ -32,6 +32,7 @@ import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.function.BiConsumer;
import java.util.function.Supplier;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
@ -86,6 +87,18 @@ public class AdditionalLauncher {
return this;
}
final public String getRawPropertyValue(
String key, Supplier<String> getDefault) {
return rawProperties.stream()
.filter(item -> item.getKey().equals(key))
.map(e -> e.getValue()).findAny().orElseGet(getDefault);
}
private String getDesciption(JPackageCommand cmd) {
return getRawPropertyValue("description", () -> cmd.getArgumentValue(
"--description", unused -> cmd.name()));
}
final public AdditionalLauncher setShortcuts(boolean menu, boolean shortcut) {
withMenuShortcut = menu;
withShortcut = shortcut;
@ -281,9 +294,30 @@ public class AdditionalLauncher {
}
}
private void verifyDescription(JPackageCommand cmd) throws IOException {
if (TKit.isWindows()) {
String expectedDescription = getDesciption(cmd);
Path launcherPath = cmd.appLauncherPath(name);
String actualDescription =
WindowsHelper.getExecutableDesciption(launcherPath);
TKit.assertEquals(expectedDescription, actualDescription,
String.format("Check file description of [%s]", launcherPath));
} else if (TKit.isLinux() && !cmd.isImagePackageType()) {
String expectedDescription = getDesciption(cmd);
Path desktopFile = LinuxHelper.getDesktopFile(cmd, name);
if (Files.exists(desktopFile)) {
TKit.assertTextStream("Comment=" + expectedDescription)
.label(String.format("[%s] file", desktopFile))
.predicate(String::equals)
.apply(Files.readAllLines(desktopFile).stream());
}
}
}
protected void verify(JPackageCommand cmd) throws IOException {
verifyIcon(cmd);
verifyShortcuts(cmd);
verifyDescription(cmd);
Path launcherPath = cmd.appLauncherPath(name);

View File

@ -163,6 +163,29 @@ public class WindowsHelper {
.executeAndGetOutput().stream().collect(Collectors.joining("\n"));
}
public static String getExecutableDesciption(Path pathToExeFile) {
Executor exec = Executor.of("powershell",
"-NoLogo",
"-NoProfile",
"-Command",
"(Get-Item \\\""
+ pathToExeFile.toAbsolutePath()
+ "\\\").VersionInfo | select FileDescription");
var lineIt = exec.dumpOutput().executeAndGetOutput().iterator();
while (lineIt.hasNext()) {
var line = lineIt.next();
if (line.trim().equals("FileDescription")) {
// Skip "---------------" and move to the description value
lineIt.next();
return lineIt.next().trim();
}
}
throw new RuntimeException(String.format(
"Failed to get file description of [%s]", pathToExeFile));
}
private static boolean isUserLocalInstall(JPackageCommand cmd) {
return cmd.hasArgument("--win-per-user-install");
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -40,7 +40,7 @@ import jdk.jpackage.test.CfgFile;
* AddLauncherTest*.* installer. The output installer should provide the
* same functionality as the default installer (see description of the default
* installer in SimplePackageTest.java) plus install three extra application
* launchers.
* launchers with unique description ("LauncherName Description").
*/
/*
@ -80,7 +80,8 @@ public class AddLauncherTest {
PackageTest packageTest = new PackageTest().configureHelloApp();
packageTest.addInitializer(cmd -> {
cmd.addArguments("--arguments", "Duke", "--arguments", "is",
"--arguments", "the", "--arguments", "King");
"--arguments", "the", "--arguments", "King",
"--description", "AddLauncherTest Description");
});
new FileAssociations(
@ -89,14 +90,17 @@ public class AddLauncherTest {
new AdditionalLauncher("Baz2")
.setDefaultArguments()
.addRawProperties(Map.entry("description", "Baz2 Description"))
.applyTo(packageTest);
new AdditionalLauncher("foo")
.setDefaultArguments("yep!")
.addRawProperties(Map.entry("description", "foo Description"))
.applyTo(packageTest);
new AdditionalLauncher("Bar")
.setDefaultArguments("one", "two", "three")
.addRawProperties(Map.entry("description", "Bar Description"))
.setIcon(GOLDEN_ICON)
.applyTo(packageTest);