I am experimenting with plugin DevKit.
What I want to do:
- On IntelliJ project open check if folder contains configuration file with specific filename; if it does then read that file and import referenced Maven projects as external model modules.
What I did:
- got some directions from old topics and platform examples:
- registered
postStartupActivity -
<extensions defaultExtensionNs="com.intellij"> <postStartupActivity implementation="my.stuff.ProjectOpenStartupActivity"/> </extensions> - implemented
ProjectActivityfor the extension point
import com.intellij.ide.actions.ImportModuleAction
internal class ProjectOpenStartupActivity : ProjectActivity, DumbAware {
override suspend fun execute(project: Project) {
val configuredPaths: List<String> = readWellKnownConfig()
val mavenProvider = ImportModuleAction.getProviders(null)
.firstOrNull { it.name == "Maven" }
writeAction {
for (mavenProjectPath in configuredPaths) { // /path/to/package-one/pom.xml
val pomFile = LocalFileSystem.getInstance()
.refreshAndFindFileByPath(mavenProjectPath) // file:///path/to/package-one/pom.xml
if (!mavenProvider.canImport(pomFile, project)) {
continue
}
val wizard = ImportModuleAction.createImportWizard(project, null, pomFile, mavenProvider)!!
ImportModuleAction.createFromWizard(project, wizard)
}
}
}
}
What I observe:
-
never ending progress bar, looks like importer got the intention but is blocked/waiting forever.
-
No exceptions are reported
-
if cancelled, the same project could be imported in a few seconds from UI (File → New → Module from existing sources → import module from external model
So question is: what could be amiss? And where should I look for any leads on what went wrong? Looks like waiting on (write?) lock, but if so then what is a proper way to invoke ImportModuleAction?
Any help is much appreciated.
General environment details:
platformType = IC
platformVersion = 2024.2.5
platformBundledPlugins = org.jetbrains.idea.maven, com.intellij.java, org.jetbrains.idea.maven.model, org.jetbrains.idea.maven.server.api
