From e458dcd5d925f078976b3a106c50e700f252e409 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Lievremont Date: Mon, 5 Aug 2024 10:08:17 +0200 Subject: [PATCH] NO JIRA Remove dead code --- .../sonarlint/ls/SonarLintLanguageServer.java | 2 +- .../ls/connected/ProjectBindingManager.java | 9 ++--- .../connected/ProjectBindingManagerTests.java | 38 ++++--------------- 3 files changed, 12 insertions(+), 37 deletions(-) diff --git a/src/main/java/org/sonarsource/sonarlint/ls/SonarLintLanguageServer.java b/src/main/java/org/sonarsource/sonarlint/ls/SonarLintLanguageServer.java index f36ba5fca..21564f846 100644 --- a/src/main/java/org/sonarsource/sonarlint/ls/SonarLintLanguageServer.java +++ b/src/main/java/org/sonarsource/sonarlint/ls/SonarLintLanguageServer.java @@ -244,7 +244,7 @@ public class SonarLintLanguageServer implements SonarLintExtendedLanguageServer, javaConfigCache = new JavaConfigCache(client, openFilesCache, lsLogOutput); this.settingsManager.addListener(lsLogOutput); this.bindingManager = new ProjectBindingManager(workspaceFoldersManager, settingsManager, - client, lsLogOutput, backendServiceFacade, openNotebooksCache, openFilesCache); + client, lsLogOutput, backendServiceFacade, openNotebooksCache); vsCodeClient.setBindingManager(bindingManager); this.telemetry = new SonarLintTelemetry(backendServiceFacade, lsLogOutput); this.backendServiceFacade.setTelemetry(telemetry); diff --git a/src/main/java/org/sonarsource/sonarlint/ls/connected/ProjectBindingManager.java b/src/main/java/org/sonarsource/sonarlint/ls/connected/ProjectBindingManager.java index 2bfbd0707..41af1e88b 100644 --- a/src/main/java/org/sonarsource/sonarlint/ls/connected/ProjectBindingManager.java +++ b/src/main/java/org/sonarsource/sonarlint/ls/connected/ProjectBindingManager.java @@ -54,7 +54,6 @@ import org.sonarsource.sonarlint.ls.SonarLintExtendedLanguageClient.ConnectionCheckResult; import org.sonarsource.sonarlint.ls.SonarLintExtendedLanguageServer; import org.sonarsource.sonarlint.ls.backend.BackendServiceFacade; -import org.sonarsource.sonarlint.ls.file.OpenFilesCache; import org.sonarsource.sonarlint.ls.folders.WorkspaceFolderWrapper; import org.sonarsource.sonarlint.ls.folders.WorkspaceFoldersManager; import org.sonarsource.sonarlint.ls.log.LanguageClientLogger; @@ -89,17 +88,16 @@ public class ProjectBindingManager implements WorkspaceSettingsChangeListener, W private AnalysisScheduler analysisManager; private final BackendServiceFacade backendServiceFacade; private final OpenNotebooksCache openNotebooksCache; - private final OpenFilesCache openFilesCache; public ProjectBindingManager(WorkspaceFoldersManager foldersManager, SettingsManager settingsManager, SonarLintExtendedLanguageClient client, - LanguageClientLogger globalLogOutput, BackendServiceFacade backendServiceFacade, OpenNotebooksCache openNotebooksCache, OpenFilesCache openFilesCache) { + LanguageClientLogger globalLogOutput, BackendServiceFacade backendServiceFacade, OpenNotebooksCache openNotebooksCache) { this(foldersManager, settingsManager, client, new ConcurrentHashMap<>(), globalLogOutput, - backendServiceFacade, openNotebooksCache, openFilesCache); + backendServiceFacade, openNotebooksCache); } public ProjectBindingManager(WorkspaceFoldersManager foldersManager, SettingsManager settingsManager, SonarLintExtendedLanguageClient client, ConcurrentMap> folderBindingCache, LanguageClientLogger globalLogOutput, BackendServiceFacade backendServiceFacade, - OpenNotebooksCache openNotebooksCache, OpenFilesCache openFilesCache) { + OpenNotebooksCache openNotebooksCache) { this.foldersManager = foldersManager; this.settingsManager = settingsManager; this.client = client; @@ -107,7 +105,6 @@ public ProjectBindingManager(WorkspaceFoldersManager foldersManager, SettingsMan this.globalLogOutput = globalLogOutput; this.backendServiceFacade = backendServiceFacade; this.openNotebooksCache = openNotebooksCache; - this.openFilesCache = openFilesCache; } // Can't use constructor injection because of cyclic dependency diff --git a/src/test/java/org/sonarsource/sonarlint/ls/connected/ProjectBindingManagerTests.java b/src/test/java/org/sonarsource/sonarlint/ls/connected/ProjectBindingManagerTests.java index 4e484f36a..701b67cd9 100644 --- a/src/test/java/org/sonarsource/sonarlint/ls/connected/ProjectBindingManagerTests.java +++ b/src/test/java/org/sonarsource/sonarlint/ls/connected/ProjectBindingManagerTests.java @@ -39,7 +39,6 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; import org.junit.jupiter.api.io.TempDir; -import org.sonarsource.sonarlint.core.client.legacy.analysis.SonarLintAnalysisEngine; import org.sonarsource.sonarlint.core.rpc.protocol.backend.connection.projects.GetAllProjectsResponse; import org.sonarsource.sonarlint.core.rpc.protocol.backend.connection.projects.GetProjectNamesByKeyResponse; import org.sonarsource.sonarlint.core.rpc.protocol.backend.connection.projects.SonarProjectDto; @@ -49,7 +48,6 @@ import org.sonarsource.sonarlint.ls.SonarLintExtendedLanguageClient; import org.sonarsource.sonarlint.ls.backend.BackendService; import org.sonarsource.sonarlint.ls.backend.BackendServiceFacade; -import org.sonarsource.sonarlint.ls.file.OpenFilesCache; import org.sonarsource.sonarlint.ls.folders.WorkspaceFolderWrapper; import org.sonarsource.sonarlint.ls.folders.WorkspaceFoldersManager; import org.sonarsource.sonarlint.ls.notebooks.OpenNotebooksCache; @@ -65,7 +63,6 @@ import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.never; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; @@ -77,51 +74,40 @@ class ProjectBindingManagerTests { private static final String FILE_PHP = "fileInAWorkspaceFolderPath.php"; private static final String PROJECT_KEY = "myProject"; private static final String PROJECT_KEY2 = "myProject2"; - private static final org.sonarsource.sonarlint.core.serverconnection.ProjectBinding FAKE_BINDING = new org.sonarsource.sonarlint.core.serverconnection.ProjectBinding(PROJECT_KEY, "sqPrefix", "idePrefix"); - private static final org.sonarsource.sonarlint.core.serverconnection.ProjectBinding FAKE_BINDING2 = new org.sonarsource.sonarlint.core.serverconnection.ProjectBinding(PROJECT_KEY2, "sqPrefix2", "idePrefix2"); private static final String CONNECTION_ID = "myServer"; - private static final String SERVER_ID2 = "myServer2"; private static final BackendServiceFacade backendServiceFacade = mock(BackendServiceFacade.class); private static final ServerConnectionSettings GLOBAL_SETTINGS = new ServerConnectionSettings(CONNECTION_ID, "http://foo", "token", null, true); - private static final ServerConnectionSettings GLOBAL_SETTINGS_DIFFERENT_SERVER_ID = new ServerConnectionSettings(SERVER_ID2, "http://foo2", "token2", null, true); private static final WorkspaceFolderSettings UNBOUND_SETTINGS = new WorkspaceFolderSettings(null, null, Collections.emptyMap(), null, null); private static final WorkspaceFolderSettings BOUND_SETTINGS = new WorkspaceFolderSettings(CONNECTION_ID, PROJECT_KEY, Collections.emptyMap(), null, null); - private static final WorkspaceFolderSettings BOUND_SETTINGS2 = new WorkspaceFolderSettings(SERVER_ID2, PROJECT_KEY2, Collections.emptyMap(), null, null); private static final WorkspaceFolderSettings BOUND_SETTINGS_DIFFERENT_PROJECT_KEY = new WorkspaceFolderSettings(CONNECTION_ID, PROJECT_KEY2, Collections.emptyMap(), null, null); - private static final WorkspaceFolderSettings BOUND_SETTINGS_DIFFERENT_SERVER_ID = new WorkspaceFolderSettings(SERVER_ID2, PROJECT_KEY, Collections.emptyMap(), null, null); - private static final String BRANCH_NAME = "main"; @RegisterExtension SonarLintLogTester logTester = new SonarLintLogTester(); @TempDir Path basedir; private Path workspaceFolderPath; - private Path workspaceFolderPath2; private Path anotherFolderPath; private Path fileInAWorkspaceFolderPath; - private Path fileInAWorkspaceFolderPath2; private Path fileNotInAWorkspaceFolderPath; ConcurrentMap> folderBindingCache; private ProjectBindingManager underTest; private final SettingsManager settingsManager = mock(SettingsManager.class); private final WorkspaceFoldersManager foldersManager = mock(WorkspaceFoldersManager.class); private final Map servers = new HashMap<>(); - private final SonarLintAnalysisEngine fakeEngine = mock(SonarLintAnalysisEngine.class); private final AnalysisScheduler analysisManager = mock(AnalysisScheduler.class); SonarLintExtendedLanguageClient client = mock(SonarLintExtendedLanguageClient.class); private final OpenNotebooksCache openNotebooksCache = mock(OpenNotebooksCache.class); - private final OpenFilesCache openFilesCache = mock(OpenFilesCache.class); @BeforeEach public void prepare() throws IOException { workspaceFolderPath = basedir.resolve("myWorkspaceFolder"); Files.createDirectories(workspaceFolderPath); - workspaceFolderPath2 = basedir.resolve("myWorkspaceFolder2"); + var workspaceFolderPath2 = basedir.resolve("myWorkspaceFolder2"); Files.createDirectories(workspaceFolderPath2); anotherFolderPath = basedir.resolve("anotherFolder"); Files.createDirectories(anotherFolderPath); fileInAWorkspaceFolderPath = workspaceFolderPath.resolve(FILE_PHP); Files.createFile(fileInAWorkspaceFolderPath); - fileInAWorkspaceFolderPath2 = workspaceFolderPath2.resolve(FILE_PHP); + var fileInAWorkspaceFolderPath2 = workspaceFolderPath2.resolve(FILE_PHP); Files.createFile(fileInAWorkspaceFolderPath2); fileNotInAWorkspaceFolderPath = anotherFolderPath.resolve(FILE_PHP); Files.createFile(fileNotInAWorkspaceFolderPath); @@ -139,7 +125,7 @@ public void prepare() throws IOException { when(openNotebooksCache.getFile(any(URI.class))).thenReturn(Optional.empty()); underTest = new ProjectBindingManager(foldersManager, settingsManager, client, folderBindingCache, logTester.getLogger(), - backendServiceFacade, openNotebooksCache, openFilesCache); + backendServiceFacade, openNotebooksCache); underTest.setAnalysisManager(analysisManager); } @@ -231,7 +217,7 @@ void test_use_sonarcloud() { @Test void ignore_first_change_event() { underTest.onChange(null, null, UNBOUND_SETTINGS); - verifyNoInteractions(settingsManager, fakeEngine); + verifyNoInteractions(settingsManager); assertThat(logTester.logs()).isEmpty(); } @@ -239,7 +225,7 @@ void ignore_first_change_event() { void ignore_change_if_same_binding() { underTest.onChange(null, UNBOUND_SETTINGS, UNBOUND_SETTINGS); underTest.onChange(null, BOUND_SETTINGS, BOUND_SETTINGS); - verifyNoInteractions(settingsManager, fakeEngine); + verifyNoInteractions(settingsManager); assertThat(logTester.logs()).isEmpty(); } @@ -249,7 +235,7 @@ void ignore_change_if_folder_binding_not_cached() { when(folder.getSettings()).thenReturn(UNBOUND_SETTINGS); underTest.onChange(folder, BOUND_SETTINGS, UNBOUND_SETTINGS); - verifyNoInteractions(settingsManager, fakeEngine); + verifyNoInteractions(settingsManager); assertThat(logTester.logs()).isEmpty(); } @@ -258,7 +244,7 @@ void ignore_change_if_file_binding_not_cached() { mockFileOutsideFolder(); underTest.onChange(null, BOUND_SETTINGS, UNBOUND_SETTINGS); - verifyNoInteractions(settingsManager, fakeEngine); + verifyNoInteractions(settingsManager); assertThat(logTester.logs()).isEmpty(); } @@ -317,7 +303,6 @@ void test_rebind_folder_after_project_key_change() { binding = underTest.getBinding(fileInAWorkspaceFolderPath.toUri()); assertThat(binding).isNotEmpty(); - verify(fakeEngine, never()).stop(); assertThat(logTester.logs()) .anyMatch(log -> log.contains("Resolved binding myProject2 for folder " + workspaceFolderPath.toString())); } @@ -340,7 +325,6 @@ void test_rebind_file_after_project_key_change() { binding = underTest.getBinding(fileNotInAWorkspaceFolderPath.toUri()); assertThat(binding).isNotEmpty(); - verify(fakeEngine, never()).stop(); assertThat(logTester.logs()) .anyMatch(log -> log.contains("Resolved binding myProject2 for folder " + anotherFolderPath.toString())); } @@ -462,7 +446,7 @@ void shouldComputeFullFilePathFromRelative() { } @Test - void should_get_binding_if_existis_empty() { + void should_get_binding_if_exist_is_empty() { var uri = URI.create("file:///folderUri"); var maybeBinding = underTest.getBindingIfExists(uri); @@ -500,10 +484,4 @@ private WorkspaceFolderWrapper mockFileInAFolder() { when(foldersManager.findFolderForFile(fileInAWorkspaceFolderPath.toUri())).thenReturn(Optional.of(folderWrapper)); return folderWrapper; } - - private WorkspaceFolderWrapper mockFileInAFolder2() { - var folderWrapper2 = spy(new WorkspaceFolderWrapper(workspaceFolderPath2.toUri(), new WorkspaceFolder(workspaceFolderPath2.toUri().toString()), logTester.getLogger())); - when(foldersManager.findFolderForFile(fileInAWorkspaceFolderPath2.toUri())).thenReturn(Optional.of(folderWrapper2)); - return folderWrapper2; - } }