【发布时间】:2010-10-23 11:17:13
【问题描述】:
我想在其透视图的标题栏中显示我正在开发的自定义 Eclipse 功能的版本号。有没有办法从运行时插件和/或工作台获取版本号?
【问题讨论】:
标签: eclipse eclipse-plugin version eclipse-pde
我想在其透视图的标题栏中显示我正在开发的自定义 Eclipse 功能的版本号。有没有办法从运行时插件和/或工作台获取版本号?
【问题讨论】:
标签: eclipse eclipse-plugin version eclipse-pde
类似:
Platform.getBundle("my.feature.id").getHeaders().get("Bundle-Version");
应该可以解决问题。
请注意 (from this thread),它不能在插件本身内的任何地方使用:this.getBundle() 直到在您的插件上调用 super.start(BundleContext) 之后才有效。
因此,如果您在调用 super.start() 之前在构造函数或 start(BundleContext) 中使用 this.getBundle(),那么它将返回 null。
如果失败,这里有一个more complete "version":
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;
}
【讨论】:
我使用第一个选项:
protected void fillStatusLine(IStatusLineManager statusLine) {
statusItem = new StatusLineContributionItem("LastModificationDate"); //$NON-NLS-1$
statusItem.setText("Ultima Actualizaci\u00f3n: "); //$NON-NLS-1$
statusLine.add(statusItem);
Dictionary<String, String> directory = Platform.getBundle("ar.com.cse.balanza.core").getHeaders();
String version = directory.get("Bundle-Version");
statusItem = new StatusLineContributionItem("CopyRight"); //$NON-NLS-1$
statusItem.setText(Messages.AppActionBar_18);
statusLine.add(statusItem);
}
【讨论】:
正如@zvikico 上面所说,接受的答案不适用于功能,仅适用于插件(OSGi 捆绑包,功能不是)。获取有关已安装功能的信息的方法是通过org.eclipse.core.runtime.Platform.getBundleGroupProviders() 和described here。
【讨论】:
VonC 提供的用于检索主要 Eclipse 版本号的版本,但不引用内部类(您应该避免这样做):
Platform.getBundle(PlatformUI.PLUGIN_ID).getHeaders().get("Bundle-Version");
【讨论】: