Skip to content

Fix incorrect test file path in SARIF report #1223

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 1 commit into from
Oct 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ private fun EngineProcessModel.setup(
val sarifReport = SarifReport(
testSets[params.testSetsId]!!,
params.generatedTestsCode,
RdSourceFindingStrategyFacade(realProtocol.rdSourceFindingStrategy)
RdSourceFindingStrategyFacade(params.testSetsId, realProtocol.rdSourceFindingStrategy)
).createReport().toJson()
reportFilePath.toFile().writeText(sarifReport)
sarifReport
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import kotlin.jvm.JvmStatic


/**
* #### Generated from [EngineProcessModel.kt:30]
* #### Generated from [EngineProcessModel.kt:31]
*/
class EngineProcessModel private constructor(
private val _setupUtContext: RdCall<SetupContextParams, Unit>,
Expand Down Expand Up @@ -180,7 +180,7 @@ val IProtocol.engineProcessModel get() = getOrCreateExtension(EngineProcessModel


/**
* #### Generated from [EngineProcessModel.kt:99]
* #### Generated from [EngineProcessModel.kt:100]
*/
data class FindMethodParamNamesArguments (
val classId: ByteArray,
Expand Down Expand Up @@ -243,7 +243,7 @@ data class FindMethodParamNamesArguments (


/**
* #### Generated from [EngineProcessModel.kt:103]
* #### Generated from [EngineProcessModel.kt:104]
*/
data class FindMethodParamNamesResult (
val paramNames: ByteArray
Expand Down Expand Up @@ -300,7 +300,7 @@ data class FindMethodParamNamesResult (


/**
* #### Generated from [EngineProcessModel.kt:92]
* #### Generated from [EngineProcessModel.kt:93]
*/
data class FindMethodsInClassMatchingSelectedArguments (
val classId: ByteArray,
Expand Down Expand Up @@ -363,7 +363,7 @@ data class FindMethodsInClassMatchingSelectedArguments (


/**
* #### Generated from [EngineProcessModel.kt:96]
* #### Generated from [EngineProcessModel.kt:97]
*/
data class FindMethodsInClassMatchingSelectedResult (
val executableIds: ByteArray
Expand Down Expand Up @@ -420,7 +420,7 @@ data class FindMethodsInClassMatchingSelectedResult (


/**
* #### Generated from [EngineProcessModel.kt:42]
* #### Generated from [EngineProcessModel.kt:43]
*/
data class GenerateParams (
val mockInstalled: Boolean,
Expand Down Expand Up @@ -543,7 +543,7 @@ data class GenerateParams (


/**
* #### Generated from [EngineProcessModel.kt:60]
* #### Generated from [EngineProcessModel.kt:61]
*/
data class GenerateResult (
val notEmptyCases: Int,
Expand Down Expand Up @@ -606,7 +606,7 @@ data class GenerateResult (


/**
* #### Generated from [EngineProcessModel.kt:111]
* #### Generated from [EngineProcessModel.kt:112]
*/
data class GenerateTestReportArgs (
val eventLogMessage: String?,
Expand Down Expand Up @@ -699,7 +699,7 @@ data class GenerateTestReportArgs (


/**
* #### Generated from [EngineProcessModel.kt:120]
* #### Generated from [EngineProcessModel.kt:121]
*/
data class GenerateTestReportResult (
val notifyMessage: String,
Expand Down Expand Up @@ -768,7 +768,7 @@ data class GenerateTestReportResult (


/**
* #### Generated from [EngineProcessModel.kt:31]
* #### Generated from [EngineProcessModel.kt:32]
*/
data class JdkInfo (
val path: String,
Expand Down Expand Up @@ -831,7 +831,7 @@ data class JdkInfo (


/**
* #### Generated from [EngineProcessModel.kt:64]
* #### Generated from [EngineProcessModel.kt:65]
*/
data class RenderParams (
val testSetsId: Long,
Expand Down Expand Up @@ -972,7 +972,7 @@ data class RenderParams (


/**
* #### Generated from [EngineProcessModel.kt:81]
* #### Generated from [EngineProcessModel.kt:82]
*/
data class RenderResult (
val generatedCode: String,
Expand Down Expand Up @@ -1035,7 +1035,7 @@ data class RenderResult (


/**
* #### Generated from [EngineProcessModel.kt:85]
* #### Generated from [EngineProcessModel.kt:86]
*/
data class SetupContextParams (
val classpathForUrlsClassloader: List<String>
Expand Down Expand Up @@ -1092,7 +1092,7 @@ data class SetupContextParams (


/**
* #### Generated from [EngineProcessModel.kt:88]
* #### Generated from [EngineProcessModel.kt:89]
*/
data class Signature (
val name: String,
Expand Down Expand Up @@ -1155,7 +1155,7 @@ data class Signature (


/**
* #### Generated from [EngineProcessModel.kt:36]
* #### Generated from [EngineProcessModel.kt:37]
*/
data class TestGeneratorParams (
val buildDir: Array<String>,
Expand Down Expand Up @@ -1230,7 +1230,7 @@ data class TestGeneratorParams (


/**
* #### Generated from [EngineProcessModel.kt:106]
* #### Generated from [EngineProcessModel.kt:107]
*/
data class WriteSarifReportArguments (
val testSetsId: Long,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@ import kotlin.jvm.JvmStatic
* #### Generated from [EngineProcessModel.kt:17]
*/
class RdSourceFindingStrategy private constructor(
private val _testsRelativePath: RdCall<Unit, String>,
private val _getSourceRelativePath: RdCall<SourceStrategeMethodArgs, String>,
private val _getSourceFile: RdCall<SourceStrategeMethodArgs, String?>
private val _testsRelativePath: RdCall<Long, String>,
private val _getSourceRelativePath: RdCall<SourceStrategyMethodArgs, String>,
private val _getSourceFile: RdCall<SourceStrategyMethodArgs, String?>
) : RdExtBase() {
//companion

companion object : ISerializersOwner {

override fun registerSerializersCore(serializers: ISerializers) {
serializers.register(SourceStrategeMethodArgs)
serializers.register(SourceStrategyMethodArgs)
}


Expand All @@ -52,16 +52,16 @@ class RdSourceFindingStrategy private constructor(

private val __StringNullableSerializer = FrameworkMarshallers.String.nullable()

const val serializationHash = -8019839448677987345L
const val serializationHash = 3794277837200536292L

}
override val serializersOwner: ISerializersOwner get() = RdSourceFindingStrategy
override val serializationHash: Long get() = RdSourceFindingStrategy.serializationHash

//fields
val testsRelativePath: RdCall<Unit, String> get() = _testsRelativePath
val getSourceRelativePath: RdCall<SourceStrategeMethodArgs, String> get() = _getSourceRelativePath
val getSourceFile: RdCall<SourceStrategeMethodArgs, String?> get() = _getSourceFile
val testsRelativePath: RdCall<Long, String> get() = _testsRelativePath
val getSourceRelativePath: RdCall<SourceStrategyMethodArgs, String> get() = _getSourceRelativePath
val getSourceFile: RdCall<SourceStrategyMethodArgs, String?> get() = _getSourceFile
//methods
//initializer
init {
Expand All @@ -79,9 +79,9 @@ class RdSourceFindingStrategy private constructor(
//secondary constructor
private constructor(
) : this(
RdCall<Unit, String>(FrameworkMarshallers.Void, FrameworkMarshallers.String),
RdCall<SourceStrategeMethodArgs, String>(SourceStrategeMethodArgs, FrameworkMarshallers.String),
RdCall<SourceStrategeMethodArgs, String?>(SourceStrategeMethodArgs, __StringNullableSerializer)
RdCall<Long, String>(FrameworkMarshallers.Long, FrameworkMarshallers.String),
RdCall<SourceStrategyMethodArgs, String>(SourceStrategyMethodArgs, FrameworkMarshallers.String),
RdCall<SourceStrategyMethodArgs, String?>(SourceStrategyMethodArgs, __StringNullableSerializer)
)

//equals trait
Expand Down Expand Up @@ -113,23 +113,26 @@ val IProtocol.rdSourceFindingStrategy get() = getOrCreateExtension(RdSourceFindi
/**
* #### Generated from [EngineProcessModel.kt:18]
*/
data class SourceStrategeMethodArgs (
data class SourceStrategyMethodArgs (
val testSetId: Long,
val classFqn: String,
val extension: String?
) : IPrintable {
//companion

companion object : IMarshaller<SourceStrategeMethodArgs> {
override val _type: KClass<SourceStrategeMethodArgs> = SourceStrategeMethodArgs::class
companion object : IMarshaller<SourceStrategyMethodArgs> {
override val _type: KClass<SourceStrategyMethodArgs> = SourceStrategyMethodArgs::class

@Suppress("UNCHECKED_CAST")
override fun read(ctx: SerializationCtx, buffer: AbstractBuffer): SourceStrategeMethodArgs {
override fun read(ctx: SerializationCtx, buffer: AbstractBuffer): SourceStrategyMethodArgs {
val testSetId = buffer.readLong()
val classFqn = buffer.readString()
val extension = buffer.readNullable { buffer.readString() }
return SourceStrategeMethodArgs(classFqn, extension)
return SourceStrategyMethodArgs(testSetId, classFqn, extension)
}

override fun write(ctx: SerializationCtx, buffer: AbstractBuffer, value: SourceStrategeMethodArgs) {
override fun write(ctx: SerializationCtx, buffer: AbstractBuffer, value: SourceStrategyMethodArgs) {
buffer.writeLong(value.testSetId)
buffer.writeString(value.classFqn)
buffer.writeNullable(value.extension) { buffer.writeString(it) }
}
Expand All @@ -145,8 +148,9 @@ data class SourceStrategeMethodArgs (
if (this === other) return true
if (other == null || other::class != this::class) return false

other as SourceStrategeMethodArgs
other as SourceStrategyMethodArgs

if (testSetId != other.testSetId) return false
if (classFqn != other.classFqn) return false
if (extension != other.extension) return false

Expand All @@ -155,14 +159,16 @@ data class SourceStrategeMethodArgs (
//hash code trait
override fun hashCode(): Int {
var __r = 0
__r = __r*31 + testSetId.hashCode()
__r = __r*31 + classFqn.hashCode()
__r = __r*31 + if (extension != null) extension.hashCode() else 0
return __r
}
//pretty print
override fun print(printer: PrettyPrinter) {
printer.println("SourceStrategeMethodArgs (")
printer.println("SourceStrategyMethodArgs (")
printer.indent {
print("testSetId = "); testSetId.print(printer); println()
print("classFqn = "); classFqn.print(printer); println()
print("extension = "); extension.print(printer); println()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,22 @@ package org.utbot.sarif

import kotlinx.coroutines.runBlocking
import org.utbot.framework.process.generated.RdSourceFindingStrategy
import org.utbot.framework.process.generated.SourceStrategeMethodArgs
import org.utbot.framework.process.generated.SourceStrategyMethodArgs
import java.io.File

class RdSourceFindingStrategyFacade(private val realStrategy: RdSourceFindingStrategy): SourceFindingStrategy() {
class RdSourceFindingStrategyFacade(
private val testSetsId: Long,
private val realStrategy: RdSourceFindingStrategy
) : SourceFindingStrategy() {
override val testsRelativePath: String
get() = runBlocking { realStrategy.testsRelativePath.startSuspending(Unit) }
get() = runBlocking { realStrategy.testsRelativePath.startSuspending(testSetsId) }

override fun getSourceRelativePath(classFqn: String, extension: String?): String = runBlocking {
realStrategy.getSourceRelativePath.startSuspending(SourceStrategeMethodArgs(classFqn, extension))
realStrategy.getSourceRelativePath.startSuspending(SourceStrategyMethodArgs(testSetsId, classFqn, extension))
}

override fun getSourceFile(classFqn: String, extension: String?): File? = runBlocking {
realStrategy.getSourceFile.startSuspending(SourceStrategeMethodArgs(classFqn, extension))?.let {
realStrategy.getSourceFile.startSuspending(SourceStrategyMethodArgs(testSetsId, classFqn, extension))?.let {
File(it)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -694,7 +694,7 @@ object CodeGenerationController {
val file = filePointer.containingFile

val srcClassPath = srcClass.containingFile.virtualFile.toNioPath()
val sarifReport = saveSarifReport(
saveSarifReport(
proc,
testSetsId,
testClassUpdated,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +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.ConcurrentHashMap
import com.jetbrains.rd.util.Logger
import com.jetbrains.rd.util.lifetime.Lifetime
import com.jetbrains.rd.util.lifetime.throwIfNotAlive
Expand Down Expand Up @@ -38,7 +38,6 @@ 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 All @@ -65,6 +64,8 @@ class EngineProcess(parent: Lifetime, val project: Project) {
private var count = 0
private var configPath: Path? = null

private val sourceFindingStrategies = ConcurrentHashMap<Long, SourceFindingStrategy>()

private fun getOrCreateLogConfig(): String {
var realPath = configPath
if (realPath == null) {
Expand Down Expand Up @@ -164,6 +165,7 @@ class EngineProcess(parent: Lifetime, val project: Project) {
}
}.awaitSignal()
current = proc
initSourceFindingStrategies()
}

proc.protocol.engineProcessModel
Expand Down Expand Up @@ -323,34 +325,39 @@ class EngineProcess(parent: Lifetime, val project: Project) {
current?.terminate()
}

fun writeSarif(reportFilePath: Path,
testSetsId: Long,
generatedTestsCode: String,
sourceFindingStrategy: SourceFindingStrategy
): String = runBlocking {
private fun initSourceFindingStrategies() {
current!!.protocol.rdSourceFindingStrategy.let {
it.getSourceFile.set { params ->
DumbService.getInstance(project).runReadActionInSmartMode<String?> {
sourceFindingStrategy.getSourceFile(
sourceFindingStrategies[params.testSetId]!!.getSourceFile(
params.classFqn,
params.extension
)?.canonicalPath
}
}
it.getSourceRelativePath.set { params ->
DumbService.getInstance(project).runReadActionInSmartMode<String> {
sourceFindingStrategy.getSourceRelativePath(
sourceFindingStrategies[params.testSetId]!!.getSourceRelativePath(
params.classFqn,
params.extension
)
}
}
it.testsRelativePath.set { _ ->
it.testsRelativePath.set { testSetId ->
DumbService.getInstance(project).runReadActionInSmartMode<String> {
sourceFindingStrategy.testsRelativePath
sourceFindingStrategies[testSetId]!!.testsRelativePath
}
}
}
}

fun writeSarif(
reportFilePath: Path,
testSetsId: Long,
generatedTestsCode: String,
sourceFindingStrategy: SourceFindingStrategy
): String = runBlocking {
sourceFindingStrategies[testSetsId] = sourceFindingStrategy
engineModel().writeSarifReport.startSuspending(
WriteSarifReportArguments(testSetsId, reportFilePath.pathString, generatedTestsCode)
)
Expand Down
Loading