PackageAdmin deprecated? [message #658414] |
Tue, 08 March 2011 07:23  |
Eclipse User |
|
|
|
In some of my JUnit tests, I use the PackageAdmin method:
public Bundle[] getBundles(String symbolicName, String versionRange);
to find a bundle that I know contains some of the data that I need for the test. In 3.7, where OSGi 4.3 is used, I see
that PackageAdmin is deprecated and that I'm supposed to use org.osgi.framework.wiring instead. Problem is, I don't find
any similar method in that package.
What is the preferred way of finding a bundle by it's symbolic id in 4.3?
Regards,
Thomas Hallgren
|
|
|
|
|
|
Re: PackageAdmin deprecated? [message #1075453 is a reply to message #1074688] |
Mon, 29 July 2013 09:04   |
Eclipse User |
|
|
|
Stephan Herrmann wrote on Sat, 27 July 2013 08:22Thomas Watson wrote on Tue, 08 March 2011 14:57Note that PackageAdmin is deprecated, but will not be removed any time soon in Equinox.
Does this answer still hold for Luna and beyond?
Yes, no plans to remove PackageAdmin implementation for the foreseeable future.
Quote:
Quote:OSGi has recommended that you iterate over the bundles to find the ones you need.
Assuming I would want to do s.t. like that, what would be the entry point for this?
For OSGi R6 there is new API. FrameworkAdmin.findProviders(Requirement). If you wanted to find all bundles with symbolic name "com.foo". Then it would look something like this:
FrameworkWiring fwkWiring = systemBundle.adapt(FrameworkWiring.class);
Collection<BundleCapability> comFooIdentities = fwkWiring.findProviders(
new Requirement(){
public String getNamespace() { return IdentityNamespace.IDENTITY_NAMESPACE; }
public Map<String, String> getDirectives() {
Collections.singletonMap(Namespace.REQUIREMENT_FILTER_DIRECTIVE,
"(osgi.identity=com.foo)");
}
public Map<String, Object> getAttributes() {
return Collections.EMPTY_MAP
}
public Resource getResource() {
return null;
}
}
);
After this you will have a Collection<BundleCapability> that contain osgi.identity capabilities all with the symbolic name "com.foo". You can then get to the bundle object behind each capability by calling BundleCapability.getRevision().getBundle().
See the PackageAdmin implementation for more:
http://git.eclipse.org/c/equinox/rt.equinox.framework.git/tree/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/legacy/PackageAdminImpl.java#n148
Quote:
Quote:So in the mean time I would stick with PackageAdmin for only the getBundles(String symbolicName, String versionRange) method.
Is this your recommendation also when I don't have a versionRange at hand and therefore pass null instead?
Yes, a null versionRange means any version. At this point moving away from PackageAdmin is not really a high priority in my mind. If it works for you then feel free to continue using it. I certainly do not plan to remove it from equinox any time soon.
Tom
|
|
|
|
Powered by
FUDForum. Page generated in 0.05479 seconds