Skip to content

Commit 4678d69

Browse files
SLCORE-1526, SLCORE-1543 refactor; apply PR review
1 parent 748ef2c commit 4678d69

File tree

8 files changed

+26
-34
lines changed

8 files changed

+26
-34
lines changed

API_CHANGES.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
* Introduce `org.sonarsource.sonarlint.core.rpc.protocol.backend.sca.ScaRpcService.openDependencyRiskInBrowser` that accepts `configScopeId` and `dependencyRiskKey` (UUID) parameters
1010
* Allow clients to record interactions with dependency risks (SCA issues) in telemetry
1111
* Introduce `org.sonarsource.sonarlint.core.rpc.protocol.backend.telemetry.TelemetryRpcService.dependencyRiskInvestigatedLocally` method
12-
* Introduce `org.sonarsource.sonarlint.core.rpc.protocol.backend.telemetry.TelemetryRpcService.dependencyRiskInvestigatedRemotely` method
1312
* Add a new `org.sonarsource.sonarlint.core.rpc.protocol.backend.sca.ScaRpcService.getDependencyRiskDetails`.
1413

1514
# 10.26
@@ -18,9 +17,6 @@
1817

1918
* Add a new `SCA_SYNCHRONIZATION` value in `org.sonarsource.sonarlint.core.rpc.protocol.backend.initialize.BackendCapability`. Clients using the feature need to declare it at initialization time.
2019
* Introduce a new `org.sonarsource.sonarlint.core.rpc.protocol.backend.tracking.ScaIssueTrackingRpcService` service and a `listAll` method
21-
* Allow changing status of SCA issues via `org.sonarsource.sonarlint.core.rpc.protocol.backend.sca.ScaRpcService.changeStatus`.
22-
* Required parameters are `configScopeId`, `issueId` and `transition`.
23-
* If transition is `ACCEPT`, `FIXED, or `SAFE`, a `comment` field is mandatory
2420

2521
# 10.25
2622

backend/core/src/main/java/org/sonarsource/sonarlint/core/sca/ScaService.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,14 @@
3232
import org.sonarsource.sonarlint.core.rpc.protocol.SonarLintRpcClient;
3333
import org.sonarsource.sonarlint.core.rpc.protocol.SonarLintRpcErrorCode;
3434
import org.sonarsource.sonarlint.core.rpc.protocol.backend.sca.DependencyRiskTransition;
35-
import org.sonarsource.sonarlint.core.rpc.protocol.backend.tracking.AffectedPackageDto;
3635
import org.sonarsource.sonarlint.core.rpc.protocol.backend.sca.GetDependencyRiskDetailsResponse;
36+
import org.sonarsource.sonarlint.core.rpc.protocol.backend.tracking.AffectedPackageDto;
3737
import org.sonarsource.sonarlint.core.rpc.protocol.backend.tracking.ScaIssueDto;
38-
import org.sonarsource.sonarlint.core.serverapi.sca.GetIssueReleaseResponse;
3938
import org.sonarsource.sonarlint.core.rpc.protocol.client.OpenUrlInBrowserParams;
4039
import org.sonarsource.sonarlint.core.serverapi.EndpointParams;
4140
import org.sonarsource.sonarlint.core.serverapi.ServerApiHelper;
4241
import org.sonarsource.sonarlint.core.serverapi.UrlUtils;
42+
import org.sonarsource.sonarlint.core.serverapi.sca.GetIssueReleaseResponse;
4343
import org.sonarsource.sonarlint.core.serverconnection.issues.ServerScaIssue;
4444
import org.sonarsource.sonarlint.core.storage.StorageService;
4545
import org.sonarsource.sonarlint.core.telemetry.TelemetryService;
@@ -152,17 +152,15 @@ private static GetDependencyRiskDetailsResponse convertToRpcResponse(GetIssueRel
152152
serverResponse.vulnerability().description(), affectedPackages);
153153
}
154154

155-
public void openDependencyRiskInBrowser(String configurationScopeId, String dependencyKey) {
155+
public void openDependencyRiskInBrowser(String configurationScopeId, UUID dependencyKey) {
156156
var effectiveBinding = configurationRepository.getEffectiveBinding(configurationScopeId);
157157
var endpointParams = effectiveBinding.flatMap(binding -> connectionRepository.getEndpointParams(binding.connectionId()));
158158
if (effectiveBinding.isEmpty() || endpointParams.isEmpty()) {
159-
LOG.warn("Configuration scope {} is not bound properly, unable to open dependency risk", configurationScopeId);
160-
return;
159+
throw new IllegalArgumentException(String.format("Configuration scope '%s' is not bound properly, unable to open dependency risk", configurationScopeId));
161160
}
162161
var branchName = branchTrackingService.awaitEffectiveSonarProjectBranch(configurationScopeId);
163162
if (branchName.isEmpty()) {
164-
LOG.warn("Configuration scope {} has no matching branch, unable to open dependency risk", configurationScopeId);
165-
return;
163+
throw new IllegalArgumentException(String.format("Configuration scope %s has no matching branch, unable to open dependency risk", configurationScopeId));
166164
}
167165

168166
var url = buildScaBrowseUrl(effectiveBinding.get().sonarProjectKey(), branchName.get(), dependencyKey, endpointParams.get());

backend/rpc-impl/src/main/java/org/sonarsource/sonarlint/core/rpc/impl/ScaRpcServiceDelegate.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,16 @@ public CompletableFuture<GetDependencyRiskDetailsResponse> getDependencyRiskDeta
6464
}
6565

6666
@Override
67-
public void openDependencyRiskInBrowser(OpenDependencyRiskInBrowserParams params) {
68-
notify(() -> getBean(ScaService.class).openDependencyRiskInBrowser(params.getConfigScopeId(), params.getDependencyKey()), params.getConfigScopeId());
67+
public CompletableFuture<Void> openDependencyRiskInBrowser(OpenDependencyRiskInBrowserParams params) {
68+
return runAsync(cancelMonitor -> {
69+
try {
70+
getBean(ScaService.class).openDependencyRiskInBrowser(
71+
params.getConfigScopeId(),
72+
params.getDependencyKey());
73+
} catch (IllegalArgumentException e) {
74+
var error = new ResponseError(SonarLintRpcErrorCode.INVALID_ARGUMENT, e.getMessage(), null);
75+
throw new ResponseErrorException(error);
76+
}
77+
}, params.getConfigScopeId());
6978
}
7079
}

backend/rpc-impl/src/main/java/org/sonarsource/sonarlint/core/rpc/impl/TelemetryRpcServiceDelegate.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -154,11 +154,6 @@ public void dependencyRiskInvestigatedLocally() {
154154
notify(() -> getBean(TelemetryService.class).dependencyRiskInvestigatedLocally());
155155
}
156156

157-
@Override
158-
public void dependencyRiskInvestigatedRemotely() {
159-
notify(() -> getBean(TelemetryService.class).dependencyRiskInvestigatedRemotely());
160-
}
161-
162157
@Override
163158
public void findingsFiltered(FindingsFilteredParams params) {
164159
notify(() -> getBean(TelemetryService.class).findingsFiltered(params.getFilterType()));

medium-tests/src/test/java/mediumtest/TelemetryMediumTests.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -342,20 +342,14 @@ void it_should_accumulate_investigated_taint_vulnerabilities(SonarLintTestHarnes
342342
void it_should_accumulate_investigated_dependency_risks(SonarLintTestHarness harness) {
343343
var backend = setupClientAndBackend(harness);
344344

345-
backend.getTelemetryService().dependencyRiskInvestigatedRemotely();
346345
backend.getTelemetryService().dependencyRiskInvestigatedLocally();
347346

348-
await().untilAsserted(() -> assertThat(backend.telemetryFileContent())
349-
.extracting(TelemetryLocalStorage::getDependencyRiskInvestigatedRemotelyCount, TelemetryLocalStorage::getDependencyRiskInvestigatedLocallyCount)
350-
.containsExactly(1, 1));
347+
await().untilAsserted(() -> assertThat(backend.telemetryFileContent().getDependencyRiskInvestigatedLocallyCount()).isEqualTo(1));
351348

352-
backend.getTelemetryService().dependencyRiskInvestigatedRemotely();
353349
backend.getTelemetryService().dependencyRiskInvestigatedLocally();
354350
backend.getTelemetryService().dependencyRiskInvestigatedLocally();
355351

356-
await().untilAsserted(() -> assertThat(backend.telemetryFileContent())
357-
.extracting(TelemetryLocalStorage::getDependencyRiskInvestigatedRemotelyCount, TelemetryLocalStorage::getDependencyRiskInvestigatedLocallyCount)
358-
.containsExactly(2, 3));
352+
await().untilAsserted(() -> assertThat(backend.telemetryFileContent().getDependencyRiskInvestigatedLocallyCount()).isEqualTo(3));
359353
}
360354

361355
@SonarLintTest

medium-tests/src/test/java/mediumtest/sca/OpenDependencyRiskInBrowserMediumTests.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@
2121

2222
import java.io.IOException;
2323
import java.net.URL;
24+
import java.time.Duration;
2425
import java.util.UUID;
26+
import java.util.concurrent.ExecutionException;
2527
import org.sonarsource.sonarlint.core.rpc.protocol.backend.sca.OpenDependencyRiskInBrowserParams;
2628
import org.sonarsource.sonarlint.core.test.utils.junit5.SonarLintTest;
2729
import org.sonarsource.sonarlint.core.test.utils.junit5.SonarLintTestHarness;
@@ -50,7 +52,7 @@ void it_should_open_dependency_risk_in_sonarqube(SonarLintTestHarness harness) t
5052
.start(fakeClient);
5153

5254
backend.getScaService().openDependencyRiskInBrowser(new OpenDependencyRiskInBrowserParams(
53-
SCOPE_ID, DEPENDENCY_KEY));
55+
SCOPE_ID, DEPENDENCY_KEY)).join();
5456

5557
var expectedUrl = String.format("http://localhost:12345/dependency-risks/%s/what?id=%s&branch=%s",
5658
urlEncode(DEPENDENCY_KEY.toString()), urlEncode(PROJECT_KEY), urlEncode(BRANCH_NAME));
@@ -66,9 +68,11 @@ void it_should_not_open_dependency_risk_if_unbound(SonarLintTestHarness harness)
6668
.withUnboundConfigScope(SCOPE_ID)
6769
.start(fakeClient);
6870

69-
backend.getScaService().openDependencyRiskInBrowser(new OpenDependencyRiskInBrowserParams(
71+
var result = backend.getScaService().openDependencyRiskInBrowser(new OpenDependencyRiskInBrowserParams(
7072
SCOPE_ID, DEPENDENCY_KEY));
7173

74+
assertThat(result).failsWithin(Duration.ofSeconds(2)).withThrowableOfType(ExecutionException.class)
75+
.withMessage("org.eclipse.lsp4j.jsonrpc.ResponseErrorException: Configuration scope 'scopeId' is not bound properly, unable to open dependency risk");
7276
verify(fakeClient, timeout(5000).times(0)).openUrlInBrowser(any(URL.class));
7377
}
7478
}

rpc-protocol/src/main/java/org/sonarsource/sonarlint/core/rpc/protocol/backend/sca/ScaRpcService.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
package org.sonarsource.sonarlint.core.rpc.protocol.backend.sca;
2121

2222
import java.util.concurrent.CompletableFuture;
23-
import org.eclipse.lsp4j.jsonrpc.services.JsonNotification;
2423
import org.eclipse.lsp4j.jsonrpc.services.JsonRequest;
2524
import org.eclipse.lsp4j.jsonrpc.services.JsonSegment;
2625

@@ -54,6 +53,6 @@ public interface ScaRpcService {
5453
@JsonRequest
5554
CompletableFuture<GetDependencyRiskDetailsResponse> getDependencyRiskDetails(GetDependencyRiskDetailsParams params);
5655

57-
@JsonNotification
58-
void openDependencyRiskInBrowser(OpenDependencyRiskInBrowserParams params);
56+
@JsonRequest
57+
CompletableFuture<Void> openDependencyRiskInBrowser(OpenDependencyRiskInBrowserParams params);
5958
}

rpc-protocol/src/main/java/org/sonarsource/sonarlint/core/rpc/protocol/backend/telemetry/TelemetryRpcService.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,6 @@ public interface TelemetryRpcService {
125125
@JsonNotification
126126
void dependencyRiskInvestigatedLocally();
127127

128-
@JsonNotification
129-
void dependencyRiskInvestigatedRemotely();
130-
131128
@JsonNotification
132129
void findingsFiltered(FindingsFilteredParams params);
133130
}

0 commit comments

Comments
 (0)