Skip to content

Commit

Permalink
SLCORE-800 Clean up deprecated classes and methods
Browse files Browse the repository at this point in the history
  • Loading branch information
kirill-knize-sonarsource authored and damien-urruty-sonarsource committed Jan 21, 2025
1 parent a9d5d61 commit 48aea00
Show file tree
Hide file tree
Showing 67 changed files with 1,006 additions and 2,828 deletions.
17 changes: 17 additions & 0 deletions API_CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,23 @@
## 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.
* Removed `org.sonarsource.sonarlint.core.rpc.protocol.client.connection.AssistCreatingConnectionParams#getServerUrl()`. Use `getConnectionParams` instead.
* Removed `org.sonarsource.sonarlint.core.rpc.protocol.backend.analysis.AnalysisRpcService#analyzeFiles`. Use `analyzeFilesAndTrack` instead.
* Removed deprecated methods in `org.sonarsource.sonarlint.core.rpc.protocol.client.issue.RaisedFindingDto`:
* `getSeverity`
* `getType`
* `getCleanCodeAttribute`
* `getImpacts`
* Use `getSeverityMode` instead.
* Removed deprecated methods in `org.sonarsource.sonarlint.core.rpc.protocol.backend.tracking.TaintVulnerabilityDto`:
* `getSeverity`
* `getType`
* `getCleanCodeAttribute`
* `getImpacts`
* Use `getSeverityMode` instead.

## New features

Expand Down
5 changes: 0 additions & 5 deletions backend/analysis-engine/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,6 @@
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
</dependency>
<dependency>
<groupId>org.sonarsource.sonarlint.core</groupId>
<artifactId>sonarlint-rpc-protocol</artifactId>
<version>${project.version}</version>
</dependency>

