public interface DispatchServices extends ExtensionPoint {
void printMsg();
}
I have then created a dummy plugin that implements that:
public class TestPlugin extends Plugin {
public TestPlugin(PluginWrapper wrapper) {
super(wrapper);
}
@Extension
public static class TestDispatcher implements DispatchServices {
@Overrides
public void printMsg() {
System.out.println("Test dispatcher called");
}
}
}
I then build the extension into a zip file using maven. That all seems to be fine(ish), the only notable problem is that my extensions.idx file is empty. I have enabled annotations inside IntelliJ but that is not the end of the world as I can manually add the package and class to the extensions.idx. So my extensions.idx file now contains:
com.example.plugin.TestDispatcher
I then basically have copied and pasted the demo code into a class in my core host application:
PluginManager pluginManager = new DefaultPluginManager(extensionDirectory);
pluginManager.loadPlugins();
pluginManager.startPlugins();
List<DispatchServices> greetings = pluginManager.getExtensions(DispatchServices.class);
System.out.println(String.format("Found %d extensions for extension point '%s'", greetings.size(), DispatchServices.class.getName()));
for (DispatchServices greeting : greetings) {
System.out.println(">>> " + greeting.toString());
}
// print extensions from classpath (non plugin)
System.out.println("Extensions added by classpath:");
Set<String> extensionClassNames = pluginManager.getExtensionClassNames(null);
for (String extension : extensionClassNames) {
System.out.println(" " + extension);
}
// print extensions for each started plugin
List<PluginWrapper> startedPlugins = pluginManager.getStartedPlugins();
for (PluginWrapper plugin : startedPlugins) {
String pluginId = plugin.getDescriptor().getPluginId();
System.out.println(String.format("Extensions added by plugin '%s':", pluginId));
extensionClassNames = pluginManager.getExtensionClassNames(pluginId);
for (String extension : extensionClassNames) {
System.out.println(" " + extension);
}
}
What I get printed to the console is:
Found 0 extensions for extension point 'com.example.api.dispatch.DispatchServices'
Extensions added by classpath:
org.restlet.ext.jackson.JacksonConverter
Extensions added by plugin 'test-plugin':
com.example.plugin.TestDispatcher
So the plugin is registered, started and the extension seems to be added by the plugin. Now what I don't understand is why I have no 0 extensions for 'com.example.api.dispatch.DispatchServices'? TestDispatcher implements DispatchServices so logically i would have thought that I should have 1 extension declared. I cant possibly look for it under the implementation name because that would defy the point of runtime extensions.
I would really appreciate any help in either my understanding or implementation.
Thanks in advance for any help.
I'm loving this framework. Great project.
Good point. Note sure why I didn't try that!