get notified when a maven project is imported
Hi -
In my plugin I create and open a maven project in IDEA.
I would like to do something when project has been successfully imported. As far as I can see, StartupManager.getInstance(project).registerPostStartupActivity etc get called to early. The modules are not yet available - ModuleManager.getInstance(project).findModuleByName(...) returns null.
Same with org.jetbrains.idea.maven.utils.MavenUtil#runWhenInitialized which looked more promising.
How can I know when a project is properly imported from maven and the modules are available?
thanks, jamie
Please sign in to leave a comment.
How do you create and open the project?
I just create a dir, write some pom files to the dir, then call com.intellij.ide.impl.ProjectUtil#openOrImport
I just create a directory, write some pom files to the directory, then call com.intellij.ide.impl.ProjectUtil.openOrImport
Sorry if this comment is duplicated, my previous one is "Pending Approval" which I haven't seen before.
You can try the following:
Also, since 2017.2 the following listener will be available https://github.com/JetBrains/intellij-community/blob/50a1dba045fd3ff57e2ce825da077afa4225110a/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenImportListener.java#L31
Awesome, thanks. Unfortunately the code you gave me in the previous comment returned immediately, and the modules were not available.
For now I settled for a "module added" listener.
@Vladislav Soroka How do I register that listener?
See documentation of Messaging API at http://www.jetbrains.org/intellij/sdk/docs/reference_guide/messaging_infrastructure.html
Usually, project is available as a method parameter and if I used the above mentioned method, then each time that method is invoked, a new Listener will be subscribed. Is there a sort of a central place (like plugin.xml) in code base where I can subscribe through a listener only once.
You can use project service or component.
http://www.jetbrains.org/intellij/sdk/docs/basics/plugin_structure/plugin_services.html#how-to-declare-a-service