Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Fix thread execution
  • Loading branch information
mmvpm committed Oct 19, 2022
commit bbc1766e54f2b61f9471b479d95a5b909bc10fd4
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import com.intellij.ide.fileTemplates.FileTemplateUtil
import com.intellij.ide.fileTemplates.JavaTemplateUtil
import com.intellij.ide.highlighter.JavaFileType
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.application.invokeLater
import com.intellij.openapi.application.runReadAction
import com.intellij.openapi.application.runWriteAction
import com.intellij.openapi.command.WriteCommandAction.runWriteCommandAction
Expand Down Expand Up @@ -157,7 +158,10 @@ object CodeGenerationController {
}
proc.forceTermination()
UtTestsDialogProcessor.updateIndicator(indicator, UtTestsDialogProcessor.ProgressRange.SARIF, "Start tests with coverage", 1.0)
runInspectionsIfNeeded(model.project, srcClassPathToSarifReport)

invokeLater {
runInspectionsIfNeeded(model.project, srcClassPathToSarifReport)
}
}
}
}
Expand Down Expand Up @@ -686,6 +690,7 @@ object CodeGenerationController {
// uploading formatted code
val file = filePointer.containingFile

val srcClassPath = srcClass.containingFile.virtualFile.toNioPath()
val sarifReport = saveSarifReport(
proc,
testSetsId,
Expand All @@ -694,10 +699,10 @@ object CodeGenerationController {
model,
reportsCountDown,
file?.text ?: generatedTestsCode,
srcClassPathToSarifReport,
srcClassPath,
indicator
)
val srcClassPath = srcClass.containingFile.virtualFile.toNioPath()
srcClassPathToSarifReport[srcClassPath] = sarifReport

unblockDocument(testClassUpdated.project, editor.document)
}
Expand Down Expand Up @@ -734,21 +739,33 @@ object CodeGenerationController {
model: GenerateTestsModel,
reportsCountDown: CountDownLatch,
generatedTestsCode: String,
srcClassPathToSarifReport: MutableMap<Path, Sarif>,
srcClassPath: Path,
indicator: ProgressIndicator
): Sarif {
) {
val project = model.project

return try {
try {
// saving sarif report
SarifReportIdea.createAndSave(proc, testSetsId, testClassId, model, generatedTestsCode, testClass, reportsCountDown, indicator)
SarifReportIdea.createAndSave(
proc,
testSetsId,
testClassId,
model,
generatedTestsCode,
testClass,
reportsCountDown,
srcClassPathToSarifReport,
srcClassPath,
indicator
)
} catch (e: Exception) {
logger.error(e) { "error in saving sarif report"}
showErrorDialogLater(
project,
message = "Cannot save Sarif report via generated tests: error occurred '${e.message}'",
title = "Failed to save Sarif report"
)
Sarif.empty()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ object SarifReportIdea {
generatedTestsCode: String,
psiClass: PsiClass,
reportsCountDown: CountDownLatch,
srcClassPathToSarifReport: MutableMap<Path, Sarif>,
srcClassPath: Path,
indicator: ProgressIndicator
): Sarif {
) {
UtTestsDialogProcessor.updateIndicator(indicator, UtTestsDialogProcessor.ProgressRange.SARIF, "Generate SARIF report for ${classId.name}", .5)
// building the path to the report file
val classFqn = classId.name
Expand All @@ -41,18 +43,17 @@ object SarifReportIdea {
}
val reportFilePath = sarifReportsPath.resolve("${classFqnToPath(classFqn)}Report.sarif")

var resultSarifReport = Sarif.empty()
IntelliJApiHelper.run(IntelliJApiHelper.Target.THREAD_POOL, indicator) {
try {
val sarifReportAsJson = proc.writeSarif(reportFilePath, testSetsId, generatedTestsCode, sourceFinding)
resultSarifReport = Sarif.fromJson(sarifReportAsJson)
val sarifReport = Sarif.fromJson(sarifReportAsJson)
srcClassPathToSarifReport[srcClassPath] = sarifReport
} catch (e: Exception) {
logger.error { e }
} finally {
reportsCountDown.countDown()
}
}
return resultSarifReport
}
}