从Eclipse IConfigurationElement获取OSGI Bundle

Hay*_*ant 5 eclipse osgi

我正在寻找实现特定扩展点的扩展,并使用以下可接受的方法来执行此操作:

IExtensionRegistry extensionRegistry = Platform.getExtensionRegistry(); if(extensionRegistry == null){return TEMPLATES; }

IConfigurationElement [] config = extensionRegistry.getConfigurationElementsFor("com.ibm.im.launchpoint.templates.template");

然后我想获得定义包的版本.我会使用以下API,但不推荐使用PluginVersionIdentifier的API:

for(IConfigurationElement e:config){BlueprintTemplate template = new BlueprintTemplate();

IExtension declaringExtension = e.getDeclaringExtension(); PluginVersionIdentifier versionIdentifier = declaringExtension.getDeclaringPluginDescriptor().getVersionIdentifier();

我在新的API中找不到替代方案 - 即从IConfigurationElement,我如何获得bundle的版本ID描述符.显然,从Bundle我可以使用Bundle.getHeaders()获取版本,获取Bundle-Version值 - 但我如何获得Bundle?Platform.getBundle(bundleId)是不够的,因为我可能安装了同一个bundle的多个版本,我需要知道我是谁.目前我有鸡肉和鸡蛋的情况,我唯一的解决方案是上面弃用的API.

Zol*_*lyi 0

我建议浏览一下 Javadoc 弃用描述,替换内容已记录在案。我找到了以下代码,但没有测试。

String contributor = e.getDeclaringExtension().getContributor().getName();
Bundle bundle = Platform.getBundle(contributor);
Version versionInfo = bundle.getVersion();
Run Code Online (Sandbox Code Playgroud)

出于好奇:为什么需要获取扩展插件的版本?据我所知,扩展点机制的目标是分离扩展器的特定信息,只需要扩展(plugin.xml)或引用的代码中描述的信息。