如何在运行时获取自定义Eclipse功能的版本号?

mun*_*ger 3 eclipse eclipse-pde eclipse-plugin version

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

Von*_*onC 6

就像是:

Platform.getBundle("my.feature.id").getHeaders().get("Bundle-Version");
Run Code Online (Sandbox Code Playgroud)

应该做的伎俩.

注意(从这个线程)它不能插件本身的任何地方使用:在你的插件上调用
this.getBundle()AFTER之前无效super.start(BundleContext).
因此,如果您this.getBundle()在构造函数中或在start(BundleContext)调用之前使用super.start()它,那么它将返回null.


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

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;
}
Run Code Online (Sandbox Code Playgroud)

  • AFAIK,这适用于插件,但不适用于功能.我不确定是否有获得功能版本的方法. (3认同)