How can I get the version number of a custom Eclipse function at runtime?

I would like to show the version number of the custom Eclipse function that I am developing in the title of my perspective. Is there a way to get the version number from the runtime and / or working environment plugin?

+3
source share
4 answers

Sort of:

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

gotta do the trick.

( ), :
this.getBundle() , 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;
}
+6

:

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);
}
+1

@zvikico, , ( OSGi, ). - org.eclipse.core.runtime.Platform.getBundleGroupProviders() .

0

The version of what VonC provided to retrieve the primary version number of Eclipse, but one that does not reference inner classes (which you should avoid):

Platform.getBundle(PlatformUI.PLUGIN_ID).getHeaders().get("Bundle-Version");
0
source

Source: https://habr.com/ru/post/1707554/


All Articles