Skip to content

Commit

Permalink
SLCORE-800 Clean up deprecated classes related to analysis
Browse files Browse the repository at this point in the history
  • Loading branch information
kirill-knize-sonarsource authored and damien-urruty-sonarsource committed Jan 10, 2025
1 parent 67a3bcf commit 4422da8
Show file tree
Hide file tree
Showing 49 changed files with 816 additions and 2,316 deletions.
3 changes: 3 additions & 0 deletions API_CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
## Breaking changes

* New feature flag `enableMonitoring` in `org.sonarsource.sonarlint.core.rpc.protocol.backend.initialize.FeatureFlagsDto` allows clients to opt into monitoring with Sentry
* Removed `org.sonarsource.sonarlint.core.rpc.protocol.SonarLintRpcClient#didRaiseIssue` and associated types. See `raiseIssues` and `raiseHotspots` instead.
* Removed `org.sonarsource.sonarlint.core.rpc.protocol.SonarLintRpcServer#getIssueTrackingService` and associated types. Tracking is managed by the backend.
* Removed `org.sonarsource.sonarlint.core.rpc.protocol.SonarLintRpcServer#getSecurityHotspotMatchingService` and associated types. Tracking is managed by the backend.

## New features

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@
import org.sonarsource.sonarlint.core.rpc.protocol.backend.initialize.InitializeParams;
import org.sonarsource.sonarlint.core.rpc.protocol.client.analysis.DidChangeAnalysisReadinessParams;
import org.sonarsource.sonarlint.core.rpc.protocol.client.analysis.DidDetectSecretParams;
import org.sonarsource.sonarlint.core.rpc.protocol.client.analysis.DidRaiseIssueParams;
import org.sonarsource.sonarlint.core.rpc.protocol.client.analysis.FileEditDto;
import org.sonarsource.sonarlint.core.rpc.protocol.client.analysis.GetInferredAnalysisPropertiesParams;
import org.sonarsource.sonarlint.core.rpc.protocol.client.analysis.QuickFixDto;
Expand Down Expand Up @@ -698,7 +697,6 @@ private void streamIssue(String configScopeId, UUID analysisId, Issue issue, Con
if (activeRule != null) {
var rawIssue = new RawIssue(issue, activeRule);
rawIssues.add(rawIssue);
client.didRaiseIssue(new DidRaiseIssueParams(configScopeId, analysisId, toDto(issue, activeRule)));
if (ruleKey.contains("secrets")) {
client.didDetectSecret(new DidDetectSecretParams(configScopeId));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
import org.sonarsource.sonarlint.core.commons.HotspotReviewStatus;
import org.sonarsource.sonarlint.core.commons.log.SonarLintLogger;
import org.sonarsource.sonarlint.core.commons.progress.SonarLintCancelMonitor;
import org.sonarsource.sonarlint.core.event.SonarServerEventReceivedEvent;
import org.sonarsource.sonarlint.core.reporting.FindingReportingService;
import org.sonarsource.sonarlint.core.repository.config.ConfigurationRepository;
import org.sonarsource.sonarlint.core.repository.connection.ConnectionConfigurationRepository;
import org.sonarsource.sonarlint.core.rpc.protocol.SonarLintRpcClient;
Expand All @@ -39,11 +41,18 @@
import org.sonarsource.sonarlint.core.rpc.protocol.backend.hotspot.CheckStatusChangePermittedResponse;
import org.sonarsource.sonarlint.core.rpc.protocol.backend.hotspot.HotspotStatus;
import org.sonarsource.sonarlint.core.rpc.protocol.client.OpenUrlInBrowserParams;
import org.sonarsource.sonarlint.core.rpc.protocol.client.hotspot.RaisedHotspotDto;
import org.sonarsource.sonarlint.core.serverapi.EndpointParams;
import org.sonarsource.sonarlint.core.serverapi.ServerApiHelper;
import org.sonarsource.sonarlint.core.serverapi.UrlUtils;
import org.sonarsource.sonarlint.core.serverapi.hotspot.ServerHotspot;
import org.sonarsource.sonarlint.core.serverapi.push.SecurityHotspotChangedEvent;
import org.sonarsource.sonarlint.core.serverapi.push.SecurityHotspotClosedEvent;
import org.sonarsource.sonarlint.core.serverapi.push.SecurityHotspotRaisedEvent;
import org.sonarsource.sonarlint.core.storage.StorageService;
import org.sonarsource.sonarlint.core.telemetry.TelemetryService;
import org.sonarsource.sonarlint.core.tracking.TaintVulnerabilityTrackingService;
import org.springframework.context.event.EventListener;

@Named
@Singleton
Expand All @@ -60,18 +69,20 @@ public class HotspotService {
private final ServerApiProvider serverApiProvider;
private final TelemetryService telemetryService;
private final SonarProjectBranchTrackingService branchTrackingService;
private final FindingReportingService findingReportingService;
private final StorageService storageService;

public HotspotService(SonarLintRpcClient client, StorageService storageService, ConfigurationRepository configurationRepository,
ConnectionConfigurationRepository connectionRepository, ServerApiProvider serverApiProvider, TelemetryService telemetryService,
SonarProjectBranchTrackingService branchTrackingService) {
SonarProjectBranchTrackingService branchTrackingService, FindingReportingService findingReportingService) {
this.client = client;
this.storageService = storageService;
this.configurationRepository = configurationRepository;
this.connectionRepository = connectionRepository;
this.serverApiProvider = serverApiProvider;
this.telemetryService = telemetryService;
this.branchTrackingService = branchTrackingService;
this.findingReportingService = findingReportingService;
}

public void openHotspotInBrowser(String configScopeId, String hotspotKey) {
Expand Down Expand Up @@ -156,10 +167,6 @@ private void saveStatusInStorage(Binding binding, String hotspotKey, HotspotRevi
.changeHotspotStatus(hotspotKey, newStatus);
}

private boolean isLocalDetectionSupported(boolean isSonarCloud, String connectionId) {
return isSonarCloud || storageService.connection(connectionId).serverInfo().read().isPresent();
}

static String buildHotspotUrl(String projectKey, String branch, String hotspotKey, EndpointParams endpointParams) {
var relativePath = (endpointParams.isSonarCloud() ? "/project/security_hotspots?id=" : "/security_hotspots?id=")
+ UrlUtils.urlEncode(projectKey)
Expand All @@ -170,4 +177,89 @@ static String buildHotspotUrl(String projectKey, String branch, String hotspotKe

return ServerApiHelper.concat(endpointParams.getBaseUrl(), relativePath);
}

@EventListener
public void onServerEventReceived(SonarServerEventReceivedEvent event) {
var connectionId = event.getConnectionId();
var serverEvent = event.getEvent();
if (serverEvent instanceof SecurityHotspotChangedEvent) {
var hotspotChangedEvent = (SecurityHotspotChangedEvent) serverEvent;
updateStorage(connectionId, hotspotChangedEvent);
republishPreviouslyRaisedHotspots(connectionId, hotspotChangedEvent);
} else if (serverEvent instanceof SecurityHotspotClosedEvent) {
var hotspotClosedEvent = (SecurityHotspotClosedEvent) serverEvent;
updateStorage(connectionId, hotspotClosedEvent);
republishPreviouslyRaisedHotspots(connectionId, hotspotClosedEvent);
} else if (serverEvent instanceof SecurityHotspotRaisedEvent) {
var hotspotRaisedEvent = (SecurityHotspotRaisedEvent) serverEvent;
// We could try to match with an existing hotspot. But we don't do it because we don't invest in hotspots right now.
updateStorage(connectionId, hotspotRaisedEvent);
}
}

private void updateStorage(String connectionId, SecurityHotspotRaisedEvent event) {
var hotspot = new ServerHotspot(
event.getHotspotKey(),
event.getRuleKey(),
event.getMainLocation().getMessage(),
event.getMainLocation().getFilePath(),
TaintVulnerabilityTrackingService.adapt(event.getMainLocation().getTextRange()),
event.getCreationDate(),
event.getStatus(),
event.getVulnerabilityProbability(),
null);
var projectKey = event.getProjectKey();
storageService.connection(connectionId).project(projectKey).findings().insert(event.getBranch(), hotspot);
}

private void updateStorage(String connectionId, SecurityHotspotClosedEvent event) {
var projectKey = event.getProjectKey();
storageService.connection(connectionId).project(projectKey).findings().deleteHotspot(event.getHotspotKey());
}

private void updateStorage(String connectionId, SecurityHotspotChangedEvent event) {
var projectKey = event.getProjectKey();
storageService.connection(connectionId).project(projectKey).findings().updateHotspot(event.getHotspotKey(), hotspot -> {
var status = event.getStatus();
if (status != null) {
hotspot.setStatus(status);
}
var assignee = event.getAssignee();
if (assignee != null) {
hotspot.setAssignee(assignee);
}
});
}

private void republishPreviouslyRaisedHotspots(String connectionId, SecurityHotspotChangedEvent event) {
var boundScopes = configurationRepository.getBoundScopesToConnectionAndSonarProject(connectionId, event.getProjectKey());
boundScopes.forEach(scope -> {
var scopeId = scope.getConfigScopeId();
findingReportingService.updateAndReportHotspots(scopeId,
raisedHotspotDto -> changedHotspotUpdater(raisedHotspotDto, event));
});
}

private static RaisedHotspotDto changedHotspotUpdater(RaisedHotspotDto raisedHotspotDto, SecurityHotspotChangedEvent event) {
if (event.getHotspotKey().equals(raisedHotspotDto.getServerKey())) {
return raisedHotspotDto.builder().withHotspotStatus(HotspotStatus.valueOf(event.getStatus().name())).buildHotspot();
}
return raisedHotspotDto;
}

private void republishPreviouslyRaisedHotspots(String connectionId, SecurityHotspotClosedEvent event) {
var boundScopes = configurationRepository.getBoundScopesToConnectionAndSonarProject(connectionId, event.getProjectKey());
boundScopes.forEach(scope -> {
var scopeId = scope.getConfigScopeId();
findingReportingService.updateAndReportHotspots(scopeId,
raisedHotspotDto -> closedHotspotUpdater(raisedHotspotDto, event));
});
}

private static RaisedHotspotDto closedHotspotUpdater(RaisedHotspotDto raisedHotspotDto, SecurityHotspotClosedEvent event) {
if (event.getHotspotKey().equals(raisedHotspotDto.getServerKey())) {
return null;
}
return raisedHotspotDto;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,8 @@
import org.sonarsource.sonarlint.core.sync.SonarProjectBranchesSynchronizationService;
import org.sonarsource.sonarlint.core.sync.SynchronizationService;
import org.sonarsource.sonarlint.core.sync.TaintSynchronizationService;
import org.sonarsource.sonarlint.core.tracking.IssueMatchingService;
import org.sonarsource.sonarlint.core.tracking.KnownFindingsStorageService;
import org.sonarsource.sonarlint.core.tracking.LocalOnlyIssueRepository;
import org.sonarsource.sonarlint.core.tracking.SecurityHotspotMatchingService;
import org.sonarsource.sonarlint.core.tracking.TaintVulnerabilityTrackingService;
import org.sonarsource.sonarlint.core.tracking.TrackingService;
import org.sonarsource.sonarlint.core.usertoken.UserTokenService;
Expand Down Expand Up @@ -161,7 +159,6 @@
IssueService.class,
AnalysisService.class,
SmartNotifications.class,
IssueMatchingService.class,
LocalOnlyIssueRepository.class,
WebSocketService.class,
ServerEventsService.class,
Expand All @@ -170,7 +167,6 @@
StorageService.class,
SeverityModeService.class,
NewCodeService.class,
SecurityHotspotMatchingService.class,
UserTokenService.class,
RequestHandlerBindingAssistant.class,
TaintVulnerabilityTrackingService.class,
Expand Down
Loading

0 comments on commit 4422da8

Please sign in to comment.