Execute a Maven Build from a Plugin Action

I have a plugin with a toolbar and on of the action is to first build a maven project and then deploy the artifact to a server.

The action (an AbstractProjectAction) is using a ProgressManager to show a progress bar and inside its run() method using ApplicationManager.getApplication().runReadAction(). Inside there it is executing Maven build with "MavenRunConfigurationType.runConfiguration(module.getProject(), params, null);".

 

When I do that I get in IntelliJ 15 CE I see this exception:

[ 105727] ERROR - llij.ide.plugins.PluginManager - Access is allowed from event dispatch thread only.
com.intellij.diagnostic.LogEventException: Access is allowed from event dispatch thread only.
at com.intellij.openapi.application.impl.ApplicationImpl.assertIsDispatchThread(ApplicationImpl.java:1114)
at com.intellij.openapi.application.impl.ApplicationImpl.assertIsDispatchThread(ApplicationImpl.java:1098)
at com.intellij.openapi.application.impl.ApplicationImpl.assertIsDispatchThread(ApplicationImpl.java:1090)
at com.intellij.openapi.fileEditor.impl.FileDocumentManagerImpl.saveAllDocuments(FileDocumentManagerImpl.java:331)
at com.intellij.openapi.fileEditor.impl.FileDocumentManagerImpl.saveAllDocuments(FileDocumentManagerImpl.java:324)
at com.intellij.execution.impl.DefaultJavaProgramRunner.doExecute(DefaultJavaProgramRunner.java:73)
at com.intellij.execution.runners.GenericProgramRunner$1.execute(GenericProgramRunner.java:43)
at com.intellij.execution.impl.ExecutionManagerImpl$5.run(ExecutionManagerImpl.java:376)
at com.intellij.execution.impl.ExecutionManagerImpl.compileAndRun(ExecutionManagerImpl.java:289)
at com.intellij.execution.impl.ExecutionManagerImpl.startRunProfile(ExecutionManagerImpl.java:419)
at com.intellij.execution.runners.GenericProgramRunner.execute(GenericProgramRunner.java:40)
at com.intellij.execution.runners.BaseProgramRunner.execute(BaseProgramRunner.java:61)
at com.intellij.execution.runners.GenericProgramRunner.execute(GenericProgramRunner.java:31)
at org.jetbrains.idea.maven.execution.MavenRunConfigurationType.runConfiguration(MavenRunConfigurationType.java:198)
at org.jetbrains.idea.maven.execution.MavenRunConfigurationType.runConfiguration(MavenRunConfigurationType.java:182)
at com.headwire.aem.tooling.intellij.communication.ServerConnectionManager.publishBundle(ServerConnectionManager.java:676)
at com.headwire.aem.tooling.intellij.communication.ServerConnectionManager.deployModule(ServerConnectionManager.java:490)
at com.headwire.aem.tooling.intellij.action.DeployToServerAction$1$1.run(DeployToServerAction.java:93)
at com.intellij.openapi.application.impl.ApplicationImpl.runReadAction(ApplicationImpl.java:951)
at com.headwire.aem.tooling.intellij.action.DeployToServerAction$1.run(DeployToServerAction.java:65)

I did not see this exception in IntelliJ 14 CE.

Is there a way to make this work executing a Maven Build from a Action?

I tried to use the ApplicationManager.getApplication().invokeLater() but then I could not make the runReadAction thread wait until the Maven Build completed. I tried to listen to Execution Events (Execution Topic) but either the calling thread would be finished before I got the event or ended up in a deadlock.

Cheers - Andy Schaefer

1 comment
Comment actions Permalink

I finally figured it out. The issue was that I used a Task.Modal in the Progress Manager which is executed on the Dispatcher Thread hence the deadlock.

 

Switching to Task.Backgroundable() to execute the action did solve the issue and I was able to wait for the Maven Build to finish before executing the deployment.

0

Please sign in to leave a comment.