【问题标题】:Detecting installed plugin in Eclipse在 Eclipse 中检测已安装的插件
【发布时间】:2021-12-11 05:51:51
【问题描述】:

我想从我正在维护的 Eclipse 插件中检测是否存在插件。从关于这个主题的其他几个问题来看,这似乎很困难。

我要检测的插件提供了一个视图。因此,以下工作,但我希望存在一个更漂亮的选择:

public static boolean internalPluginInstalled() {
    IExtensionRegistry reg = Platform.getExtensionRegistry();       
    IExtensionPoint point = reg.getExtensionPoint("org.eclipse.ui.views");
    IExtension[] extensions = point.getExtensions();
    for(IExtension extension : extensions) {
        IConfigurationElement[] configs = extension.getConfigurationElements();
        for (IConfigurationElement config : configs) {
            if (config.getName().equals("view") && config.getAttribute("id").equals("view.id.goes.here")) {
                return true;
            }
        }
    }
    return false;
}

【问题讨论】:

    标签: eclipse eclipse-plugin


    【解决方案1】:

    使用Platform.getBundle (org.eclipse.core.runtime.Platform):

    Bundle bundle = Platform.getBundle("plugin id");
    

    如果安装了插件,bundle 将不为空。

    bundle.getState() 会返回插件的确切状态 - 如果插件已启动,则为 Bundle.ACTIVE

    【讨论】:

      猜你喜欢
      • 2010-10-12
      • 2013-02-22
      • 1970-01-01
      • 1970-01-01
      • 2015-10-20
      • 2019-11-01
      • 2015-01-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多