@@ -46,56 +46,56 @@ import kotlin.uuid.Uuid
4646
4747class RobotCodeRunProfileState (private val config : RobotCodeRunConfiguration , environment : ExecutionEnvironment ) :
4848 CommandLineState (environment), ProcessListener {
49-
49+
5050 companion object {
5151 const val DEBUGGER_DEFAULT_PORT = 6612
5252 val DEBUG_PORT : Key <Int > = Key .create(" ROBOTCODE_DEBUG_PORT" )
5353 const val TESTFRAMEWORK_NAME = " RobotCode"
5454 }
55-
55+
5656 val debugClient = RobotCodeDebugProtocolClient ()
5757 lateinit var debugServer: IDebugProtocolServer
5858 var isInitialized = false
5959 private set
6060 var isConfigurationDone = false
6161 private set
62-
62+
6363 val afterInitialize = Signal <Unit >()
6464 val afterConfigurationDone = Signal <Unit >()
65-
66-
65+
66+
6767 init {
6868 debugClient.onTerminated.adviseEternal {
6969 if (socket.isConnected) socket.close()
7070 }
7171 }
72-
72+
7373 private lateinit var socket: Socket
74-
74+
7575 override fun startProcess (): ProcessHandler {
7676 val project = environment.project
7777 val profile =
7878 environment.runProfile as ? RobotCodeRunConfiguration ? : throw CantRunException (" Invalid run configuration" )
79-
79+
8080 // TODO: Add support for configurable paths
8181 val defaultPaths = arrayOf(" -dp" , " ." )
82-
82+
8383 val debug = environment.runner is RobotCodeDebugProgramRunner
84-
84+
8585 val included = mutableListOf<String >()
8686 for (test in profile.includedTestItems) {
87- included.add(" -- bl" )
87+ included.add(" -bl" )
8888 included.add(test.longname)
8989 }
90-
90+
9191 val connection = mutableListOf<String >()
92-
92+
9393 val port = findFreePort(DEBUGGER_DEFAULT_PORT )
9494 if (port != DEBUGGER_DEFAULT_PORT ) {
9595 included.add(" --tcp" )
9696 included.add(port.toString())
9797 }
98-
98+
9999 val commandLine = project.buildRobotCodeCommandLine(
100100 arrayOf(
101101 * defaultPaths,
@@ -104,30 +104,30 @@ class RobotCodeRunProfileState(private val config: RobotCodeRunConfiguration, en
104104 * (if (! debug) arrayOf(" --no-debug" ) else arrayOf()),
105105 * (included.toTypedArray())
106106 ), noColor = false // ,extraArgs = arrayOf("-v", "--log", "--log-level", "TRACE")
107-
107+
108108 )
109-
109+
110110 val handler = KillableColoredProcessHandler (commandLine) // handler.setHasPty(true)
111111 handler.putUserData(DEBUG_PORT , port)
112112 ProcessTerminatedListener .attach(handler)
113113 handler.addProcessListener(this )
114-
114+
115115 // RunContentManager.getInstance(project).showRunContent(environment.executor, handler)
116-
116+
117117 return handler
118118 }
119-
119+
120120 override fun execute (executor : Executor , runner : ProgramRunner <* >): ExecutionResult {
121121 val processHandler = startProcess()
122122 val (console, properties) = createAndAttachConsoleInEDT(processHandler, executor)
123-
123+
124124 val result = DefaultExecutionResult (console, processHandler, * createActions(console, processHandler))
125125 result.setRestartActions(properties.createRerunFailedTestsAction(console))
126-
126+
127127 return result
128128 }
129-
130-
129+
130+
131131 private fun createAndAttachConsoleInEDT (
132132 processHandler : ProcessHandler , executor : Executor
133133 ): Pair <BaseTestsOutputConsoleView , SMTRunnerConsoleProperties > {
@@ -136,34 +136,34 @@ class RobotCodeRunProfileState(private val config: RobotCodeRunConfiguration, en
136136 ApplicationManager .getApplication().invokeAndWait {
137137 try {
138138 val propertiesProvider = config as SMRunnerConsolePropertiesProvider
139-
139+
140140 val consoleProperties = propertiesProvider.createTestConsoleProperties(executor)
141141 if (consoleProperties is RobotRunnerConsoleProperties ) {
142142 consoleProperties.state = this
143143 }
144-
144+
145145 var splitterPropertyName = SMTestRunnerConnectionUtil .getSplitterPropertyName(TESTFRAMEWORK_NAME )
146146 var consoleView = RobotCodeRunnerConsoleView (consoleProperties, splitterPropertyName)
147147 SMTestRunnerConnectionUtil .initConsoleView(consoleView, TESTFRAMEWORK_NAME )
148148 consoleView.attachToProcess(processHandler)
149149 consoleRef.set(consoleView)
150150 // consoleRef.set(createAndAttachConsole("RobotCode", processHandler, consoleProperties))
151151 propertiesRef.set(consoleProperties)
152-
152+
153153 } catch (e: ExecutionException ) {
154154 consoleRef.set(e)
155155 } catch (e: RuntimeException ) {
156156 consoleRef.set(e)
157157 }
158158 }
159-
159+
160160 if (consoleRef.get() is ExecutionException ) {
161161 throw consoleRef.get() as ExecutionException
162162 } else if (consoleRef.get() is RuntimeException ) throw consoleRef.get() as RuntimeException
163-
163+
164164 return Pair (consoleRef.get() as BaseTestsOutputConsoleView , propertiesRef.get() as SMTRunnerConsoleProperties )
165165 }
166-
166+
167167 private suspend fun tryConnectToServerWithTimeout (
168168 host : String , port : Int , timeoutMillis : Long , retryIntervalMillis : Long
169169 ): Socket ? {
@@ -180,62 +180,62 @@ class RobotCodeRunProfileState(private val config: RobotCodeRunConfiguration, en
180180 } catch (_: Exception ) {
181181 }
182182 delay(retryIntervalMillis)
183-
183+
184184 }
185185 socket
186186 }
187187 } catch (e: TimeoutCancellationException ) {
188188 null
189189 }
190190 }
191-
191+
192192 @OptIn(ExperimentalUuidApi ::class ) override fun startNotified (event : ProcessEvent ) {
193193 runBlocking(Dispatchers .IO ) {
194-
194+
195195 var port = event.processHandler.getUserData(DEBUG_PORT ) ? : throw CantRunException (" No debug port found." )
196-
196+
197197 socket = tryConnectToServerWithTimeout(" 127.0.0.1" , port, 10000 , retryIntervalMillis = 100 )
198198 ? : throw CantRunException (" Unable to establish connection to debug server." )
199-
199+
200200 val launcher: Launcher <IDebugProtocolServer > =
201201 DSPLauncher .createClientLauncher(debugClient, socket.getInputStream(), socket.getOutputStream())
202-
202+
203203 launcher.startListening()
204-
204+
205205 debugServer = launcher.remoteProxy
206-
206+
207207 val arguments = InitializeRequestArguments ().apply {
208208 clientID = Uuid .random().toString()
209209 adapterID = Uuid .random().toString()
210-
210+
211211 clientName = " RobotCode4IJ"
212212 locale = " en_US"
213-
213+
214214 supportsRunInTerminalRequest = false
215215 supportsStartDebuggingRequest = false
216216 pathFormat = " path"
217217 supportsVariableType = true
218218 supportsVariablePaging = false
219-
219+
220220 linesStartAt1 = true
221221 columnsStartAt1 = true
222222 }
223-
223+
224224 val response = debugServer.initialize(arguments).await()
225225 isInitialized = true
226-
226+
227227 afterInitialize.fire(Unit )
228-
228+
229229 if (response.supportsConfigurationDoneRequest) {
230230 debugServer.configurationDone(ConfigurationDoneArguments ()).await()
231231 isConfigurationDone = true
232232 }
233-
233+
234234 afterConfigurationDone.fire(Unit )
235235 debugServer.attach(emptyMap<String , Object >())
236236 }
237237 }
238-
238+
239239 override fun processTerminated (event : ProcessEvent ) {
240240 if (socket.isConnected) socket.close()
241241 }
0 commit comments