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

8214158: Implement HostServices.showDocument on macOS without calling AWT #634

Closed
wants to merge 5 commits into from
Closed

Conversation

@mipastgt
Copy link
Member

@mipastgt mipastgt commented Sep 28, 2021

Fixes the issue by using the "open" command as discussed before.
See: https://bugs.openjdk.java.net/browse/JDK-8214158


Progress

  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue
  • Change must be properly reviewed

Issue

  • JDK-8214158: Implement HostServices.showDocument on macOS without calling AWT

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.java.net/jfx pull/634/head:pull/634
$ git checkout pull/634

Update a local copy of the PR:
$ git checkout pull/634
$ git pull https://git.openjdk.java.net/jfx pull/634/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 634

View PR using the GUI difftool:
$ git pr show -t 634

Using diff file

Download this PR as a diff file:
https://git.openjdk.java.net/jfx/pull/634.diff

@bridgekeeper
Copy link

@bridgekeeper bridgekeeper bot commented Sep 28, 2021

👋 Welcome back mpaus! 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
Copy link

@openjdk openjdk bot commented Sep 28, 2021

⚠️ @mipastgt a branch with the same name as the source branch for this pull request (master) is present in the target repository. If you eventually integrate this pull request then the branch master in your personal fork will diverge once you sync your personal fork with the upstream repository.

To avoid this situation, create a new branch for your changes and reset the master branch. You can do this by running the following commands in a local repository for your personal fork. Note: you do not have to name the new branch NEW-BRANCH-NAME.

$ git checkout -b NEW-BRANCH-NAME
$ git branch -f master 55faac49082ee8c92893dac15d2777011ec7dca0
$ git push -f origin master

Then proceed to create a new pull request with NEW-BRANCH-NAME as the source branch and close this one.

@openjdk openjdk bot added the rfr label Sep 28, 2021
@mlbridge
Copy link

@mlbridge mlbridge bot commented Sep 28, 2021

@kevinrushforth
Copy link
Member

@kevinrushforth kevinrushforth commented Sep 28, 2021

/reviewers 2

@openjdk
Copy link

@openjdk openjdk bot commented Sep 28, 2021

@kevinrushforth
The number of required reviews for this PR is now set to 2 (with at least 1 of role reviewers).

@kevinrushforth
Copy link
Member

@kevinrushforth kevinrushforth commented Sep 28, 2021

This seems like a good RFE. I have a couple overall questions.

First, calling open was originally proposed in the since-abandoned Draft PR javafxports/openjdk-jfx#310. As I wrote there:

One thing of note is that the AWT code, which we are currently calling, uses a native method to call LSOpenURLsWithRole rather than "exec"-ing a new process from Java. I'm not sure why (maybe the open command wasn't as robust when it was implemented? Or maybe there is some benefit to using LSOpenURLsWithRole?), but we will need to make sure that there isn't a regression in behavior as a result."

Can you comment on this?

Second, can you provide a manual test for this? I was thinking something that would go somewhere under tests/manual and when run, provide an option to open one of two or three different file types (e.g., a .txt file and a .html file) that are also checked in to the same dir as the test program. It could use FIle::toURI or similar to construct the URI string.

@mipastgt
Copy link
Member Author

@mipastgt mipastgt commented Sep 28, 2021

First of all. Shall I follow the bot request above and create a new pull request? Wouldn't we loose the discussion here then?

@mipastgt
Copy link
Member Author

@mipastgt mipastgt commented Sep 28, 2021

To answer your questions:

  1. I have no idea about LSOpenURLsWithRole. I am not a Mac developer.

  2. I have manually tested the change:

     Button showHtml = new Button("HTML");
     showHtml.setOnAction(e -> {this.getHostServices().showDocument(new File("data/test.html").toURI().toString());});
     
     Button showTxt = new Button("TXT");
     showTxt.setOnAction(e -> {this.getHostServices().showDocument(new File("data/test.txt").toURI().toString());});
     
     Button showCsv = new Button("CSV");
     showCsv.setOnAction(e -> {this.getHostServices().showDocument(new File("data/test.csv").toURI().toString());});
    

