How to find plugin id in eclipse rcp application
is there an API method to get the current plugin id?
note: my rcp app contains more than one plugin project, some of them do not contain Plugin class (Activator class)
so I can't get the plugin id in this way:
Plugin.getBundle().getSymbolicName();
In every plugin class, you must have your private instance variable for your plugin and you must implement the getInstance () method to return an instance reference, I believe you should already be doing this if you don't see the docomentaion reference for the Plugin class. After YorPluginClass1.getInstance().getBundle().getSymbolicName();
and YorPluginClass2.getInstance().getBundle().getSymbolicName();
should be specified that their respective symbolic plugin names should be returned.
I am using the following code in one of mine Activators
:
/**
* Returns the bundle id of the bundle that contains the provided object, or <code>null</code>
* if the bundle could not be determined.
*
* @param clazz the object to test
* @return the build ID or <code>null</code>
*/
public String getBundleId(Class<? extends Object> clazz) {
if (clazz == null) return null;
final PackageAdmin packageAdmin = getBundleAdmin();
if (packageAdmin == null) return null;
final Bundle source = packageAdmin.getBundle(clazz);
if (source == null || source.getSymbolicName() == null) return null;
return source.getSymbolicName();
}
/**
* Returns the OSGi Package Admin service, if available.
*/
public PackageAdmin getBundleAdmin() {
if (bundleTracker == null) {
bundleTracker = new ServiceTracker(getContext(), PackageAdmin.class.getName(), null);
bundleTracker.open();
}
return (PackageAdmin) bundleTracker.getService();
}
And yes, I know it is PackageAdmin
outdated, but I didn't have time to update it ...