Eclipse-plugin-dev: How to get current bundle version?
Asked Answered
C

2

13

In Eclipse plugin development: How to get current bundle version?

It is just in Manifest.MF

Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Nodeclipse
Bundle-SymbolicName: org.nodeclipse.ui;singleton:=true
Bundle-Version: 0.6.0.qualifier
Bundle-Activator: org.nodeclipse.ui.Activator
Require-Bundle: org.eclipse.ui,

However Java has method only to look at Bundle Implementation version getClass().getPackage().getImplementationVersion();

Croatia answered 9/10, 2013 at 2:26 Comment(0)
I
15

In a plug-in you can use:

Bundle bundle = Platform.getBundle("org.nodeeclipse.ui");
Version version = bundle.getVersion();

Version has getMajor, getMinor, getMicro, getQualifier methods.

Platform is org.eclipse.core.runtime.Platform

Intense answered 9/10, 2013 at 9:29 Comment(2)
I think this is too brittle. If the bundle name changes, this code will no longer work.Transpacific
@RaffiKhatchadourian If you want the bundle you are currently running in then, yes, use FrameworkUtil.getBundle. However when you are doing things like processing extension point definitions all you have is the plugin id so in that case use this method.Intense
V
25

In a more OSGi way, not having to know your name, and official standard way:

 Version version = FrameworkUtil.getBundle(getClass()).getVersion();

Notice that the bundle version you get is from the bundle from which the this was loaded. So do not put this in a convenience library in another bundle!

Villiers answered 10/10, 2013 at 6:30 Comment(0)
I
15

In a plug-in you can use:

Bundle bundle = Platform.getBundle("org.nodeeclipse.ui");
Version version = bundle.getVersion();

Version has getMajor, getMinor, getMicro, getQualifier methods.

Platform is org.eclipse.core.runtime.Platform

Intense answered 9/10, 2013 at 9:29 Comment(2)
I think this is too brittle. If the bundle name changes, this code will no longer work.Transpacific
@RaffiKhatchadourian If you want the bundle you are currently running in then, yes, use FrameworkUtil.getBundle. However when you are doing things like processing extension point definitions all you have is the plugin id so in that case use this method.Intense

© 2022 - 2024 — McMap. All rights reserved.