From f3c56f6a50bb80dd8df0d3eb81e3119554a4f73b Mon Sep 17 00:00:00 2001 From: Egor Kulikov Date: Fri, 22 Jul 2022 01:24:03 +0300 Subject: [PATCH 1/2] Refactor grpc related logic --- .../actions/GenerateForAssertionAction.kt | 4 +- .../plugin/actions/GenerateForClassAction.kt | 4 +- .../plugin/actions/GenerateForFileAction.kt | 4 +- .../plugin/actions/GenerateForFolderAction.kt | 4 +- .../actions/GenerateForFunctionAction.kt | 4 +- .../plugin/actions/GenerateForLineAction.kt | 4 +- .../actions/GenerateForPredicateAction.kt | 8 +- .../actions/GenerateForProjectAction.kt | 4 +- .../actions/GenerateForSnippetAction.kt | 4 +- .../actions/ReconfigureProjectAction.kt | 4 +- .../plugin/actions/RunWithCoverageAction.kt | 7 +- .../utbot/cpp/clion/plugin/client/Client.kt | 8 +- .../clion/plugin/client/LoggingChannels.kt | 4 +- .../CheckProjectConfigurationRequest.kt | 4 +- .../requests/CreateBuildFolderRequest.kt | 4 +- .../requests/GenerateJsonFilesRequest.kt | 4 +- .../cpp/clion/plugin/grpc/ActionsRequests.kt | 111 +++++++++ .../plugin/grpc/ConfigurationRequests.kt | 32 +++ .../plugin/grpc/CoverageAndResultRequests.kt | 31 +++ .../clion/plugin/grpc/GrpcMessagingUtils.kt | 35 +++ .../cpp/clion/plugin/grpc/VersionRequests.kt | 6 + .../clion/plugin/settings/UTBotAllSettings.kt | 9 +- .../UTBotTargetsController.kt | 2 +- .../plugin/ui/wizard/steps/ConnectionStep.kt | 6 +- .../utbot/cpp/clion/plugin/utils/FileUtils.kt | 23 +- .../clion/plugin/utils/GetGrpcMessageUtil.kt | 221 ------------------ .../utbot/cpp/clion/plugin/utils/shortcuts.kt | 3 +- 27 files changed, 279 insertions(+), 275 deletions(-) create mode 100644 clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/grpc/ActionsRequests.kt create mode 100644 clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/grpc/ConfigurationRequests.kt create mode 100644 clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/grpc/CoverageAndResultRequests.kt create mode 100644 clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/grpc/GrpcMessagingUtils.kt create mode 100644 clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/grpc/VersionRequests.kt delete mode 100644 clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/utils/GetGrpcMessageUtil.kt 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..9a12835d 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.getAssertionRequest import org.utbot.cpp.clion.plugin.client.requests.AssertionRequest class GenerateForAssertionAction : GenerateTestsBaseAction() { override fun actionPerformed(e: AnActionEvent) { AssertionRequest( - getAssertionRequestMessage(e), + getAssertionRequest(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..d1210573 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.getClassRequest 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), + getClassRequest(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..de61a1ce 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.getFileRequest 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(getFileRequest(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..c99ca7a9 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.getFolderRequest import org.utbot.cpp.clion.plugin.client.requests.FolderRequest class GenerateForFolderAction : GenerateTestsBaseAction() { override fun actionPerformed(e: AnActionEvent) { FolderRequest( - getFolderRequestMessage(e), + getFolderRequest(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..7a2d9282 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.getFunctionRequest 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), + getFunctionRequest(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..e9a3b7ab 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.getLineRequest 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), + getLineRequest(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..a138573d 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.getFunctionRequest +import org.utbot.cpp.clion.plugin.grpc.getPredicateRequest 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 = getPredicateRequest(e, comparisonOperator, validationType, valueToCompare) PredicateRequest( predicateRequest, e.project!! @@ -122,7 +122,7 @@ class GenerateForPredicateAction : GenerateTestsBaseAction() { FunctionReturnTypeRequest( e.project!!, - getFunctionRequestMessage(e) + getFunctionRequest(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..b2589415 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.getProjectRequest 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), + getProjectRequest(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..712bb068 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.getSnippetRequest import org.utbot.cpp.clion.plugin.client.requests.SnippetRequest class GenerateForSnippetAction : GenerateTestsBaseAction() { override fun actionPerformed(e: AnActionEvent) { SnippetRequest( - getSnippetRequestMessage(e), + getSnippetRequest(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..9a5240b1 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.getProjectConfigRequest 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), + getProjectConfigRequest(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..da57e9df 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.getCoverageAndResultsRequest 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 = getCoverageAndResultsRequest(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..f7cfb009 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.getProjectConfigRequest +import org.utbot.cpp.clion.plugin.grpc.getVersionRequests 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) + getProjectConfigRequest(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(getVersionRequests()) 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..3773aada 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.getDummyRequest +import org.utbot.cpp.clion.plugin.grpc.getLogChannelRequest 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 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..971c37b4 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.getProjectConfigRequest 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, getProjectConfigRequest(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..3239444f 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.getProjectConfigRequest 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!!, getProjectConfigRequest(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..0f2aa451 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.getProjectConfigRequest 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, getProjectConfigRequest(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/ActionsRequests.kt b/clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/grpc/ActionsRequests.kt new file mode 100644 index 00000000..65e3d395 --- /dev/null +++ b/clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/grpc/ActionsRequests.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 getProjectRequest(e: AnActionEvent): Testgen.ProjectRequest = getProjectRequest(e.activeProject()) + +fun getFolderRequest(e: AnActionEvent): Testgen.FolderRequest { + val project = e.activeProject() + val localPath = e.getRequiredData(CommonDataKeys.VIRTUAL_FILE).path + + return Testgen.FolderRequest.newBuilder() + .setProjectRequest(getProjectRequest(e)) + .setFolderPath(localPath.convertToRemotePathIfNeeded(project)) + .build() +} + +fun getFileRequest(e: AnActionEvent): Testgen.FileRequest { + val project = e.activeProject() + val filePath = e.getRequiredData(CommonDataKeys.VIRTUAL_FILE).path + + return Testgen.FileRequest.newBuilder() + .setProjectRequest(getProjectRequest(project)) + .setFilePath(filePath.convertToRemotePathIfNeeded(project)) + .build() +} + +fun getClassRequest(e: AnActionEvent): Testgen.ClassRequest = Testgen.ClassRequest.newBuilder() + .setLineRequest(getLineRequest(e)) + .build() + +fun getFunctionRequest(e: AnActionEvent): Testgen.FunctionRequest { + val lineRequest = getLineRequest(e) + return Testgen.FunctionRequest.newBuilder() + .setLineRequest(lineRequest) + .build() +} + +fun getSnippetRequest(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 getLineRequest(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 getLineRequest(project, lineNumber, filePath) +} + +fun getAssertionRequest(e: AnActionEvent): Testgen.AssertionRequest { + return Testgen.AssertionRequest.newBuilder() + .setLineRequest(getLineRequest(e)) + .build() +} + +fun getPredicateRequest( + e: AnActionEvent, + predicate: String, + validationType: Util.ValidationType, + returnValue: String, +): Testgen.PredicateRequest { + val predicateInfo = getPredicateRequest(predicate, returnValue, validationType) + return Testgen.PredicateRequest.newBuilder() + .setLineRequest(getLineRequest(e)) + .setPredicateInfo(predicateInfo) + .build() +} + +private fun getPredicateRequest(predicate: String, returnValue: String, type: Util.ValidationType): Util.PredicateInfo = + Util.PredicateInfo.newBuilder() + .setPredicate(predicate) + .setReturnValue(returnValue) + .setType(type) + .build() + +private fun getProjectRequest(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 getLineRequest(project: Project, line: Int, filePath: String): Testgen.LineRequest = + Testgen.LineRequest.newBuilder() + .setProjectRequest(getProjectRequest(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/ConfigurationRequests.kt b/clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/grpc/ConfigurationRequests.kt new file mode 100644 index 00000000..7d398366 --- /dev/null +++ b/clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/grpc/ConfigurationRequests.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 getProjectTargetsRequest(project: Project): Testgen.ProjectTargetsRequest = + Testgen.ProjectTargetsRequest.newBuilder() + .setProjectContext(getProjectContextMessage(project)) + .build() + +fun getDummyRequest(): Testgen.DummyRequest = Testgen.DummyRequest.newBuilder().build() + +fun getLogChannelRequest(logLevel: String): Testgen.LogChannelRequest = + Testgen.LogChannelRequest.newBuilder() + .setLogLevel(logLevel) + .build() + +fun getProjectConfigRequest(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() +} + +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/CoverageAndResultRequests.kt b/clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/grpc/CoverageAndResultRequests.kt new file mode 100644 index 00000000..397abc14 --- /dev/null +++ b/clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/grpc/CoverageAndResultRequests.kt @@ -0,0 +1,31 @@ +package org.utbot.cpp.clion.plugin.grpc + +import com.intellij.openapi.project.Project +import org.utbot.cpp.clion.plugin.utils.convertToRemotePathIfNeeded +import testsgen.Testgen + +//TODO: what is the meaning of "testSuiteName"? +//TODO: why can "testName" be empty? It is something strange. +fun getCoverageAndResultsRequest( + 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/VersionRequests.kt b/clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/grpc/VersionRequests.kt new file mode 100644 index 00000000..98205196 --- /dev/null +++ b/clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/grpc/VersionRequests.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 getVersionRequests(): 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..55d939b4 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.getProjectTargetsRequest 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 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..14e6d685 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.getVersionRequests 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(getVersionRequests()).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) From 0ff0e98e52baf56213d2bdc0331fe5743ad9f443 Mon Sep 17 00:00:00 2001 From: Egor Kulikov Date: Mon, 25 Jul 2022 11:12:35 +0300 Subject: [PATCH 2/2] Several renamings, comment added --- .../actions/GenerateForAssertionAction.kt | 4 +- .../plugin/actions/GenerateForClassAction.kt | 4 +- .../plugin/actions/GenerateForFileAction.kt | 4 +- .../plugin/actions/GenerateForFolderAction.kt | 4 +- .../actions/GenerateForFunctionAction.kt | 4 +- .../plugin/actions/GenerateForLineAction.kt | 4 +- .../actions/GenerateForPredicateAction.kt | 8 ++-- .../actions/GenerateForProjectAction.kt | 4 +- .../actions/GenerateForSnippetAction.kt | 4 +- .../actions/ReconfigureProjectAction.kt | 4 +- .../plugin/actions/RunWithCoverageAction.kt | 4 +- .../utbot/cpp/clion/plugin/client/Client.kt | 8 ++-- .../clion/plugin/client/LoggingChannels.kt | 12 +++--- .../CheckProjectConfigurationRequest.kt | 4 +- .../requests/CreateBuildFolderRequest.kt | 4 +- .../requests/GenerateJsonFilesRequest.kt | 4 +- ...ionsRequests.kt => ActionsGrpcRequests.kt} | 42 +++++++++---------- ...quests.kt => ConfigurationGrpcRequests.kt} | 18 ++++---- ...ts.kt => CoverageAndResultGrpcRequests.kt} | 10 +++-- ...sionRequests.kt => VersionGrpcRequests.kt} | 2 +- .../UTBotTargetsController.kt | 4 +- .../plugin/ui/wizard/steps/ConnectionStep.kt | 4 +- 22 files changed, 81 insertions(+), 79 deletions(-) rename clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/grpc/{ActionsRequests.kt => ActionsGrpcRequests.kt} (65%) rename clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/grpc/{ConfigurationRequests.kt => ConfigurationGrpcRequests.kt} (69%) rename clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/grpc/{CoverageAndResultRequests.kt => CoverageAndResultGrpcRequests.kt} (83%) rename clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/grpc/{VersionRequests.kt => VersionGrpcRequests.kt} (55%) 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 9a12835d..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.grpc.getAssertionRequest +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( - getAssertionRequest(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 d1210573..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.grpc.getClassRequest +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( - getClassRequest(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 de61a1ce..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.grpc.getFileRequest +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(getFileRequest(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 c99ca7a9..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.grpc.getFolderRequest +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( - getFolderRequest(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 7a2d9282..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.grpc.getFunctionRequest +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( - getFunctionRequest(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 e9a3b7ab..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.grpc.getLineRequest +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( - getLineRequest(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 a138573d..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.grpc.getFunctionRequest -import org.utbot.cpp.clion.plugin.grpc.getPredicateRequest +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 = getPredicateRequest(e, comparisonOperator, validationType, valueToCompare) + val predicateRequest = getPredicateGrpcRequest(e, comparisonOperator, validationType, valueToCompare) PredicateRequest( predicateRequest, e.project!! @@ -122,7 +122,7 @@ class GenerateForPredicateAction : GenerateTestsBaseAction() { FunctionReturnTypeRequest( e.project!!, - getFunctionRequest(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 b2589415..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.grpc.getProjectRequest +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( - getProjectRequest(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 712bb068..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.grpc.getSnippetRequest +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( - getSnippetRequest(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 9a5240b1..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.grpc.getProjectConfigRequest +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!!, - getProjectConfigRequest(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 da57e9df..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 @@ -4,7 +4,7 @@ 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.grpc.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 @@ -20,7 +20,7 @@ class RunWithCoverageAction(val element: PsiElement) : GenerateTestsBaseAction() val suiteName = testArgs.suite val testedMethodName = testArgs.name val filePath = e.getRequiredData(CommonDataKeys.VIRTUAL_FILE).path - val request = getCoverageAndResultsRequest(e.activeProject(), filePath, suiteName, testedMethodName) + 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 f7cfb009..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.grpc.getProjectConfigRequest -import org.utbot.cpp.clion.plugin.grpc.getVersionRequests +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, - getProjectConfigRequest(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(getVersionRequests()) + 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 3773aada..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.grpc.getDummyRequest -import org.utbot.cpp.clion.plugin.grpc.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 971c37b4..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.grpc.getProjectConfigRequest +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, getProjectConfigRequest(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 3239444f..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.grpc.getProjectConfigRequest +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!!, getProjectConfigRequest(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 0f2aa451..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.grpc.getProjectConfigRequest +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, getProjectConfigRequest(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/ActionsRequests.kt b/clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/grpc/ActionsGrpcRequests.kt similarity index 65% rename from clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/grpc/ActionsRequests.kt rename to clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/grpc/ActionsGrpcRequests.kt index 65e3d395..6beeb17f 100644 --- a/clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/grpc/ActionsRequests.kt +++ b/clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/grpc/ActionsGrpcRequests.kt @@ -7,40 +7,40 @@ import org.utbot.cpp.clion.plugin.utils.convertToRemotePathIfNeeded import testsgen.Testgen import testsgen.Util -fun getProjectRequest(e: AnActionEvent): Testgen.ProjectRequest = getProjectRequest(e.activeProject()) +fun getProjectGrpcRequest(e: AnActionEvent): Testgen.ProjectRequest = getProjectGrpcRequest(e.activeProject()) -fun getFolderRequest(e: AnActionEvent): Testgen.FolderRequest { +fun getFolderGrpcRequest(e: AnActionEvent): Testgen.FolderRequest { val project = e.activeProject() val localPath = e.getRequiredData(CommonDataKeys.VIRTUAL_FILE).path return Testgen.FolderRequest.newBuilder() - .setProjectRequest(getProjectRequest(e)) + .setProjectRequest(getProjectGrpcRequest(e)) .setFolderPath(localPath.convertToRemotePathIfNeeded(project)) .build() } -fun getFileRequest(e: AnActionEvent): Testgen.FileRequest { +fun getFileGrpcRequest(e: AnActionEvent): Testgen.FileRequest { val project = e.activeProject() val filePath = e.getRequiredData(CommonDataKeys.VIRTUAL_FILE).path return Testgen.FileRequest.newBuilder() - .setProjectRequest(getProjectRequest(project)) + .setProjectRequest(getProjectGrpcRequest(project)) .setFilePath(filePath.convertToRemotePathIfNeeded(project)) .build() } -fun getClassRequest(e: AnActionEvent): Testgen.ClassRequest = Testgen.ClassRequest.newBuilder() - .setLineRequest(getLineRequest(e)) +fun getClassGrpcRequest(e: AnActionEvent): Testgen.ClassRequest = Testgen.ClassRequest.newBuilder() + .setLineRequest(getLineGrpcRequest(e)) .build() -fun getFunctionRequest(e: AnActionEvent): Testgen.FunctionRequest { - val lineRequest = getLineRequest(e) +fun getFunctionGrpcRequest(e: AnActionEvent): Testgen.FunctionRequest { + val lineRequest = getLineGrpcRequest(e) return Testgen.FunctionRequest.newBuilder() .setLineRequest(lineRequest) .build() } -fun getSnippetRequest(e: AnActionEvent): Testgen.SnippetRequest { +fun getSnippetGrpcRequest(e: AnActionEvent): Testgen.SnippetRequest { val project = e.activeProject() val localPath = e.getRequiredData(CommonDataKeys.VIRTUAL_FILE).path @@ -51,42 +51,42 @@ fun getSnippetRequest(e: AnActionEvent): Testgen.SnippetRequest { .build() } -fun getLineRequest(e: AnActionEvent): Testgen.LineRequest { +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 getLineRequest(project, lineNumber, filePath) + return getLineGrpcRequest(project, lineNumber, filePath) } -fun getAssertionRequest(e: AnActionEvent): Testgen.AssertionRequest { +fun getAssertionGrpcRequest(e: AnActionEvent): Testgen.AssertionRequest { return Testgen.AssertionRequest.newBuilder() - .setLineRequest(getLineRequest(e)) + .setLineRequest(getLineGrpcRequest(e)) .build() } -fun getPredicateRequest( +fun getPredicateGrpcRequest( e: AnActionEvent, predicate: String, validationType: Util.ValidationType, returnValue: String, ): Testgen.PredicateRequest { - val predicateInfo = getPredicateRequest(predicate, returnValue, validationType) + val predicateInfo = getPredicateGrpcRequest(predicate, returnValue, validationType) return Testgen.PredicateRequest.newBuilder() - .setLineRequest(getLineRequest(e)) + .setLineRequest(getLineGrpcRequest(e)) .setPredicateInfo(predicateInfo) .build() } -private fun getPredicateRequest(predicate: String, returnValue: String, type: Util.ValidationType): Util.PredicateInfo = +private fun getPredicateGrpcRequest(predicate: String, returnValue: String, type: Util.ValidationType): Util.PredicateInfo = Util.PredicateInfo.newBuilder() .setPredicate(predicate) .setReturnValue(returnValue) .setType(type) .build() -private fun getProjectRequest(project: Project): Testgen.ProjectRequest { +private fun getProjectGrpcRequest(project: Project): Testgen.ProjectRequest { val settings = project.allSettings() return Testgen.ProjectRequest.newBuilder() .setSettingsContext(getSettingsContextMessage(project)) @@ -98,9 +98,9 @@ private fun getProjectRequest(project: Project): Testgen.ProjectRequest { } -private fun getLineRequest(project: Project, line: Int, filePath: String): Testgen.LineRequest = +private fun getLineGrpcRequest(project: Project, line: Int, filePath: String): Testgen.LineRequest = Testgen.LineRequest.newBuilder() - .setProjectRequest(getProjectRequest(project)) + .setProjectRequest(getProjectGrpcRequest(project)) .setSourceInfo(getSourceInfo(project, line, filePath)) .build() diff --git a/clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/grpc/ConfigurationRequests.kt b/clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/grpc/ConfigurationGrpcRequests.kt similarity index 69% rename from clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/grpc/ConfigurationRequests.kt rename to clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/grpc/ConfigurationGrpcRequests.kt index 7d398366..488114b2 100644 --- a/clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/grpc/ConfigurationRequests.kt +++ b/clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/grpc/ConfigurationGrpcRequests.kt @@ -4,19 +4,12 @@ import com.intellij.openapi.project.Project import com.jetbrains.cidr.cpp.cmake.workspace.CMakeWorkspace import testsgen.Testgen -fun getProjectTargetsRequest(project: Project): Testgen.ProjectTargetsRequest = +fun getProjectTargetsGrpcRequest(project: Project): Testgen.ProjectTargetsRequest = Testgen.ProjectTargetsRequest.newBuilder() .setProjectContext(getProjectContextMessage(project)) .build() -fun getDummyRequest(): Testgen.DummyRequest = Testgen.DummyRequest.newBuilder().build() - -fun getLogChannelRequest(logLevel: String): Testgen.LogChannelRequest = - Testgen.LogChannelRequest.newBuilder() - .setLogLevel(logLevel) - .build() - -fun getProjectConfigRequest(project: Project, configMode: Testgen.ConfigMode): Testgen.ProjectConfigRequest { +fun getProjectConfigGrpcRequest(project: Project, configMode: Testgen.ConfigMode): Testgen.ProjectConfigRequest { val builder = Testgen.ProjectConfigRequest.newBuilder() .setProjectContext(getProjectContextMessage(project)) .setConfigMode(configMode) @@ -25,6 +18,13 @@ fun getProjectConfigRequest(project: Project, configMode: Testgen.ConfigMode): T 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 } diff --git a/clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/grpc/CoverageAndResultRequests.kt b/clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/grpc/CoverageAndResultGrpcRequests.kt similarity index 83% rename from clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/grpc/CoverageAndResultRequests.kt rename to clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/grpc/CoverageAndResultGrpcRequests.kt index 397abc14..72492572 100644 --- a/clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/grpc/CoverageAndResultRequests.kt +++ b/clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/grpc/CoverageAndResultGrpcRequests.kt @@ -4,10 +4,12 @@ import com.intellij.openapi.project.Project import org.utbot.cpp.clion.plugin.utils.convertToRemotePathIfNeeded import testsgen.Testgen -//TODO: what is the meaning of "testSuiteName"? -//TODO: why can "testName" be empty? It is something strange. -fun getCoverageAndResultsRequest( - project:Project, +/** + * [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 = "", diff --git a/clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/grpc/VersionRequests.kt b/clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/grpc/VersionGrpcRequests.kt similarity index 55% rename from clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/grpc/VersionRequests.kt rename to clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/grpc/VersionGrpcRequests.kt index 98205196..15e82f8e 100644 --- a/clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/grpc/VersionRequests.kt +++ b/clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/grpc/VersionGrpcRequests.kt @@ -3,4 +3,4 @@ package org.utbot.cpp.clion.plugin.grpc import testsgen.Testgen //TODO: hardcoding the version is a bad practice, determine it somehow -fun getVersionRequests(): Testgen.VersionInfo = Testgen.VersionInfo.newBuilder().setVersion("2022.7").build() \ No newline at end of file +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/ui/targetsToolWindow/UTBotTargetsController.kt b/clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/ui/targetsToolWindow/UTBotTargetsController.kt index 55d939b4..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.grpc.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 14e6d685..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.grpc.getVersionRequests +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 @@ -113,7 +113,7 @@ class ConnectionStep( connectionStatus.value = ConnectionStatus.connecting runCatching { GrpcClient(port, host, "DummyId").use { client -> - serverVersion = client.stub.handshake(getVersionRequests()).version + serverVersion = client.stub.handshake(getVersionGrpcRequest()).version if (serverVersion != UTBotAllSettings.clientVersion) return ConnectionStatus.warning return ConnectionStatus.connected