Listen to pycharm run/debug events, and android studio gradle tasks.

Answered

I'm developing a plugin that does stuff before & after compilation / build events.


I used `CompileTask` & `<compiler.task execute="BEFORE" .... >` to catch the "before build" event.
I used `CompilationStatusListener` to catch the after execution event.

However, this only works on Intellij Idea, it doesn't work with android studio gradle tasks, even though it works with gradle on Idea.
But it works on AS when I Right-Click a folder and hit "build".
It also doesn't work at all in Pycharm.

What am I missing?

0
16 comments

See com.android.tools.idea.project.AndroidProjectBuildNotifications

0

@Yann Cebron
Thanks, which Android studio plugins/jars do I need to add to the classpath in order to use:

<depends>com.intellij.modules.androidstudio</depends>
0

@Yann Cebron
Yeah I know, I added almost all the jars in plugins/<pluginname>/lib and it's still not recognised.

0

Use

<depends>org.jetbrains.android</depends>
0

Well I cannot judge what "almost all the jars" means or not :)

0

I was hoping that you know which ones should be added. I'll try to add even more. These things really need a documentation.

0

android.jar is the necessary file. I'd recommend switching to Gradle setup to avoid all this manual hassle http://www.jetbrains.org/intellij/sdk/docs/basics/getting_started.html

0

Thanks! that was it.
Is there a a listener for Pycharm's interpreter events?

0

You can implement com.intellij.execution.ExecutionListener and register on ExecutionManager.EXECUTION_TOPIC, then listen specifically for Python runners/specific configurations

0

So I've been searching, but I couldn't find any info about specific Python processes/ runners.

0

There's com.jetbrains.python.run.PythonRunner and com.jetbrains.python.run.PythonRunConfiguration (or super com.jetbrains.python.run.AbstractPythonRunConfiguration)

0

so I did this (plugin.xml):

<depends optional="true" config-file="python_config.xml">com.intellij.modules.python</depends>

(python_config.xml):

<idea-plugin>
<project-components>
<component>
<implementation-class>PythonDrumroll</implementation-class>
</component>
</project-components>
</idea-plugin>

(PythonDrumroll):

class PythonDrumroll(private val project: Project) : Drumroll(project) {
init {
play("wow")
messages.subscribe(ExecutionManager.EXECUTION_TOPIC, object : ExecutionListener {
override fun processStarted(executorId: String, env: ExecutionEnvironment, handler: ProcessHandler) {
super.processStarted(executorId, env, handler)

println("hey kids!")
if (env.runProfile is PythonRunner)
play("drumroll_faded")
}
})
}
}

Drumroll:

open class Drumroll(private val project: Project) {

enum class BuildState { Success, Error, Warning }

protected val messages by lazy { project.messageBus.connect() }

//...
}

 

But it doesn't work, I also tried `AbstractPythonRunConfiguration<*>` instead of `PythonRunner` but still no luck.
I tried added the `play("wow") in `init` and it didn't play, which made me suspect the component isn't loaded.

I have the same setup with android and it works fine:

class AndroidDrumroll(private val project: Project) : Drumroll(project) {

init {
AndroidProjectBuildNotifications.subscribe(project) { ctx ->
//...
}
}
}

 

0

Are there any updates on this? I'm also trying to understand how to listen to PyCharm builds. I've tried

com.intellij.task.ProjectTaskListener

but it doesn't seem to fire and I haven't been able to find anything on https://plugins.jetbrains.com/intellij-platform-explorer/listeners

0

Please sign in to leave a comment.