tags:

views:

51

answers:

1

Hi there,

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.

A: 

I suggest browsing a bit the Javadoc deprecation descriptions, the replacement is documented. I found the following code, but did not test it.

String contributor = e.getDeclaringExtension().getContributor().getName();
Bundle bundle = Platform.getBundle(contributor);
Version versionInfo = bundle.getVersion();

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.

Zoltán Ujhelyi
again, this doesn't really help me, since there might be multiple bundles with that ID, but only one of them within which THIS extension is defined.Another point, Bundle does not have a getVersion method.The reason I need this is that I am registering a 'document template' as an extension point, and may have different versions of this template. So when a template loads, I'd like to know which version it is, for notation etc.. For now, I have using an extra attribute in the schema for my extension point, which is a shame.
Hayden Marchant
I think, that extra attribute is the better solution. This way it is possible to update the plug-in without updating the extension version, and without modifying the receiver to update for the new version.It is interesting, that the bundle does not contain the getVersion() method. Maybe it is a new method in Eclipse 3.6, that I was using when researched the contributor.
Zoltán Ujhelyi