-
Notifications
You must be signed in to change notification settings - Fork 95
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
Support Hamcrest 3.0 in 'JUnit 4/5' classpath containers #1611
Conversation
Fixes eclipse-jdt#1610 Co-authored-by: Christoph Läubrich <[email protected]>
At the moment hamcrest-core seems not to be available in version 3. I assume that's because Orbit-SimRel does not provide it (yet)? Or simply nobody pulls it into SimRel (which I think is good). But since version 2, hamcrest-core is empty any way and only serves the purpose to redirect to the fat |
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.
As I20240825 seems to be broken since hamcrest 3.0 was added either hamcrest 3.0 hast to be removed or supported.
I think this needs to be merged as soon as possible The hamcrest 3.0 bundle has already landed in the release train repository and removing/excluding it is not a trivial exercise. Given we have little control over what is installed in the end, we had best not be broken when it's present. And what happens when 3.1 becomes available? Does this same problem come back? |
@@ -305,10 +305,10 @@ public boolean accept(File dir, String name) { | |||
"org.junit", new VersionRange("[4.13.0,5.0.0)"), null, "org.junit_4.*.jar", "org.junit.source", "source-bundle/", JUnitPreferencesConstants.JUNIT4_JAVADOC); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ | |||
|
|||
private static final JUnitPluginDescription HAMCREST_CORE_PLUGIN= new JUnitPluginDescription( | |||
"org.hamcrest.core", new VersionRange("[2.2.0,2.3.0)"), null, "org.hamcrest.core_2.*.jar", "org.hamcrest.core.source", "source-bundle/", JUnitPreferencesConstants.HAMCREST_CORE_JAVADOC); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ | |||
"org.hamcrest.core", new VersionRange("[2.2.0,3.1.0)"), null, "org.hamcrest.core_2.*.jar", "org.hamcrest.core.source", "source-bundle/", JUnitPreferencesConstants.HAMCREST_CORE_JAVADOC); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-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.
Will the same problem resurface when 3.1 is released? It will happen in the future...
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 don't know why so strict ranges are used here. The usual construct is '[current.min, next.major)' and as 3.0 is good I would assume all 3.x versions should be good.
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.
Indeed my sense is we'd be better to assume that hamcrest will be well behaved with respect to semantic versions now that they are publishing OSGi bundles directly.
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.
Does it actually fix the issue if 3.0 is NOT present?
As shown in #1610 (comment) the 2.2.0 seems to be completely empty for JUNIT 5 so don't we need 3.x as lower bound?
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.
It's sort of not empty because it contains this abomination re-exporting a bundle regardless of whether it might be version 1000.0.0 of that bundle:
Automatic-Module-Name org.hamcrest.core.deprecated
Bundle-ManifestVersion 2
Bundle-Name Bundle org.hamcrest : hamcrest-core
Bundle-SymbolicName org.hamcrest.core
Bundle-Version 2.2.0.v20230809-1000
Eclipse-Wrapped-Bundle org.hamcrest:hamcrest-core:2.2
Implementation-Title hamcrest-core
Implementation-Vendor hamcrest.org
Implementation-Version 2.2
Import-Package java.lang
Manifest-Version 1.0
Require-Bundle org.hamcrest;bundle-version="2.2.0";visibility:=reexport
Require-Capability osgi.ee;filter:="(&(osgi.ee=JavaSE)(version=1.7))"
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.
It's sort of not empty because it contains this abomination re-exporting a bundle regardless of whether it might be version 1000.0.0 of that bundle:
While this is relevant inside an OSGi framework it doesn't help for the classpath container because that one is just a collection of jars. So this entry actually is obsolete for 2.2... but we can remove it on the next cycle probably.
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.
Does it actually fix the issue if 3.0 is NOT present?
As shown in #1610 (comment) the 2.2.0 seems to be completely empty for JUNIT 5 so don't we need 3.x as lower bound?
Yes, it does. The reason why the JUnit-5
container does not fail completely is that for JUnit-5
library entries that are not found and therefore null
, are removed, while for JUnit-4 they are preserved. So if a desired library is not found it leads to an NPE when initializing a JUnit-4
container, while for JUnit-5
the missing library is simply discarded, in this case hamcrest, which leads to compilation errors:
Line 150 in b83ffe1
entriesList.removeIf(e -> e == null); |
It's sort of not empty because it contains this abomination re-exporting a bundle regardless of whether it might be version 1000.0.0 of that bundle:
While this is relevant inside an OSGi framework it doesn't help for the classpath container because that one is just a collection of jars. So this entry actually is obsolete for 2.2... but we can remove it on the next cycle probably.
That's right. Therefore I already created #1612.
Will the same problem resurface when 3.1 is released? It will happen in the future...
That's right. But this PR is inteded to just fix the linked issue in the presence of hamcrest-3.0. I assume there won't be a 3.1 within the next three months.
And on the long run I think the fetching of libraries should be be made more dynamic any ways (I assume no one what's to bump the version all the time?).
I'm thinking about a 'declarative' way where one declares the 'anchor/root'-packages to include (maybe an 'anchor-class' if there are split-packages) and the Eclipse OSGi runtime is queried for the bundles providing it.
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.
We really need to move forward here for this release cycle so someone needs to push the magic button. Things are definitely badly broken without a fix. Please, please. 🙏
IMO we need JDT @eclipse-jdt/eclipse-jdt-project-leads to step up here. |
Copying @noopur2507 |
The main problem seems that the JDT feature does not reflect the needed bundles (!) with version ranges in their feature like this:
That way P2 would have installed the "old" version as well and If it is not possible we would have seen an error at build-time instead of runtime. |
See also eclipse-platform/eclipse.platform.releng.aggregator#1245 where the changes were done after hamcrest update from 1.x to 2.x. |
It brings back bad memories of killing off a nice weekend. 😱 |
Moving from hamcrest 2.x to 3.x in JDT/JUnit should be done when we have more time for testing. However, currently, it's OK to release the current PR to accommodate hamcrest 3.x. Removing hamcrest-core and other related enhancements can be taken up for the next release. |
So can this then be submitted now in order to have it in an I-builds as soon as possible? |
Thank you. |
What it does
Fixes #1610
How to test
Make sure you have hamcrest 3.0 in your TP, e.g. from https://download.eclipse.org/tools/orbit/simrel/orbit-aggregation/2024-09/ and have a JDT project with the
JUnit 4 or 5
classpath container.I'm not exactly sure about the version range, the last time it was updated to only support hamcrest 2.2, but as written in #1610 (comment), hamcrest 3.0 is probably a drop-in preplacement and both could be supported.
Given that we are late in the release-cycle it might even happen that not everyone is able to update to hamcrest-3.0
CC @laeubi and @iloveeclipse and maybe @merks is also interested.
Author checklist