Skip to content

Built-in SARIF reports visualizer #1166

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Oct 19, 2022
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
Next Next commit
Rebase onto main
  • Loading branch information
mmvpm committed Oct 19, 2022
commit f0e08a57c575a7fa5021dc705756f52c89d931fb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class EngineProcessModel private constructor(
private val _obtainClassId: RdCall<String, ByteArray>,
private val _findMethodsInClassMatchingSelected: RdCall<FindMethodsInClassMatchingSelectedArguments, FindMethodsInClassMatchingSelectedResult>,
private val _findMethodParamNames: RdCall<FindMethodParamNamesArguments, FindMethodParamNamesResult>,
private val _writeSarifReport: RdCall<WriteSarifReportArguments, Unit>,
private val _writeSarifReport: RdCall<WriteSarifReportArguments, String>,
private val _generateTestReport: RdCall<GenerateTestReportArgs, GenerateTestReportResult>
) : RdExtBase() {
//companion
Expand Down Expand Up @@ -73,7 +73,7 @@ class EngineProcessModel private constructor(
}


const val serializationHash = 3907671513584285891L
const val serializationHash = -621732450296355904L

}
override val serializersOwner: ISerializersOwner get() = EngineProcessModel
Expand All @@ -89,7 +89,7 @@ class EngineProcessModel private constructor(
val obtainClassId: RdCall<String, ByteArray> get() = _obtainClassId
val findMethodsInClassMatchingSelected: RdCall<FindMethodsInClassMatchingSelectedArguments, FindMethodsInClassMatchingSelectedResult> get() = _findMethodsInClassMatchingSelected
val findMethodParamNames: RdCall<FindMethodParamNamesArguments, FindMethodParamNamesResult> get() = _findMethodParamNames
val writeSarifReport: RdCall<WriteSarifReportArguments, Unit> get() = _writeSarifReport
val writeSarifReport: RdCall<WriteSarifReportArguments, String> get() = _writeSarifReport
val generateTestReport: RdCall<GenerateTestReportArgs, GenerateTestReportResult> get() = _generateTestReport
//methods
//initializer
Expand Down Expand Up @@ -133,7 +133,7 @@ class EngineProcessModel private constructor(
RdCall<String, ByteArray>(FrameworkMarshallers.String, FrameworkMarshallers.ByteArray),
RdCall<FindMethodsInClassMatchingSelectedArguments, FindMethodsInClassMatchingSelectedResult>(FindMethodsInClassMatchingSelectedArguments, FindMethodsInClassMatchingSelectedResult),
RdCall<FindMethodParamNamesArguments, FindMethodParamNamesResult>(FindMethodParamNamesArguments, FindMethodParamNamesResult),
RdCall<WriteSarifReportArguments, Unit>(WriteSarifReportArguments, FrameworkMarshallers.Void),
RdCall<WriteSarifReportArguments, String>(WriteSarifReportArguments, FrameworkMarshallers.String),
RdCall<GenerateTestReportArgs, GenerateTestReportResult>(GenerateTestReportArgs, GenerateTestReportResult)
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,12 @@ import org.utbot.framework.codegen.model.UtilClassKind
import org.utbot.framework.codegen.model.UtilClassKind.Companion.UT_UTILS_CLASS_NAME
import org.utbot.framework.plugin.api.ClassId
import org.utbot.framework.plugin.api.CodegenLanguage
import org.utbot.intellij.plugin.inspection.UTBotInspectionManager
import org.utbot.intellij.plugin.inspection.UnitTestBotInspectionManager
import org.utbot.intellij.plugin.models.GenerateTestsModel
import org.utbot.intellij.plugin.models.packageName
import org.utbot.intellij.plugin.process.EngineProcess
import org.utbot.intellij.plugin.process.RdTestGenerationResult
import org.utbot.intellij.plugin.sarif.SarifReportIdea
import org.utbot.intellij.plugin.sarif.SourceFindingStrategyIdea
import org.utbot.intellij.plugin.ui.*
import org.utbot.intellij.plugin.ui.utils.getOrCreateSarifReportsPath
import org.utbot.intellij.plugin.ui.utils.showErrorDialogLater
Expand Down Expand Up @@ -180,7 +179,7 @@ object CodeGenerationController {
if (!sarifHasResults) {
return
}
UTBotInspectionManager
UnitTestBotInspectionManager
.getInstance(project, srcClassPathToSarifReport)
.createNewGlobalContext()
.doInspections(AnalysisScope(project))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ import java.util.concurrent.ConcurrentHashMap
import java.util.concurrent.ConcurrentMap

/**
* Overrides some methods of [GlobalInspectionContextImpl] to satisfy the logic of [UTBotInspectionTool].
* Overrides some methods of [GlobalInspectionContextImpl] to satisfy the logic of [UnitTestBotInspectionTool].
*/
class UTBotInspectionContext(
class UnitTestBotInspectionContext(
project: Project,
contentManager: NotNullLazyValue<out ContentManager>,
val srcClassPathToSarifReport: MutableMap<Path, Sarif>
private val srcClassPathToSarifReport: MutableMap<Path, Sarif>
) : GlobalInspectionContextImpl(project, contentManager) {

/**
Expand All @@ -26,14 +26,14 @@ class UTBotInspectionContext(
ConcurrentHashMap()

private val globalInspectionToolWrapper by lazy {
val utbotInspectionTool = UTBotInspectionTool.getInstance(srcClassPathToSarifReport)
val utbotInspectionTool = UnitTestBotInspectionTool.getInstance(srcClassPathToSarifReport)
GlobalInspectionToolWrapper(utbotInspectionTool).also {
it.initialize(/* context = */ this)
}
}

/**
* Returns [InspectionProfileImpl] with only one inspection tool - [UTBotInspectionTool].
* Returns [InspectionProfileImpl] with only one inspection tool - [UnitTestBotInspectionTool].
*/
override fun getCurrentProfile(): InspectionProfileImpl {
val supplier = InspectionToolsSupplier.Simple(listOf(globalInspectionToolWrapper))
Expand All @@ -51,12 +51,12 @@ class UTBotInspectionContext(
}

/**
* Overriding is needed to provide [UTBotInspectionToolPresentation]
* Overriding is needed to provide [UnitTestBotInspectionToolPresentation]
* instead of the standard implementation of the [InspectionToolPresentation].
*/
override fun getPresentation(toolWrapper: InspectionToolWrapper<*, *>): InspectionToolPresentation {
return myPresentationMap.computeIfAbsent(toolWrapper) {
UTBotInspectionToolPresentation(globalInspectionToolWrapper, context = this)
UnitTestBotInspectionToolPresentation(globalInspectionToolWrapper, context = this)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ import org.utbot.sarif.Sarif
import java.nio.file.Path

/**
* Overrides some methods of [InspectionManagerEx] to satisfy the logic of [UTBotInspectionTool].
* Overrides some methods of [InspectionManagerEx] to satisfy the logic of [UnitTestBotInspectionTool].
*/
class UTBotInspectionManager(project: Project) : InspectionManagerEx(project) {
class UnitTestBotInspectionManager(project: Project) : InspectionManagerEx(project) {

private var srcClassPathToSarifReport: MutableMap<Path, Sarif> = mutableMapOf()

companion object {
fun getInstance(project: Project, srcClassPathToSarifReport: MutableMap<Path, Sarif>) =
UTBotInspectionManager(project).also {
UnitTestBotInspectionManager(project).also {
it.srcClassPathToSarifReport = srcClassPathToSarifReport
}
}
Expand All @@ -32,8 +32,8 @@ class UTBotInspectionManager(project: Project) : InspectionManagerEx(project) {
}

/**
* Overriding is needed to provide [UTBotInspectionContext] instead of [GlobalInspectionContextImpl].
* Overriding is needed to provide [UnitTestBotInspectionContext] instead of [GlobalInspectionContextImpl].
*/
override fun createNewGlobalContext(): GlobalInspectionContextImpl =
UTBotInspectionContext(project, myContentManager, srcClassPathToSarifReport)
UnitTestBotInspectionContext(project, myContentManager, srcClassPathToSarifReport)
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import java.nio.file.Path
/**
* Global inspection tool that displays detected errors from the SARIF report.
*/
class UTBotInspectionTool : GlobalSimpleInspectionTool() {
class UnitTestBotInspectionTool : GlobalSimpleInspectionTool() {

/**
* Map from the path to the class under test to [Sarif] for it.
Expand All @@ -22,7 +22,7 @@ class UTBotInspectionTool : GlobalSimpleInspectionTool() {

companion object {
fun getInstance(srcClassPathToSarifReport: MutableMap<Path, Sarif>) =
UTBotInspectionTool().also {
UnitTestBotInspectionTool().also {
it.srcClassPathToSarifReport = srcClassPathToSarifReport
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ import com.intellij.codeInspection.ui.DefaultInspectionToolPresentation
/**
* Overrides [resolveProblem] to avoid suppressing quick fix buttons.
*/
class UTBotInspectionToolPresentation(
class UnitTestBotInspectionToolPresentation(
toolWrapper: InspectionToolWrapper<*, *>,
context: UTBotInspectionContext
context: UnitTestBotInspectionContext
) : DefaultInspectionToolPresentation(toolWrapper, context) {

/**
* This method is called when the user clicks on the quick fix button.
* In the case of [UTBotInspectionTool] we do not want to remove the button after applying the fix.
* In the case of [UnitTestBotInspectionTool] we do not want to remove the button after applying the fix.
*
* See [DefaultInspectionToolPresentation.resolveProblem] for more details.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import com.intellij.psi.PsiMethod
import com.intellij.psi.impl.file.impl.JavaFileManager
import com.intellij.psi.search.GlobalSearchScope
import com.intellij.refactoring.util.classMembers.MemberInfo
import com.jetbrains.rd.framework.util.asCompletableFuture
import com.jetbrains.rd.util.Logger
import com.jetbrains.rd.util.lifetime.Lifetime
import com.jetbrains.rd.util.lifetime.throwIfNotAlive
Expand Down Expand Up @@ -37,6 +38,7 @@ import org.utbot.rd.ProcessWithRdServer
import org.utbot.rd.loggers.UtRdKLoggerFactory
import org.utbot.rd.rdPortArgument
import org.utbot.rd.startUtProcessWithRdServer
import org.utbot.sarif.Sarif
import org.utbot.sarif.SourceFindingStrategy
import java.io.File
import java.nio.file.Path
Expand Down Expand Up @@ -349,7 +351,9 @@ class EngineProcess(parent: Lifetime, val project: Project) {
}
}
}
engineModel().writeSarifReport.start(WriteSarifReportArguments(testSetsId, reportFilePath.pathString, generatedTestsCode))
engineModel().writeSarifReport.startSuspending(
WriteSarifReportArguments(testSetsId, reportFilePath.pathString, generatedTestsCode)
)
}

fun generateTestsReport(model: GenerateTestsModel, eventLogMessage: String?): Triple<String, String?, Boolean> = runBlocking {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ object SarifReportIdea {
UtTestsDialogProcessor.updateIndicator(indicator, UtTestsDialogProcessor.ProgressRange.SARIF, "Generate SARIF report for ${classId.name}", .5)
// building the path to the report file
val classFqn = classId.name
val (sarifReportsPath, sourceFinding) = WriteAction.computeAndWait<Pair<Path, SourceFindingStrategyIdea>, Exception> { model.testModule.getOrCreateSarifReportsPath(model.testSourceRoot) to SourceFindingStrategyIdea(psiClass) }
val (sarifReportsPath, sourceFinding) = WriteAction.computeAndWait<Pair<Path, SourceFindingStrategyIdea>, Exception> {
model.testModule.getOrCreateSarifReportsPath(model.testSourceRoot) to SourceFindingStrategyIdea(psiClass)
}
val reportFilePath = sarifReportsPath.resolve("${classFqnToPath(classFqn)}Report.sarif")

IntelliJApiHelper.run(IntelliJApiHelper.Target.THREAD_POOL, indicator) {
Expand Down
2 changes: 1 addition & 1 deletion utbot-intellij/src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
groupKey="group.names.probable.bugs"
enabledByDefault="true"
level="ERROR"
implementationClass="org.utbot.intellij.plugin.inspection.UTBotInspectionTool"/>
implementationClass="org.utbot.intellij.plugin.inspection.UnitTestBotInspectionTool"/>
</extensions>

</idea-plugin>