Skip to content

Commit b39a29a

Browse files
SLCORE-1541 Introduce a backend capability for SCA synchronization
1 parent e85862c commit b39a29a

File tree

4 files changed

+28
-6
lines changed

4 files changed

+28
-6
lines changed

API_CHANGES.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
# 10.26
2+
3+
## New features
4+
5+
* 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.
6+
* Introduce a new `org.sonarsource.sonarlint.core.rpc.protocol.backend.tracking.ScaIssueTrackingRpcService` service and a `listAll` method
7+
18
# 10.25
29

310
## Breaking changes

backend/core/src/main/java/org/sonarsource/sonarlint/core/sync/ScaSynchronizationService.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
import org.sonarsource.sonarlint.core.commons.log.SonarLintLogger;
2323
import org.sonarsource.sonarlint.core.commons.progress.SonarLintCancelMonitor;
2424
import org.sonarsource.sonarlint.core.event.ScaIssuesSynchronizedEvent;
25+
import org.sonarsource.sonarlint.core.rpc.protocol.backend.initialize.BackendCapability;
26+
import org.sonarsource.sonarlint.core.rpc.protocol.backend.initialize.InitializeParams;
2527
import org.sonarsource.sonarlint.core.serverapi.ServerApi;
2628
import org.sonarsource.sonarlint.core.serverconnection.issues.ServerScaIssue;
2729
import org.sonarsource.sonarlint.core.serverconnection.storage.UpdateSummary;
@@ -36,13 +38,18 @@ public class ScaSynchronizationService {
3638

3739
private final StorageService storageService;
3840
private final ApplicationEventPublisher eventPublisher;
41+
private final boolean isScaSynchronizationEnabled;
3942

40-
public ScaSynchronizationService(StorageService storageService, ApplicationEventPublisher eventPublisher) {
43+
public ScaSynchronizationService(StorageService storageService, ApplicationEventPublisher eventPublisher, InitializeParams initializeParams) {
4144
this.storageService = storageService;
4245
this.eventPublisher = eventPublisher;
46+
this.isScaSynchronizationEnabled = initializeParams.getBackendCapabilities().contains(BackendCapability.SCA_SYNCHRONIZATION);
4347
}
4448

4549
public void synchronize(ServerApi serverApi, String connectionId, String sonarProjectKey, String branchName, SonarLintCancelMonitor cancelMonitor) {
50+
if (!isScaSynchronizationEnabled) {
51+
return;
52+
}
4653
if (!isScaSupported(serverApi, connectionId)) {
4754
return;
4855
}

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

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import static org.assertj.core.api.Assertions.tuple;
3939
import static org.awaitility.Awaitility.await;
4040
import static org.sonarsource.sonarlint.core.rpc.protocol.backend.initialize.BackendCapability.FULL_SYNCHRONIZATION;
41+
import static org.sonarsource.sonarlint.core.rpc.protocol.backend.initialize.BackendCapability.SCA_SYNCHRONIZATION;
4142
import static org.sonarsource.sonarlint.core.serverconnection.issues.ServerScaIssue.Severity;
4243
import static org.sonarsource.sonarlint.core.serverconnection.issues.ServerScaIssue.Status;
4344
import static org.sonarsource.sonarlint.core.serverconnection.issues.ServerScaIssue.Type;
@@ -52,6 +53,7 @@ class ScaIssuesMediumTests {
5253
@SonarLintTest
5354
void it_should_return_no_sca_issues_if_the_scope_does_not_exist(SonarLintTestHarness harness) {
5455
var backend = harness.newBackend()
56+
.withBackendCapability(SCA_SYNCHRONIZATION)
5557
.start();
5658

5759
var scaIssues = listAllScaIssues(backend, CONFIG_SCOPE_ID);
@@ -62,6 +64,7 @@ void it_should_return_no_sca_issues_if_the_scope_does_not_exist(SonarLintTestHar
6264
@SonarLintTest
6365
void it_should_return_no_sca_issues_if_the_scope_is_not_bound(SonarLintTestHarness harness) {
6466
var backend = harness.newBackend()
67+
.withBackendCapability(SCA_SYNCHRONIZATION)
6568
.withUnboundConfigScope(CONFIG_SCOPE_ID)
6669
.start();
6770

@@ -73,6 +76,7 @@ void it_should_return_no_sca_issues_if_the_scope_is_not_bound(SonarLintTestHarne
7376
@SonarLintTest
7477
void it_should_return_no_sca_issues_if_the_storage_is_empty(SonarLintTestHarness harness) {
7578
var backend = harness.newBackend()
79+
.withBackendCapability(SCA_SYNCHRONIZATION)
7680
.withSonarQubeConnection(CONNECTION_ID)
7781
.withBoundConfigScope(CONFIG_SCOPE_ID, CONNECTION_ID, PROJECT_KEY)
7882
.start();
@@ -89,6 +93,7 @@ void it_should_return_the_stored_sca_issues(SonarLintTestHarness harness) {
8993
.start();
9094
var scaIssueKey = UUID.fromString("550e8400-e29b-41d4-a716-446655440000");
9195
var backend = harness.newBackend()
96+
.withBackendCapability(SCA_SYNCHRONIZATION)
9297
.withSonarQubeConnection(CONNECTION_ID, server,
9398
storage -> storage.withProject(PROJECT_KEY,
9499
project -> project.withMainBranch("main",
@@ -120,6 +125,7 @@ void it_should_refresh_sca_issues_when_requested(SonarLintTestHarness harness) {
120125
"2.1.0", List.of("CONFIRM")))))
121126
.start();
122127
var backend = harness.newBackend()
128+
.withBackendCapability(SCA_SYNCHRONIZATION)
123129
.withSonarQubeConnection(CONNECTION_ID, server,
124130
storage -> storage
125131
.withGlobalSettings(Map.of("sonar.sca.enabled", "true"))
@@ -153,7 +159,7 @@ void it_should_notify_client_when_new_sca_issues_are_added(SonarLintTestHarness
153159
harness.newBackend()
154160
.withSonarQubeConnection(CONNECTION_ID, server)
155161
.withBoundConfigScope(CONFIG_SCOPE_ID, CONNECTION_ID, PROJECT_KEY)
156-
.withBackendCapability(FULL_SYNCHRONIZATION)
162+
.withBackendCapability(FULL_SYNCHRONIZATION, SCA_SYNCHRONIZATION)
157163
.start(client);
158164
client.waitForSynchronization();
159165

@@ -196,7 +202,7 @@ void it_should_notify_client_when_sca_issues_are_removed(SonarLintTestHarness ha
196202
.withType(Type.VULNERABILITY)
197203
.withSeverity(Severity.HIGH)))))
198204
.withBoundConfigScope(CONFIG_SCOPE_ID, CONNECTION_ID, PROJECT_KEY)
199-
.withBackendCapability(FULL_SYNCHRONIZATION)
205+
.withBackendCapability(FULL_SYNCHRONIZATION, SCA_SYNCHRONIZATION)
200206
.start(client);
201207
client.waitForSynchronization();
202208

@@ -235,7 +241,7 @@ void it_should_notify_client_when_sca_issues_are_updated(SonarLintTestHarness ha
235241
.withStatus(Status.OPEN)
236242
.withTransitions(List.of(ServerScaIssue.Transition.REOPEN))))))
237243
.withBoundConfigScope(CONFIG_SCOPE_ID, CONNECTION_ID, PROJECT_KEY)
238-
.withBackendCapability(FULL_SYNCHRONIZATION)
244+
.withBackendCapability(FULL_SYNCHRONIZATION, SCA_SYNCHRONIZATION)
239245
.start(client);
240246
client.waitForSynchronization();
241247

@@ -250,7 +256,8 @@ void it_should_notify_client_when_sca_issues_are_updated(SonarLintTestHarness ha
250256
.extracting(ScaIssueDto::getId, ScaIssueDto::getType, ScaIssueDto::getSeverity, ScaIssueDto::getStatus, ScaIssueDto::getTransitions, ScaIssueDto::getPackageName,
251257
ScaIssueDto::getPackageVersion)
252258
.containsExactly(
253-
tuple(scaIssueKey, ScaIssueDto.Type.VULNERABILITY, ScaIssueDto.Severity.LOW, ScaIssueDto.Status.ACCEPT, List.of(ScaIssueDto.Transition.REOPEN), "com.example.vulnerable", "2.1.0"));
259+
tuple(scaIssueKey, ScaIssueDto.Type.VULNERABILITY, ScaIssueDto.Severity.LOW, ScaIssueDto.Status.ACCEPT, List.of(ScaIssueDto.Transition.REOPEN), "com.example.vulnerable",
260+
"2.1.0"));
254261
});
255262
}
256263

rpc-protocol/src/main/java/org/sonarsource/sonarlint/core/rpc/protocol/backend/initialize/BackendCapability.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,6 @@ public enum BackendCapability {
2929
FULL_SYNCHRONIZATION,
3030
TELEMETRY,
3131
MONITORING,
32-
ISSUE_STREAMING
32+
ISSUE_STREAMING,
33+
SCA_SYNCHRONIZATION,
3334
}

0 commit comments

Comments
 (0)