我想在其透视图的标题栏中显示我正在开发的自定义 Eclipse 功能的版本号。有没有办法从运行时插件和/或工作台获取版本号?
问问题
5332 次
4 回答
6
就像是:
Platform.getBundle("my.feature.id").getHeaders().get("Bundle-Version");
应该做的伎俩。
注意(来自这个线程)它不能在插件本身的任何地方使用:在插件上调用
this.getBundle()
AFTER 之前无效。
因此,如果您在构造函数中或在调用之前使用,那么它将返回 null。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;
}
于 2009-05-03T17:54:59.700 回答
1
我使用第一个选项:
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);
}
于 2011-12-02T16:13:07.480 回答
0
正如@zvikico 上面所说,接受的答案不适用于功能,仅适用于插件(OSGi 捆绑包,功能不是)。获取有关已安装功能的信息的方法是通过这里描述org.eclipse.core.runtime.Platform.getBundleGroupProviders()
的。
于 2013-03-13T20:14:03.600 回答
0
VonC 提供的用于检索主要 Eclipse 版本号的版本,但不引用内部类(您应该避免这样做):
Platform.getBundle(PlatformUI.PLUGIN_ID).getHeaders().get("Bundle-Version");
于 2013-07-08T20:29:23.050 回答