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

7903300: Add test library support to jtreg plugin #117

Closed
wants to merge 3 commits into from

Conversation

lgxbslgx
Copy link
Member

@lgxbslgx lgxbslgx commented Sep 11, 2022

Hi all,

Currently, when we open a jtreg test file which uses the JUnit or TestNG, the plugin can't identify the related classes of the JUnit or TestNG. So the statement such as import org.junit.Test is marked as red with error message Cannot resolve symbol 'junit'.

This patch adds the jtreg libraries directory to the lib path of the Jetbrains IDEA when opening the JUnit or TestNG test files so that the Jetbrains IDEA can identify the related classes.

Thanks for taking the time to review.

Best Regards,
-- Guoxiong


Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue

Issue

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jtreg.git pull/117/head:pull/117
$ git checkout pull/117

Update a local copy of the PR:
$ git checkout pull/117
$ git pull https://git.openjdk.org/jtreg.git pull/117/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 117

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

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jtreg/pull/117.diff

Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Sep 11, 2022

👋 Welcome back gli! 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 changed the title CODETOOLS-7903300 7903300: Add test library support to jtreg plugin Sep 11, 2022
@openjdk openjdk bot added the rfr Pull request is ready for review label Sep 11, 2022
@mlbridge
Copy link

mlbridge bot commented Sep 11, 2022

Webrevs

testInfo.jtregLib = library;
rootModel.addLibrary(library);
} else if (testInfo.jtregLib != null) {
rootModel.removeLibrary(testInfo.jtregLib);
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure this is logically correct. While I can understand adding jtreg/testng library to the model as soon as a new test file requiring it is opened, removing the library seems more problematic. In principle we should remove the testng/junit library from the model only if there's no open test that's a jtreg test. Which doesn't seem to be what's happening in the code.

Copy link
Member Author

Choose a reason for hiding this comment

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

The TestRootManager#addLibrary will record the reference count in the field TestRootManager.moduleLibRefCount. And the TestRootManager#removeLibrary only actually removes the lib from the module when the count becomes 1.

@mcimadamore
Copy link
Contributor

Note that there is a workaround for the problem mentioned in this PR (not that I think it wouldn't be nice to fix). The IDE will typically suggest to add relevant test libraries when clicking on the light-bulb fix icon beside a TestNG/JUnit import.

@lgxbslgx
Copy link
Member Author

Note that there is a workaround for the problem mentioned in this PR (not that I think it wouldn't be nice to fix). The IDE will typically suggest to add relevant test libraries when clicking on the light-bulb fix icon beside a TestNG/JUnit import.

Yes, I fixed the problem locally by using this way. But I think it is good to let the plugin fix it automatically, so I write this patch.

/**
* Create (if not existing) and get the jtreg project library.
*/
public static Library createJTRegLibrary(Project project, String oldDir, String newDir) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Wouldn't it be better to split this into a function that creates the library, and one that updates it? I find it odd that the file listener is calling this with oldDir == newDir. Maybe just add option for oldDir to be null, so that we only drop the old root if one is given?

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 adjusted the api, added update method and delegated the create method to it. And I also fixed the possible NPE and avoided the duplicated lib entries.

@mcimadamore
Copy link
Contributor

Also, when updating the plugin, it is better to update the gradle.properties file to bump the version, and to include some notes (e.g. bug number and synopsis). This will allow upgrade to occur smoothly (and issues to be pinpointed correctly).

@lgxbslgx
Copy link
Member Author

Also, when updating the plugin, it is better to update the gradle.properties file to bump the version, and to include some notes (e.g. bug number and synopsis). This will allow upgrade to occur smoothly (and issues to be pinpointed correctly).

I bumped the version and revised the notes.

I think the plugin should be released periodically (may be several months). But now it seems you want to release a new version one patch. I don't know the current release flow so I follow your command.

Copy link
Contributor

@mcimadamore mcimadamore left a comment

Choose a reason for hiding this comment

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

Looks good

@lgxbslgx
Copy link
Member Author

@mcimadamore Thanks for the review. Still waiting for a formal reviewer to review it.

@bridgekeeper
Copy link

bridgekeeper bot commented Dec 4, 2023

@lgxbslgx This pull request has been inactive for more than 4 weeks and will be automatically closed if another 4 weeks passes without any activity. To avoid this, simply add a new comment to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration!

Copy link
Collaborator

@jonathan-gibbons jonathan-gibbons left a comment

Choose a reason for hiding this comment

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

Endorsing @mcimadamore's review

@openjdk
Copy link

openjdk bot commented Dec 7, 2023

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

7903300: Add test library support to jtreg plugin

Reviewed-by: mcimadamore, jjg

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 53 new commits pushed to 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 (@mcimadamore, @jonathan-gibbons) 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 Pull request is ready to be integrated label Dec 7, 2023
@lgxbslgx
Copy link
Member Author

lgxbslgx commented Dec 9, 2023

Thanks for the review. Could I get your help to sponsor this patch?

/integrate

@openjdk openjdk bot added the sponsor Pull request is ready to be sponsored label Dec 9, 2023
@openjdk
Copy link

openjdk bot commented Dec 9, 2023

@lgxbslgx
Your change (at version e0d865a) is now ready to be sponsored by a Committer.

@sormuras
Copy link
Member

/sponsor

@openjdk
Copy link

openjdk bot commented Dec 18, 2023

Going to push as commit a396e2f.
Since your change was applied there have been 54 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 Dec 18, 2023
@openjdk openjdk bot closed this Dec 18, 2023
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review sponsor Pull request is ready to be sponsored labels Dec 18, 2023
@openjdk
Copy link

openjdk bot commented Dec 18, 2023

@sormuras @lgxbslgx Pushed as commit a396e2f.

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

@lgxbslgx lgxbslgx deleted the CODETOOLS-7903300 branch December 19, 2023 01:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
integrated Pull request has been integrated
Development

Successfully merging this pull request may close these issues.

4 participants