我尋找實現特定擴展點的擴展,並且正在使用以下可以接受的方法來做到這一點:在Eclipse IConfigurationElement得到OSGI包
IExtensionRegistry extensionRegistry = Platform.getExtensionRegistry();如果(extensionRegistry == null){ return TEMPLATES; }
IConfigurationElement [] config = extensionRegistry.getConfigurationElementsFor(「com.ibm.im.launchpoint.templates.template」);
然後我想要獲取定義包的版本。我將使用以下API,但不推薦使用API PluginVersionIdentifier:
(IConfigurationElement e:config)BlueprintTemplate template = new BlueprintTemplate();
IExtension declaringExtension = e.getDeclaringExtension(); PluginVersionIdentifier versionIdentifier = declaringExtension.getDeclaringPluginDescriptor()。getVersionIdentifier();
我無法在新的API中找到替代方案 - 即從IConfigurationElement中,我如何獲取捆綁的版本ID描述符。顯然,從Bundle中我可以使用Bundle.getHeaders()獲得版本,獲得Bundle-Version值 - 但是我怎樣才能獲得Bundle呢? Platform.getBundle(bundleId)是不夠的,因爲我可能安裝了同一個bundle的多個版本,我需要知道我是誰。目前,我有一個雞蛋情況,我唯一的解決方案是上面的棄用API。
再次,這並沒有真正幫助我,因爲可能會有多個包含該ID的捆綁包,但只有其中一個包含了該擴展的定義。 另一點,Bundle沒有getVersion方法。 我需要的原因是我正在註冊一個'文檔模板'作爲擴展點,並且可能有此模板的不同版本。所以當模板加載時,我想知道它是哪個版本,用於記號等等。現在,我在模式中爲擴展點使用了一個額外的屬性,這是一個恥辱。 – 2010-06-21 06:06:34
我認爲,這個額外的屬性是更好的解決方案。通過這種方式,可以在不更新擴展版本的情況下更新插件,也無需修改接收器即可更新新版本。 有趣的是,該包不包含getVersion()方法。也許這是Eclipse 3.6中的一個新方法,我在研究貢獻者時使用了它。 – 2010-06-21 07:55:04