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 committed Oct 1, 2024
1 parent b636792 commit 7782a48
Show file tree
Hide file tree
Showing 39 changed files with 1,794 additions and 2,467 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,14 @@
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;
import org.sonarsource.sonarlint.core.rpc.protocol.client.analysis.RawIssueDto;
import org.sonarsource.sonarlint.core.rpc.protocol.client.analysis.RawIssueFlowDto;
import org.sonarsource.sonarlint.core.rpc.protocol.client.analysis.RawIssueLocationDto;
import org.sonarsource.sonarlint.core.rpc.protocol.client.analysis.TextEditDto;
import org.sonarsource.sonarlint.core.rpc.protocol.client.issue.RaiseIssuesParams;
import org.sonarsource.sonarlint.core.rpc.protocol.common.ImpactSeverity;
import org.sonarsource.sonarlint.core.rpc.protocol.common.SoftwareQuality;
import org.sonarsource.sonarlint.core.rpc.protocol.common.TextRangeDto;
Expand Down Expand Up @@ -693,7 +693,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 @@ -65,98 +65,19 @@
@Named
@Singleton
public class SecurityHotspotMatchingService {
private static final int FETCH_ALL_SECURITY_HOTSPOTS_THRESHOLD = 10;
private static final SonarLintLogger LOG = SonarLintLogger.get();
private final ConfigurationRepository configurationRepository;
private final StorageService storageService;
private final SonarProjectBranchTrackingService branchTrackingService;
private final HotspotSynchronizationService hotspotSynchronizationService;
private final PathTranslationService pathTranslationService;
private final FindingReportingService findingReportingService;
private final ExecutorService executorService;

public SecurityHotspotMatchingService(ConfigurationRepository configurationRepository, StorageService storageService,
SonarProjectBranchTrackingService branchTrackingService, HotspotSynchronizationService hotspotSynchronizationService,
PathTranslationService pathTranslationService, FindingReportingService findingReportingService) {
public SecurityHotspotMatchingService(ConfigurationRepository configurationRepository, StorageService storageService, FindingReportingService findingReportingService) {
this.configurationRepository = configurationRepository;
this.storageService = storageService;
this.branchTrackingService = branchTrackingService;
this.hotspotSynchronizationService = hotspotSynchronizationService;
this.pathTranslationService = pathTranslationService;
this.findingReportingService = findingReportingService;
this.executorService = Executors.newSingleThreadExecutor(r -> new Thread(r, "sonarlint-server-tracking-hotspot-updater"));
}

public Map<Path, List<Either<ServerMatchedSecurityHotspotDto, LocalOnlySecurityHotspotDto>>> matchWithServerSecurityHotspots(String configurationScopeId,
Map<Path, List<ClientTrackedFindingDto>> clientTrackedHotspotsByIdeRelativePath, boolean shouldFetchHotspotsFromServer, SonarLintCancelMonitor cancelMonitor) {
var effectiveBindingOpt = configurationRepository.getEffectiveBinding(configurationScopeId);
var activeBranchOpt = branchTrackingService.awaitEffectiveSonarProjectBranch(configurationScopeId);
var translationOpt = pathTranslationService.getOrComputePathTranslation(configurationScopeId);
if (effectiveBindingOpt.isEmpty() || activeBranchOpt.isEmpty() || translationOpt.isEmpty()) {
return clientTrackedHotspotsByIdeRelativePath.entrySet().stream()
.map(e -> Map.entry(e.getKey(), e.getValue().stream()
.map(issue -> Either.<ServerMatchedSecurityHotspotDto, LocalOnlySecurityHotspotDto>forRight(
new LocalOnlySecurityHotspotDto(UUID.randomUUID())))
.collect(Collectors.toList())))
.collect(toMap(Map.Entry::getKey, Map.Entry::getValue));
}
var binding = effectiveBindingOpt.get();
var activeBranch = activeBranchOpt.get();
if (shouldFetchHotspotsFromServer) {
refreshServerSecurityHotspots(cancelMonitor, binding, activeBranch, clientTrackedHotspotsByIdeRelativePath, translationOpt.get());
}
var newCodeDefinition = storageService.binding(binding).newCodeDefinition().read();
return clientTrackedHotspotsByIdeRelativePath.entrySet().stream().map(e -> {
var serverRelativePath = e.getKey();
var serverHotspots = storageService.binding(binding).findings().loadHotspots(activeBranch, serverRelativePath);
var matches = matchSecurityHotspots(serverHotspots, e.getValue())
.stream().map(result -> {
if (result.isLeft()) {
var serverSecurityHotspot = result.getLeft();
var creationDate = serverSecurityHotspot.getCreationDate();
var isOnNewCode = newCodeDefinition.map(definition -> definition.isOnNewCode(creationDate.toEpochMilli())).orElse(true);
return Either.<ServerMatchedSecurityHotspotDto, LocalOnlySecurityHotspotDto>forLeft(
new ServerMatchedSecurityHotspotDto(UUID.randomUUID(), serverSecurityHotspot.getKey(), creationDate.toEpochMilli(),
HotspotStatus.valueOf(serverSecurityHotspot.getStatus().name()), isOnNewCode));
} else {
return Either.<ServerMatchedSecurityHotspotDto, LocalOnlySecurityHotspotDto>forRight(new LocalOnlySecurityHotspotDto(result.getRight().getId()));
}
}).collect(Collectors.toList());
return Map.entry(serverRelativePath, matches);
}).collect(toMap(Map.Entry::getKey, Map.Entry::getValue));
}

private void refreshServerSecurityHotspots(SonarLintCancelMonitor cancelMonitor, Binding binding, String activeBranch,
Map<Path, List<ClientTrackedFindingDto>> clientTrackedHotspotsByIdeRelativePath, FilePathTranslation translation) {
var serverFileRelativePaths = clientTrackedHotspotsByIdeRelativePath.keySet()
.stream().map(translation::ideToServerPath).collect(Collectors.toSet());
var downloadAllSecurityHotspotsAtOnce = serverFileRelativePaths.size() > FETCH_ALL_SECURITY_HOTSPOTS_THRESHOLD;
var fetchTasks = new LinkedList<CompletableFuture<?>>();
if (downloadAllSecurityHotspotsAtOnce) {
fetchTasks.add(CompletableFuture.runAsync(() -> hotspotSynchronizationService.fetchProjectHotspots(binding, activeBranch, cancelMonitor), executorService));
} else {
fetchTasks.addAll(serverFileRelativePaths.stream()
.map(serverFileRelativePath -> CompletableFuture
.runAsync(() -> hotspotSynchronizationService.fetchFileHotspots(binding, activeBranch, serverFileRelativePath, cancelMonitor), executorService))
.collect(Collectors.toList()));
}
CompletableFuture.allOf(fetchTasks.toArray(new CompletableFuture[0])).join();
}

private static List<Either<ServerHotspot, LocalOnlySecurityHotspot>> matchSecurityHotspots(Collection<ServerHotspot> serverHotspots,
List<ClientTrackedFindingDto> clientTrackedHotspots) {
var matcher = new IssueMatcher<>(new ClientTrackedFindingMatchingAttributeMapper(), new ServerHotspotMatchingAttributesMapper());
var matchingResult = matcher.match(clientTrackedHotspots, serverHotspots);
return clientTrackedHotspots.stream().<Either<ServerHotspot, LocalOnlySecurityHotspot>>map(clientTrackedHotspot -> {
var match = matchingResult.getMatch(clientTrackedHotspot);
if (match != null) {
return Either.forLeft(match);
} else {
return Either.forRight(new LocalOnlySecurityHotspot(UUID.randomUUID()));
}
}).collect(Collectors.toList());
}

@EventListener
public void onServerEventReceived(SonarServerEventReceivedEvent event) {
var connectionId = event.getConnectionId();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,17 +117,6 @@ public CompletableFuture<GetAutoDetectedNodeJsResponse> getAutoDetectedNodeJs()
});
}

