从 Eclipse IConfigurationElement 获取 OSGI Bundle
我正在寻找实现特定扩展点的扩展,并使用以下可接受的方法来执行此操作:
IExtensionRegistry extensionRegistry = Platform.getExtensionRegistry(); if (extensionRegistry == null) { 返回模板; IConfigurationElement
[] config = extensionRegistry.getConfigurationElementsFor("com.ibm.im.launchpoint.templates.template");
然后我想获取定义包的版本。我将使用以下 API,但不推荐使用 PluginVersionIdentifier 的 API:
for (IConfigurationElement e : config) { BlueprintTemplate 模板 = new BlueprintTemplate();
IExtension declaringExtension = e.getDeclaringExtension(); PluginVersionIdentifier versionIdentifier = declaringExtension.getDeclaringPluginDescriptor().getVersionIdentifier();
我在新 API 中找不到替代方案 - 即从 IConfigurationElement 中,如何获取包的版本 id 描述符。显然,从 Bundle 中我可以使用 Bundle.getHeaders() 获取版本,获取 Bundle-Version 值 - 但我如何首先获取 Bundle ??? Platform.getBundle(bundleId) 是不够的,因为我可能安装了同一包的多个版本,并且我需要知道我是谁。现在我有一只鸡和一只鸡。鸡蛋的情况,我唯一的解决方案是上面不推荐使用的API。
I am looking for extensions that implement a specific extension point, and am using the following acceptable method to do this:
IExtensionRegistry extensionRegistry = Platform.getExtensionRegistry();
if (extensionRegistry == null) {
return TEMPLATES;
}
IConfigurationElement[] config = extensionRegistry.getConfigurationElementsFor("com.ibm.im.launchpoint.templates.template");
I then would like to get the version of the defining bundle. I would use the following API, but the API for PluginVersionIdentifier is deprecated:
for (IConfigurationElement e : config) {
BlueprintTemplate template = new BlueprintTemplate();
IExtension declaringExtension = e.getDeclaringExtension();
PluginVersionIdentifier versionIdentifier = declaringExtension.getDeclaringPluginDescriptor().getVersionIdentifier();
I could not find an alternative in the new API - i.e. from a IConfigurationElement, how do I get the version id descriptor of the bundle. Obviously, from the Bundle I can get the version using the Bundle.getHeaders(), getting the Bundle-Version value - but how do I get the Bundle in the first place??? Platform.getBundle(bundleId) is not enough since I might have multiple versions of same bundle installed, and I need to know who I am. At the moment I have a chicken & egg situation, and the only solution I have is the above deprecated API.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
所有这些信息都基于 Eclipse 3.6:
如果您位于 osgi 环境中,您的
IContributor
将是RegistryContributor
的实例,当然您有或没有这个问题。RegistryContributor 为您提供了两种方法:
getID()
和getActualID()
。如果这是从片段加载的,则 getID() 可能会返回主机包。getActualID()
始终加载贡献者代表的片段/包的 ID。您可以在BundleContext.getBundle(long id)
方法中使用此 id。这是一个片段:我使用了一种失败方法,如果 IContributor 将来获得新的默认实现,该方法将优雅地降级为非版本感知解决方案。捆绑包 ID 对于 OSGi 实例来说是唯一的,因此它将加载正确版本的捆绑包。
All this information is based on Eclipse 3.6:
Your
IContributor
will be an instance ofRegistryContributor
if you are in the osgi environment which of course you are or you wouldn't be having this issue.RegistryContributor gives you two methods:
getID()
andgetActualID()
.getID()
may return the host bundle if this was loaded from a fragment.getActualID()
always loads the id of the fragment/bundle the contributor represents. You can use this id in yourBundleContext.getBundle(long id)
method. Here is a snippet:I use a fall through method that will degrade gracefully to a non-version aware solution if IContributor gets a new default implementation in the future. The bundle id is unique to an instance of OSGi so it will load the correct version of the bundle.
我建议浏览一下 Javadoc 弃用描述,替换内容已记录在案。我找到了以下代码,但没有测试。
出于好奇:为什么需要获取扩展插件的版本?据我所知,扩展点机制的目标是分离扩展器的特定信息,只需要扩展(plugin.xml)或引用的代码中描述的信息。
I suggest browsing a bit the Javadoc deprecation descriptions, the replacement is documented. I found the following code, but did not test it.
Out of curiosity: why do you need to get the version of the extending plug-in? As far as I know, the goal of the extension point mechanism is to detach specific information about the extender, and only the information described in the extension (plugin.xml) or the referenced code is needed.