@@ -46,56 +46,56 @@ import kotlin.uuid.Uuid
46
46
47
47
class RobotCodeRunProfileState (private val config : RobotCodeRunConfiguration , environment : ExecutionEnvironment ) :
48
48
CommandLineState (environment), ProcessListener {
49
-
49
+
50
50
companion object {
51
51
const val DEBUGGER_DEFAULT_PORT = 6612
52
52
val DEBUG_PORT : Key <Int > = Key .create(" ROBOTCODE_DEBUG_PORT" )
53
53
const val TESTFRAMEWORK_NAME = " RobotCode"
54
54
}
55
-
55
+
56
56
val debugClient = RobotCodeDebugProtocolClient ()
57
57
lateinit var debugServer: IDebugProtocolServer
58
58
var isInitialized = false
59
59
private set
60
60
var isConfigurationDone = false
61
61
private set
62
-
62
+
63
63
val afterInitialize = Signal <Unit >()
64
64
val afterConfigurationDone = Signal <Unit >()
65
-
66
-
65
+
66
+
67
67
init {
68
68
debugClient.onTerminated.adviseEternal {
69
69
if (socket.isConnected) socket.close()
70
70
}
71
71
}
72
-
72
+
73
73
private lateinit var socket: Socket
74
-
74
+
75
75
override fun startProcess (): ProcessHandler {
76
76
val project = environment.project
77
77
val profile =
78
78
environment.runProfile as ? RobotCodeRunConfiguration ? : throw CantRunException (" Invalid run configuration" )
79
-
79
+
80
80
// TODO: Add support for configurable paths
81
81
val defaultPaths = arrayOf(" -dp" , " ." )
82
-
82
+
83
83
val debug = environment.runner is RobotCodeDebugProgramRunner
84
-
84
+
85
85
val included = mutableListOf<String >()
86
86
for (test in profile.includedTestItems) {
87
- included.add(" -- bl" )
87
+ included.add(" -bl" )
88
88
included.add(test.longname)
89
89
}
90
-
90
+
91
91
val connection = mutableListOf<String >()
92
-
92
+
93
93
val port = findFreePort(DEBUGGER_DEFAULT_PORT )
94
94
if (port != DEBUGGER_DEFAULT_PORT ) {
95
95
included.add(" --tcp" )
96
96
included.add(port.toString())
97
97
}
98
-
98
+
99
99
val commandLine = project.buildRobotCodeCommandLine(
100
100
arrayOf(
101
101
* defaultPaths,
@@ -104,30 +104,30 @@ class RobotCodeRunProfileState(private val config: RobotCodeRunConfiguration, en
104
104
* (if (! debug) arrayOf(" --no-debug" ) else arrayOf()),
105
105
* (included.toTypedArray())
106
106
), noColor = false // ,extraArgs = arrayOf("-v", "--log", "--log-level", "TRACE")
107
-
107
+
108
108
)
109
-
109
+
110
110
val handler = KillableColoredProcessHandler (commandLine) // handler.setHasPty(true)
111
111
handler.putUserData(DEBUG_PORT , port)
112
112
ProcessTerminatedListener .attach(handler)
113
113
handler.addProcessListener(this )
114
-
114
+
115
115
// RunContentManager.getInstance(project).showRunContent(environment.executor, handler)
116
-
116
+
117
117
return handler
118
118
}
119
-
119
+
120
120
override fun execute (executor : Executor , runner : ProgramRunner <* >): ExecutionResult {
121
121
val processHandler = startProcess()
122
122
val (console, properties) = createAndAttachConsoleInEDT(processHandler, executor)
123
-
123
+
124
124
val result = DefaultExecutionResult (console, processHandler, * createActions(console, processHandler))
125
125
result.setRestartActions(properties.createRerunFailedTestsAction(console))
126
-
126
+
127
127
return result
128
128
}
129
-
130
-
129
+
130
+
131
131
private fun createAndAttachConsoleInEDT (
132
132
processHandler : ProcessHandler , executor : Executor
133
133
): Pair <BaseTestsOutputConsoleView , SMTRunnerConsoleProperties > {
@@ -136,34 +136,34 @@ class RobotCodeRunProfileState(private val config: RobotCodeRunConfiguration, en
136
136
ApplicationManager .getApplication().invokeAndWait {
137
137
try {
138
138
val propertiesProvider = config as SMRunnerConsolePropertiesProvider
139
-
139
+
140
140
val consoleProperties = propertiesProvider.createTestConsoleProperties(executor)
141
141
if (consoleProperties is RobotRunnerConsoleProperties ) {
142
142
consoleProperties.state = this
143
143
}
144
-
144
+
145
145
var splitterPropertyName = SMTestRunnerConnectionUtil .getSplitterPropertyName(TESTFRAMEWORK_NAME )
146
146
var consoleView = RobotCodeRunnerConsoleView (consoleProperties, splitterPropertyName)
147
147
SMTestRunnerConnectionUtil .initConsoleView(consoleView, TESTFRAMEWORK_NAME )
148
148
consoleView.attachToProcess(processHandler)
149
149
consoleRef.set(consoleView)
150
150
// consoleRef.set(createAndAttachConsole("RobotCode", processHandler, consoleProperties))
151
151
propertiesRef.set(consoleProperties)
152
-
152
+
153
153
} catch (e: ExecutionException ) {
154
154
consoleRef.set(e)
155
155
} catch (e: RuntimeException ) {
156
156
consoleRef.set(e)
157
157
}
158
158
}
159
-
159
+
160
160
if (consoleRef.get() is ExecutionException ) {
161
161
throw consoleRef.get() as ExecutionException
162
162
} else if (consoleRef.get() is RuntimeException ) throw consoleRef.get() as RuntimeException
163
-
163
+
164
164
return Pair (consoleRef.get() as BaseTestsOutputConsoleView , propertiesRef.get() as SMTRunnerConsoleProperties )
165
165
}
166
-
166
+
167
167
private suspend fun tryConnectToServerWithTimeout (
168
168
host : String , port : Int , timeoutMillis : Long , retryIntervalMillis : Long
169
169
): Socket ? {
@@ -180,62 +180,62 @@ class RobotCodeRunProfileState(private val config: RobotCodeRunConfiguration, en
180
180
} catch (_: Exception ) {
181
181
}
182
182
delay(retryIntervalMillis)
183
-
183
+
184
184
}
185
185
socket
186
186
}
187
187
} catch (e: TimeoutCancellationException ) {
188
188
null
189
189
}
190
190
}
191
-
191
+
192
192
@OptIn(ExperimentalUuidApi ::class ) override fun startNotified (event : ProcessEvent ) {
193
193
runBlocking(Dispatchers .IO ) {
194
-
194
+
195
195
var port = event.processHandler.getUserData(DEBUG_PORT ) ? : throw CantRunException (" No debug port found." )
196
-
196
+
197
197
socket = tryConnectToServerWithTimeout(" 127.0.0.1" , port, 10000 , retryIntervalMillis = 100 )
198
198
? : throw CantRunException (" Unable to establish connection to debug server." )
199
-
199
+
200
200
val launcher: Launcher <IDebugProtocolServer > =
201
201
DSPLauncher .createClientLauncher(debugClient, socket.getInputStream(), socket.getOutputStream())
202
-
202
+
203
203
launcher.startListening()
204
-
204
+
205
205
debugServer = launcher.remoteProxy
206
-
206
+
207
207
val arguments = InitializeRequestArguments ().apply {
208
208
clientID = Uuid .random().toString()
209
209
adapterID = Uuid .random().toString()
210
-
210
+
211
211
clientName = " RobotCode4IJ"
212
212
locale = " en_US"
213
-
213
+
214
214
supportsRunInTerminalRequest = false
215
215
supportsStartDebuggingRequest = false
216
216
pathFormat = " path"
217
217
supportsVariableType = true
218
218
supportsVariablePaging = false
219
-
219
+
220
220
linesStartAt1 = true
221
221
columnsStartAt1 = true
222
222
}
223
-
223
+
224
224
val response = debugServer.initialize(arguments).await()
225
225
isInitialized = true
226
-
226
+
227
227
afterInitialize.fire(Unit )
228
-
228
+
229
229
if (response.supportsConfigurationDoneRequest) {
230
230
debugServer.configurationDone(ConfigurationDoneArguments ()).await()
231
231
isConfigurationDone = true
232
232
}
233
-
233
+
234
234
afterConfigurationDone.fire(Unit )
235
235
debugServer.attach(emptyMap<String , Object >())
236
236
}
237
237
}
238
-
238
+
239
239
override fun processTerminated (event : ProcessEvent ) {
240
240
if (socket.isConnected) socket.close()
241
241
}
0 commit comments