-
Notifications
You must be signed in to change notification settings - Fork 71
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
Compute junit5 runtime Plug-ins dynamically in RequiredPlugins-Container and reference junit and hamcrest only via Import-Package #684
Conversation
private static final Collection<String> JUNIT5_RUNTIME_PLUGINS = Set.of("org.junit", "junit-jupiter-api", | ||
"junit-jupiter-engine", "junit-platform-commons", "junit-platform-engine", "org.hamcrest.core", | ||
"org.opentest4j"); | ||
private static final Set<String> JUNIT5_RUNTIME_PLUGINS = Set.of("org.junit", // |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder why org.junit
(i.e. the Junit-4 bundle is added), if a Test-Plugin references the JUnit-5 API?
Can anyone tell?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use JUnit 4 API in JUnit5 tests via the junit-vintage-engine
(even though it is not really a JUnit5 test then) so one is able to mix JUnit 3/4/5 ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but then one imports the org.junit packge or requires that bundle?
Or is the intention to make it available without any further addo once one imports the Jupiter-API?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually require it to importpackage/requirebundle junit is bad, why should I ever want that? Beside that you should look at the JUnit Container at JDT that defines the set of junit jars and I think PDE is inspired by that.
Actually one wants to define the used engine (like in BND Tests or Surefire) and then it might be enough to determine transitive requirements.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually require it to importpackage/requirebundle junit is bad, why should I ever want that?
I more think, why I should ever not want that? All other dependencies needed for compilation have to be specified, why should a Junit dependency used for compilation (not runtime), be different in this case?
We have only dedicated 'test-plugins/fragments' in PDE, so there is IMHO no great need to treat them differently.
And as said in another comment, I have the impression that this can lead to compilation failures in Tycho because in the IDE the classpath sees more jars than in the build.
Test Results 246 files + 6 246 suites +6 1h 1m 30s ⏱️ + 16m 10s For more details on these failures and errors, see this check. Results for commit 758234c. ± Comparison against base commit 7dd52e7. This pull request removes 1 test.
♻️ This comment has been updated with latest results. |
If you are already working in that area, it would be great if PDE would not only check imports/require bundles but also the Precence of the JUnit3/4/5 container on the classpath what actually is a much better way than using imports. |
It looks promising. Of course one has to wonder the origin of the access restriction:
The bundle has this
So only org.junit.internal packages are marked internal. |
77ba855
to
c3504d4
Compare
The problem is that PDE seem not to be worried about missing imports of those junit packages.
Sure that's not a problem. Did that alraedy, but I'm not sure what you want to do in that case. Since that container also adds the junit-5 jars, I would say that the addition through PDE can be disabled in this case. |
c3504d4
to
6150a56
Compare
I have the Impression that this Problem is caused/hidden by the Auto-Magic addition of the junit5-runtime/junit4 bundles to the CP. |
I really doubt that ;-) PDE currently looks for "junit" in the manifest and then adds "magic stuff" to the classpath (and therefore runtime!) of the project, so if you only add the JUnit container the compilation works but running as plugintest fails because no JUnit "bundles" are found, so PDE should simply interpret the presence of JUnit container as "we require the bundles", where the jars of the bundle are already bundles, the only thing is that as far as I know they are from the installation and not from the target platform! |
6150a56
to
b8dba2c
Compare
Are you referring to a plain Junit-Test or a JUnit Plugin Test? Because for the latter PDE usually just adds all bundles from the TP to the test runtime and if the launcher is not present it adds the bundles from the running IDE (hoping they work together).
So as far as I understand, the JUnit-Container adds the launcher jars from the running IDE (installation), while this PDE features adds the junit-launcher jars from the TP? |
@laeubi I think the current state is what you have described? |
Tycho has a rich detection of the required JUnit Framework and supports the JUnit Classpathcontainer beside that one can configure that explicitly if required. Still JDT users seem to be happy enough with "one JUnit" shipped with the IDE. So PDE should either require to import every requirement or should not require it at all (if junit container is there), but looking for some require bundle and then adding others is simply a hack for the lazy ;-) |
Just try the attached example in an empty workspace: test.junit.zip
So even though the junit is in the bundle and selected for the run the test does not work without the imports in PDE. If you look at the classpath the same bundles are there for the JUnit Container and for Plugin Dependencies I tried adding a while back some patches for that but they where not accepted to I leave this alone but this makes using JUnit way more complex with PDE than necessary and prevents one from using Plugin tests in the same bundle or need to use hacks like optional imports of junit. |
b8dba2c
to
fb0ce22
Compare
Fully agree and I never said that adding the launcher jars to the class-path is a great thing. :) That being said, actually the content of the jars just added to the classpath by this 'feature/hack' should not be accessible if the package is not imported or the bundle not required in the Manifest, because the jars are added with the access-rule Nevertheless I think the discussion lost a bit its focus and I would like to complete this for the actual intend now, i.e. compute the launcher bundles dynamically and support the old BSN's and make PDE ready for a newer hamcrest version. |
This requires to import the hamcrest packages, if they are used and those test-plugins don't rely on the re-export of hamcrest by org.junit anymore. + Only use junit-4 assertion methods and replace use of junit-3 assertions. + Remove unnecessary hard-coded references to the hamcrest bundle name
And add support for old junit bundle names from Eclipse-Orbit.
fb0ce22
to
758234c
Compare
This PR does two things, mainly with the goal to not require a specific hamcrest bundle name:
And add support for old junit bundle names from Orbit.
This requires to import the hamcrest packages, if they are used and those test-plugins don't rely on the re-export of hamcrest by org.junit anymore.
Additionally only use junit-4 assertion methods and replace use of junit-3 assertions.
And remove unnecessary hard-coded references to the hamcrest bundle name.
@merks what do you think?