Skip to content

Commit

Permalink
SLCORE-1027 Do not wipe cache for unrelated files
Browse files Browse the repository at this point in the history
  • Loading branch information
nquinquenel committed Nov 5, 2024
1 parent 352d42b commit 8444503
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.sonarsource.sonarlint.core.ServerApiProvider;
import org.sonarsource.sonarlint.core.commons.Binding;
import org.sonarsource.sonarlint.core.commons.LocalOnlyIssue;
import org.sonarsource.sonarlint.core.commons.NewCodeDefinition;
import org.sonarsource.sonarlint.core.commons.Transition;
import org.sonarsource.sonarlint.core.commons.Version;
import org.sonarsource.sonarlint.core.commons.progress.SonarLintCancelMonitor;
Expand All @@ -45,9 +46,9 @@
import org.sonarsource.sonarlint.core.local.only.LocalOnlyIssueStorageService;
import org.sonarsource.sonarlint.core.local.only.XodusLocalOnlyIssueStore;
import org.sonarsource.sonarlint.core.mode.SeverityModeService;
import org.sonarsource.sonarlint.core.newcode.NewCodeService;
import org.sonarsource.sonarlint.core.reporting.FindingReportingService;
import org.sonarsource.sonarlint.core.repository.config.ConfigurationRepository;
import org.sonarsource.sonarlint.core.repository.reporting.PreviouslyRaisedFindingsRepository;
import org.sonarsource.sonarlint.core.rpc.protocol.SonarLintRpcErrorCode;
import org.sonarsource.sonarlint.core.rpc.protocol.backend.issue.CheckStatusChangePermittedResponse;
import org.sonarsource.sonarlint.core.rpc.protocol.backend.issue.EffectiveIssueDetailsDto;
Expand Down Expand Up @@ -101,14 +102,14 @@ public class IssueService {
private final ApplicationEventPublisher eventPublisher;
private final FindingReportingService findingReportingService;
private final SeverityModeService severityModeService;
private final PreviouslyRaisedFindingsRepository previouslyRaisedFindingsRepository;
private final NewCodeService newCodeService;
private final RulesService rulesService;
private final TaintVulnerabilityTrackingService taintVulnerabilityTrackingService;

public IssueService(ConfigurationRepository configurationRepository, ServerApiProvider serverApiProvider, StorageService storageService,
LocalOnlyIssueStorageService localOnlyIssueStorageService, LocalOnlyIssueRepository localOnlyIssueRepository,
ApplicationEventPublisher eventPublisher, FindingReportingService findingReportingService, SeverityModeService severityModeService,
PreviouslyRaisedFindingsRepository previouslyRaisedFindingsRepository, RulesService rulesService, TaintVulnerabilityTrackingService taintVulnerabilityTrackingService) {
NewCodeService newCodeService, RulesService rulesService, TaintVulnerabilityTrackingService taintVulnerabilityTrackingService) {
this.configurationRepository = configurationRepository;
this.serverApiProvider = serverApiProvider;
this.storageService = storageService;
Expand All @@ -117,7 +118,7 @@ public IssueService(ConfigurationRepository configurationRepository, ServerApiPr
this.eventPublisher = eventPublisher;
this.findingReportingService = findingReportingService;
this.severityModeService = severityModeService;
this.previouslyRaisedFindingsRepository = previouslyRaisedFindingsRepository;
this.newCodeService = newCodeService;
this.rulesService = rulesService;
this.taintVulnerabilityTrackingService = taintVulnerabilityTrackingService;
}
Expand Down Expand Up @@ -344,15 +345,21 @@ private boolean reopenLocalIssue(String issueId, String configurationScopeId, So

public EffectiveIssueDetailsDto getEffectiveIssueDetails(String configurationScopeId, UUID findingId, SonarLintCancelMonitor cancelMonitor)
throws IssueNotFoundException, RuleNotFoundException {
var maybeIssue =
previouslyRaisedFindingsRepository.getRaisedIssueWithScopeAndId(configurationScopeId, findingId);
var maybeHotspot = previouslyRaisedFindingsRepository.getRaisedHotspotWithScopeAndId(configurationScopeId, findingId);
var effectiveBinding = configurationRepository.getEffectiveBinding(configurationScopeId);
String connectionId = null;
if (effectiveBinding.isPresent()) {
connectionId = effectiveBinding.get().getConnectionId();
}
var isMQRMode = severityModeService.isMQRModeForConnection(connectionId);
var newCodeDefinition = newCodeService.getFullNewCodeDefinition(configurationScopeId).orElseGet(NewCodeDefinition::withAlwaysNew);
var maybeIssue = findingReportingService.findReportedIssue(findingId, newCodeDefinition, isMQRMode);
var maybeHotspot = findingReportingService.findReportedHotspot(findingId, newCodeDefinition, isMQRMode);
var maybeTaint = taintVulnerabilityTrackingService.getTaintVulnerability(configurationScopeId, findingId, cancelMonitor);

if (maybeIssue.isPresent()) {
return getFindingDetails(maybeIssue.get(), configurationScopeId, cancelMonitor);
} else if (maybeHotspot.isPresent()) {
return getFindingDetails(maybeHotspot.get(), configurationScopeId, cancelMonitor);
if (maybeIssue != null) {
return getFindingDetails(maybeIssue, configurationScopeId, cancelMonitor);
} else if (maybeHotspot != null) {
return getFindingDetails(maybeHotspot, configurationScopeId, cancelMonitor);
} else if (maybeTaint.isPresent()) {
return getTaintDetails(maybeTaint.get(), configurationScopeId, cancelMonitor);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.UnaryOperator;
import java.util.stream.Collectors;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
import org.sonarsource.sonarlint.core.commons.Binding;
import org.sonarsource.sonarlint.core.commons.NewCodeDefinition;
Expand Down Expand Up @@ -201,4 +202,26 @@ private static <F extends RaisedFindingDto> Map<URI, List<F>> updateFindings(Una
});
return updatedFindings;
}

@CheckForNull
public RaisedIssueDto findReportedIssue(UUID issueId, NewCodeDefinition newCodeDefinition, boolean isMQRMode) {
for (var findingsForFile: issuesPerFileUri.values()) {
var optFinding = findingsForFile.stream().filter(issue -> issue.getId().equals(issueId)).findFirst();
if (optFinding.isPresent()) {
return toRaisedIssueDto(optFinding.get(), newCodeDefinition, isMQRMode);
}
}
return null;
}

@CheckForNull
public RaisedHotspotDto findReportedHotspot(UUID hotspotId, NewCodeDefinition newCodeDefinition, boolean isMQRMode) {
for (var findingsForFile: securityHotspotsPerFileUri.values()) {
var optFinding = findingsForFile.stream().filter(hotspot -> hotspot.getId().equals(hotspotId)).findFirst();
if (optFinding.isPresent()) {
return toRaisedHotspotDto(optFinding.get(), newCodeDefinition, isMQRMode);
}
}
return null;
}
}

0 comments on commit 8444503

Please sign in to comment.