実行時にカスタムEclipseフィーチャーのバージョン番号を取得するにはどうすればよいですか?

StackOverflow https://stackoverflow.com/questions/817299

質問

開発中のカスタムEclipse機能のバージョン番号を、そのパースペクティブのタイトルバーに表示したいと思います。ランタイムプラグインやワークベンチからバージョン番号を取得する方法はありますか?

役に立ちましたか?

解決

次のようなもの:

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

トリックを行う必要があります。

注(このスレッドから)プラグイン自体のどこでも 使用できます:
this.getBundle()は、プラグインで super.start(BundleContext)が呼び出されるまで有効ではありません。
したがって、コンストラクタ内または start(BundleContext)内で this.getBundle()を使用してから super.start()を呼び出す場合は、 nullを返します。


それが失敗した場合、ここにより完全な" 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()を介してこちらで説明しています。

Eclipseのプライマリバージョン番号を取得するためにVonCが提供したものの、内部クラスを参照しないバージョン(これは避けるべきです):

Platform.getBundle(PlatformUI.PLUGIN_ID).getHeaders().get("Bundle-Version");
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top