@Override
public CompletableFuture<AnalyzeFilesResponse> analyzeFiles(AnalyzeFilesParams params) {
var configurationScopeId = params.getConfigurationScopeId();
return requestAsync(cancelChecker -> {
var analysisResults = getBean(AnalysisService.class)
.analyze(cancelChecker, params.getConfigurationScopeId(), params.getAnalysisId(), params.getFilesToAnalyze(),
params.getExtraProperties(), params.getStartTime(), false, false, false).join();
return generateAnalyzeFilesResponse(analysisResults);
}, configurationScopeId);
}

@Override
public CompletableFuture<AnalyzeFilesResponse> analyzeFilesAndTrack(AnalyzeFilesAndTrackParams params) {
var configurationScopeId = params.getConfigurationScopeId();
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@
import org.sonarsource.sonarlint.core.rpc.protocol.backend.newcode.NewCodeRpcService;
import org.sonarsource.sonarlint.core.rpc.protocol.backend.rules.RulesRpcService;
import org.sonarsource.sonarlint.core.rpc.protocol.backend.telemetry.TelemetryRpcService;
import org.sonarsource.sonarlint.core.rpc.protocol.backend.tracking.IssueTrackingRpcService;
import org.sonarsource.sonarlint.core.rpc.protocol.backend.tracking.SecurityHotspotMatchingRpcService;
import org.sonarsource.sonarlint.core.rpc.protocol.backend.tracking.TaintVulnerabilityTrackingRpcService;
import org.sonarsource.sonarlint.core.spring.SpringApplicationContextInitializer;
import org.sonarsource.sonarlint.core.storage.StorageService;
Expand Down Expand Up @@ -215,16 +213,6 @@ public IssueRpcService getIssueService() {
return new IssueRpcServiceDelegate(this);
}

@Override
public IssueTrackingRpcService getIssueTrackingService() {
return new IssueTrackingRpcServiceDelegate(this);
}

@Override
public SecurityHotspotMatchingRpcService getSecurityHotspotMatchingService() {
return new SecurityHotspotMatchingRpcServiceDelegate(this);
}

@Override
public NewCodeRpcService getNewCodeService() {
return new NewCodeRpcServiceDelegate(this);
Expand Down
Loading

0 comments on commit 7782a48

Please sign in to comment.