<!-- Tests -->
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,6 @@ public static RaisedIssueDto toRaisedIssueDto(TrackedIssue issue, NewCodeDefinit
return new RaisedIssueDto(issue.getId(), issue.getServerKey(), issue.getRuleKey(), issue.getMessage(),
isMQRMode ? Either.forRight(new MQRModeDetails(RuleDetailsAdapter.adapt(issue.getCleanCodeAttribute()), RuleDetailsAdapter.toDto(issue.getImpacts())))
: Either.forLeft(new StandardModeDetails(RuleDetailsAdapter.adapt(issue.getSeverity()), RuleDetailsAdapter.adapt(issue.getType()))),
RuleDetailsAdapter.adapt(issue.getSeverity()),
RuleDetailsAdapter.adapt(issue.getType()),
RuleDetailsAdapter.adapt(issue.getCleanCodeAttribute()), RuleDetailsAdapter.toDto(issue.getImpacts()),
requireNonNull(issue.getIntroductionDate()), newCodeDefinition.isOnNewCode(issue.getIntroductionDate()), issue.isResolved(),
toTextRangeDto(issue.getTextRangeWithHash()),
issue.getFlows().stream().map(RuleDetailsAdapter::adapt).collect(Collectors.toList()),
Expand All @@ -72,9 +69,6 @@ public static RaisedHotspotDto toRaisedHotspotDto(TrackedIssue issue, NewCodeDef
isMQRMode && !issue.getImpacts().isEmpty() ?
Either.forRight(new MQRModeDetails(RuleDetailsAdapter.adapt(issue.getCleanCodeAttribute()), RuleDetailsAdapter.toDto(issue.getImpacts())))
: Either.forLeft(new StandardModeDetails(RuleDetailsAdapter.adapt(issue.getSeverity()), RuleDetailsAdapter.adapt(issue.getType()))),
RuleDetailsAdapter.adapt(issue.getSeverity()),
RuleDetailsAdapter.adapt(issue.getType()),
RuleDetailsAdapter.adapt(issue.getCleanCodeAttribute()), RuleDetailsAdapter.toDto(issue.getImpacts()),
requireNonNull(issue.getIntroductionDate()), newCodeDefinition.isOnNewCode(issue.getIntroductionDate()), issue.isResolved(),
toTextRangeDto(issue.getTextRangeWithHash()),
issue.getFlows().stream().map(RuleDetailsAdapter::adapt).collect(Collectors.toList()),
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 @@ -96,8 +96,7 @@ public class IssueService {
private static final Map<ResolutionStatus, Transition> transitionByResolutionStatus = Map.of(
ResolutionStatus.ACCEPT, Transition.ACCEPT,
ResolutionStatus.WONT_FIX, Transition.WONT_FIX,
ResolutionStatus.FALSE_POSITIVE, Transition.FALSE_POSITIVE
);
ResolutionStatus.FALSE_POSITIVE, Transition.FALSE_POSITIVE);

private final ConfigurationRepository configurationRepository;
private final ServerApiProvider serverApiProvider;
Expand Down Expand Up @@ -426,28 +425,31 @@ public static RaisedIssueDto raisedIssueUpdater(RaisedIssueDto previouslyRaisedI
UnaryOperator<RaisedIssueDto> issueUpdater = it -> it.builder().withResolution(resolved).buildIssue();
updatedIssue = updateIssue(updatedIssue, impactedIssueKeys, issueUpdater);
}
if (userSeverity != null) {
UnaryOperator<RaisedIssueDto> issueUpdater = it -> it.builder().withSeverity(IssueSeverity.valueOf(userSeverity.name())).buildIssue();
updatedIssue = updateIssue(updatedIssue, impactedIssueKeys, issueUpdater);
}
if (userType != null) {
UnaryOperator<RaisedIssueDto> issueUpdater = it -> it.builder().withType(RuleType.valueOf(userType.name())).buildIssue();
updatedIssue = updateIssue(updatedIssue, impactedIssueKeys, issueUpdater);
if (updatedIssue.getSeverityMode().isLeft()) {
// if the event does not match the local severity mode, we skip updating as we would only have partial information
// the data will be updated at the next sync
var standardModeDetails = updatedIssue.getSeverityMode().getLeft();
if (userSeverity != null) {
UnaryOperator<RaisedIssueDto> issueUpdater = it -> it.builder().withStandardModeDetails(IssueSeverity.valueOf(userSeverity.name()), standardModeDetails.getType())
.buildIssue();
updatedIssue = updateIssue(updatedIssue, impactedIssueKeys, issueUpdater);
}
if (userType != null) {
UnaryOperator<RaisedIssueDto> issueUpdater = it -> it.builder().withStandardModeDetails(standardModeDetails.getSeverity(), RuleType.valueOf(userType.name()))
.buildIssue();
updatedIssue = updateIssue(updatedIssue, impactedIssueKeys, issueUpdater);
}
}
for (var issue : event.getImpactedIssues()) {
if (!issue.getImpacts().isEmpty() && isMQRMode) {
if (!issue.getImpacts().isEmpty() && isMQRMode && updatedIssue.getSeverityMode().isRight()) {
var mqrModeDetails = updatedIssue.getSeverityMode().getRight();
var impacts = issue.getImpacts().entrySet().stream()
.map(impact ->
new ImpactDto(
SoftwareQuality.valueOf(impact.getKey().name()),
org.sonarsource.sonarlint.core.rpc.protocol.common.ImpactSeverity.valueOf(impact.getValue().name())
)
).collect(Collectors.toList());
UnaryOperator<RaisedIssueDto> issueUpdater =
it -> it.builder().withMQRModeDetails(
it.getCleanCodeAttribute(),
mergeImpacts(it.getSeverityMode().getRight().getImpacts(), impacts)
).buildIssue();
.map(impact -> new ImpactDto(
SoftwareQuality.valueOf(impact.getKey().name()),
org.sonarsource.sonarlint.core.rpc.protocol.common.ImpactSeverity.valueOf(impact.getValue().name())))
.collect(Collectors.toList());
UnaryOperator<RaisedIssueDto> issueUpdater = it -> it.builder()
.withMQRModeDetails(mqrModeDetails.getCleanCodeAttribute(), mergeImpacts(it.getSeverityMode().getRight().getImpacts(), impacts)).buildIssue();
updatedIssue = updateIssue(updatedIssue, impactedIssueKeys, issueUpdater);
}

Expand Down
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 48aea00

Please sign in to comment.