The code fragment above reliably opens the HTML document in Firefox (my default browser), the text document in BBEdit (my default text editor) and the CSV document in LibreOffice (my default Excel :-)

This also works if you just use the plain strings without conversion to an URI.

Here are the printed Java/FX version strings for completness:

java.runtime.version: 18-ea+16-926
javafx.runtime.version: 18-internal+0-2021-09-28-174132

@kevinrushforth
Copy link
Member

@kevinrushforth kevinrushforth commented Sep 29, 2021

First of all. Shall I follow the bot request above and create a new pull request? Wouldn't we loose the discussion here then?

As long as you don't otherwise need to update your master branch, you can wait to reset it until after this PR is integrated. If you prefer to create a new branch and a new PR, then you could link to the discussion. I'll leave it up to you.

I have no idea about LSOpenURLsWithRole. I am not a Mac developer.

I think calling Runtime::exec("open", uri) is fine. It matches the behavior on Windows and Linux. I'll do some testing, but I don't anticipate any problems.

I have manually tested the change.

In that case, can you create a new manual test as part of this PR? I recommend a new directory: tests/manual/desktop/HostServices (my thinking is that tests/manual/desktop could eventually include tests for FileChooser or other similar manual tests). I'm open to other names as well. You can look at tests/manual/web/InputTypeAcceptAttributeTest.java for an example of a good manual test. I recommend adding at least a .txt and a .html file. You can hard-code the filenames so you don't need to use a FileChooser.

@openjdk openjdk bot removed the rfr label Sep 29, 2021
@openjdk openjdk bot added the rfr label Sep 29, 2021
Copy link
Member

@kevinrushforth kevinrushforth left a comment

Both the fix and the test look good. I left two minor formatting comments, but I'll approve it as-is. If you want to fix them, I'll re-approve.

tests/manual/desktop/HostServices/test.txt Outdated Show resolved Hide resolved
arapte
arapte approved these changes Oct 1, 2021
Copy link
Member

@arapte arapte left a comment

Looks good. Verified on Mac and Windows.

@openjdk
Copy link

@openjdk openjdk bot commented Oct 1, 2021

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

8214158: Implement HostServices.showDocument on macOS without calling AWT

Reviewed-by: kcr, arapte

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 1 new commit pushed to the master branch:

  • 30f5606: 8231644: TreeTableView Regression: Indentation wrong using Label as column content type

Please see this link for an up-to-date comparison between the source branch of this pull request and the master branch.
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.

As you do not have Committer status in this project an existing Committer must agree to sponsor your change. Possible candidates are the reviewers of this PR (@kevinrushforth, @arapte) but any other Committer may sponsor as well.

➡️ To flag this PR as ready for integration with the above commit message, type /integrate in a new comment. (Afterwards, your sponsor types /sponsor in a new comment to perform the integration).

@openjdk openjdk bot added the ready label Oct 1, 2021
@mipastgt
Copy link
Member Author

@mipastgt mipastgt commented Oct 1, 2021

/integrate

@openjdk
Copy link

@openjdk openjdk bot commented Oct 1, 2021

@mipastgt
Your change (at version 24ceab1) is now ready to be sponsored by a Committer.

@openjdk openjdk bot added the sponsor label Oct 1, 2021
@kevinrushforth
Copy link
Member

@kevinrushforth kevinrushforth commented Oct 1, 2021

/sponsor

@openjdk
Copy link

@openjdk openjdk bot commented Oct 1, 2021

Going to push as commit f3c72b9.
Since your change was applied there has been 1 commit pushed to the master branch:

  • 30f5606: 8231644: TreeTableView Regression: Indentation wrong using Label as column content type

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot closed this Oct 1, 2021
@openjdk
Copy link

@openjdk openjdk bot commented Oct 1, 2021

@kevinrushforth @mipastgt Pushed as commit f3c72b9.

💡 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
3 participants