Что-то вроде:
Platform.getBundle("my.feature.id").getHeaders().get("Bundle-Version");
должен сделать трюк.
Обратите внимание ( из этой темы ), что его нельзя использовать нигде внутри самого плагина:
this.getBundle()
недействителен, пока ПОСЛЕ super.start(BundleContext)
не будет вызвано для вашего плагина.
Так что если вы используете this.getBundle()
в своем конструкторе или в start(BundleContext)
перед вызовом super.start()
, тогда он вернет ноль.
Если это не помогло, у вас есть более полная "версия" :
public static String getPlatformVersion() {
String version = null;
try {
Dictionary dictionary =
org.eclipse.ui.internal.WorkbenchPlugin.getDefault().getBundle().getHeaders();
version = (String) dictionary.get("Bundle-Version"); //$NON-NLS-1$
} catch (NoClassDefFoundError e) {
version = getProductVersion();
}
return version;
}
public static String getProductVersion() {
String version = null;
try {
// this approach fails in "Rational Application Developer 6.0.1"
IProduct product = Platform.getProduct();
String aboutText = product.getProperty("aboutText"); //$NON-NLS-1$
String pattern = "Version: (.*)\n"; //$NON-NLS-1$
Pattern p = Pattern.compile(pattern);
Matcher m = p.matcher(aboutText);
boolean found = m.find();
if (found) {
version = m.group(1);
}
} catch (Exception e) {
}
return version;
}