Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SLCORE-1039 Differentiate added/modified files in FS API #1163

Merged
merged 1 commit into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions API_CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# 11.11

## Breaking changes

* Signature of `org.sonarsource.sonarlint.core.rpc.protocol.backend.file.DidUpdateFileSystemParams#DidUpdateFileSystemParams` was changed
* Parameter `addedOrChangedFiles` was split into `addedFiles` and `changedFiles`

# 10.10

## New features
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,19 +132,33 @@ public void didUpdateFileSystem(DidUpdateFileSystemParams params) {
removed.add(clientFile);
}
});

var added = new ArrayList<ClientFile>();
params.getAddedFiles().forEach(clientFileDto -> {
var clientFile = fromDto(clientFileDto);
var previousFile = filesByUri.put(clientFileDto.getUri(), clientFile);
// We only send send the ADDED event for files that were actually added (not existing before)
if (previousFile == null) {
added.add(clientFile);
}
var byScope = filesByConfigScopeIdCache.get(clientFileDto.getConfigScopeId());
byScope.put(clientFileDto.getUri(), clientFile);
});

var updated = new ArrayList<ClientFile>();
params.getAddedOrChangedFiles().forEach(clientFileDto -> {
params.getChangedFiles().forEach(clientFileDto -> {
var clientFile = fromDto(clientFileDto);
var previousFile = filesByUri.put(clientFileDto.getUri(), clientFile);
// Modifying an unknown file is equals to adding it
if (previousFile != null) {
updated.add(clientFile);
} else{
} else {
added.add(clientFile);
}
var byScope = filesByConfigScopeIdCache.get(clientFileDto.getConfigScopeId());
byScope.put(clientFileDto.getUri(), clientFile);
});

eventPublisher.publishEvent(new FileSystemUpdatedEvent(removed, added, updated));
}

Expand Down
2 changes: 1 addition & 1 deletion its/tests/src/test/java/its/FileExclusionTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ void should_respect_exclusion_settings_on_SQ() {
var filePath = Path.of("src/main/java/foo/Foo.java");
var clientFileDto = new ClientFileDto(filePath.toUri(), filePath, configScopeId, null, StandardCharsets.UTF_8.name(),
filePath.toAbsolutePath(), null, null, true);
var didUpdateFileSystemParams = new DidUpdateFileSystemParams(List.of(), List.of(clientFileDto));
var didUpdateFileSystemParams = new DidUpdateFileSystemParams(List.of(clientFileDto), List.of(), List.of());
backend.getFileService().didUpdateFileSystem(didUpdateFileSystemParams);

// Firstly check file is included
Expand Down
7 changes: 5 additions & 2 deletions its/tests/src/test/java/its/SonarCloudTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -715,8 +715,11 @@ public void log(LogParams params) {
private static List<RawIssueDto> analyze(String projectKey, String fileName, String configScopeId, String ... properties) {
final var baseDir = Paths.get("projects/" + projectKey).toAbsolutePath();
final var filePath = baseDir.resolve(fileName);
backend.getFileService().didUpdateFileSystem(new DidUpdateFileSystemParams(List.of(),
List.of(new ClientFileDto(filePath.toUri(), Path.of(fileName), configScopeId, false, null, filePath, null, null, true))));
backend.getFileService().didUpdateFileSystem(new DidUpdateFileSystemParams(
List.of(new ClientFileDto(filePath.toUri(), Path.of(fileName), configScopeId, false, null, filePath, null, null, true)),
List.of(),
List.of()
));

var analyzeResponse = backend.getAnalysisService().analyzeFiles(
new AnalyzeFilesParams(configScopeId, UUID.randomUUID(), List.of(filePath.toUri()), toMap(properties), System.currentTimeMillis())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1405,8 +1405,11 @@ private void analyzeProject(String projectDirName, String projectKey, String...
private List<RawIssueDto> analyzeFile(String configScopeId, String baseDir, String filePathStr, String... properties) {
var filePath = Path.of("projects").resolve(baseDir).resolve(filePathStr);
var fileUri = filePath.toUri();
backend.getFileService().didUpdateFileSystem(new DidUpdateFileSystemParams(List.of(),
List.of(new ClientFileDto(fileUri, Path.of(filePathStr), configScopeId, false, null, filePath.toAbsolutePath(), null, null, true))));
backend.getFileService().didUpdateFileSystem(new DidUpdateFileSystemParams(
List.of(new ClientFileDto(fileUri, Path.of(filePathStr), configScopeId, false, null, filePath.toAbsolutePath(), null, null, true)),
List.of(),
List.of()
));

var analyzeResponse = backend.getAnalysisService().analyzeFiles(
new AnalyzeFilesParams(configScopeId, UUID.randomUUID(), List.of(fileUri), toMap(properties), System.currentTimeMillis())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -351,8 +351,11 @@ private static void bindProject(String projectName, String projectKey) {
private List<RawIssueDto> analyzeFile(String projectDir, String filePathStr, String... properties) {
var filePath = Path.of("projects").resolve(projectDir).resolve(filePathStr);
var fileUri = filePath.toUri();
backend.getFileService().didUpdateFileSystem(new DidUpdateFileSystemParams(List.of(),
List.of(new ClientFileDto(fileUri, Path.of(filePathStr), CONFIG_SCOPE_ID, false, null, filePath.toAbsolutePath(), null, null, true))));
backend.getFileService().didUpdateFileSystem(new DidUpdateFileSystemParams(
List.of(new ClientFileDto(fileUri, Path.of(filePathStr), CONFIG_SCOPE_ID, false, null, filePath.toAbsolutePath(), null, null, true)),
List.of(),
List.of()
));

var analyzeResponse = backend.getAnalysisService().analyzeFiles(
new AnalyzeFilesParams(CONFIG_SCOPE_ID, UUID.randomUUID(), List.of(fileUri), toMap(properties), System.currentTimeMillis())
Expand Down
7 changes: 5 additions & 2 deletions its/tests/src/test/java/its/StandaloneTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,11 @@ public void log(LogParams params) {
private List<RawIssueDto> analyzeFile(String configScopeId, String baseDir, String filePathStr, String... properties) {
var filePath = Path.of("projects").resolve(baseDir).resolve(filePathStr);
var fileUri = filePath.toUri();
backend.getFileService().didUpdateFileSystem(new DidUpdateFileSystemParams(List.of(),
List.of(new ClientFileDto(fileUri, Path.of(filePathStr), configScopeId, false, null, filePath.toAbsolutePath(), null, null, true))));
backend.getFileService().didUpdateFileSystem(new DidUpdateFileSystemParams(
List.of(new ClientFileDto(fileUri, Path.of(filePathStr), configScopeId, false, null, filePath.toAbsolutePath(), null, null, true)),
List.of(),
List.of()
));

var analyzeResponse = backend.getAnalysisService().analyzeFiles(
new AnalyzeFilesParams(configScopeId, UUID.randomUUID(), List.of(fileUri), toMap(properties), System.currentTimeMillis())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,12 @@ void test_uses_binding_clues_when_updating_fs(@TempDir Path tmp) throws IOExcept
var clue = tmp.resolve("sonar-project.properties");
Files.writeString(clue, "sonar.projectKey=" + SLCORE_PROJECT_KEY + "\nsonar.projectName=" + SLCORE_PROJECT_NAME, StandardCharsets.UTF_8);

backend.getFileService().didUpdateFileSystem(new DidUpdateFileSystemParams(List.of(),
List.of(new ClientFileDto(clue.toUri(), Paths.get("sonar-project.properties"), CONFIG_SCOPE_ID, null, StandardCharsets.UTF_8.name(), clue, null, null, true))));
backend.getFileService().didUpdateFileSystem(new DidUpdateFileSystemParams(
List.of(new ClientFileDto(clue.toUri(), Paths.get("sonar-project.properties"), CONFIG_SCOPE_ID, null, StandardCharsets.UTF_8.name()
, clue, null, null, true)),
List.of(),
List.of()
));

ArgumentCaptor<Map<String, List<BindingSuggestionDto>>> suggestionCaptor = ArgumentCaptor.forClass(Map.class);
verify(fakeClient, timeout(5000).times(2)).suggestBinding(suggestionCaptor.capture());
Expand Down Expand Up @@ -310,8 +314,11 @@ void test_uses_binding_clues_from_shared_configuration_when_updating_fs(@TempDir
var clue = tmp.resolve(".sonarlint/connectedMode.json");
Files.writeString(clue, "{\"projectKey\": \"" + SLCORE_PROJECT_KEY + "\",\"sonarQubeUri\": \"" + sonarqubeMock.baseUrl() + "\"}", StandardCharsets.UTF_8);

backend.getFileService().didUpdateFileSystem(new DidUpdateFileSystemParams(List.of(),
List.of(new ClientFileDto(clue.toUri(), Paths.get(".sonarlint/connectedMode.json"), CONFIG_SCOPE_ID, null, StandardCharsets.UTF_8.name(), clue, null, null, true))));
backend.getFileService().didUpdateFileSystem(new DidUpdateFileSystemParams(
List.of(new ClientFileDto(clue.toUri(), Paths.get(".sonarlint/connectedMode.json"), CONFIG_SCOPE_ID, null, StandardCharsets.UTF_8.name(), clue, null, null, true)),
List.of(),
List.of())
);

ArgumentCaptor<Map<String, List<BindingSuggestionDto>>> suggestionCaptor = ArgumentCaptor.forClass(Map.class);
verify(fakeClient, timeout(5000).times(2)).suggestBinding(suggestionCaptor.capture());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ void should_suggest_sonarqube_connection_when_initializing_fs(@TempDir Path tmp)
backend = newBackend()
.build(fakeClient);

backend.getFileService().didUpdateFileSystem(new DidUpdateFileSystemParams(Collections.emptyList(), List.of(fileDto)));
backend.getFileService().didUpdateFileSystem(new DidUpdateFileSystemParams(List.of(fileDto), Collections.emptyList(), Collections.emptyList()));

ArgumentCaptor<Map<String, List<ConnectionSuggestionDto>>> suggestionCaptor = ArgumentCaptor.forClass(Map.class);
verify(fakeClient, timeout(5000)).suggestConnection(suggestionCaptor.capture());
Expand Down Expand Up @@ -122,7 +122,7 @@ void should_not_suggest_connection_for_empty_values(String projectKey, String se

backend = newBackend().build(fakeClient);

backend.getFileService().didUpdateFileSystem(new DidUpdateFileSystemParams(Collections.emptyList(), List.of(fileDto)));
backend.getFileService().didUpdateFileSystem(new DidUpdateFileSystemParams(List.of(fileDto), Collections.emptyList(), Collections.emptyList()));

await().pollDelay(Duration.ofMillis(300)).untilAsserted(() -> assertThat(fakeClient.getSuggestionsByConfigScope()).isEmpty());
}
Expand All @@ -146,7 +146,7 @@ void should_suggest_connection_for_non_empty_values(String projectKey, String se

backend = newBackend().build(fakeClient);

backend.getFileService().didUpdateFileSystem(new DidUpdateFileSystemParams(Collections.emptyList(), List.of(fileDto)));
backend.getFileService().didUpdateFileSystem(new DidUpdateFileSystemParams(List.of(fileDto), Collections.emptyList(), Collections.emptyList()));

await().atMost(Duration.ofSeconds(2)).untilAsserted(() -> assertThat(fakeClient.getSuggestionsByConfigScope()).hasSize(1));
}
Expand All @@ -166,7 +166,7 @@ void should_suggest_sonarcloud_connection_when_initializing_fs(@TempDir Path tmp
backend = newBackend()
.build(fakeClient);

backend.getFileService().didUpdateFileSystem(new DidUpdateFileSystemParams(Collections.emptyList(), List.of(fileDto)));
backend.getFileService().didUpdateFileSystem(new DidUpdateFileSystemParams(List.of(fileDto), Collections.emptyList(), Collections.emptyList()));

ArgumentCaptor<Map<String, List<ConnectionSuggestionDto>>> suggestionCaptor = ArgumentCaptor.forClass(Map.class);
verify(fakeClient, timeout(5000)).suggestConnection(suggestionCaptor.capture());
Expand Down Expand Up @@ -199,7 +199,7 @@ void should_suggest_connection_when_initializing_fs_for_csharp_project(@TempDir
backend = newBackend()
.build(fakeClient);

backend.getFileService().didUpdateFileSystem(new DidUpdateFileSystemParams(Collections.emptyList(), List.of(fileDto)));
backend.getFileService().didUpdateFileSystem(new DidUpdateFileSystemParams(List.of(fileDto), Collections.emptyList(), Collections.emptyList()));

ArgumentCaptor<Map<String, List<ConnectionSuggestionDto>>> suggestionCaptor = ArgumentCaptor.forClass(Map.class);
verify(fakeClient, timeout(5000)).suggestConnection(suggestionCaptor.capture());
Expand All @@ -226,7 +226,7 @@ void should_suggest_connection_when_initializing_fs_with_scanner_file(@TempDir P
backend = newBackend()
.build(fakeClient);

backend.getFileService().didUpdateFileSystem(new DidUpdateFileSystemParams(Collections.emptyList(), List.of(fileDto)));
backend.getFileService().didUpdateFileSystem(new DidUpdateFileSystemParams(List.of(fileDto), Collections.emptyList(), Collections.emptyList()));

ArgumentCaptor<Map<String, List<ConnectionSuggestionDto>>> suggestionCaptor = ArgumentCaptor.forClass(Map.class);
verify(fakeClient, timeout(5000)).suggestConnection(suggestionCaptor.capture());
Expand All @@ -253,7 +253,7 @@ void should_suggest_sonarcloud_connection_when_initializing_fs_with_scanner_file
backend = newBackend()
.build(fakeClient);

backend.getFileService().didUpdateFileSystem(new DidUpdateFileSystemParams(Collections.emptyList(), List.of(fileDto)));
backend.getFileService().didUpdateFileSystem(new DidUpdateFileSystemParams(List.of(fileDto), Collections.emptyList(), Collections.emptyList()));

ArgumentCaptor<Map<String, List<ConnectionSuggestionDto>>> suggestionCaptor = ArgumentCaptor.forClass(Map.class);
verify(fakeClient, timeout(5000)).suggestConnection(suggestionCaptor.capture());
Expand Down Expand Up @@ -393,7 +393,7 @@ void should_suggest_sonarqube_connection_when_pascal_case(@TempDir Path tmp) thr
backend = newBackend()
.build(fakeClient);

backend.getFileService().didUpdateFileSystem(new DidUpdateFileSystemParams(Collections.emptyList(), List.of(fileDto)));
backend.getFileService().didUpdateFileSystem(new DidUpdateFileSystemParams(List.of(fileDto), Collections.emptyList(), Collections.emptyList()));

ArgumentCaptor<Map<String, List<ConnectionSuggestionDto>>> suggestionCaptor = ArgumentCaptor.forClass(Map.class);
verify(fakeClient, timeout(5000)).suggestConnection(suggestionCaptor.capture());
Expand Down Expand Up @@ -422,7 +422,7 @@ void should_suggest_sonarcloud_connection_when_pascal_case(@TempDir Path tmp) th
backend = newBackend()
.build(fakeClient);

backend.getFileService().didUpdateFileSystem(new DidUpdateFileSystemParams(Collections.emptyList(), List.of(fileDto)));
backend.getFileService().didUpdateFileSystem(new DidUpdateFileSystemParams(List.of(fileDto), Collections.emptyList(), Collections.emptyList()));

ArgumentCaptor<Map<String, List<ConnectionSuggestionDto>>> suggestionCaptor = ArgumentCaptor.forClass(Map.class);
verify(fakeClient, timeout(5000)).suggestConnection(suggestionCaptor.capture());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -391,8 +391,12 @@ void it_should_report_multi_file_issues_for_files_added_after_initialization(@Te
backend.getConfigurationService().didAddConfigurationScopes(new DidAddConfigurationScopesParams(List.of(
new ConfigurationScopeDto(CONFIG_SCOPE_ID, null, false, CONFIG_SCOPE_ID, null))));
backend.getFileService().didUpdateFileSystem(
new DidUpdateFileSystemParams(List.of(), List.of(new ClientFileDto(fileIssueUri, baseDir.relativize(fileIssue), CONFIG_SCOPE_ID, false, null, fileIssue, null, null, true),
new ClientFileDto(fileFuncDefUri, baseDir.relativize(fileFuncDef), CONFIG_SCOPE_ID, false, null, fileFuncDef, null, null, true))));
new DidUpdateFileSystemParams(
List.of(new ClientFileDto(fileIssueUri, baseDir.relativize(fileIssue), CONFIG_SCOPE_ID, false, null, fileIssue, null, null, true),
new ClientFileDto(fileFuncDefUri, baseDir.relativize(fileFuncDef), CONFIG_SCOPE_ID, false, null, fileFuncDef, null, null, true)),
List.of(),
List.of()
));

result = backend.getAnalysisService().analyzeFiles(new AnalyzeFilesParams(CONFIG_SCOPE_ID, analysisId,
List.of(fileIssueUri), Map.of(), System.currentTimeMillis())).join();
Expand Down Expand Up @@ -482,8 +486,12 @@ void it_should_update_module_file_system_on_file_events_creating_file(@TempDir P
"def foo(a):\n" +
" print(a)\n");
var fileFuncDefUri = fileFuncDef.toUri();
backend.getFileService().didUpdateFileSystem(new DidUpdateFileSystemParams(List.of(),
List.of(new ClientFileDto(fileFuncDefUri, baseDir.relativize(fileFuncDef), CONFIG_SCOPE_ID, false, null, fileFuncDef, null, null, true))));
backend.getFileService().didUpdateFileSystem(new DidUpdateFileSystemParams(
List.of(new ClientFileDto(fileFuncDefUri, baseDir.relativize(fileFuncDef), CONFIG_SCOPE_ID, false, null, fileFuncDef, null, null,
true)),
List.of(),
List.of()
));

parentConfigScopeResult = backend.getAnalysisService().analyzeFiles(new AnalyzeFilesParams(CONFIG_SCOPE_ID,
analysisId, List.of(fileIssueUri), Map.of(), System.currentTimeMillis())).join();
Expand Down Expand Up @@ -530,7 +538,7 @@ void it_should_update_module_file_system_on_file_events_deleting_file(@TempDir P
assertThat(rawIssue.getRuleKey()).isEqualTo("python:S930");

removeFile(baseDir, "fileFuncDef.py");
backend.getFileService().didUpdateFileSystem(new DidUpdateFileSystemParams(List.of(fileFuncDefUri), List.of()));
backend.getFileService().didUpdateFileSystem(new DidUpdateFileSystemParams(List.of(), List.of(), List.of(fileFuncDefUri)));

result = backend.getAnalysisService().analyzeFiles(new AnalyzeFilesParams(CONFIG_SCOPE_ID, analysisId,
List.of(fileIssueUri), Map.of(), System.currentTimeMillis())).join();
Expand Down Expand Up @@ -574,9 +582,12 @@ void it_should_update_module_file_system_on_file_events_editing_file(@TempDir Pa
assertThat(rawIssue.getRuleKey()).isEqualTo("python:S930");

editFile(baseDir, "fileFuncDef.py", "");
backend.getFileService().didUpdateFileSystem(new DidUpdateFileSystemParams(List.of(),
backend.getFileService().didUpdateFileSystem(new DidUpdateFileSystemParams(
List.of(new ClientFileDto(fileFuncDefUri, baseDir.relativize(fileFuncDef),
CONFIG_SCOPE_ID, false, null, fileFuncDef, "", null, true))));
CONFIG_SCOPE_ID, false, null, fileFuncDef, "", null, true)),
List.of(),
List.of()
));

result = backend.getAnalysisService().analyzeFiles(new AnalyzeFilesParams(CONFIG_SCOPE_ID, analysisId,
List.of(fileIssueUri), Map.of(), System.currentTimeMillis())).join();
Expand Down
Loading