[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [equinox-dev] What is the best way to get the version of a bundle

Pascal, from which perspective would you like to get the bundle version?

From the Bundle itself:

org.osgi.framework.Version version = org.osgi.framework.Bundle.getVersion();

Through the resolver API (arguably a little trickier):

Map<org.osgi.resource.Resource,List<org.osgi.resource.Wire>> results = org.osgi.service.resolver.Resolver.resolve(org.osgi.service.resolver.ResolveContext ctx);
Resource resource = results.keySet().iterator().next();
List<Capability> capabilities = resource.getCapabilities(IdentityNamespace.IDENTITY_NAMESPACE);
Map<String,Object> attributes = capabilities.get(0).getAttributes();
org.osgi.framework.Version version = (org.osgi.framework.Version)attributes.get(IdentityNamespace.CAPABILITY_VERSION_ATTRIBUTE);

There are a number of convenience APIs as well, but as I said earlier it really depends from which perspective you are trying... from a running framework or from some external agent analyzing a set of bundles.

- Ray

On Tue, Dec 13, 2016 at 9:45 PM, Pascal Rapicault <pascal@xxxxxxxxxxxxx> wrote:
With Platform.getBundle officially removed, and PackageAdmin on its way out, could someone indicate the API of choice (and recommended code snippet) to use to get the version of a given bundle?

equinox-dev mailing list
To change your delivery options, retrieve your password, or unsubscribe from this list, visit

Raymond AugÃÂ(@rotty3000)
Senior Software ArchitectÂLiferay, Inc.Â(@Liferay)
Board Member & EEG Co-Chair, OSGi Alliance (@OSGiAlliance)