Skip to content

Moving PublishedGradleVersionsWrapper to a declarative OSGi service#1152

Open
vogella wants to merge 1 commit into
eclipse-buildship:masterfrom
vogellacompany:ds-work
Open

Moving PublishedGradleVersionsWrapper to a declarative OSGi service#1152
vogella wants to merge 1 commit into
eclipse-buildship:masterfrom
vogellacompany:ds-work

Conversation

@vogella
Copy link
Copy Markdown
Contributor

@vogella vogella commented Apr 22, 2022

With this change the PublishedGradleVersionsWrapper is published as
declarative OSGi service instead registering it via the activator.

For #1151

Fixes #?

Context

* information is provided. This handles, for example, those scenarios where the
* versions cannot be retrieved because the user is behind a proxy or offline.
*/
@Component(property = { "service.ranking:Integer=1" }, service = PublishedGradleVersionsWrapper.class)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do you really need a non default service rank here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Do you really need a non default service rank here?

If you look at the activator it also sets this ranking so I just replicated it.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is a final class, it is very unlikley that there are more than one service and even if they seem to be totaly eqivialent so this is most probably obsolete.

Service ranking is only important if there are multiple service of the same type and you need to have some kind of ordering of them.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is a final class, it is very unlikley that there are more than one service and even if they seem to be totaly eqivialent so this is most probably obsolete.

Service ranking is only important if there are multiple service of the same type and you need to have some kind of ordering of them.

Agree, but changing logic AND implementation is IMHO a bad way. So leaving the priority in should allow @donat to review this easier. And next step could be to remove with a follow-up commit.


public static PublishedGradleVersionsWrapper publishedGradleVersions() {
return (PublishedGradleVersionsWrapper) getInstance().publishedGradleVersionsServiceTracker.getService();
BundleContext bundleContext = FrameworkUtil.getBundle(CorePlugin.class).getBundleContext();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

How is the tracker closed in your example?

Copy link
Copy Markdown
Contributor

@laeubi laeubi Apr 22, 2022

Choose a reason for hiding this comment

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

All services are automatically freed when the bundle stops, you can of course clear them manually if you like also see for a more complete example:

https://github.com/eclipse-platform/eclipse.platform.runtime/pull/28/files

In the current code you do not check for null and you increment the use-count on each call.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Your decisions of course, I usually try to avoid migrating useless/outdated stuff as one has to test this twice then or no one feels to change this later on.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks, I update the PR with your suggestion.

With this change the PublishedGradleVersionsWrapper is published as
declarative OSGi service instead registering it via the activator.

For eclipse-buildship#1151
}

private static <T> T getService(Class<T> service) {
BundleContext context = plugin.getBundle().getBundleContext();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

you might want to check if the plugin !=null

@donat donat force-pushed the master branch 5 times, most recently from 7e55112 to 7040f04 Compare September 13, 2023 08:59
@donat donat force-pushed the master branch 19 times, most recently from 4c6e8d6 to adde486 Compare January 16, 2025 17:40
@donat donat force-pushed the master branch 4 times, most recently from ffec47b to 03dc167 Compare January 21, 2025 13:05
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.

2 participants