Search in sources :

Example 1 with ConnectedSonarLintEngine

use of org.sonarsource.sonarlint.core.client.api.connected.ConnectedSonarLintEngine in project sonarlint-core by SonarSource.

the class ServerIssueTrackerTest method should_get_issues_from_engine_without_downloading.

@Test
public void should_get_issues_from_engine_without_downloading() {
    String moduleKey = "dummy module";
    String filePath = "dummy file";
    ConnectedSonarLintEngine engine = mock(ConnectedSonarLintEngine.class);
    ServerIssueTracker tracker = new ServerIssueTracker(mock(Logger.class), mock(Console.class), mock(CachingIssueTracker.class));
    tracker.update(engine, moduleKey, Collections.singleton(filePath));
    verify(engine).getServerIssues(moduleKey, filePath);
    verifyNoMoreInteractions(engine);
}
Also used : ConnectedSonarLintEngine(org.sonarsource.sonarlint.core.client.api.connected.ConnectedSonarLintEngine) Test(org.junit.Test)

Example 2 with ConnectedSonarLintEngine

use of org.sonarsource.sonarlint.core.client.api.connected.ConnectedSonarLintEngine in project sonarlint-core by SonarSource.

the class ServerIssueTrackerTest method should_get_issues_from_engine_if_download_failed.

@Test
public void should_get_issues_from_engine_if_download_failed() {
    String moduleKey = "dummy module";
    String filePath = "dummy file";
    ConnectedSonarLintEngine engine = mock(ConnectedSonarLintEngine.class);
    ServerConfiguration serverConfiguration = mock(ServerConfiguration.class);
    ServerIssueTracker tracker = new ServerIssueTracker(mock(Logger.class), mock(Console.class), mock(CachingIssueTracker.class));
    when(engine.downloadServerIssues(serverConfiguration, moduleKey, filePath)).thenThrow(new DownloadException());
    tracker.update(serverConfiguration, engine, moduleKey, Collections.singleton(filePath));
    verify(engine).downloadServerIssues(serverConfiguration, moduleKey, filePath);
    verify(engine).getServerIssues(moduleKey, filePath);
    verifyNoMoreInteractions(engine);
}
Also used : ServerConfiguration(org.sonarsource.sonarlint.core.client.api.connected.ServerConfiguration) DownloadException(org.sonarsource.sonarlint.core.client.api.exceptions.DownloadException) ConnectedSonarLintEngine(org.sonarsource.sonarlint.core.client.api.connected.ConnectedSonarLintEngine) Test(org.junit.Test)

Example 3 with ConnectedSonarLintEngine

use of org.sonarsource.sonarlint.core.client.api.connected.ConnectedSonarLintEngine in project sonarlint-core by SonarSource.

the class ConnectedStaleStorageMediumTest method test_stale_global.

@Test
public void test_stale_global() throws Exception {
    writeUpdateStatus(storage, "0");
    ConnectedSonarLintEngine sonarlint = new ConnectedSonarLintEngineImpl(config);
    assertThat(sonarlint.getState()).isEqualTo(State.NEED_UPDATE);
    assertThat(sonarlint.getGlobalStorageStatus()).isNotNull();
    assertThat(sonarlint.getModuleStorageStatus("foo")).isNull();
    try {
        sonarlint.allModulesByKey();
        fail("Expected exception");
    } catch (Exception e) {
        assertThat(e).isInstanceOf(GlobalUpdateRequiredException.class).hasMessage("Please update server 'localhost'");
    }
    try {
        sonarlint.getRuleDetails("rule");
        fail("Expected exception");
    } catch (Exception e) {
        assertThat(e).isInstanceOf(GlobalUpdateRequiredException.class).hasMessage("Please update server 'localhost'");
    }
    try {
        sonarlint.analyze(new ConnectedAnalysisConfiguration(null, baseDir.toPath(), temp.newFolder().toPath(), Collections.<ClientInputFile>emptyList(), ImmutableMap.<String, String>of()), mock(IssueListener.class), null, null);
        fail("Expected exception");
    } catch (Exception e) {
        assertThat(e).isInstanceOf(GlobalUpdateRequiredException.class).hasMessage("Please update server 'localhost'");
    }
}
Also used : IssueListener(org.sonarsource.sonarlint.core.client.api.common.analysis.IssueListener) ConnectedSonarLintEngineImpl(org.sonarsource.sonarlint.core.ConnectedSonarLintEngineImpl) ConnectedAnalysisConfiguration(org.sonarsource.sonarlint.core.client.api.connected.ConnectedAnalysisConfiguration) ClientInputFile(org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile) ConnectedSonarLintEngine(org.sonarsource.sonarlint.core.client.api.connected.ConnectedSonarLintEngine) GlobalUpdateRequiredException(org.sonarsource.sonarlint.core.client.api.exceptions.GlobalUpdateRequiredException) IOException(java.io.IOException) Test(org.junit.Test)

