Skip to content

Commit bbc1766

Browse files
committed
Fix thread execution
1 parent 357035e commit bbc1766

File tree

2 files changed

+29
-11
lines changed

2 files changed

+29
-11
lines changed

utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/generator/CodeGenerationController.kt

+24-7
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import com.intellij.ide.fileTemplates.FileTemplateUtil
88
import com.intellij.ide.fileTemplates.JavaTemplateUtil
99
import com.intellij.ide.highlighter.JavaFileType
1010
import com.intellij.openapi.application.ApplicationManager
11+
import com.intellij.openapi.application.invokeLater
1112
import com.intellij.openapi.application.runReadAction
1213
import com.intellij.openapi.application.runWriteAction
1314
import com.intellij.openapi.command.WriteCommandAction.runWriteCommandAction
@@ -157,7 +158,10 @@ object CodeGenerationController {
157158
}
158159
proc.forceTermination()
159160
UtTestsDialogProcessor.updateIndicator(indicator, UtTestsDialogProcessor.ProgressRange.SARIF, "Start tests with coverage", 1.0)
160-
runInspectionsIfNeeded(model.project, srcClassPathToSarifReport)
161+
162+
invokeLater {
163+
runInspectionsIfNeeded(model.project, srcClassPathToSarifReport)
164+
}
161165
}
162166
}
163167
}
@@ -686,6 +690,7 @@ object CodeGenerationController {
686690
// uploading formatted code
687691
val file = filePointer.containingFile
688692

693+
val srcClassPath = srcClass.containingFile.virtualFile.toNioPath()
689694
val sarifReport = saveSarifReport(
690695
proc,
691696
testSetsId,
@@ -694,10 +699,10 @@ object CodeGenerationController {
694699
model,
695700
reportsCountDown,
696701
file?.text ?: generatedTestsCode,
702+
srcClassPathToSarifReport,
703+
srcClassPath,
697704
indicator
698705
)
699-
val srcClassPath = srcClass.containingFile.virtualFile.toNioPath()
700-
srcClassPathToSarifReport[srcClassPath] = sarifReport
701706

702707
unblockDocument(testClassUpdated.project, editor.document)
703708
}
@@ -734,21 +739,33 @@ object CodeGenerationController {
734739
model: GenerateTestsModel,
735740
reportsCountDown: CountDownLatch,
736741
generatedTestsCode: String,
742+
srcClassPathToSarifReport: MutableMap<Path, Sarif>,
743+
srcClassPath: Path,
737744
indicator: ProgressIndicator
738-
): Sarif {
745+
) {
739746
val project = model.project
740747

741-
return try {
748+
try {
742749
// saving sarif report
743-
SarifReportIdea.createAndSave(proc, testSetsId, testClassId, model, generatedTestsCode, testClass, reportsCountDown, indicator)
750+
SarifReportIdea.createAndSave(
751+
proc,
752+
testSetsId,
753+
testClassId,
754+
model,
755+
generatedTestsCode,
756+
testClass,
757+
reportsCountDown,
758+
srcClassPathToSarifReport,
759+
srcClassPath,
760+
indicator
761+
)
744762
} catch (e: Exception) {
745763
logger.error(e) { "error in saving sarif report"}
746764
showErrorDialogLater(
747765
project,
748766
message = "Cannot save Sarif report via generated tests: error occurred '${e.message}'",
749767
title = "Failed to save Sarif report"
750768
)
751-
Sarif.empty()
752769
}
753770
}
754771

utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/sarif/SarifReportIdea.kt

+5-4
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,10 @@ object SarifReportIdea {
3131
generatedTestsCode: String,
3232
psiClass: PsiClass,
3333
reportsCountDown: CountDownLatch,
34+
srcClassPathToSarifReport: MutableMap<Path, Sarif>,
35+
srcClassPath: Path,
3436
indicator: ProgressIndicator
35-
): Sarif {
37+
) {
3638
UtTestsDialogProcessor.updateIndicator(indicator, UtTestsDialogProcessor.ProgressRange.SARIF, "Generate SARIF report for ${classId.name}", .5)
3739
// building the path to the report file
3840
val classFqn = classId.name
@@ -41,18 +43,17 @@ object SarifReportIdea {
4143
}
4244
val reportFilePath = sarifReportsPath.resolve("${classFqnToPath(classFqn)}Report.sarif")
4345

44-
var resultSarifReport = Sarif.empty()
4546
IntelliJApiHelper.run(IntelliJApiHelper.Target.THREAD_POOL, indicator) {
4647
try {
4748
val sarifReportAsJson = proc.writeSarif(reportFilePath, testSetsId, generatedTestsCode, sourceFinding)
48-
resultSarifReport = Sarif.fromJson(sarifReportAsJson)
49+
val sarifReport = Sarif.fromJson(sarifReportAsJson)
50+
srcClassPathToSarifReport[srcClassPath] = sarifReport
4951
} catch (e: Exception) {
5052
logger.error { e }
5153
} finally {
5254
reportsCountDown.countDown()
5355
}
5456
}
55-
return resultSarifReport
5657
}
5758
}
5859

0 commit comments

Comments
 (0)