Gradle task execution
Hello!
1) In my plugin I use com.intellij.openapi.externalSystem.util.ExternalSystemUtil.runTask method to run gradle task. I pass com.intellij.openapi.externalSystem.task.TaskCallback instance to this method. TaskCallback has 2 methods: onSuccess and onFailure. But anytime when I start gradle task, onSuccess is invoked. Even if task wasn't executed or error was thrown. Therefore TaskCallback -- bad choice for me. I want to be notified when task is completed or failed. How can I do this?
P.S. I have custom task of custom Gradle-plugin. In particular, this task installs apk on device. But when 'error: no devices/emulators found' shows in console output, TaskCallback.onSuccess is invoked. I expected onFailure in this case. Maybe, should I use something else API for my purpose?
2) Also I want to be able to stop task execution. I see that 'Stop' action (red square) is a good solution for this. But how to place this action into my custom toolbar (inside custom tool window) programmatically so that to get notifications when this action was invoked?
I add 'Stop' action to group in my plugin.xml. And add the following code:
val actionManager = ActionManager.getInstance()
val group = actionManager.getAction("my_group_id") as ActionGroup
val toolbar = actionManager.createActionToolbar(ActionPlaces.UNKNOWN, group, false)
panel = SimpleToolWindowPanel(false, true).apply {
setToolbar(toolbar.component)
setContent(...)
}
// where 'panel' is main JPanel
But when I launch an application (in Android Studio), the 'Stop' action inside my custom toolbar remains inactive, however the original 'Stop' action inside main top panel (where 'Debug', 'Run', etc.) becomes active (a red color). How can I make my 'Stop' action have the same behavior as the original?
请先登录再写评论。
> But when 'error: no devices/emulators found' shows in console output, TaskCallback.onSuccess is invoked.
Please make sure, that when invoked from console, this task error output also causes build to fail.
If a task only prints message to console, but does not notify Gradle build system about failure (e.g., does not throw an exception), invocation will still be considered successful and TaskCallback.onSuccess will be invoked
> I add 'Stop' action to group in my plugin.xml.
Please, share the related plugin.xml fragment
> But when 'error: no devices/emulators found' shows in console output, TaskCallback.onSuccess is invoked
It throws org.gradle.api.tasks.TaskExecutionException
> I add 'Stop' action to group in my plugin.xml.
My plugin.xml fragment (I changed group id):
Anybody will help me?
I apologize for the delay.
I found out, that there is a difference in behavior between Intellij IDEA and Android Studio (or Android project in IntelliJ).
While former behaves as expected (with failure status in UI and onFailure() callback), latter shows success status and onSuccess() callback.
Please, file an issue for Android Studio team.
Okey, Thanks. What's about the 'Stop' action question?
Accodring to sources of StopAction, there is a limited set of places, where the "Global" Stop action can be.
If a stop action is used in a plugin, it needs a context - a RunContentDescriptor to work with (see com/intellij/execution/actions/StopAction.java:230)
To provide one, a UI component (e.g., the toolwindow) parent to the stop action, should implement com.intellij.openapi.actionSystem.DataProvider and respond with proper RunContentDescriptor.
You can check the StopAction code to see, how to obtain RunContentDescriptor for globally running process