在 Eclipse 中检测已安装的插件
Detecting installed plugin in Eclipse
我想从我正在维护的 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;
}
使用Platform.getBundle
(org.eclipse.core.runtime.Platform
):
Bundle bundle = Platform.getBundle("plugin id");
bundle
如果安装了插件则为非空
bundle.getState()
returns 插件的确切状态 - Bundle.ACTIVE
如果插件已经启动。
我想从我正在维护的 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;
}
使用Platform.getBundle
(org.eclipse.core.runtime.Platform
):
Bundle bundle = Platform.getBundle("plugin id");
bundle
如果安装了插件则为非空
bundle.getState()
returns 插件的确切状态 - Bundle.ACTIVE
如果插件已经启动。