From 0077dd2a94dd0b3f48e395cea645134f6635b506 Mon Sep 17 00:00:00 2001 From: Sheng Chen Date: Thu, 11 Jul 2024 10:40:14 +0800 Subject: [PATCH] fix - Slice the build target list to 1 when running gradle tests --- .../handler/GradleDelegateCommandHandler.java | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/extension/jdtls.ext/com.microsoft.gradle.bs.importer/src/com/microsoft/gradle/bs/importer/handler/GradleDelegateCommandHandler.java b/extension/jdtls.ext/com.microsoft.gradle.bs.importer/src/com/microsoft/gradle/bs/importer/handler/GradleDelegateCommandHandler.java index ae0247456..bb17c418c 100644 --- a/extension/jdtls.ext/com.microsoft.gradle.bs.importer/src/com/microsoft/gradle/bs/importer/handler/GradleDelegateCommandHandler.java +++ b/extension/jdtls.ext/com.microsoft.gradle.bs.importer/src/com/microsoft/gradle/bs/importer/handler/GradleDelegateCommandHandler.java @@ -48,9 +48,17 @@ public Object executeCommand(String commandId, List arguments, IProgress List btIds = targets.stream().filter(bt -> { return bt.getTags().contains(BuildTargetTag.INTEGRATION_TEST) || bt.getTags().contains(BuildTargetTag.TEST); }).map(BuildTarget::getId).collect(Collectors.toList()); - if (btIds.isEmpty() || btIds.size() > 1) { + if (btIds.isEmpty()) { throw new IllegalStateException("Invalid number of build targets: " + btIds.size()); } + + if (btIds.size() > 1) { + // The build server only allows to accept one build target per test request. At client side, + // each test request is sent per project, so even multiple build targets are found, they + // belongs to the same project. Thus, we only use the first one here. Build server will use + // this single build target to locate the project to test. + btIds = btIds.subList(0, 1); + } TestParams testParams = new TestParams(btIds); testParams.setDataKind("scala-test-suites-selection"); testParams.setArguments(getArguments(arguments)); @@ -64,8 +72,8 @@ public Object executeCommand(String commandId, List arguments, IProgress } ScalaTestSuites scalaTestSuites = new ScalaTestSuites( testSelections, - getJvmOptions(arguments), // jvmOptions - getEnvVarPairs(arguments) // envVariables + getJvmOptions(arguments), + getEnvVarPairs(arguments) ); testParams.setData(scalaTestSuites); buildServerConnection.buildTargetTest(testParams).join();