RFR: 7903300: Add test library support to jtreg plugin

Guoxiong Li gli at openjdk.org
Thu Sep 15 14:19:01 UTC 2022


On Thu, 15 Sep 2022 13:37:26 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:

>> 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
>
> plugins/idea/src/main/java/com/oracle/plugin/jtreg/components/JTRegFileManagerListener.java line 149:
> 
>> 147:                     rootModel.addLibrary(library);
>> 148:                 } else if (testInfo.jtregLib != null) {
>> 149:                     rootModel.removeLibrary(testInfo.jtregLib);
> 
> 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.

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.

-------------

PR: https://git.openjdk.org/jtreg/pull/117


More information about the jtreg-dev mailing list