런타임에 사용자 정의 이클립스 기능의 버전 번호를 어떻게 얻을 수 있습니까?

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

문제

제목 표시 줄에서 개발중인 사용자 정의 이클립스 기능의 버전 번호를 표시하고 싶습니다. 런타임 플러그인 및/또는 워크 벤치에서 버전 번호를 얻는 방법이 있습니까?

도움이 되었습니까?

해결책

같은 것 :

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

트릭을해야합니다.

메모 (이 스레드에서) 어디서나 사용할 수 없습니다 이내에 플러그인 자체 :
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;
}

다른 팁

첫 번째 옵션을 사용합니다.

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 번들, 기능이 아닌 OSGI 번들) 만 작동합니다. 설치된 기능에 대한 정보를 얻는 방법은 org.eclipse.core.runtime.Platform.getBundleGroupProviders() ~처럼 여기에 설명되어 있습니다.

기본 Eclipse 버전 번호를 검색하기 위해 VONC가 제공 한 버전이지만 내부 클래스를 참조하지 않는 버전 (수행하지 않아야합니다).

Platform.getBundle(PlatformUI.PLUGIN_ID).getHeaders().get("Bundle-Version");
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top