generated from JetBrains/intellij-platform-plugin-template
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(run-service): ensure correct process lifecycle handling and remov…
…e unnecessary imports The commit addresses an issue where the process lifecycle was not being handled correctly in the RunService class. It removes unnecessary imports and ensures that the process listener and execution listener are properly notified during the process lifecycle. The new CheckExecutionListener class and Context class have been added to handle these notifications correctly.
- Loading branch information
Showing
2 changed files
with
74 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
src/main/kotlin/cc/unitmesh/devti/provider/RunServiceExt.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. | ||
package cc.unitmesh.devti.provider | ||
|
||
import com.intellij.execution.ExecutionListener | ||
import com.intellij.execution.process.ProcessHandler | ||
import com.intellij.execution.process.ProcessListener | ||
import com.intellij.execution.runners.ExecutionEnvironment | ||
import com.intellij.openapi.Disposable | ||
import java.util.concurrent.CountDownLatch | ||
|
||
class CheckExecutionListener( | ||
private val executorId: String, | ||
private val context: Context, | ||
) : ExecutionListener { | ||
override fun processStartScheduled(executorId: String, env: ExecutionEnvironment) { | ||
checkAndExecute(executorId, env) { | ||
context.executionListener?.processStartScheduled(executorId, env) | ||
} | ||
} | ||
|
||
override fun processNotStarted(executorId: String, env: ExecutionEnvironment) { | ||
checkAndExecute(executorId, env) { | ||
context.latch.countDown() | ||
context.executionListener?.processNotStarted(executorId, env) | ||
} | ||
} | ||
|
||
override fun processStarting(executorId: String, env: ExecutionEnvironment) { | ||
checkAndExecute(executorId, env) { | ||
context.executionListener?.processStarting(executorId, env) | ||
} | ||
} | ||
|
||
override fun processStarted(executorId: String, env: ExecutionEnvironment, handler: ProcessHandler) { | ||
checkAndExecute(executorId, env) { | ||
context.executionListener?.processStarted(executorId, env, handler) | ||
} | ||
} | ||
|
||
override fun processTerminating(executorId: String, env: ExecutionEnvironment, handler: ProcessHandler) { | ||
checkAndExecute(executorId, env) { | ||
context.executionListener?.processTerminating(executorId, env, handler) | ||
} | ||
} | ||
|
||
override fun processTerminated( | ||
executorId: String, | ||
env: ExecutionEnvironment, | ||
handler: ProcessHandler, | ||
exitCode: Int | ||
) { | ||
checkAndExecute(executorId, env) { | ||
context.executionListener?.processTerminated(executorId, env, handler, exitCode) | ||
} | ||
} | ||
|
||
private fun checkAndExecute(executorId: String, env: ExecutionEnvironment, action: () -> Unit) { | ||
if (this.executorId == executorId && env in context.environments) { | ||
action() | ||
} | ||
} | ||
} | ||
|
||
class Context( | ||
val processListener: ProcessListener?, | ||
val executionListener: ExecutionListener?, | ||
val latch: CountDownLatch | ||
) : Disposable { | ||
val environments: MutableList<ExecutionEnvironment> = mutableListOf() | ||
override fun dispose() {} | ||
} |