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

Rework PluginRegistry API and introduce VersionMatchRule enum #1163

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

HannesWell
Copy link
Member

@HannesWell HannesWell commented Feb 21, 2024

Modernize the PluginRegistry API that contains the antiquated org.eclipse.osgi.service.resolver.VersionRange by providing alternatives using the org.osgi.framework.VersionRange and deprecating the existing methods for removal.

In conjunction with that also mark PluginRegistry.PluginFilter as deprecated for removal since it is effectively a Predicate<IPluginModelBase> and just use the latter in the new methods.

This is currently an early draft to discuss the overall direction. Since the intention is to focus on the API callers of the now deprecated methods are not replaced in this PR. I'll do that in a follow-up.

About the API I'm also contemplating to further modernize the methods in PluginRegistry that now return a List to return a Stream instead. Then we could also save the filter arguments since callers can just filter the returned stream if desired.

Furthermore I would also like to replace the integer and string constants in IMatchRules by a corresponding Enum VersionMatchRules (or similar) that also provides method to obtain a predicate for a reference version that implements the literals matching rule or to obtain a corresponding VersionRange from a reference version (which ever is needed).

Part of #1069

Copy link

github-actions bot commented Feb 22, 2024

Test Results

  273 files   -    16    273 suites   - 16   33m 37s ⏱️ - 22m 13s
  953 tests  - 2 627    900 ✅  - 2 603   52 💤  - 25  0 ❌ ±0  1 🔥 +1 
2 925 runs   - 7 946  2 763 ✅  - 7 905  159 💤  - 44  0 ❌ ±0  3 🔥 +3 

For more details on these errors, see this check.

Results for commit f6d15ec. ± Comparison against base commit 689759d.

This pull request removes 2627 tests.
org.eclipse.pde.api.tools.anttasks.tests.ApiToolingAnalysisAntTaskTests ‑ test1
org.eclipse.pde.api.tools.anttasks.tests.ApiToolingAnalysisAntTaskTests ‑ test2
org.eclipse.pde.api.tools.anttasks.tests.ApiToolingAnalysisAntTaskTests ‑ test3
org.eclipse.pde.api.tools.anttasks.tests.ApiToolingAnalysisAntTaskTests ‑ test4
org.eclipse.pde.api.tools.anttasks.tests.ApiToolingAnalysisAntTaskTests ‑ test5
org.eclipse.pde.api.tools.anttasks.tests.ApiToolingAnalysisAntTaskTests ‑ test6
org.eclipse.pde.api.tools.anttasks.tests.ApiToolingAnalysisAntTaskTests ‑ test7
org.eclipse.pde.api.tools.anttasks.tests.ApiToolingApiFreezeAntTaskTests ‑ test1
org.eclipse.pde.api.tools.anttasks.tests.ApiToolingApiFreezeAntTaskTests ‑ test2
org.eclipse.pde.api.tools.anttasks.tests.ApiToolingApiFreezeAntTaskTests ‑ test3
…

♻️ This comment has been updated with latest results.

@HannesWell HannesWell changed the title Replace APIs using equinox VersionRange and PluginRegistry.PluginFilter Rework PluginRegistry API and introduce VersionMatchRule enum Jul 15, 2024
@HannesWell
Copy link
Member Author

This PR now focus only on the rework of the PluginRegistry API and has a adjustments of the pde.project description API moved out into #1340.

In the meantime I made greater changes to the PluginRegistry.findModel(s)() methods and introduced a VersionMatchRule enum. VersionMatchRule represents the rules currently defined in IMatchRules as int constants and handled in various places in the PDE code base in a type-safe manner and also provides the represented logic in one place.

The rework is not yet completely finished, but the overall direction is settled and I would like to gather feedback already.
On the long run the goal is also to replace IMatchRules respectively the usage of int literals by the new VersionMatchRule enum.

*/
@Deprecated(forRemoval = true, since = "3.19 (removal in 2026-09 or later)")
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Btw. what do you think about mentioning the earliest removal date here?
I think it would help consumers to understand better when the actual removal will happen earliest.

Comment on lines +333 to +336
public static Stream<IPluginModelBase> findModels(String id, String version, VersionMatchRule matchRule) {
Version reference = version != null ? Version.valueOf(version) : null;
return selectModels(id, version != null ? p -> matchRule.matches(VersionUtil.getVersion(p), reference) : null);
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of having one overload of findModel(s) that accepts a VersionRange and one that accepts a version String plus a VersionMatchRule we could also just provide one method with a VersionRange.
With the new VersionMatchRule one would then use

findModel("foo.bar", EQUIVALENT.rangeFor(version))

instead of

findModel("foo.bar", versionStr, EQUIVALENT)

Of course the level of convenience is also influenced from if one has a Version object or a version String.
Maybe this justifies to keep both so in case one has a Version object the former solution can be used and if one has a version String the latter approach is nicer.

I'm torn on this question.

Besides replacing the Equinox resolver VersionRange by the osgi
VersionRange, this also remove the rarely used filter parameter from the
findModel(s)() methods. Instead of a List the findModels() methods now
return a stream that can also be filtered if desired.

In all cases plug-ins with null IPluginBase or ID are now discarded.

Part of eclipse-pde#1069
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

Successfully merging this pull request may close these issues.

None yet

1 participant