Communicate between two plugins using MessageBus Follow
Answered
I've created two plugins and I'm trying to get them to communicate. The implementation I'm using is shown below. Plugin B still isn't receiving the message from Plugin A. What am I doing wrong? Or is there another way I can accomplish this?
Plugin A: com.plugina.analysis
MarkerNotifier is implemented this way.
public interface MarkerNotifier {
Topic<MarkerNotifier> FILE_NOTIFIER_TOPIC = Topic.create("New Markers", MarkerNotifier.class);
void loadNewMarkers();
}
This is how I send the update from the plugin.
MessageBus messageBus = activeProject.getMessageBus();
MarkerNotifier publisher = messageBus.syncPublisher(MarkerNotifier.FILE_NOTIFIER_TOPIC);
publisher.loadNewMarkers();
Plugin B: com.pluginb.viewer
Plugin B depends on Plugin A.
<depends>com.plugina.analysis</depends>
The jars from Plugin A are placed the a libs folder in Plugin B.
compile fileTree(include: ['*.jar'], dir: 'libs')
I listen to the topic using the following code:
MessageBus bus = project.getMessageBus();
bus.connect().subscribe(MarkerNotifier.FILE_NOTIFIER_TOPIC, new MarkerNotifier() {
@Override
public void loadNewMarkers() {
Notifications.Bus.notify(new Notification(Constants.PLUGIN_GROUP_DISPLAY_ID, resource.getString("Messages.Title.SuggestStarted"), "Markers generated", NotificationType.INFORMATION));
}
});
Please sign in to leave a comment.
Please show/link full sources of both sides.
The project isn't public as yet so I can't share the full sources. What specific classes or configuration do you need?
Any suggestions or online code examples I can follow?
>The jars from Plugin A are placed the a libs folder in Plugin B.
This might be the potential issue: plugin B should not use its own copy of MarkerNotifier, but rely on the plugin A (it should be available in the classpath, as B depends on A).
How would I add it to the classpath?
There is documentation for doing this when using DevKit but I'm using Gradle.
http://www.jetbrains.org/intellij/sdk/docs/basics/plugin_structure/plugin_dependencies.html
https://github.com/JetBrains/gradle-intellij-plugin#configuration
Help states you can also use project(':subproject') instead of plugin ID in Plugin Repository, but I can't find an example for you.
I've tried adding the PluginA as a module to PluginB project. Then I tried using project(':subproject') to include the project but I get an error. This should be placed in the dependencies section of the build.gradle file? Subproject should be the name of the project/module?
@Oshando, everything looks fine to me. Could you share the sources to recreate the problem?