簡體   English   中英

如何在eclipse rcp應用程序中找到插件ID

[英]how to find plugin id in eclipse rcp application

是否有獲取當前插件 ID 的 API 方法?

注意:我的 rcp 應用程序包含多個插件項目,其中一些不包含插件類(Activator 類)

所以我無法使用這種方法獲取插件 ID:

Plugin.getBundle().getSymbolicName();

在每個插件類中,你必須有你的插件的私有靜態實例變量,並且你應該實現一個 getInstance() 方法來返回對實例的引用,我相信你一定已經這樣做了,如果沒有看到參考文檔插件類。 YorPluginClass1.getInstance().getBundle().getSymbolicName(); YorPluginClass2.getInstance().getBundle().getSymbolicName(); 應該給出應該返回它們各自插件的符號名稱。

我在其中一個Activators使用以下代碼:

/**
 * Returns the bundle id of the bundle that contains the provided object, or <code>null</code>
 * if the bundle could not be determined.
 * 
 * @param clazz the object to test
 * @return the build ID or <code>null</code>
 */
public String getBundleId(Class<? extends Object> clazz) {
    if (clazz == null) return null;

    final PackageAdmin packageAdmin = getBundleAdmin();
    if (packageAdmin == null) return null;

    final Bundle source = packageAdmin.getBundle(clazz);
    if (source == null || source.getSymbolicName() == null) return null;

    return source.getSymbolicName();
}

/**
 * Returns the OSGi Package Admin service, if available.
 */
public PackageAdmin getBundleAdmin() {
    if (bundleTracker == null) {
        bundleTracker = new ServiceTracker(getContext(), PackageAdmin.class.getName(), null);
        bundleTracker.open();
    }
    return (PackageAdmin) bundleTracker.getService();
}

是的,我知道PackageAdmin已被棄用,但我還沒有時間更新它...

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM