diff --git a/clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/actions/GenerateForAssertionAction.kt b/clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/actions/GenerateForAssertionAction.kt index 37d52b46..2e3f0fff 100644 --- a/clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/actions/GenerateForAssertionAction.kt +++ b/clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/actions/GenerateForAssertionAction.kt @@ -2,13 +2,13 @@ package org.utbot.cpp.clion.plugin.actions import com.intellij.openapi.actionSystem.AnActionEvent import com.intellij.openapi.actionSystem.CommonDataKeys -import org.utbot.cpp.clion.plugin.utils.getAssertionRequestMessage +import org.utbot.cpp.clion.plugin.grpc.getAssertionGrpcRequest import org.utbot.cpp.clion.plugin.client.requests.AssertionRequest class GenerateForAssertionAction : GenerateTestsBaseAction() { override fun actionPerformed(e: AnActionEvent) { AssertionRequest( - getAssertionRequestMessage(e), + getAssertionGrpcRequest(e), e.project!!, ).execute() } diff --git a/clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/actions/GenerateForClassAction.kt b/clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/actions/GenerateForClassAction.kt index 0fffedad..b51b7b9e 100644 --- a/clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/actions/GenerateForClassAction.kt +++ b/clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/actions/GenerateForClassAction.kt @@ -2,14 +2,14 @@ package org.utbot.cpp.clion.plugin.actions import com.intellij.openapi.actionSystem.AnActionEvent import com.intellij.openapi.actionSystem.CommonDataKeys -import org.utbot.cpp.clion.plugin.utils.getClassRequestMessage +import org.utbot.cpp.clion.plugin.grpc.getClassGrpcRequest import org.utbot.cpp.clion.plugin.client.requests.ClassRequest import org.utbot.cpp.clion.plugin.utils.isCPPFileName class GenerateForClassAction : GenerateTestsBaseAction() { override fun actionPerformed(e: AnActionEvent) { ClassRequest( - getClassRequestMessage(e), + getClassGrpcRequest(e), e.project!!, ).execute() } diff --git a/clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/actions/GenerateForFileAction.kt b/clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/actions/GenerateForFileAction.kt index 1448c10b..a4c7aaab 100644 --- a/clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/actions/GenerateForFileAction.kt +++ b/clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/actions/GenerateForFileAction.kt @@ -2,13 +2,13 @@ package org.utbot.cpp.clion.plugin.actions import com.intellij.openapi.actionSystem.AnActionEvent import com.intellij.openapi.actionSystem.CommonDataKeys -import org.utbot.cpp.clion.plugin.utils.getFileRequestMessage +import org.utbot.cpp.clion.plugin.grpc.getFileGrpcRequest import org.utbot.cpp.clion.plugin.client.requests.FileRequest import org.utbot.cpp.clion.plugin.utils.isCPPorCFileName class GenerateForFileAction : GenerateTestsBaseAction() { override fun actionPerformed(e: AnActionEvent) { - FileRequest(getFileRequestMessage(e), e.project!!).execute() + FileRequest(getFileGrpcRequest(e), e.project!!).execute() } // action is available only if the selected file ends in .cpp, .hpp, .c or .h diff --git a/clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/actions/GenerateForFolderAction.kt b/clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/actions/GenerateForFolderAction.kt index d9e33a9f..83ce3156 100644 --- a/clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/actions/GenerateForFolderAction.kt +++ b/clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/actions/GenerateForFolderAction.kt @@ -2,13 +2,13 @@ package org.utbot.cpp.clion.plugin.actions import com.intellij.openapi.actionSystem.AnActionEvent import com.intellij.openapi.actionSystem.CommonDataKeys -import org.utbot.cpp.clion.plugin.utils.getFolderRequestMessage +import org.utbot.cpp.clion.plugin.grpc.getFolderGrpcRequest import org.utbot.cpp.clion.plugin.client.requests.FolderRequest class GenerateForFolderAction : GenerateTestsBaseAction() { override fun actionPerformed(e: AnActionEvent) { FolderRequest( - getFolderRequestMessage(e), + getFolderGrpcRequest(e), e.project!! ).execute() } diff --git a/clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/actions/GenerateForFunctionAction.kt b/clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/actions/GenerateForFunctionAction.kt index d8688ce4..bfd99641 100644 --- a/clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/actions/GenerateForFunctionAction.kt +++ b/clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/actions/GenerateForFunctionAction.kt @@ -2,7 +2,7 @@ package org.utbot.cpp.clion.plugin.actions import com.intellij.openapi.actionSystem.AnActionEvent import com.intellij.openapi.actionSystem.CommonDataKeys -import org.utbot.cpp.clion.plugin.utils.getFunctionRequestMessage +import org.utbot.cpp.clion.plugin.grpc.getFunctionGrpcRequest import org.utbot.cpp.clion.plugin.client.requests.FunctionRequest class GenerateForFunctionAction : GenerateTestsBaseAction() { @@ -13,7 +13,7 @@ class GenerateForFunctionAction : GenerateTestsBaseAction() { override fun actionPerformed(e: AnActionEvent) { FunctionRequest( - getFunctionRequestMessage(e), + getFunctionGrpcRequest(e), e.project!! ).execute() } diff --git a/clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/actions/GenerateForLineAction.kt b/clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/actions/GenerateForLineAction.kt index 396fd02b..16962c14 100644 --- a/clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/actions/GenerateForLineAction.kt +++ b/clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/actions/GenerateForLineAction.kt @@ -2,7 +2,7 @@ package org.utbot.cpp.clion.plugin.actions import com.intellij.openapi.actionSystem.AnActionEvent import com.intellij.openapi.actionSystem.CommonDataKeys -import org.utbot.cpp.clion.plugin.utils.getLineRequestMessage +import org.utbot.cpp.clion.plugin.grpc.getLineGrpcRequest import org.utbot.cpp.clion.plugin.client.requests.LineRequest class GenerateForLineAction : GenerateTestsBaseAction() { @@ -15,7 +15,7 @@ class GenerateForLineAction : GenerateTestsBaseAction() { override fun actionPerformed(e: AnActionEvent) { LineRequest( - getLineRequestMessage(e), + getLineGrpcRequest(e), e.project!! ).execute() } diff --git a/clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/actions/GenerateForPredicateAction.kt b/clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/actions/GenerateForPredicateAction.kt index 6f7a7f49..9f3459f0 100644 --- a/clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/actions/GenerateForPredicateAction.kt +++ b/clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/actions/GenerateForPredicateAction.kt @@ -9,8 +9,8 @@ import com.intellij.ui.DocumentAdapter import com.intellij.ui.components.fields.ExtendableTextField import javax.swing.ListSelectionModel import javax.swing.event.DocumentEvent -import org.utbot.cpp.clion.plugin.utils.getFunctionRequestMessage -import org.utbot.cpp.clion.plugin.utils.getPredicateRequestMessage +import org.utbot.cpp.clion.plugin.grpc.getFunctionGrpcRequest +import org.utbot.cpp.clion.plugin.grpc.getPredicateGrpcRequest import org.utbot.cpp.clion.plugin.client.requests.FunctionReturnTypeRequest import org.utbot.cpp.clion.plugin.client.requests.PredicateRequest import org.utbot.cpp.clion.plugin.utils.client @@ -88,7 +88,7 @@ class GenerateForPredicateAction : GenerateTestsBaseAction() { override fun actionPerformed(e: AnActionEvent) { fun sendPredicateToServer(validationType: ValidationType, valueToCompare: String, comparisonOperator: String) { - val predicateRequest = getPredicateRequestMessage(validationType, valueToCompare, comparisonOperator, e) + val predicateRequest = getPredicateGrpcRequest(e, comparisonOperator, validationType, valueToCompare) PredicateRequest( predicateRequest, e.project!! @@ -122,7 +122,7 @@ class GenerateForPredicateAction : GenerateTestsBaseAction() { FunctionReturnTypeRequest( e.project!!, - getFunctionRequestMessage(e) + getFunctionGrpcRequest(e) ) { functionReturnType -> val type = functionReturnType.validationType chooseComparisonOperator(type) { comparisonOperator -> diff --git a/clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/actions/GenerateForProjectAction.kt b/clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/actions/GenerateForProjectAction.kt index 2a265b30..e2ecc3e2 100644 --- a/clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/actions/GenerateForProjectAction.kt +++ b/clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/actions/GenerateForProjectAction.kt @@ -1,7 +1,7 @@ package org.utbot.cpp.clion.plugin.actions import com.intellij.openapi.actionSystem.AnActionEvent -import org.utbot.cpp.clion.plugin.utils.getProjectRequestMessage +import org.utbot.cpp.clion.plugin.grpc.getProjectGrpcRequest import org.utbot.cpp.clion.plugin.client.requests.ProjectRequest import org.utbot.cpp.clion.plugin.utils.client @@ -12,7 +12,7 @@ class GenerateForProjectAction : GenerateTestsBaseAction() { override fun actionPerformed(e: AnActionEvent) { ProjectRequest( - getProjectRequestMessage(e), + getProjectGrpcRequest(e), e.project!! ).apply { e.client.executeRequest(this) diff --git a/clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/actions/GenerateForSnippetAction.kt b/clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/actions/GenerateForSnippetAction.kt index 94476f1e..b570c2bb 100644 --- a/clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/actions/GenerateForSnippetAction.kt +++ b/clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/actions/GenerateForSnippetAction.kt @@ -2,13 +2,13 @@ package org.utbot.cpp.clion.plugin.actions import com.intellij.openapi.actionSystem.AnActionEvent import com.intellij.openapi.actionSystem.CommonDataKeys -import org.utbot.cpp.clion.plugin.utils.getSnippetRequestMessage +import org.utbot.cpp.clion.plugin.grpc.getSnippetGrpcRequest import org.utbot.cpp.clion.plugin.client.requests.SnippetRequest class GenerateForSnippetAction : GenerateTestsBaseAction() { override fun actionPerformed(e: AnActionEvent) { SnippetRequest( - getSnippetRequestMessage(e), + getSnippetGrpcRequest(e), e.project!! ).execute() } diff --git a/clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/actions/ReconfigureProjectAction.kt b/clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/actions/ReconfigureProjectAction.kt index d0d7bc53..1c573399 100644 --- a/clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/actions/ReconfigureProjectAction.kt +++ b/clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/actions/ReconfigureProjectAction.kt @@ -4,7 +4,7 @@ import com.intellij.notification.Notification import com.intellij.notification.NotificationAction import com.intellij.openapi.actionSystem.AnActionEvent import org.utbot.cpp.clion.plugin.UTBot -import org.utbot.cpp.clion.plugin.utils.getProjectConfigRequestMessage +import org.utbot.cpp.clion.plugin.grpc.getProjectConfigGrpcRequest import org.utbot.cpp.clion.plugin.client.requests.CheckProjectConfigurationRequest import testsgen.Testgen @@ -16,7 +16,7 @@ class ReconfigureProjectAction: NotificationAction(UTBot.message("projectConfigu override fun actionPerformed(e: AnActionEvent) { CheckProjectConfigurationRequest( e.project!!, - getProjectConfigRequestMessage(e.project!!, Testgen.ConfigMode.ALL), + getProjectConfigGrpcRequest(e.project!!, Testgen.ConfigMode.ALL), ).execute() } diff --git a/clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/actions/RunWithCoverageAction.kt b/clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/actions/RunWithCoverageAction.kt index c0d4a60d..c1dfbb38 100644 --- a/clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/actions/RunWithCoverageAction.kt +++ b/clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/actions/RunWithCoverageAction.kt @@ -1,10 +1,12 @@ package org.utbot.cpp.clion.plugin.actions import com.intellij.openapi.actionSystem.AnActionEvent +import com.intellij.openapi.actionSystem.CommonDataKeys import com.intellij.openapi.diagnostic.Logger import com.intellij.psi.PsiElement -import org.utbot.cpp.clion.plugin.utils.getCoverageAndResultsRequest +import org.utbot.cpp.clion.plugin.grpc.getCoverageAndResultsGrpcRequest import org.utbot.cpp.clion.plugin.client.requests.RunWithCoverageRequest +import org.utbot.cpp.clion.plugin.grpc.activeProject import org.utbot.cpp.clion.plugin.ui.testsResults.TestNameAndTestSuite @@ -17,7 +19,8 @@ class RunWithCoverageAction(val element: PsiElement) : GenerateTestsBaseAction() val testArgs = TestNameAndTestSuite.getFromPsiElement(element) val suiteName = testArgs.suite val testedMethodName = testArgs.name - val request = getCoverageAndResultsRequest(e, suiteName, testedMethodName) + val filePath = e.getRequiredData(CommonDataKeys.VIRTUAL_FILE).path + val request = getCoverageAndResultsGrpcRequest(e.activeProject(), filePath, suiteName, testedMethodName) RunWithCoverageRequest( e.project!!, request diff --git a/clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/client/Client.kt b/clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/client/Client.kt index af7bbd49..839dbb10 100644 --- a/clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/client/Client.kt +++ b/clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/client/Client.kt @@ -21,8 +21,8 @@ import kotlinx.coroutines.runBlocking import kotlinx.coroutines.withTimeout import kotlinx.coroutines.Job -import org.utbot.cpp.clion.plugin.utils.getProjectConfigRequestMessage -import org.utbot.cpp.clion.plugin.utils.getVersionInfo +import org.utbot.cpp.clion.plugin.grpc.getProjectConfigGrpcRequest +import org.utbot.cpp.clion.plugin.grpc.getVersionGrpcRequest import org.utbot.cpp.clion.plugin.client.requests.CheckProjectConfigurationRequest import org.utbot.cpp.clion.plugin.listeners.ConnectionStatus import org.utbot.cpp.clion.plugin.listeners.UTBotEventsListener @@ -84,7 +84,7 @@ class Client( fun configureProject() { CheckProjectConfigurationRequest( project, - getProjectConfigRequestMessage(project, Testgen.ConfigMode.CHECK) + getProjectConfigGrpcRequest(project, Testgen.ConfigMode.CHECK) ).also { executeRequest(it) } @@ -96,7 +96,7 @@ class Client( requestsCS.launch { // Logger.info("sending HandShake request!") try { - stub.handshake(getVersionInfo()) + stub.handshake(getVersionGrpcRequest()) logger.info { "Handshake successful!" } } catch (e: Exception) { logger.warn { "HandShake failed with the following error: ${e.message}" } diff --git a/clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/client/LoggingChannels.kt b/clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/client/LoggingChannels.kt index 71edec64..2ede3ac5 100644 --- a/clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/client/LoggingChannels.kt +++ b/clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/client/LoggingChannels.kt @@ -5,8 +5,8 @@ import com.intellij.openapi.project.Project import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.catch import kotlinx.coroutines.flow.collect -import org.utbot.cpp.clion.plugin.utils.getDummyRequest -import org.utbot.cpp.clion.plugin.utils.getLogChannelRequest +import org.utbot.cpp.clion.plugin.grpc.getDummyGrpcRequest +import org.utbot.cpp.clion.plugin.grpc.getLogChannelGrpcRequest import org.utbot.cpp.clion.plugin.ui.userLog.OutputProvider import org.utbot.cpp.clion.plugin.ui.userLog.UTBotConsole import org.utbot.cpp.clion.plugin.utils.invokeOnEdt @@ -58,11 +58,11 @@ class GTestChannel(project: Project): BaseChannel(project) { override val console: UTBotConsole = project.service().gtestOutputChannel.outputConsole override suspend fun close(stub: TestsGenServiceGrpcKt.TestsGenServiceCoroutineStub) { - stub.closeGTestChannel(getDummyRequest()) + stub.closeGTestChannel(getDummyGrpcRequest()) } override suspend fun open(stub: TestsGenServiceGrpcKt.TestsGenServiceCoroutineStub): Flow { - return stub.openGTestChannel(getLogChannelRequest(logLevel)) + return stub.openGTestChannel(getLogChannelGrpcRequest(logLevel)) } } @@ -72,10 +72,10 @@ class ServerLogChannel(project: Project): BaseChannel(project) { override val console: UTBotConsole = project.service().serverOutputChannel.outputConsole override suspend fun close(stub: TestsGenServiceGrpcKt.TestsGenServiceCoroutineStub) { - stub.closeLogChannel(getDummyRequest()) + stub.closeLogChannel(getDummyGrpcRequest()) } override suspend fun open(stub: TestsGenServiceGrpcKt.TestsGenServiceCoroutineStub): Flow { - return stub.openLogChannel(getLogChannelRequest(logLevel)) + return stub.openLogChannel(getLogChannelGrpcRequest(logLevel)) } } diff --git a/clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/client/requests/CheckProjectConfigurationRequest.kt b/clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/client/requests/CheckProjectConfigurationRequest.kt index 19820488..e6df00a5 100644 --- a/clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/client/requests/CheckProjectConfigurationRequest.kt +++ b/clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/client/requests/CheckProjectConfigurationRequest.kt @@ -5,7 +5,7 @@ import com.intellij.openapi.project.Project import kotlinx.coroutines.Job import kotlinx.coroutines.flow.Flow import org.utbot.cpp.clion.plugin.UTBot -import org.utbot.cpp.clion.plugin.utils.getProjectConfigRequestMessage +import org.utbot.cpp.clion.plugin.grpc.getProjectConfigGrpcRequest import org.utbot.cpp.clion.plugin.client.handlers.CheckProjectConfigurationHandler import testsgen.Testgen import testsgen.TestsGenServiceGrpcKt @@ -16,7 +16,7 @@ class CheckProjectConfigurationRequest( ): BaseRequest>(request, project) { override val logMessage: String = "Sending request to check project configuration." - constructor(project: Project): this(project, getProjectConfigRequestMessage(project, Testgen.ConfigMode.CHECK)) + constructor(project: Project): this(project, getProjectConfigGrpcRequest(project, Testgen.ConfigMode.CHECK)) constructor(e: AnActionEvent): this(e.project!!) override suspend fun TestsGenServiceGrpcKt.TestsGenServiceCoroutineStub.send(cancellationJob: Job?): Flow { diff --git a/clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/client/requests/CreateBuildFolderRequest.kt b/clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/client/requests/CreateBuildFolderRequest.kt index f7138be5..06ffb367 100644 --- a/clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/client/requests/CreateBuildFolderRequest.kt +++ b/clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/client/requests/CreateBuildFolderRequest.kt @@ -5,7 +5,7 @@ import com.intellij.openapi.project.Project import kotlinx.coroutines.Job import kotlinx.coroutines.flow.Flow import org.utbot.cpp.clion.plugin.UTBot -import org.utbot.cpp.clion.plugin.utils.getProjectConfigRequestMessage +import org.utbot.cpp.clion.plugin.grpc.getProjectConfigGrpcRequest import org.utbot.cpp.clion.plugin.client.handlers.CreateBuildDirHandler import testsgen.Testgen import testsgen.TestsGenServiceGrpcKt @@ -16,7 +16,7 @@ class CreateBuildDirRequest( ): BaseRequest>(request, project) { override val logMessage: String = "Sending request to check project configuration." - constructor(e: AnActionEvent): this(e.project!!, getProjectConfigRequestMessage(e.project!!, Testgen.ConfigMode.CREATE_BUILD_DIR)) + constructor(e: AnActionEvent): this(e.project!!, getProjectConfigGrpcRequest(e.project!!, Testgen.ConfigMode.CREATE_BUILD_DIR)) override suspend fun TestsGenServiceGrpcKt.TestsGenServiceCoroutineStub.send(cancellationJob: Job?): Flow { return this.configureProject(request) diff --git a/clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/client/requests/GenerateJsonFilesRequest.kt b/clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/client/requests/GenerateJsonFilesRequest.kt index 6fb3d6ea..a45185bb 100644 --- a/clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/client/requests/GenerateJsonFilesRequest.kt +++ b/clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/client/requests/GenerateJsonFilesRequest.kt @@ -5,7 +5,7 @@ import com.intellij.openapi.project.Project import kotlinx.coroutines.Job import kotlinx.coroutines.flow.Flow import org.utbot.cpp.clion.plugin.UTBot -import org.utbot.cpp.clion.plugin.utils.getProjectConfigRequestMessage +import org.utbot.cpp.clion.plugin.grpc.getProjectConfigGrpcRequest import org.utbot.cpp.clion.plugin.client.handlers.GenerateJsonHandler import testsgen.Testgen import testsgen.TestsGenServiceGrpcKt @@ -16,7 +16,7 @@ class GenerateJsonFilesRequest( ): BaseRequest>(request, project) { override val logMessage: String = "Sending request to check project configuration." - constructor(project: Project): this(project, getProjectConfigRequestMessage(project, Testgen.ConfigMode.GENERATE_JSON_FILES)) + constructor(project: Project): this(project, getProjectConfigGrpcRequest(project, Testgen.ConfigMode.GENERATE_JSON_FILES)) constructor(e: AnActionEvent): this(e.project!!) override suspend fun TestsGenServiceGrpcKt.TestsGenServiceCoroutineStub.send(cancellationJob: Job?): Flow { diff --git a/clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/grpc/ActionsGrpcRequests.kt b/clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/grpc/ActionsGrpcRequests.kt new file mode 100644 index 00000000..6beeb17f --- /dev/null +++ b/clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/grpc/ActionsGrpcRequests.kt @@ -0,0 +1,111 @@ +package org.utbot.cpp.clion.plugin.grpc + +import com.intellij.openapi.actionSystem.AnActionEvent +import com.intellij.openapi.actionSystem.CommonDataKeys +import com.intellij.openapi.project.Project +import org.utbot.cpp.clion.plugin.utils.convertToRemotePathIfNeeded +import testsgen.Testgen +import testsgen.Util + +fun getProjectGrpcRequest(e: AnActionEvent): Testgen.ProjectRequest = getProjectGrpcRequest(e.activeProject()) + +fun getFolderGrpcRequest(e: AnActionEvent): Testgen.FolderRequest { + val project = e.activeProject() + val localPath = e.getRequiredData(CommonDataKeys.VIRTUAL_FILE).path + + return Testgen.FolderRequest.newBuilder() + .setProjectRequest(getProjectGrpcRequest(e)) + .setFolderPath(localPath.convertToRemotePathIfNeeded(project)) + .build() +} + +fun getFileGrpcRequest(e: AnActionEvent): Testgen.FileRequest { + val project = e.activeProject() + val filePath = e.getRequiredData(CommonDataKeys.VIRTUAL_FILE).path + + return Testgen.FileRequest.newBuilder() + .setProjectRequest(getProjectGrpcRequest(project)) + .setFilePath(filePath.convertToRemotePathIfNeeded(project)) + .build() +} + +fun getClassGrpcRequest(e: AnActionEvent): Testgen.ClassRequest = Testgen.ClassRequest.newBuilder() + .setLineRequest(getLineGrpcRequest(e)) + .build() + +fun getFunctionGrpcRequest(e: AnActionEvent): Testgen.FunctionRequest { + val lineRequest = getLineGrpcRequest(e) + return Testgen.FunctionRequest.newBuilder() + .setLineRequest(lineRequest) + .build() +} + +fun getSnippetGrpcRequest(e: AnActionEvent): Testgen.SnippetRequest { + val project = e.activeProject() + val localPath = e.getRequiredData(CommonDataKeys.VIRTUAL_FILE).path + + return Testgen.SnippetRequest.newBuilder() + .setProjectContext(getProjectContextMessage(project)) + .setSettingsContext(getSettingsContextMessage(project)) + .setFilePath(localPath.convertToRemotePathIfNeeded(project)) + .build() +} + +fun getLineGrpcRequest(e: AnActionEvent): Testgen.LineRequest { + val project = e.getRequiredData(CommonDataKeys.PROJECT) + val filePath = e.getRequiredData(CommonDataKeys.VIRTUAL_FILE).path + val editor = e.getRequiredData(CommonDataKeys.EDITOR) + val lineNumber = editor.caretModel.logicalPosition.line + 1 + + return getLineGrpcRequest(project, lineNumber, filePath) +} + +fun getAssertionGrpcRequest(e: AnActionEvent): Testgen.AssertionRequest { + return Testgen.AssertionRequest.newBuilder() + .setLineRequest(getLineGrpcRequest(e)) + .build() +} + +fun getPredicateGrpcRequest( + e: AnActionEvent, + predicate: String, + validationType: Util.ValidationType, + returnValue: String, +): Testgen.PredicateRequest { + val predicateInfo = getPredicateGrpcRequest(predicate, returnValue, validationType) + return Testgen.PredicateRequest.newBuilder() + .setLineRequest(getLineGrpcRequest(e)) + .setPredicateInfo(predicateInfo) + .build() +} + +private fun getPredicateGrpcRequest(predicate: String, returnValue: String, type: Util.ValidationType): Util.PredicateInfo = + Util.PredicateInfo.newBuilder() + .setPredicate(predicate) + .setReturnValue(returnValue) + .setType(type) + .build() + +private fun getProjectGrpcRequest(project: Project): Testgen.ProjectRequest { + val settings = project.allSettings() + return Testgen.ProjectRequest.newBuilder() + .setSettingsContext(getSettingsContextMessage(project)) + .setProjectContext(getProjectContextMessage(project)) + .setTargetPath(settings.convertedTargetPath) + .addAllSourcePaths(settings.convertedSourcePaths) + .setSynchronizeCode(settings.isRemoteScenario) + .build() +} + + +private fun getLineGrpcRequest(project: Project, line: Int, filePath: String): Testgen.LineRequest = + Testgen.LineRequest.newBuilder() + .setProjectRequest(getProjectGrpcRequest(project)) + .setSourceInfo(getSourceInfo(project, line, filePath)) + .build() + +private fun getSourceInfo(project: Project, line: Int, filePath: String): Util.SourceInfo = + Util.SourceInfo.newBuilder() + .setLine(line) + .setFilePath(filePath.convertToRemotePathIfNeeded(project)) + .build() diff --git a/clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/grpc/ConfigurationGrpcRequests.kt b/clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/grpc/ConfigurationGrpcRequests.kt new file mode 100644 index 00000000..488114b2 --- /dev/null +++ b/clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/grpc/ConfigurationGrpcRequests.kt @@ -0,0 +1,32 @@ +package org.utbot.cpp.clion.plugin.grpc + +import com.intellij.openapi.project.Project +import com.jetbrains.cidr.cpp.cmake.workspace.CMakeWorkspace +import testsgen.Testgen + +fun getProjectTargetsGrpcRequest(project: Project): Testgen.ProjectTargetsRequest = + Testgen.ProjectTargetsRequest.newBuilder() + .setProjectContext(getProjectContextMessage(project)) + .build() + +fun getProjectConfigGrpcRequest(project: Project, configMode: Testgen.ConfigMode): Testgen.ProjectConfigRequest { + val builder = Testgen.ProjectConfigRequest.newBuilder() + .setProjectContext(getProjectContextMessage(project)) + .setConfigMode(configMode) + getCmakeOptions(project)?.let { builder.setCmakeOptions(0, it) } + + return builder.build() +} + +fun getDummyGrpcRequest(): Testgen.DummyRequest = Testgen.DummyRequest.newBuilder().build() + +fun getLogChannelGrpcRequest(logLevel: String): Testgen.LogChannelRequest = + Testgen.LogChannelRequest.newBuilder() + .setLogLevel(logLevel) + .build() + +private fun getCmakeOptions(project: Project): String? = + CMakeWorkspace.getInstance(project).profileInfos + .map { it.profile } + .firstOrNull { it.enabled } + ?.generationOptions \ No newline at end of file diff --git a/clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/grpc/CoverageAndResultGrpcRequests.kt b/clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/grpc/CoverageAndResultGrpcRequests.kt new file mode 100644 index 00000000..72492572 --- /dev/null +++ b/clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/grpc/CoverageAndResultGrpcRequests.kt @@ -0,0 +1,33 @@ +package org.utbot.cpp.clion.plugin.grpc + +import com.intellij.openapi.project.Project +import org.utbot.cpp.clion.plugin.utils.convertToRemotePathIfNeeded +import testsgen.Testgen + +/** + * [testName] and [testSuiteName] are non-empty if a concrete test is specified. + * Request for several tests leaves these fields empty. + */ +fun getCoverageAndResultsGrpcRequest( + project: Project, + filePath: String, + testSuiteName: String = "", + testName: String = "", + includeCoverage: Boolean = true, +): Testgen.CoverageAndResultsRequest { + val remoteFilePath = filePath.convertToRemotePathIfNeeded(project) + + return Testgen.CoverageAndResultsRequest.newBuilder() + .setCoverage(includeCoverage) + .setProjectContext(getProjectContextMessage(project)) + .setSettingsContext(getSettingsContextMessage(project)) + .setTestFilter(getTestFilter(remoteFilePath, testName, testSuiteName)) + .build() +} + +private fun getTestFilter(filePath: String, testName: String = "", testSuiteName: String = ""): Testgen.TestFilter = + Testgen.TestFilter.newBuilder() + .setTestFilePath(filePath) + .setTestName(testName) + .setTestSuite(testSuiteName) + .build() diff --git a/clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/grpc/GrpcMessagingUtils.kt b/clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/grpc/GrpcMessagingUtils.kt new file mode 100644 index 00000000..77779ec5 --- /dev/null +++ b/clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/grpc/GrpcMessagingUtils.kt @@ -0,0 +1,35 @@ +package org.utbot.cpp.clion.plugin.grpc + +import com.intellij.openapi.actionSystem.AnActionEvent +import com.intellij.openapi.components.service +import com.intellij.openapi.project.Project +import org.utbot.cpp.clion.plugin.settings.UTBotAllSettings +import testsgen.Testgen + +fun getSettingsContextMessage(project: Project): Testgen.SettingsContext { + val settings = project.allSettings() + return Testgen.SettingsContext.newBuilder() + .setVerbose(settings.verbose) + .setUseStubs(settings.useStubs) + .setTimeoutPerTest(settings.timeoutPerTest) + .setTimeoutPerFunction(settings.timeoutPerFunction) + .setGenerateForStaticFunctions(settings.generateForStaticFunctions) + .setUseDeterministicSearcher(settings.useDeterministicSearcher) + .build() +} + +fun getProjectContextMessage(project: Project): Testgen.ProjectContext { + val settings = project.allSettings() + return Testgen.ProjectContext.newBuilder() + .setProjectName(project.name) + .setProjectPath(settings.convertedProjectPath) + .setBuildDirRelativePath(settings.buildDirRelativePath) + .setResultsDirRelativePath("") // this path is used only by command line interface, server doesn't require it. + .setTestDirPath(settings.convertedTestDirPath) + .build() +} + +fun Project.allSettings() = this.service() + +fun AnActionEvent.activeProject() = this.project + ?: error("A project related to action event $this not found") \ No newline at end of file diff --git a/clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/grpc/VersionGrpcRequests.kt b/clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/grpc/VersionGrpcRequests.kt new file mode 100644 index 00000000..15e82f8e --- /dev/null +++ b/clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/grpc/VersionGrpcRequests.kt @@ -0,0 +1,6 @@ +package org.utbot.cpp.clion.plugin.grpc + +import testsgen.Testgen + +//TODO: hardcoding the version is a bad practice, determine it somehow +fun getVersionGrpcRequest(): Testgen.VersionInfo = Testgen.VersionInfo.newBuilder().setVersion("2022.7").build() \ No newline at end of file diff --git a/clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/settings/UTBotAllSettings.kt b/clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/settings/UTBotAllSettings.kt index 1425dbf0..18699def 100644 --- a/clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/settings/UTBotAllSettings.kt +++ b/clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/settings/UTBotAllSettings.kt @@ -212,8 +212,13 @@ class UTBotAllSettings(val project: Project) { val convertedProjectPath: String get() = projectPath.convertToRemotePathIfNeeded(project) - fun isLocalHost() = serverName == "localhost" || serverName == "127.0.0.01" - fun isRemoteScenario() = !(remotePath == projectPath && isLocalHost()) || isWindows() + //TODO: it seems to be a kind of boolshit to me + private val isLocalHost: Boolean + get() = serverName == "localhost" || serverName == "127.0.0.01" + + //TODO: it is unclear, requires a comment + val isRemoteScenario: Boolean + get() = !(remotePath == projectPath && isLocalHost) || isWindows fun predictPaths() { logger.info("predict paths was called") diff --git a/clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/ui/targetsToolWindow/UTBotTargetsController.kt b/clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/ui/targetsToolWindow/UTBotTargetsController.kt index a2595e10..c7d7d314 100644 --- a/clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/ui/targetsToolWindow/UTBotTargetsController.kt +++ b/clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/ui/targetsToolWindow/UTBotTargetsController.kt @@ -2,7 +2,7 @@ package org.utbot.cpp.clion.plugin.ui.targetsToolWindow import com.intellij.openapi.project.Project import com.intellij.ui.CollectionListModel -import org.utbot.cpp.clion.plugin.utils.getProjectTargetsRequest +import org.utbot.cpp.clion.plugin.grpc.getProjectTargetsGrpcRequest import org.utbot.cpp.clion.plugin.client.Client import org.utbot.cpp.clion.plugin.client.requests.ProjectTargetsRequest import org.utbot.cpp.clion.plugin.listeners.ConnectionStatus @@ -39,7 +39,7 @@ class UTBotTargetsController(val project: Project) { logger.trace { "Requesting project targets from server!" } ProjectTargetsRequest( project, - getProjectTargetsRequest(project), + getProjectTargetsGrpcRequest(project), ) { targetsResponse -> invokeOnEdt { listModel.apply { diff --git a/clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/ui/wizard/steps/ConnectionStep.kt b/clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/ui/wizard/steps/ConnectionStep.kt index 2c8affa7..917130ed 100644 --- a/clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/ui/wizard/steps/ConnectionStep.kt +++ b/clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/ui/wizard/steps/ConnectionStep.kt @@ -24,7 +24,7 @@ import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.SupervisorJob import kotlinx.coroutines.launch -import org.utbot.cpp.clion.plugin.utils.getVersionInfo +import org.utbot.cpp.clion.plugin.grpc.getVersionGrpcRequest import org.utbot.cpp.clion.plugin.client.GrpcClient import org.utbot.cpp.clion.plugin.settings.UTBotAllSettings import org.utbot.cpp.clion.plugin.settings.UTBotSettingsModel @@ -103,7 +103,7 @@ class ConnectionStep( portTextField.text = UTBotAllSettings.DEFAULT_PORT.toString() hostTextField.text = UTBotAllSettings.DEFAULT_HOST remotePathTextField.text = project.utbotSettings.projectPath - if (isWindows()) + if (isWindows) remotePathTextField.text = toWSLPathOnWindows(remotePathTextField.text) } } @@ -113,7 +113,7 @@ class ConnectionStep( connectionStatus.value = ConnectionStatus.connecting runCatching { GrpcClient(port, host, "DummyId").use { client -> - serverVersion = client.stub.handshake(getVersionInfo()).version + serverVersion = client.stub.handshake(getVersionGrpcRequest()).version if (serverVersion != UTBotAllSettings.clientVersion) return ConnectionStatus.warning return ConnectionStatus.connected diff --git a/clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/utils/FileUtils.kt b/clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/utils/FileUtils.kt index e9e72f8d..8753c27b 100644 --- a/clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/utils/FileUtils.kt +++ b/clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/utils/FileUtils.kt @@ -6,6 +6,7 @@ import com.intellij.openapi.vfs.LocalFileSystem import com.intellij.psi.PsiDirectory import kotlin.io.path.div import org.apache.commons.io.FilenameUtils +import org.utbot.cpp.clion.plugin.grpc.allSettings import java.io.File import java.nio.file.FileVisitResult import java.nio.file.Files @@ -168,17 +169,16 @@ fun Set.removeDirectoriesRecursive(dirsToRemove: List): Se * * If [isRemoteScenario] == false, this function returns [path] unchanged. * - * @param path - absolute path on local machine to be converted */ fun String.convertToRemotePathIfNeeded(project: Project): String { - if (project.utbotSettings.isRemoteScenario()) + if (project.allSettings().isRemoteScenario) return this.convertToRemotePath(project) return this } fun String.convertToRemotePath(project: Project): String { val relativeToProjectPath = this.getRelativeToProjectPath(project) - return FilenameUtils.separatorsToUnix(Paths.get(project.utbotSettings.remotePath, relativeToProjectPath).toString()) + return FilenameUtils.separatorsToUnix(Paths.get(project.allSettings().remotePath, relativeToProjectPath).toString()) } /** @@ -186,19 +186,20 @@ fun String.convertToRemotePath(project: Project): String { * * If remote path == "", this function returns [path] unchanged. * - * @param path - absolute path on docker to be converted + * @param path - absolute path in Docker to be converted */ +//TODO: it seems that this method should return Path, not String +//TODO: update documentation after refactoring fun String.convertFromRemotePathIfNeeded(project: Project): String { - if (project.utbotSettings.isRemoteScenario()) + if (project.allSettings().isRemoteScenario) return this.convertFromRemotePath(project) return this } -fun String.convertFromRemotePath(project: Project): String { - val relativeToProjectPath = FilenameUtils.separatorsToSystem(relativize(project.utbotSettings.remotePath, this)) - return FilenameUtils.separatorsToSystem(Paths.get(project.utbotSettings.projectPath, relativeToProjectPath).toString()) +private fun String.convertFromRemotePath(project: Project): String { + val settings = project.allSettings() + val relativeToProjectPath = FilenameUtils.separatorsToSystem(relativize(settings.remotePath, this)) + return FilenameUtils.separatorsToSystem(Paths.get(settings.projectPath, relativeToProjectPath).toString()) } -fun String.getRelativeToProjectPath(project: Project): String { - return relativize(project.utbotSettings.projectPath, this) -} +private fun String.getRelativeToProjectPath(project: Project): String = relativize(project.allSettings().projectPath, this) diff --git a/clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/utils/GetGrpcMessageUtil.kt b/clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/utils/GetGrpcMessageUtil.kt deleted file mode 100644 index 213cc7a7..00000000 --- a/clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/utils/GetGrpcMessageUtil.kt +++ /dev/null @@ -1,221 +0,0 @@ -package org.utbot.cpp.clion.plugin.utils - -import com.intellij.openapi.actionSystem.AnActionEvent -import com.intellij.openapi.actionSystem.CommonDataKeys -import com.intellij.openapi.components.service -import com.intellij.openapi.project.Project -import com.jetbrains.cidr.cpp.cmake.workspace.CMakeWorkspace -import org.utbot.cpp.clion.plugin.settings.UTBotAllSettings -import testsgen.Testgen -import testsgen.Util - -fun getSettingsContextMessage(params: UTBotAllSettings): Testgen.SettingsContext { - return Testgen.SettingsContext.newBuilder() - .setVerbose(params.verbose) - .setUseStubs(params.useStubs) - .setTimeoutPerTest(params.timeoutPerTest) - .setTimeoutPerFunction(params.timeoutPerFunction) - .setGenerateForStaticFunctions(params.generateForStaticFunctions) - .setUseDeterministicSearcher(params.useDeterministicSearcher) - .build() -} - -fun getProjectContextMessage(params: UTBotAllSettings, project: Project): Testgen.ProjectContext { - return Testgen.ProjectContext.newBuilder() - .setProjectName(project.name) - .setProjectPath(params.convertedProjectPath) - .setBuildDirRelativePath(params.buildDirRelativePath) - .setResultsDirRelativePath("") // this path is used only for console interface, server don't use it. - .setTestDirPath(params.convertedTestDirPath) - .build() -} - -fun getProjectContextMessage(e: AnActionEvent): Testgen.ProjectContext { - return getProjectContextMessage(e.project?.service()!!, e.project!!) -} - -fun getProjectRequestMessage(project: Project, params: UTBotAllSettings): Testgen.ProjectRequest { - return Testgen.ProjectRequest.newBuilder() - .setSettingsContext( - getSettingsContextMessage( - project.service() - ) - ) - .setProjectContext(getProjectContextMessage(params, project)) - .setTargetPath(params.convertedTargetPath) - .addAllSourcePaths(params.convertedSourcePaths) - .setSynchronizeCode(project.utbotSettings.isRemoteScenario()) - .build() -} - -fun getSourceInfoMessage(line: Int, filePath: String, project: Project): Util.SourceInfo { - return Util.SourceInfo.newBuilder() - .setLine(line) - .setFilePath(filePath.convertToRemotePathIfNeeded(project)) - .build() -} - -fun getLineRequestMessage(project: Project, params: UTBotAllSettings, line: Int, filePath: String): Testgen.LineRequest { - val projectRequest = getProjectRequestMessage(project, params) - val sourceInfo = getSourceInfoMessage(line, filePath, project) - return Testgen.LineRequest.newBuilder() - .setProjectRequest(projectRequest) - .setSourceInfo(sourceInfo) - .build() -} - -fun getLineRequestMessage(e: AnActionEvent): Testgen.LineRequest { - val project = e.getRequiredData(CommonDataKeys.PROJECT) - val filePath = e.getRequiredData(CommonDataKeys.VIRTUAL_FILE).path - val editor = e.getRequiredData(CommonDataKeys.EDITOR) - val utbotSettings = project.utbotSettings - val lineNumber = editor.caretModel.logicalPosition.line + 1 - return getLineRequestMessage(project, utbotSettings, lineNumber, filePath) -} - -fun getFunctionRequestMessage(e: AnActionEvent): Testgen.FunctionRequest { - val lineRequest = getLineRequestMessage(e) - return Testgen.FunctionRequest.newBuilder() - .setLineRequest(lineRequest) - .build() -} - -fun getProjectRequestMessage(e: AnActionEvent): Testgen.ProjectRequest { - return getProjectRequestMessage(e.project!!, e.project!!.service()) -} - -fun getFileRequestMessage(e: AnActionEvent): Testgen.FileRequest { - // this function is supposed to be called in actions' performAction(), so update() validated these properties - val project: Project = e.project!! - val utbotSettings = project.utbotSettings - val filePath = e.getRequiredData(CommonDataKeys.VIRTUAL_FILE).path - return Testgen.FileRequest.newBuilder() - .setProjectRequest(getProjectRequestMessage(project, utbotSettings)) - .setFilePath(filePath.convertToRemotePathIfNeeded(project)) - .build() -} - -fun getPredicateInfoMessage(predicate: String, returnValue: String, type: Util.ValidationType): Util.PredicateInfo { - return Util.PredicateInfo.newBuilder() - .setPredicate(predicate) - .setReturnValue(returnValue) - .setType(type) - .build() -} - -fun getClassRequestMessage(e: AnActionEvent): Testgen.ClassRequest { - return Testgen.ClassRequest.newBuilder().setLineRequest( - getLineRequestMessage(e) - ).build() -} - -fun getFolderRequestMessage(e: AnActionEvent): Testgen.FolderRequest { - val localPath = e.getRequiredData(CommonDataKeys.VIRTUAL_FILE).path - return Testgen.FolderRequest.newBuilder() - .setProjectRequest(getProjectRequestMessage(e)) - .setFolderPath(localPath.convertToRemotePathIfNeeded(e.project!!)) - .build() -} - -fun getSnippetRequestMessage(e: AnActionEvent): Testgen.SnippetRequest { - val localPath = e.getRequiredData(CommonDataKeys.VIRTUAL_FILE).path - return Testgen.SnippetRequest.newBuilder() - .setProjectContext(getProjectContextMessage(e)) - .setSettingsContext(getSettingsContextMessage(e.project!!.service())) - .setFilePath(localPath.convertToRemotePathIfNeeded(e.project!!)) - .build() -} - -fun getAssertionRequestMessage(e: AnActionEvent): Testgen.AssertionRequest { - return Testgen.AssertionRequest.newBuilder() - .setLineRequest(getLineRequestMessage(e)) - .build() -} - -fun getPredicateRequestMessage( - validationType: Util.ValidationType, returnValue: String, predicate: String, - e: AnActionEvent -): Testgen.PredicateRequest { - val predicateInfo = getPredicateInfoMessage(predicate, returnValue, validationType) - return Testgen.PredicateRequest.newBuilder() - .setLineRequest(getLineRequestMessage(e)) - .setPredicateInfo(predicateInfo) - .build() -} - -fun getProjectConfigRequestMessage(project: Project, configMode: Testgen.ConfigMode): Testgen.ProjectConfigRequest { - val builder = Testgen.ProjectConfigRequest.newBuilder() - .setProjectContext(getProjectContextMessage(project.service(), project)) - .setConfigMode(configMode) - - getCmakeOptions(project)?.let { - builder.setCmakeOptions(0, it) - } - - return builder.build() -} - -fun getCmakeOptions(project: Project): String? { - return CMakeWorkspace.getInstance(project).profileInfos.find { - it.profile.enabled - }?.profile?.generationOptions -} - -fun getDummyRequest(): Testgen.DummyRequest = Testgen.DummyRequest.newBuilder().build() - -fun getLogChannelRequest(logLevel: String): Testgen.LogChannelRequest = - Testgen.LogChannelRequest.newBuilder().setLogLevel(logLevel).build() - -fun getTestFilter(e: AnActionEvent): Testgen.TestFilter { - val filePath = e.getRequiredData(CommonDataKeys.VIRTUAL_FILE).path - val testName = "" - val testSuite = "" - return getTestFilter(filePath, testName, testSuite) -} - -fun getTestFilter(filePath: String, testName: String = "", testSuite: String = ""): Testgen.TestFilter = - Testgen.TestFilter.newBuilder() - .setTestFilePath(filePath) - .setTestName(testName) - .setTestSuite(testSuite) - .build() - -fun getCoverageAndResultsRequest( - utbotSettings: UTBotAllSettings, - filePath: String, - testSuite: String = "", - testName: String = "", - includeCoverage: Boolean = true -): Testgen.CoverageAndResultsRequest { - val remoteFilePath = filePath.convertToRemotePathIfNeeded(utbotSettings.project) - return Testgen.CoverageAndResultsRequest.newBuilder() - .setCoverage(includeCoverage) - .setProjectContext(getProjectContextMessage(utbotSettings, utbotSettings.project)) - .setSettingsContext(getSettingsContextMessage(utbotSettings.project.service())) - .setTestFilter(getTestFilter(remoteFilePath, testName, testSuite)) - .build() -} - -fun getCoverageAndResultsRequest( - e: AnActionEvent, - suiteName: String = "", - testName: String = "", - includeCoverage: Boolean = true -): Testgen.CoverageAndResultsRequest { - val utbotSettings = e.project!!.utbotSettings - return getCoverageAndResultsRequest( - utbotSettings, - e.getRequiredData(CommonDataKeys.VIRTUAL_FILE).path, - suiteName, - testName, - includeCoverage - ) -} - -fun getProjectTargetsRequest(project: Project): Testgen.ProjectTargetsRequest { - return Testgen.ProjectTargetsRequest.newBuilder() - .setProjectContext(getProjectContextMessage(project.service(), project)) - .build() -} - -fun getVersionInfo(): Testgen.VersionInfo = Testgen.VersionInfo.newBuilder().setVersion("2022.7").build() diff --git a/clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/utils/shortcuts.kt b/clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/utils/shortcuts.kt index 3318934f..bd8f4d9e 100644 --- a/clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/utils/shortcuts.kt +++ b/clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/utils/shortcuts.kt @@ -32,4 +32,5 @@ fun invokeOnEdt(task: () -> Unit) { ApplicationManager.getApplication().invokeLater(task) } -fun isWindows() = System.getProperty("os.name").contains("win", ignoreCase = true) +val isWindows + get() = System.getProperty("os.name").contains("win", ignoreCase = true)