Example 4 with ConnectedSonarLintEngine

use of org.sonarsource.sonarlint.core.client.api.connected.ConnectedSonarLintEngine in project sonarlint-intellij by SonarSource.

the class ServerIssueUpdater method fetchAndMatchServerIssues.

public void fetchAndMatchServerIssues(Collection<VirtualFile> virtualFiles, ProgressIndicator indicator, boolean waitForCompletion) {
    if (!projectSettings.isBindingEnabled()) {
        // not in connected mode
        return;
    }
    try {
        SonarQubeServer server = projectBindingManager.getSonarQubeServer();
        ConnectedSonarLintEngine engine = projectBindingManager.getConnectedEngine();
        String moduleKey = projectSettings.getProjectKey();
        boolean downloadAll = virtualFiles.size() >= FETCH_ALL_ISSUES_THRESHOLD;
        String msg;
        if (downloadAll) {
            msg = "Fetching all server issues";
        } else {
            msg = "Fetching server issues";
        }
        if (waitForCompletion) {
            msg += " (waiting for results)";
        }
        console.debug(msg);
        indicator.setText(msg);
        // submit tasks
        List<Future<Void>> updateTasks = fetchAndMatchServerIssues(virtualFiles, server, engine, moduleKey, downloadAll);
        if (waitForCompletion) {
            waitForTasks(updateTasks);
        }
    } catch (InvalidBindingException e) {
    // ignore, do nothing
    }
}
Also used : InvalidBindingException(org.sonarlint.intellij.exception.InvalidBindingException) SonarQubeServer(org.sonarlint.intellij.config.global.SonarQubeServer) CompletableFuture(java.util.concurrent.CompletableFuture) Future(java.util.concurrent.Future) ConnectedSonarLintEngine(org.sonarsource.sonarlint.core.client.api.connected.ConnectedSonarLintEngine)

Example 5 with ConnectedSonarLintEngine

use of org.sonarsource.sonarlint.core.client.api.connected.ConnectedSonarLintEngine in project sonarlint-intellij by SonarSource.

the class SonarLintEngineManager method checkConnectedEngineStatus.

private static void checkConnectedEngineStatus(ConnectedSonarLintEngine engine, SonarLintProjectNotifications notifications, String serverId, String projectKey) throws InvalidBindingException {
    // Check if engine's global storage is OK
    ConnectedSonarLintEngine.State state = engine.getState();
    if (state != ConnectedSonarLintEngine.State.UPDATED) {
        if (state != ConnectedSonarLintEngine.State.NEED_UPDATE) {
            notifications.notifyServerNotUpdated();
        } else if (state != ConnectedSonarLintEngine.State.NEVER_UPDATED) {
            notifications.notifyServerStorageNeedsUpdate(serverId);
        }
        throw new InvalidBindingException("Server is not updated: " + serverId);
    }
    // Check if module's storage is OK. Global storage was updated and all project's binding that were open too,
    // but we might have now opened a new project with a different binding.
    ModuleStorageStatus moduleStorageStatus = engine.getModuleStorageStatus(projectKey);
    if (moduleStorageStatus == null) {
        notifications.notifyModuleInvalid();
        throw new InvalidBindingException("Project is bound to a module that doesn't exist: " + projectKey);
    } else if (moduleStorageStatus.isStale()) {
        notifications.notifyModuleStale();
        throw new InvalidBindingException("Stale module's storage: " + projectKey);
    }
}
Also used : InvalidBindingException(org.sonarlint.intellij.exception.InvalidBindingException) ConnectedSonarLintEngine(org.sonarsource.sonarlint.core.client.api.connected.ConnectedSonarLintEngine) ModuleStorageStatus(org.sonarsource.sonarlint.core.client.api.connected.ModuleStorageStatus)

Aggregations

ConnectedSonarLintEngine (org.sonarsource.sonarlint.core.client.api.connected.ConnectedSonarLintEngine)16 Test (org.junit.Test)7 InvalidBindingException (org.sonarlint.intellij.exception.InvalidBindingException)6 SonarQubeServer (org.sonarlint.intellij.config.global.SonarQubeServer)5 ServerConfiguration (org.sonarsource.sonarlint.core.client.api.connected.ServerConfiguration)5 IOException (java.io.IOException)3 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)2 Project (com.intellij.openapi.project.Project)2 FileUtil (com.intellij.openapi.util.io.FileUtil)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 Path (java.nio.file.Path)2 Collections (java.util.Collections)2 LinkedList (java.util.LinkedList)2 List (java.util.List)2 Before (org.junit.Before)2 Rule (org.junit.Rule)2 TemporaryFolder (org.junit.rules.TemporaryFolder)2 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 ArgumentMatchers.argThat (org.mockito.ArgumentMatchers.argThat)2