Starting plugin with a non UI contribution [message #1821672] |
Tue, 18 February 2020 08:12  |
Eclipse User |
|
|
|
Hi all,
I got two plugin:
the first one contains all the logic of the user experience, i.e. button, text area and so on, and declare an extension point
<plugin>
<extension-point id="any.id" name="Save" schema="any.id.exsd"/>
...
</plugin>
#################
#### any.id.exsd ####
#################
<element name="client">
<complexType>
<attribute name="class" type="string">
<annotation>
<documentation>
</documentation>
<appinfo>
<meta.attribute kind="java" basedOn=":my.package.ISave"/>
</appinfo>
</annotation>
</attribute>
</complexType>
</element>
the purpose of this extension is to store some data to a datastore.
the second one contains only the logic of implementing the way to persist the data, it implements the any.id plugin
<plugin>
<extension point="any.id">
<client class="another.package.SaveToDatabase">
</client>
</extension>
....
</plugin>
where, obviusly SaveToDatabase class implement the ISave interface.
Given that there's many way to store the data, a database is only one of those, the second plugin is provided via a p2 repository, it means we don't know at deploy time of the product which plugin is available.
So when I try to invoke the implementors of my extension point via the following code
String saveExtensionPointId = "any.id";
IConfigurationElement[] config = Platform.getExtensionRegistry().getConfigurationElementsFor(saveExtensionPointId);
Arrays.asList(config).forEach(c -> {
try {
ISave s = (ISaveCounter) c.createExecutableExtension("class");
s.save(...);
} catch (Exception e) {
}
});
the config[] is empty, which means the second plugin has not been started, the eclipse rcp framework did not analyze the plugin itself and register the extension point to the given id.
The only way I get everything works fine is
to deploy both the plugin in the same product, in a monolithic way, and declare the autostart for second plugin, but in this way I did not have the advantages of the repo.
or
declare some UI object, such as a menu, which do nothing, only to have the Activator started.
Not elegant at all.
PS: changing the Bundle-ActivationPolicy: makes no effect
Am I missing something?
Or I am doing something wrong?
Hope everything is clear in order to understand what is wrong.
TIA.
|
|
|
|
|
Re: Starting plugin with a non UI contribution [message #1821958 is a reply to message #1821949] |
Mon, 24 February 2020 09:01  |
Eclipse User |
|
|
|
I missed your comment on the empty config array. AFIAK, the configuration elements are available before a plugin is active, i.e. as long as the plugin is resolved.
getConfigurationElementsFor "Returns an empty array if the extension point does not exist, has no extensions configured, or none of the extensions contain configuration elements"
Observations:
- "any.id" is not a valid extension-point id. I guess that is from anonymizing your example. Do not a fully qualified name in your plugin, it will automatically be prefixed with your plugin ID. Do use the fully qualified name in your second plugin that refers to the extension point.
- use RegistryFactory.getRegistry() instead of Platform.getExtensionRegistry()
If this doesn't help, you could try to use an debugger on ExtensionRegistry#getConfigurationElementsFor, to see if the extension point is correctly registered.
|
|
|
Powered by
FUDForum. Page generated in 0.04782 seconds