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

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

Closed
wants to merge 6 commits into from

Conversation

sashamatveev
Copy link
Member

@sashamatveev sashamatveev commented Feb 9, 2022

Added ability to override description for additional launchers via "description" property.


Progress

  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue
  • Change must be properly reviewed
  • Change requires a CSR request to be approved

Issues

  • JDK-8279995: jpackage --add-launcher option should allow overriding description
  • JDK-8281672: jpackage --add-launcher option should allow overriding description (CSR)

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

@bridgekeeper
Copy link

bridgekeeper bot commented Feb 9, 2022

👋 Welcome back almatvee! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk openjdk bot added the rfr Pull request is ready for review label Feb 9, 2022
@openjdk
Copy link

openjdk bot commented Feb 9, 2022

@sashamatveev The following label will be automatically applied to this pull request:

  • core-libs

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.

@mlbridge
Copy link

mlbridge bot commented Feb 9, 2022

Webrevs

@alexeysemenyukoracle
Copy link
Member

I don't quite understand how these changes affect the description of launcher executables on Windows. I'd expect changes at least in

public void prepareApplicationFiles(Map<String, ? super Object> params)
. Can you elaborate, please?

@@ -89,14 +90,17 @@ public void test() {

new AdditionalLauncher("Baz2")
.setDefaultArguments()
.addRawProperties(Map.entry("description", "Baz2 Description"))

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?

Copy link
Member Author

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.

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().

@kevinrushforth
Copy link
Member

This will need a CSR.

@sashamatveev
Copy link
Member Author

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.

@alexeysemenyukoracle
Copy link
Member

Unfortunately, manual testing adds zero value to automated test runs. This feature can be covered with automated tests so it should be.

@openjdk openjdk bot added the csr Pull request needs approved CSR before integration label Feb 11, 2022
@sashamatveev
Copy link
Member Author

Added automated tests for .exe files in Windows and .desktop files on Linux.

}
}
}
TKit.assertTrue(descriptionIsValid, "Invalid file description");

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.

Comment on lines 86 to 90
Map.Entry<String, String> entry = rawProperties.stream()
.filter(item -> item.getKey().equals(key))
.findFirst().orElse(null);

return entry == null ? null : entry.getValue();

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.

Copy link
Member Author

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.

Comment on lines 258 to 275
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());
}
}
Copy link
Member

@alexeysemenyukoracle alexeysemenyukoracle Feb 11, 2022

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.

Copy link
Member Author

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");
Copy link
Member

@alexeysemenyukoracle alexeysemenyukoracle Feb 15, 2022

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");

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.

Copy link
Member Author

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.

@openjdk
Copy link

openjdk bot commented Feb 17, 2022

@sashamatveev this pull request can not be integrated into master due to one or more merge conflicts. To resolve these merge conflicts and update this pull request you can run the following commands in the local repository for your personal fork:

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

@openjdk openjdk bot added the merge-conflict Pull request has merge conflict with target branch label Feb 17, 2022
@openjdk openjdk bot removed the merge-conflict Pull request has merge conflict with target branch label Feb 17, 2022
Comment on lines 142 to 165
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;
}

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.

Copy link
Member Author

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.

@openjdk openjdk bot removed the csr Pull request needs approved CSR before integration label Feb 23, 2022
@openjdk
Copy link

openjdk bot commented Feb 25, 2022

@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:

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

Reviewed-by: asemenyuk

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 master branch:

  • e96c599: 8271232: JFR: Scrub recording data
  • 735e86b: 8282345: handle latest VS2022 in abstract_vm_version
  • b96b743: 8281015: Further simplify NMT backend
  • 9471f24: 8280684: JfrRecorderService failes with guarantee(num_written > 0) when no space left on device.
  • 3efd6aa: 8282347: AARCH64: Untaken branch in has_negatives stub
  • cd36be4: 8206187: javax/management/remote/mandatory/connection/DefaultAgentFilterTest.java fails with Port already in use
  • bf19fc6: 8280357: user.home = "?" when running with systemd DynamicUser=true
  • b6843a1: 8005885: enhance PrintCodeCache to print more data
  • 23995f8: 8281525: Enable Zc:strictStrings flag in Visual Studio build
  • 20e78f7: 8282307: Parallel: Incorrect discovery mode in PCReferenceProcessor
  • ... and 79 more: https://git.openjdk.java.net/jdk/compare/1864481df10d2f616cbfdecebf3bebbae04de5e1...master

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 master branch, type /integrate in a new comment.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Feb 25, 2022
@sashamatveev
Copy link
Member Author

/integrate

@openjdk
Copy link

openjdk bot commented Feb 25, 2022

Going to push as commit fb8bf81.
Since your change was applied there have been 90 commits pushed to the master branch:

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated Pull request has been integrated label Feb 25, 2022
@openjdk openjdk bot closed this Feb 25, 2022
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels Feb 25, 2022
@openjdk
Copy link

openjdk bot commented Feb 25, 2022

@sashamatveev Pushed as commit fb8bf81.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core-libs [email protected] integrated Pull request has been integrated
Development

Successfully merging this pull request may close these issues.

3 participants