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

error on import statements of test classes using module-info #417

Open
ghost opened this issue Jan 29, 2019 · 15 comments
Open

error on import statements of test classes using module-info #417

ghost opened this issue Jan 29, 2019 · 15 comments

Comments

@ghost
Copy link

ghost commented Jan 29, 2019

Could not setup simple java gradle project with module-info.java and tests without error using java 11.
Netbeans gradle shows me error on import statements of test-classes using java jigsaw module-info.

Simple gradle Java project with:

gradleJava/src/main/java/module-info.java:

module gradleJava {
    requires java.desktop;
}

gradleJava/src/test/java/PropertyChangeListenerTests.java:

import java.beans.PropertyChangeListener;

public class PropertyChangeListenerTests {

    @Test
    public void propertyChangeListenerTest() {
        PropertyChangeListener listener;
    }
}

Netbeans shows the line "import java.beans.PropertyChangeListener;" as error:
"package java.beans" does not exist.

Expect that netbeans-grade plugin uses module-info.java of src/main for src/test and does not show the error on the import statements of the test.
I want to use different locations src/main for source code and src/test for unit tests.

I tried it in IntelliJ and there it works as expected.

Screenshot of error in netbeans:
error on import statements

Simple sample project for opening in netbeans to show the error:
gradleJava.zip

@kelemen
Copy link
Owner

kelemen commented Jan 29, 2019

Can you try using somethine else than the default package?

@ghost
Copy link
Author

ghost commented Jan 30, 2019

The same error on tests exists also when I use a package. I have stripped down the error in the attached gradleJava.zip to a minimum, for easy reproducing and fix.

error module-info and test

Our main goal is to contribute to openjdk-jfx, but there I have the same problem in the tests.

error openjdk-jfx

@kelemen
Copy link
Owner

kelemen commented Jan 30, 2019

Thanks for the report and the sample project, I will have a look next week (or maybe sunday), as I'm on holiday at the moment.

@ghost
Copy link
Author

ghost commented Jan 31, 2019

Have a nice holiday!
If I can be of assistance, please do not hesitate to contact me.
For developing with java jigsaw module system, it is essential to have this bug fixed.

kelemen added a commit that referenced this issue Feb 3, 2019
…his seems to fix the issue #417 (module-info.java not being recognized for test source sets) but I don't actually now what NB is doing, and this change just mimics the behaviour of the Maven integration.
@kelemen
Copy link
Owner

kelemen commented Feb 3, 2019

I have made some adjustment to better mimic what the Maven integration does. However, I'm a little puzzled on what actually NB is doing to use the module-info.java from the main source set. However, the recently pushed changes seems to fix the issue for me.

Can you try building the master branch and see if it works for you?

@ghost
Copy link
Author

ghost commented Feb 4, 2019

I will try and write my feedback here :-)

@ghost
Copy link
Author

ghost commented Feb 5, 2019

I build the master branch with your changes and verified the behavior.

Sadly it did not change anything for me. In the class "PropertyChangeListenerTests" the "import java.beans" are highlighted again as error with the same tooltip "package java.beans does not exists".

If we make an appointment, i can share you my screen over skype, so that you can verify what I have done.

Have you tried opening the attached project in "gradleJava.zip" with your changes?

@kelemen
Copy link
Owner

kelemen commented Feb 5, 2019

I have checked this with your attached project. To be honest I closed the file and then the project, restarted NB and opened the project again (that said, this hints to a very unreliable behaviour). No need to share your screen, I believe you and you shouldn't really be able to do the wrong thing. It seems I will have to check some other things.

That said, the current development version of NB has a completely different Gradle integration packaged. I recommend you building NB from the sources (https://github.com/apache/incubator-netbeans), it is pretty easy to build (though takes a while), and see if that works for you first.

@ghost
Copy link
Author

ghost commented Feb 6, 2019

I have cloned and build incubator-netbeans like you recommended.
Good news, the "import java.beans." in PropertyChangeListenerTests is now correctly validated as expected. If I remove the associated "requires java.desktop;" line from module-info.java, the validation shows an error in PropertyChangeListenerTest as expected, if i add the "requires"-statement, it show no validation error in this line as expected.

Bad news, now the import-statement of "import org.junit.Test;" is now shown as error, with the message "package org.junit is not visible ...", but maybe this behavior is correct and I have to do some more configuration in netbeans? Any hint or tips for me?

bildschirmfoto 2019-02-06 um 16 55 18

@ghost
Copy link
Author

ghost commented Feb 6, 2019

As you can see on the following screen-shot in the build incubator-netbeans the test passed successfully. So I can run it.
Therefore I do not understand why netbeans is showing me the error "package org.junit is not visible.."?

bildschirmfoto 2019-02-06 um 17 22 17

@kelemen
Copy link
Owner

kelemen commented Feb 6, 2019

I had a brief look at the source code, and it seems that it misses an implementation of CompilerOptionsQueryImplementation. That said, I wonder if implementing that will make that plugin has the same issue as this one.

Anyway, you should report issues of that plugin here: https://issues.apache.org/jira/projects/NETBEANS/issues

@ghost
Copy link
Author

ghost commented Feb 7, 2019

I have found an already created issue for this error:
https://issues.apache.org/jira/browse/NETBEANS-2004
and I append what I already wrote here and copied also the link to here.

Maybe if we can get in touch with a developer from netbeans knowing the relevant module/code, the solution/knowledge found out can be relevant or helpfull for fixing both issues, your plugin and the incubator-netbeans gradle integration.

@kelemen
Copy link
Owner

kelemen commented Feb 7, 2019

I have already talked about this with an NB developer but it seems I did not quite understood what is to do properly. Anyway, I will try harder to analize the sources of NB a little harder but I'll probably only have time on the weekend.

@kelemen
Copy link
Owner

kelemen commented Feb 13, 2019

I went through some NB and nb-javac sources on the weekend but it seems a little odd to me because - though I probably missed something - the only way I saw to tell NB to use the main's module-info.java in test is to have them on the same source path but I remember that doing so causes other weird issues (not to mention that the Maven integration does not do that). I will need more time for this (something I have little of at the moment).

@ghost
Copy link
Author

ghost commented Feb 15, 2019

Thanks for you patience for further investigation. Hope that this issue will also be fixed in the incubator-netbeans. Can I do something to support them?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant