如何在运行时获取自定义Eclipse功能的版本号? [英] How can I obtain the version number of a custom Eclipse feature at runtime?

查看:307
本文介绍了如何在运行时获取自定义Eclipse功能的版本号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在其视角的标题栏中显示我正在开发的自定义Eclipse功能的版本号。有没有办法从运行时插件和/或工作台获取版本号?

I would like to display the version number of a custom Eclipse feature I am developing in the title bar of its perspective. Is there a way to obtain the version number from the runtime plugin and/or workbench?

推荐答案



Something like:

Platform.getBundle("my.feature.id").getHeaders().get("Bundle-Version");

应该这样做。

注意(从这个主题),它不能在任何地方使用 插件本身:

this.getBundle()在AFTER super.start之前无效(BundleContext)已经在您的插件上调用。

所以如果您在构造函数中使用 this.getBundle()或者在 start(BundleContext)之前调用 super.start(),那么它将返回null。

Note (from this thread) that it can not be used anywhere within the plugin itself:
this.getBundle() is not valid until AFTER super.start(BundleContext) has been called on your plugin.
So if you are using this.getBundle() within your constructor or within your start(BundleContext) before calling super.start() then it will return null.

如果失败,你在这里有一个更完整的版本

If that fails, you have here a 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;
}

这篇关于如何在运行时获取自定义Eclipse功能的版本号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