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

Support Hamcrest 3.0 in 'JUnit 4/5' classpath containers #1611

Merged
merged 1 commit into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public void initializeDefaultPreferences() {
// see https://github.com/junit-team/junit/issues/570
prefs.put(JUnitPreferencesConstants.JUNIT3_JAVADOC, "http://junit.sourceforge.net/junit3.8.1/javadoc/"); //$NON-NLS-1$
prefs.put(JUnitPreferencesConstants.JUNIT4_JAVADOC, "http://junit.org/junit4/javadoc/latest/"); //$NON-NLS-1$
prefs.put(JUnitPreferencesConstants.HAMCREST_CORE_JAVADOC, "http://hamcrest.org/JavaHamcrest/javadoc/1.3/"); //$NON-NLS-1$
prefs.put(JUnitPreferencesConstants.HAMCREST_CORE_JAVADOC, "https://hamcrest.org/JavaHamcrest/javadoc/3.0/"); //$NON-NLS-1$

String junit5JavadocLocation= "http://junit.org/junit5/docs/current/api/"; //$NON-NLS-1$
prefs.put(JUnitPreferencesConstants.JUNIT_JUPITER_API_JAVADOC, junit5JavadocLocation);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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$
Copy link
Contributor

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...

Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Contributor

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?

Copy link
Contributor

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))"

Copy link
Contributor

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.

Copy link
Contributor Author

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-4container, while for JUnit-5 the missing library is simply discarded, in this case hamcrest, which leads to compilation errors:

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.

Copy link
Contributor

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. 🙏


private static final JUnitPluginDescription HAMCREST_PLUGIN= new JUnitPluginDescription(
"org.hamcrest", new VersionRange("[2.2.0,2.3.0)"), null, "org.hamcrest_2.*.jar", "org.hamcrest.source", "source-bundle/", JUnitPreferencesConstants.HAMCREST_JAVADOC); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
"org.hamcrest", new VersionRange("[2.2.0,3.1.0)"), null, "org.hamcrest_2.*.jar", "org.hamcrest.source", "source-bundle/", JUnitPreferencesConstants.HAMCREST_JAVADOC); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$

public static final JUnitPluginDescription JUNIT_JUPITER_API_PLUGIN= new JUnitPluginDescription(
"junit-jupiter-api", new VersionRange("[5.0.0,6.0.0)"), null, "junit-jupiter-api_5.*.jar", "junit-jupiter-api.source", "", //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$//$NON-NLS-4$//$NON-NLS-5$
Expand Down
Loading