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);
}
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);
}
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'");
}
}
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
}
}
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);
}
}
Aggregations