-
Notifications
You must be signed in to change notification settings - Fork 380
/
Utils.kt
78 lines (58 loc) · 2.79 KB
/
Utils.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/*
* Use of this source code is governed by the MIT license that can be
* found in the LICENSE file.
*/
@file:Suppress("UnstableApiUsage")
package org.rust.cargo.runconfig.buildtool
import com.intellij.build.BuildProgressListener
import com.intellij.build.events.BuildEvent
import com.intellij.execution.ExecutionListener
import com.intellij.execution.ExecutionManager
import com.intellij.execution.process.ProcessHandler
import com.intellij.execution.runners.ExecutionEnvironment
import com.intellij.openapi.progress.EmptyProgressIndicator
import com.intellij.openapi.util.Key
import org.rust.cargo.toolchain.CargoCommandLine
typealias CargoPatch = (CargoCommandLine) -> CargoCommandLine
val ExecutionEnvironment.cargoPatches: MutableList<CargoPatch>
get() = putUserDataIfAbsent(CARGO_PATCHES, mutableListOf())
private val CARGO_PATCHES: Key<MutableList<CargoPatch>> = Key.create("CARGO.PATCHES")
private val ExecutionEnvironment.executionListener: ExecutionListener
get() = project.messageBus.syncPublisher(ExecutionManager.EXECUTION_TOPIC)
fun ExecutionEnvironment.notifyProcessStartScheduled() =
executionListener.processStartScheduled(executor.id, this)
fun ExecutionEnvironment.notifyProcessStarting() =
executionListener.processStarting(executor.id, this)
fun ExecutionEnvironment.notifyProcessNotStarted() =
executionListener.processNotStarted(executor.id, this)
fun ExecutionEnvironment.notifyProcessStarted(handler: ProcessHandler) =
executionListener.processStarted(executor.id, this, handler)
fun ExecutionEnvironment.notifyProcessTerminating(handler: ProcessHandler) =
executionListener.processTerminating(executor.id, this, handler)
fun ExecutionEnvironment.notifyProcessTerminated(handler: ProcessHandler, exitCode: Int) =
executionListener.processTerminated(executor.id, this, handler, exitCode)
val ExecutionEnvironment.isActivateToolWindowBeforeRun: Boolean
get() = runnerAndConfigurationSettings?.isActivateToolWindowBeforeRun != false
class MockProgressIndicator : EmptyProgressIndicator() {
private val _textHistory: MutableList<String?> = mutableListOf()
val textHistory: List<String?> get() = _textHistory
override fun setText(text: String?) {
super.setText(text)
_textHistory += text
}
override fun setText2(text: String?) {
super.setText2(text)
_textHistory += text
}
}
object EmptyBuildProgressListener : BuildProgressListener {
override fun onEvent(buildId: Any, event: BuildEvent) = Unit
}
@Suppress("UnstableApiUsage")
class MockBuildProgressListener : BuildProgressListener {
private val _eventHistory: MutableList<BuildEvent> = mutableListOf()
val eventHistory: List<BuildEvent> get() = _eventHistory
override fun onEvent(buildId: Any, event: BuildEvent) {
_eventHistory.add(event)
}
}