diff --git a/utbot-framework/src/main/kotlin/org/utbot/framework/process/EngineMain.kt b/utbot-framework/src/main/kotlin/org/utbot/framework/process/EngineMain.kt index 17c8ea2a92..2498c729e0 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/framework/process/EngineMain.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/framework/process/EngineMain.kt @@ -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 diff --git a/utbot-framework/src/main/kotlin/org/utbot/framework/process/generated/EngineProcessModel.Generated.kt b/utbot-framework/src/main/kotlin/org/utbot/framework/process/generated/EngineProcessModel.Generated.kt index 92abf930d4..8b4555029c 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/framework/process/generated/EngineProcessModel.Generated.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/framework/process/generated/EngineProcessModel.Generated.kt @@ -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, @@ -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, @@ -243,7 +243,7 @@ data class FindMethodParamNamesArguments ( /** - * #### Generated from [EngineProcessModel.kt:103] + * #### Generated from [EngineProcessModel.kt:104] */ data class FindMethodParamNamesResult ( val paramNames: ByteArray @@ -300,7 +300,7 @@ data class FindMethodParamNamesResult ( /** - * #### Generated from [EngineProcessModel.kt:92] + * #### Generated from [EngineProcessModel.kt:93] */ data class FindMethodsInClassMatchingSelectedArguments ( val classId: ByteArray, @@ -363,7 +363,7 @@ data class FindMethodsInClassMatchingSelectedArguments ( /** - * #### Generated from [EngineProcessModel.kt:96] + * #### Generated from [EngineProcessModel.kt:97] */ data class FindMethodsInClassMatchingSelectedResult ( val executableIds: ByteArray @@ -420,7 +420,7 @@ data class FindMethodsInClassMatchingSelectedResult ( /** - * #### Generated from [EngineProcessModel.kt:42] + * #### Generated from [EngineProcessModel.kt:43] */ data class GenerateParams ( val mockInstalled: Boolean, @@ -543,7 +543,7 @@ data class GenerateParams ( /** - * #### Generated from [EngineProcessModel.kt:60] + * #### Generated from [EngineProcessModel.kt:61] */ data class GenerateResult ( val notEmptyCases: Int, @@ -606,7 +606,7 @@ data class GenerateResult ( /** - * #### Generated from [EngineProcessModel.kt:111] + * #### Generated from [EngineProcessModel.kt:112] */ data class GenerateTestReportArgs ( val eventLogMessage: String?, @@ -699,7 +699,7 @@ data class GenerateTestReportArgs ( /** - * #### Generated from [EngineProcessModel.kt:120] + * #### Generated from [EngineProcessModel.kt:121] */ data class GenerateTestReportResult ( val notifyMessage: String, @@ -768,7 +768,7 @@ data class GenerateTestReportResult ( /** - * #### Generated from [EngineProcessModel.kt:31] + * #### Generated from [EngineProcessModel.kt:32] */ data class JdkInfo ( val path: String, @@ -831,7 +831,7 @@ data class JdkInfo ( /** - * #### Generated from [EngineProcessModel.kt:64] + * #### Generated from [EngineProcessModel.kt:65] */ data class RenderParams ( val testSetsId: Long, @@ -972,7 +972,7 @@ data class RenderParams ( /** - * #### Generated from [EngineProcessModel.kt:81] + * #### Generated from [EngineProcessModel.kt:82] */ data class RenderResult ( val generatedCode: String, @@ -1035,7 +1035,7 @@ data class RenderResult ( /** - * #### Generated from [EngineProcessModel.kt:85] + * #### Generated from [EngineProcessModel.kt:86] */ data class SetupContextParams ( val classpathForUrlsClassloader: List @@ -1092,7 +1092,7 @@ data class SetupContextParams ( /** - * #### Generated from [EngineProcessModel.kt:88] + * #### Generated from [EngineProcessModel.kt:89] */ data class Signature ( val name: String, @@ -1155,7 +1155,7 @@ data class Signature ( /** - * #### Generated from [EngineProcessModel.kt:36] + * #### Generated from [EngineProcessModel.kt:37] */ data class TestGeneratorParams ( val buildDir: Array, @@ -1230,7 +1230,7 @@ data class TestGeneratorParams ( /** - * #### Generated from [EngineProcessModel.kt:106] + * #### Generated from [EngineProcessModel.kt:107] */ data class WriteSarifReportArguments ( val testSetsId: Long, diff --git a/utbot-framework/src/main/kotlin/org/utbot/framework/process/generated/RdSourceFindingStrategy.Generated.kt b/utbot-framework/src/main/kotlin/org/utbot/framework/process/generated/RdSourceFindingStrategy.Generated.kt index 8fadc70d0a..86afa5f6bd 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/framework/process/generated/RdSourceFindingStrategy.Generated.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/framework/process/generated/RdSourceFindingStrategy.Generated.kt @@ -18,16 +18,16 @@ import kotlin.jvm.JvmStatic * #### Generated from [EngineProcessModel.kt:17] */ class RdSourceFindingStrategy private constructor( - private val _testsRelativePath: RdCall, - private val _getSourceRelativePath: RdCall, - private val _getSourceFile: RdCall + private val _testsRelativePath: RdCall, + private val _getSourceRelativePath: RdCall, + private val _getSourceFile: RdCall ) : RdExtBase() { //companion companion object : ISerializersOwner { override fun registerSerializersCore(serializers: ISerializers) { - serializers.register(SourceStrategeMethodArgs) + serializers.register(SourceStrategyMethodArgs) } @@ -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 get() = _testsRelativePath - val getSourceRelativePath: RdCall get() = _getSourceRelativePath - val getSourceFile: RdCall get() = _getSourceFile + val testsRelativePath: RdCall get() = _testsRelativePath + val getSourceRelativePath: RdCall get() = _getSourceRelativePath + val getSourceFile: RdCall get() = _getSourceFile //methods //initializer init { @@ -79,9 +79,9 @@ class RdSourceFindingStrategy private constructor( //secondary constructor private constructor( ) : this( - RdCall(FrameworkMarshallers.Void, FrameworkMarshallers.String), - RdCall(SourceStrategeMethodArgs, FrameworkMarshallers.String), - RdCall(SourceStrategeMethodArgs, __StringNullableSerializer) + RdCall(FrameworkMarshallers.Long, FrameworkMarshallers.String), + RdCall(SourceStrategyMethodArgs, FrameworkMarshallers.String), + RdCall(SourceStrategyMethodArgs, __StringNullableSerializer) ) //equals trait @@ -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 { - override val _type: KClass = SourceStrategeMethodArgs::class + companion object : IMarshaller { + override val _type: KClass = 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) } } @@ -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 @@ -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() } diff --git a/utbot-framework/src/main/kotlin/org/utbot/sarif/RdSourceFindingStrategy.kt b/utbot-framework/src/main/kotlin/org/utbot/sarif/RdSourceFindingStrategy.kt index 68adbb1295..5b38c1e18c 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/sarif/RdSourceFindingStrategy.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/sarif/RdSourceFindingStrategy.kt @@ -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) } } diff --git a/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/generator/CodeGenerationController.kt b/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/generator/CodeGenerationController.kt index d9bd620c52..400d6cc8ab 100644 --- a/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/generator/CodeGenerationController.kt +++ b/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/generator/CodeGenerationController.kt @@ -694,7 +694,7 @@ object CodeGenerationController { val file = filePointer.containingFile val srcClassPath = srcClass.containingFile.virtualFile.toNioPath() - val sarifReport = saveSarifReport( + saveSarifReport( proc, testSetsId, testClassUpdated, diff --git a/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/process/EngineProcess.kt b/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/process/EngineProcess.kt index b27680ff42..2a5fef497d 100644 --- a/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/process/EngineProcess.kt +++ b/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/process/EngineProcess.kt @@ -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 @@ -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 @@ -65,6 +64,8 @@ class EngineProcess(parent: Lifetime, val project: Project) { private var count = 0 private var configPath: Path? = null + private val sourceFindingStrategies = ConcurrentHashMap() + private fun getOrCreateLogConfig(): String { var realPath = configPath if (realPath == null) { @@ -164,6 +165,7 @@ class EngineProcess(parent: Lifetime, val project: Project) { } }.awaitSignal() current = proc + initSourceFindingStrategies() } proc.protocol.engineProcessModel @@ -323,15 +325,11 @@ 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 { - sourceFindingStrategy.getSourceFile( + sourceFindingStrategies[params.testSetId]!!.getSourceFile( params.classFqn, params.extension )?.canonicalPath @@ -339,18 +337,27 @@ class EngineProcess(parent: Lifetime, val project: Project) { } it.getSourceRelativePath.set { params -> DumbService.getInstance(project).runReadActionInSmartMode { - sourceFindingStrategy.getSourceRelativePath( + sourceFindingStrategies[params.testSetId]!!.getSourceRelativePath( params.classFqn, params.extension ) } } - it.testsRelativePath.set { _ -> + it.testsRelativePath.set { testSetId -> DumbService.getInstance(project).runReadActionInSmartMode { - 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) ) diff --git a/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/sarif/SarifReportIdea.kt b/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/sarif/SarifReportIdea.kt index 8939abcdf4..25494deb6e 100644 --- a/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/sarif/SarifReportIdea.kt +++ b/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/sarif/SarifReportIdea.kt @@ -5,7 +5,6 @@ import com.intellij.psi.PsiClass import com.intellij.openapi.progress.ProgressIndicator import org.utbot.common.PathUtil.classFqnToPath import org.utbot.intellij.plugin.ui.utils.getOrCreateSarifReportsPath -import com.intellij.openapi.vfs.VfsUtil import java.util.concurrent.CountDownLatch import mu.KotlinLogging import org.utbot.framework.plugin.api.ClassId @@ -13,7 +12,6 @@ import org.utbot.intellij.plugin.generator.UtTestsDialogProcessor import org.utbot.intellij.plugin.models.GenerateTestsModel import org.utbot.intellij.plugin.process.EngineProcess import org.utbot.sarif.Sarif -import org.utbot.intellij.plugin.ui.utils.getOrCreateSarifReportsPath import org.utbot.intellij.plugin.util.IntelliJApiHelper import java.nio.file.Path diff --git a/utbot-rd/src/main/rdgen/org/utbot/rd/models/EngineProcessModel.kt b/utbot-rd/src/main/rdgen/org/utbot/rd/models/EngineProcessModel.kt index b10382b545..5fd4cded76 100644 --- a/utbot-rd/src/main/rdgen/org/utbot/rd/models/EngineProcessModel.kt +++ b/utbot-rd/src/main/rdgen/org/utbot/rd/models/EngineProcessModel.kt @@ -15,15 +15,16 @@ object RdInstrumenterAdapter: Ext(EngineProcessProtocolRoot) { } object RdSourceFindingStrategy : Ext(EngineProcessProtocolRoot) { - val sourceStrategeMethodArgs = structdef { + val sourceStrategyMethodArgs = structdef { + field("testSetId", PredefinedType.long) field("classFqn", PredefinedType.string) field("extension", PredefinedType.string.nullable) } init { - call("testsRelativePath", PredefinedType.void, PredefinedType.string).async - call("getSourceRelativePath", sourceStrategeMethodArgs, PredefinedType.string).async - call("getSourceFile", sourceStrategeMethodArgs, PredefinedType.string.nullable).async + call("testsRelativePath", PredefinedType.long, PredefinedType.string).async + call("getSourceRelativePath", sourceStrategyMethodArgs, PredefinedType.string).async + call("getSourceFile", sourceStrategyMethodArgs, PredefinedType.string.nullable).async } }