1
1
package org.utbot.intellij.plugin.process
2
2
3
3
import com.intellij.ide.plugins.cl.PluginClassLoader
4
+ import com.intellij.openapi.application.runReadAction
4
5
import com.intellij.openapi.project.DumbService
5
6
import com.intellij.openapi.project.Project
7
+ import com.intellij.openapi.util.Computable
6
8
import com.intellij.psi.PsiMethod
7
9
import com.intellij.psi.impl.file.impl.JavaFileManager
8
10
import com.intellij.psi.search.GlobalSearchScope
@@ -30,14 +32,14 @@ import org.utbot.instrumentation.util.KryoHelper
30
32
import org.utbot.intellij.plugin.UtbotBundle
31
33
import org.utbot.intellij.plugin.models.GenerateTestsModel
32
34
import org.utbot.intellij.plugin.ui.TestReportUrlOpeningListener
33
- import org.utbot.intellij.plugin.util.assertIsNonDispatchThread
34
- import org.utbot.intellij.plugin.util.assertIsReadAccessAllowed
35
+ import org.utbot.intellij.plugin.util.assertReadAccessNotAllowed
35
36
import org.utbot.intellij.plugin.util.signature
36
37
import org.utbot.rd.*
37
38
import org.utbot.rd.exceptions.InstantProcessDeathException
38
39
import org.utbot.rd.generated.SettingForResult
39
40
import org.utbot.rd.generated.SettingsModel
40
41
import org.utbot.rd.generated.settingsModel
42
+ import org.utbot.rd.generated.synchronizationModel
41
43
import org.utbot.rd.loggers.UtRdKLoggerFactory
42
44
import org.utbot.sarif.SourceFindingStrategy
43
45
import java.io.File
@@ -163,7 +165,8 @@ class EngineProcess private constructor(val project: Project, rdProcess: Process
163
165
private val sourceFindingStrategies = ConcurrentHashMap <Long , SourceFindingStrategy >()
164
166
165
167
fun setupUtContext (classpathForUrlsClassloader : List <String >) {
166
- engineModel.setupUtContext.start(lifetime, SetupContextParams (classpathForUrlsClassloader))
168
+ assertReadAccessNotAllowed()
169
+ engineModel.setupUtContext.startBlocking(SetupContextParams (classpathForUrlsClassloader))
167
170
}
168
171
169
172
private fun computeSourceFileByClass (params : ComputeSourceFileByClassArguments ): String =
@@ -184,6 +187,8 @@ class EngineProcess private constructor(val project: Project, rdProcess: Process
184
187
jdkInfo : JdkInfo ,
185
188
isCancelled : (Unit ) -> Boolean
186
189
) {
190
+ assertReadAccessNotAllowed()
191
+
187
192
engineModel.isCancelled.set(handler = isCancelled)
188
193
instrumenterAdapterModel.computeSourceFileByClass.set(handler = this ::computeSourceFileByClass)
189
194
@@ -193,19 +198,18 @@ class EngineProcess private constructor(val project: Project, rdProcess: Process
193
198
dependencyPaths,
194
199
JdkInfo (jdkInfo.path.pathString, jdkInfo.version)
195
200
)
196
- engineModel.createTestGenerator.start(lifetime, params)
201
+ engineModel.createTestGenerator.startBlocking( params)
197
202
}
198
203
199
204
fun obtainClassId (canonicalName : String ): ClassId {
200
- assertIsNonDispatchThread ()
205
+ assertReadAccessNotAllowed ()
201
206
return kryoHelper.readObject(engineModel.obtainClassId.startBlocking(canonicalName))
202
207
}
203
208
204
209
fun findMethodsInClassMatchingSelected (clazzId : ClassId , srcMethods : List <MemberInfo >): List <ExecutableId > {
205
- assertIsNonDispatchThread()
206
- assertIsReadAccessAllowed()
210
+ assertReadAccessNotAllowed()
207
211
208
- val srcSignatures = srcMethods.map { it.signature() }
212
+ val srcSignatures = runReadAction { srcMethods.map { it.signature() } }
209
213
val rdSignatures = srcSignatures.map { Signature (it.name, it.parameterTypes) }
210
214
val binaryClassId = kryoHelper.writeObject(clazzId)
211
215
val arguments = FindMethodsInClassMatchingSelectedArguments (binaryClassId, rdSignatures)
@@ -215,10 +219,13 @@ class EngineProcess private constructor(val project: Project, rdProcess: Process
215
219
}
216
220
217
221
fun findMethodParamNames (classId : ClassId , methods : List <MemberInfo >): Map <ExecutableId , List <String >> {
218
- assertIsNonDispatchThread()
219
- assertIsReadAccessAllowed()
222
+ assertReadAccessNotAllowed()
220
223
221
- val bySignature = methods.associate { it.signature() to it.paramNames() }
224
+ val bySignature = executeWithTimeoutSuspended {
225
+ DumbService .getInstance(project).runReadActionInSmartMode(Computable {
226
+ methods.associate { it.signature() to it.paramNames() }
227
+ })
228
+ }
222
229
val arguments = FindMethodParamNamesArguments (
223
230
kryoHelper.writeObject(classId),
224
231
kryoHelper.writeObject(bySignature)
@@ -253,7 +260,7 @@ class EngineProcess private constructor(val project: Project, rdProcess: Process
253
260
fuzzingValue : Double ,
254
261
searchDirectory : String
255
262
): RdTestGenerationResult {
256
- assertIsNonDispatchThread ()
263
+ assertReadAccessNotAllowed ()
257
264
val params = GenerateParams (
258
265
mockInstalled,
259
266
staticsMockingIsConfigured,
@@ -290,7 +297,7 @@ class EngineProcess private constructor(val project: Project, rdProcess: Process
290
297
enableTestsTimeout : Boolean ,
291
298
testClassPackageName : String
292
299
): Pair <String , UtilClassKind ?> {
293
- assertIsNonDispatchThread ()
300
+ assertReadAccessNotAllowed ()
294
301
val params = RenderParams (
295
302
testSetsId,
296
303
kryoHelper.writeObject(classUnderTest),
@@ -352,7 +359,7 @@ class EngineProcess private constructor(val project: Project, rdProcess: Process
352
359
generatedTestsCode : String ,
353
360
sourceFindingStrategy : SourceFindingStrategy
354
361
): String {
355
- assertIsNonDispatchThread ()
362
+ assertReadAccessNotAllowed ()
356
363
357
364
val params = WriteSarifReportArguments (testSetsId, reportFilePath.pathString, generatedTestsCode)
358
365
@@ -361,7 +368,7 @@ class EngineProcess private constructor(val project: Project, rdProcess: Process
361
368
}
362
369
363
370
fun generateTestsReport (model : GenerateTestsModel , eventLogMessage : String? ): Triple <String , String ?, Boolean > {
364
- assertIsNonDispatchThread ()
371
+ assertReadAccessNotAllowed ()
365
372
366
373
val forceMockWarning = UtbotBundle .takeIf (
367
374
" test.report.force.mock.warning" ,
@@ -410,11 +417,13 @@ class EngineProcess private constructor(val project: Project, rdProcess: Process
410
417
411
418
fun <T > executeWithTimeoutSuspended (block : () -> T ): T {
412
419
try {
413
- synchronizationModel.suspendTimeoutTimer.startBlocking(true )
420
+ assertReadAccessNotAllowed()
421
+ protocol.synchronizationModel.suspendTimeoutTimer.startBlocking(true )
414
422
return block()
415
423
}
416
424
finally {
417
- synchronizationModel.suspendTimeoutTimer.startBlocking(false )
425
+ assertReadAccessNotAllowed()
426
+ protocol.synchronizationModel.suspendTimeoutTimer.startBlocking(false )
418
427
}
419
428
}
420
429
}
0 commit comments