-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
8279995: jpackage --add-launcher option should allow overriding description #7399
Conversation
👋 Welcome back almatvee! A progress list of the required criteria for merging this PR into |
@sashamatveev The following label will be automatically applied to this pull request:
When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command. |
Webrevs
|
I don't quite understand how these changes affect the description of launcher executables on Windows. I'd expect changes at least in jdk/src/jdk.jpackage/windows/classes/jdk/jpackage/internal/WindowsAppImageBuilder.java Line 97 in 739769c
|
@@ -89,14 +90,17 @@ public void test() { | |||
|
|||
new AdditionalLauncher("Baz2") | |||
.setDefaultArguments() | |||
.addRawProperties(Map.entry("description", "Baz2 Description")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How expected description is verified in the test?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not think that we have ability to check description on executable files. I added it for manual verification.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Powershell can be used to extract the description from an executable. E.g.:
$ powershell -NoLogo -NoProfile -Command "(Get-Item build\\windows-x64\\images\\jdk\\bin\\java.exe).VersionInfo | select FileDescription"
FileDescription
---------------
Java(TM) Platform SE binary
You can create jdk.jpackage.test.AdditionalLauncher.verifyDescription() function that will call this script and call this function from jdk.jpackage.test.AdditionalLauncher.verify().
This will need a CSR. |
AddLauncherArguments.java class reads parameters for additional launcher from property file and if this class contains particular property we will prefer it when generating additional launchers. Thus I do not think that anything else needs to be change. I tested it and it works fine. Testing was done manually. |
Unfortunately, manual testing adds zero value to automated test runs. This feature can be covered with automated tests so it should be. |
Added automated tests for .exe files in Windows and .desktop files on Linux. |
} | ||
} | ||
} | ||
TKit.assertTrue(descriptionIsValid, "Invalid file description"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd use TKit.assertEquals()
to compare the expected description with the actual one. This will produce a meaningful error message in log output in case they don't match.
Map.Entry<String, String> entry = rawProperties.stream() | ||
.filter(item -> item.getKey().equals(key)) | ||
.findFirst().orElse(null); | ||
|
||
return entry == null ? null : entry.getValue(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be simply
rawProperties.stream().findAny(item -> item.getKey().equals(key)).map(e -> e.getValue()).orElse(null);
Or slightly better:
public String getRawPropertyValue(String key, Supplier<String> getDefault) {
return rawProperties.stream().findAny(item -> item.getKey().equals(key)).map(e -> e.getValue()).orElseGet(getDefault);
}
Then we can create a function that will return the expected description of an additional launcher:
private String getDesciption(JPackageCommand cmd) {
return getRawPropertyValue("description", () -> cmd.getArgumentValue("--description", unused -> "Unknown"));
}
This will let you avoid if (expectedDescription != null)
checks and always verify launcher description.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed as suggested, except app name is used instead of "Unknown", since our default description is app name.
Path launcherPath = cmd.appLauncherPath(name); | ||
Executor exec = Executor.of("powershell", | ||
"-NoLogo", | ||
"-NoProfile", | ||
"-Command", | ||
"(Get-Item \\\"" + | ||
launcherPath.toAbsolutePath() + | ||
"\\\").VersionInfo | select FileDescription"); | ||
boolean descriptionIsValid = false; | ||
List<String> lines = exec.executeAndGetOutput(); | ||
if (lines != null) { | ||
for (int i = 0; i < lines.size(); i++) { | ||
if (lines.get(i).trim().equals("FileDescription")) { | ||
i += 2; // Skip "---------------" and move to description | ||
descriptionIsValid = | ||
expectedDescription.equals(lines.get(i).trim()); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This piece of code can be placed in WindowsHelper.getExecutableDesciption(Path pathToExeFile)
function to make it reusable in other tests if needed. This way it can be used to verify the description of the main launcher.
if (lines != null)
check is rudimentary.
Instead of running the loop, I'd simply check the output second from the last line for "---" and if so, would return the last line of the output. Otherwise would throw an exception indicating the command returned an unexpected result.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I kept original implementation. Actually, powershell returns 6 lines: empty, FileDescription, ----, Actual Description, empty, empty. I think it is better to make sure FileDescription is present and go from top to bottom in case if output can be something like: empty, ErrorMessage, ---, Actual error message, empty, empty.
String actualDescription = | ||
WindowsHelper.getExecutableDesciption(launcherPath); | ||
TKit.assertEquals(expectedDescription, actualDescription, | ||
"Invalid file description"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The message should be the name of an action taken, not the error description. The testing framework will build the error message itself. So it can be Check file description of <launcher_path>
. You can use TKit.assertDirectoryExists()
as a reference -
public static void assertDirectoryExists(Path path) { |
} | ||
} | ||
|
||
TKit.assertNotNull(description, "Failed to get file description"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Failure to get the executable's description through powersehll script is not an issue of a test case being executed. This is the testing framework issue. Throwing RuntimeException with the message containing file path will be the appropriate error handling. Having a file name in the exception message will help to localize the issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed. Error message also fixed for description check.
@sashamatveev this pull request can not be integrated into git checkout JDK-8279995
git fetch https://git.openjdk.java.net/jdk master
git merge FETCH_HEAD
# resolve conflicts and follow the instructions given by git merge
git commit -m "Merge master"
git push |
public static String getExecutableDesciption(Path pathToExeFile) { | ||
String description = null; | ||
Executor exec = Executor.of("powershell", | ||
"-NoLogo", | ||
"-NoProfile", | ||
"-Command", | ||
"(Get-Item \\\"" | ||
+ pathToExeFile.toAbsolutePath() | ||
+ "\\\").VersionInfo | select FileDescription"); | ||
List<String> lines = exec.executeAndGetOutput(); | ||
for (int i = 0; i < lines.size(); i++) { | ||
if (lines.get(i).trim().equals("FileDescription")) { | ||
i += 2; // Skip "---------------" and move to description | ||
description = lines.get(i).trim(); | ||
} | ||
} | ||
|
||
if (description == null) { | ||
throw new RuntimeException(String.format( | ||
"Failed to get file description of [%s]", pathToExeFile)); | ||
} | ||
|
||
return description; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about this:
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();
var description = lineIt.next().trim();
if (lineIt.hasNext()) {
throw new RuntimeException("Unexpected input");
}
return description;
}
}
throw new RuntimeException(String.format(
"Failed to get file description of [%s]", pathToExeFile));
}
Added Executor.dumpOutput()
call to save the output of powershell command in the test log for easier debugging.
No null initialized description
variable. No iteration over the list using the index. Check for the end of the output.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed. Except I removed if (lineIt.hasNext()) { throw new RuntimeException("Unexpected input"); }, since there are empty lines after description in output and this check triggers exception.
@sashamatveev This change now passes all automated pre-integration checks. ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details. After integration, the commit message for the final commit will be:
You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed. At the time when this comment was updated there had been 89 new commits pushed to the
As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details. ➡️ To integrate this PR with the above commit message to the |
/integrate |
Going to push as commit fb8bf81.
Your commit was automatically rebased without conflicts. |
@sashamatveev Pushed as commit fb8bf81. 💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored. |
Added ability to override description for additional launchers via "description" property.
Progress
Issues
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.java.net/jdk pull/7399/head:pull/7399
$ git checkout pull/7399
Update a local copy of the PR:
$ git checkout pull/7399
$ git pull https://git.openjdk.java.net/jdk pull/7399/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 7399
View PR using the GUI difftool:
$ git pr show -t 7399
Using diff file
Download this PR as a diff file:
https://git.openjdk.java.net/jdk/pull/7399.diff