Skip to content

Commit

Permalink
SLCORE-983 Remove enableTracking flag
Browse files Browse the repository at this point in the history
  • Loading branch information
damien-urruty-sonarsource committed Feb 6, 2025
1 parent 7a1f841 commit 9cdaa08
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,10 @@ public class AnalysisFinishedEvent {
private final List<RawIssue> issues;
private final Set<String> reportedRuleKeys;
private final Set<SonarLanguage> detectedLanguages;
private final boolean trackingEnabled;
private final boolean shouldFetchServerIssues;

public AnalysisFinishedEvent(UUID analysisId, String configurationScopeId, long analysisDuration, Map<URI, SonarLanguage> languagePerFile, boolean succeededForAllFiles,
List<RawIssue> issues, boolean enableTracking, boolean shouldFetchServerIssues) {
List<RawIssue> issues, boolean shouldFetchServerIssues) {
this.analysisId = analysisId;
this.configurationScopeId = configurationScopeId;
this.analysisDuration = analysisDuration;
Expand All @@ -52,7 +51,6 @@ public AnalysisFinishedEvent(UUID analysisId, String configurationScopeId, long
this.issues = issues;
this.reportedRuleKeys = issues.stream().map(RawIssue::getRuleKey).collect(Collectors.toSet());
this.detectedLanguages = languagePerFile.values().stream().filter(Objects::nonNull).collect(Collectors.toSet());
this.trackingEnabled = enableTracking;
this.shouldFetchServerIssues = shouldFetchServerIssues;
}

Expand Down Expand Up @@ -92,10 +90,6 @@ public List<RawIssue> getHotspots() {
return issues.stream().filter(RawIssue::isSecurityHotspot).toList();
}

public boolean isTrackingEnabled() {
return trackingEnabled;
}

public boolean shouldFetchServerIssues() {
return shouldFetchServerIssues;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,9 @@ public AnalysisService(SonarLintRpcClient client, ConfigurationRepository config
this.automaticAnalysisEnabled = initializeParams.isAutomaticAnalysisEnabled();
this.clientFileSystemService = clientFileSystemService;
this.monitoringService = monitoringService;
this.esLintBridgeServerPath = initializeParams.getLanguageSpecificRequirements() != null && initializeParams.getLanguageSpecificRequirements().getJsTsRequirements() != null ?
initializeParams.getLanguageSpecificRequirements().getJsTsRequirements().getBundlePath() : null;
this.esLintBridgeServerPath = initializeParams.getLanguageSpecificRequirements() != null && initializeParams.getLanguageSpecificRequirements().getJsTsRequirements() != null
? initializeParams.getLanguageSpecificRequirements().getJsTsRequirements().getBundlePath()
: null;
}

public List<String> getSupportedFilePatterns(String configScopeId) {
Expand Down Expand Up @@ -641,7 +642,7 @@ public boolean shouldUseEnterpriseCSharpAnalyzer(String configurationScopeId) {
}

public CompletableFuture<AnalysisResults> analyze(SonarLintCancelMonitor cancelMonitor, String configurationScopeId, UUID analysisId, List<URI> filePathsToAnalyze,
Map<String, String> extraProperties, long startTime, boolean enableTracking, boolean shouldFetchServerIssues, boolean hotspotsOnly) {
Map<String, String> extraProperties, long startTime, boolean shouldFetchServerIssues, boolean hotspotsOnly) {
var analysisEngine = engineCache.getOrCreateAnalysisEngine(configurationScopeId);
var analysisConfig = getAnalysisConfigForEngine(configurationScopeId, filePathsToAnalyze, extraProperties, hotspotsOnly);

Expand All @@ -654,9 +655,9 @@ public CompletableFuture<AnalysisResults> analyze(SonarLintCancelMonitor cancelM

cancelMonitor.checkCanceled();
var raisedIssues = new ArrayList<RawIssue>();
eventPublisher.publishEvent(new AnalysisStartedEvent(configurationScopeId, analysisId, analysisConfig.inputFiles(), enableTracking));
eventPublisher.publishEvent(new AnalysisStartedEvent(configurationScopeId, analysisId, analysisConfig.inputFiles()));
var analyzeCommand = new AnalyzeCommand(configurationScopeId, analysisConfig,
issue -> streamIssue(configurationScopeId, analysisId, issue, ruleDetailsCache, raisedIssues, enableTracking), SonarLintLogger.getTargetForCopy(),
issue -> streamIssue(configurationScopeId, analysisId, issue, ruleDetailsCache, raisedIssues), SonarLintLogger.getTargetForCopy(),
monitoringService.newTrace("AnalysisService", "analyze"));
var rpcProgressMonitor = new RpcProgressMonitor(client, cancelMonitor, configurationScopeId, analysisId);
return analysisEngine.post(analyzeCommand, rpcProgressMonitor)
Expand All @@ -668,7 +669,7 @@ public CompletableFuture<AnalysisResults> analyze(SonarLintCancelMonitor cancelM
var analysisDuration = endTime - startTime;
logSummary(raisedIssues, analysisDuration);
eventPublisher.publishEvent(new AnalysisFinishedEvent(analysisId, configurationScopeId, analysisDuration,
languagePerFile, results.failedAnalysisFiles().isEmpty(), raisedIssues, enableTracking, shouldFetchServerIssues));
languagePerFile, results.failedAnalysisFiles().isEmpty(), raisedIssues, shouldFetchServerIssues));
results.setRawIssues(raisedIssues.stream().map(issue -> toDto(issue.getIssue(), issue.getActiveRule())).toList());
} else {
LOG.error("Error during analysis", error);
Expand All @@ -685,8 +686,7 @@ private static void logSummary(ArrayList<RawIssue> rawIssues, long analysisDurat
LOG.info("Analysis detected {} and {} in {}ms", pluralize(issuesCount, "issue"), pluralize(hotspotsCount, "Security Hotspot"), analysisDuration);
}

private void streamIssue(String configScopeId, UUID analysisId, Issue issue, ConcurrentHashMap<String, RuleDetailsForAnalysis> ruleDetailsCache, List<RawIssue> rawIssues,
boolean enableTracking) {
private void streamIssue(String configScopeId, UUID analysisId, Issue issue, ConcurrentHashMap<String, RuleDetailsForAnalysis> ruleDetailsCache, List<RawIssue> rawIssues) {
var ruleKey = issue.getRuleKey();
var activeRule = ruleDetailsCache.computeIfAbsent(ruleKey, k -> {
try {
Expand All @@ -701,9 +701,7 @@ private void streamIssue(String configScopeId, UUID analysisId, Issue issue, Con
if (ruleKey.contains("secrets")) {
client.didDetectSecret(new DidDetectSecretParams(configScopeId));
}
if (enableTracking) {
eventPublisher.publishEvent(new RawIssueDetectedEvent(configScopeId, analysisId, rawIssue));
}
eventPublisher.publishEvent(new RawIssueDetectedEvent(configScopeId, analysisId, rawIssue));
}
}

Expand Down Expand Up @@ -897,7 +895,7 @@ private UUID triggerForcedAnalysis(String configurationScopeId, List<URI> files,
if (isReadyForAnalysis(configurationScopeId)) {
var analysisId = UUID.randomUUID();
scheduledAnalysisExecutor.submit(() -> {
analyze(new SonarLintCancelMonitor(), configurationScopeId, analysisId, files, Map.of(), System.currentTimeMillis(), true, true, hotspotsOnly);
analyze(new SonarLintCancelMonitor(), configurationScopeId, analysisId, files, Map.of(), System.currentTimeMillis(), true, hotspotsOnly);
return analysisId;
});
}
Expand All @@ -909,7 +907,7 @@ private void triggerAnalysis(String configurationScopeId, List<URI> files) {
scheduledAnalysisExecutor.submit(() -> {
if (shouldTriggerAutomaticAnalysis(configurationScopeId)) {
List<URI> filteredFiles = fileExclusionService.filterOutClientExcludedFiles(configurationScopeId, files);
analyze(new SonarLintCancelMonitor(), configurationScopeId, UUID.randomUUID(), filteredFiles, Map.of(), System.currentTimeMillis(), true, true, false);
analyze(new SonarLintCancelMonitor(), configurationScopeId, UUID.randomUUID(), filteredFiles, Map.of(), System.currentTimeMillis(), true, false);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,11 @@ public class AnalysisStartedEvent {
private final String configurationScopeId;
private final UUID analysisId;
private final List<ClientInputFile> files;
private final boolean enableTracking;

public AnalysisStartedEvent(String configurationScopeId, UUID analysisId, Iterable<ClientInputFile> files, boolean enableTracking) {
public AnalysisStartedEvent(String configurationScopeId, UUID analysisId, Iterable<ClientInputFile> files) {
this.configurationScopeId = configurationScopeId;
this.analysisId = analysisId;
this.files = StreamSupport.stream(files.spliterator(), false).toList();
this.enableTracking = enableTracking;
}

public UUID getAnalysisId() {
Expand All @@ -60,10 +58,6 @@ public Set<URI> getFileUris() {
return files.stream().map(ClientInputFile::uri).collect(toSet());
}

public boolean isTrackingEnabled() {
return enableTracking;
}

public UnaryOperator<String> getFileContentProvider() {
return path -> files.stream()
.filter(ClientInputFile::isDirty)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,11 @@ public TrackingService(SonarLintRpcClient client, ConfigurationRepository config

@EventListener
public void onAnalysisStarted(AnalysisStartedEvent event) {
if (event.isTrackingEnabled()) {
var configurationScopeId = event.getConfigurationScopeId();
var matchingSession = startMatchingSession(configurationScopeId, event.getFileRelativePaths(), event.getFileContentProvider());
matchingSessionByAnalysisId.put(event.getAnalysisId(), matchingSession);
reportingService.resetFindingsForFiles(configurationScopeId, event.getFileUris());
reportingService.initFilesToAnalyze(event.getAnalysisId(), event.getFileUris());
}
var configurationScopeId = event.getConfigurationScopeId();
var matchingSession = startMatchingSession(configurationScopeId, event.getFileRelativePaths(), event.getFileContentProvider());
matchingSessionByAnalysisId.put(event.getAnalysisId(), matchingSession);
reportingService.resetFindingsForFiles(configurationScopeId, event.getFileUris());
reportingService.initFilesToAnalyze(event.getAnalysisId(), event.getFileUris());
}

@EventListener
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ public CompletableFuture<AnalyzeFilesResponse> analyzeFilesAndTrack(AnalyzeFiles
return requestAsync(cancelChecker -> {
var analysisResults = getBean(AnalysisService.class)
.analyze(cancelChecker, params.getConfigurationScopeId(), params.getAnalysisId(), params.getFilesToAnalyze(), params.getExtraProperties(), params.getStartTime(),
true, params.isShouldFetchServerIssues(), false).join();
params.isShouldFetchServerIssues(), false)
.join();
return generateAnalyzeFilesResponse(analysisResults);
}, configurationScopeId);
}
Expand Down Expand Up @@ -179,8 +180,7 @@ public CompletableFuture<ForceAnalyzeResponse> analyzeVCSChangedFiles(AnalyzeVCS
public CompletableFuture<ShouldUseEnterpriseCSharpAnalyzerResponse> shouldUseEnterpriseCSharpAnalyzer(ShouldUseEnterpriseCSharpAnalyzerParams params) {
return requestAsync(
cancelChecker -> new ShouldUseEnterpriseCSharpAnalyzerResponse(getBean(AnalysisService.class)
.shouldUseEnterpriseCSharpAnalyzer(params.getConfigurationScopeId()))
);
.shouldUseEnterpriseCSharpAnalyzer(params.getConfigurationScopeId())));
}

private static AnalyzeFilesResponse generateAnalyzeFilesResponse(AnalysisResults analysisResults) {
Expand Down

0 comments on commit 9cdaa08

Please sign in to comment.