use of org.sonarsource.sonarlint.core.client.api.connected.ServerConfiguration in project sonarlint-core by SonarSource.
the class NotificationTimerTask method requestForServer.
private void requestForServer(ServerConfiguration serverConfiguration, List<NotificationConfiguration> configs) {
try {
Map<String, ZonedDateTime> request = configs.stream().collect(Collectors.toMap(NotificationConfiguration::projectKey, NotificationTimerTask::getLastNotificationTime, MERGE_TIMES));
NotificationChecker notificationChecker = checkerFactory.create(serverConfiguration);
List<SonarQubeNotification> notifications = notificationChecker.request(request);
for (SonarQubeNotification n : notifications) {
Stream<NotificationConfiguration> matchingConfStream = configs.stream();
if (n.projectKey() != null) {
matchingConfStream = matchingConfStream.filter(c -> c.projectKey().equals(n.projectKey()));
}
matchingConfStream.forEach(c -> {
c.listener().handle(n);
c.lastNotificationTime().set(n.time());
});
}
} catch (Exception e) {
LOG.warn("Failed to request SonarQube events to " + serverConfiguration.getUrl(), e);
}
}
use of org.sonarsource.sonarlint.core.client.api.connected.ServerConfiguration in project sonarlint-core by SonarSource.
the class ConnectedModeTest method checkForUpdate.
@Test
public void checkForUpdate() throws Exception {
updateGlobal();
updateModule(PROJECT_KEY_JAVA);
ServerConfiguration serverConfig = getServerConfig(true);
StorageUpdateCheckResult result = engine.checkIfGlobalStorageNeedUpdate(serverConfig, null);
assertThat(result.needUpdate()).isFalse();
// restarting server should not lead to notify an update
ORCHESTRATOR.restartServer();
result = engine.checkIfGlobalStorageNeedUpdate(serverConfig, null);
assertThat(result.needUpdate()).isFalse();
// Change a global setting that is not in the whitelist
setSettings(null, "sonar.foo", "bar");
result = engine.checkIfGlobalStorageNeedUpdate(serverConfig, null);
assertThat(result.needUpdate()).isFalse();
// Change a global setting that *is* in the whitelist
setSettingsMultiValue(null, "sonar.inclusions", "**/*");
// Activate a new rule
SearchWsResponse response = newAdminWsClient(ORCHESTRATOR).qualityProfiles().search(new SearchWsRequest().setLanguage("java"));
String profileKey = response.getProfilesList().stream().filter(p -> p.getName().equals("SonarLint IT Java")).findFirst().get().getKey();
ORCHESTRATOR.getServer().adminWsClient().post("api/qualityprofiles/activate_rule", "profile_key", profileKey, "rule_key", "squid:S1228");
result = engine.checkIfGlobalStorageNeedUpdate(serverConfig, null);
assertThat(result.needUpdate()).isTrue();
assertThat(result.changelog()).containsOnly("Global settings updated", "Quality profile 'SonarLint IT Java' for language 'Java' updated");
result = engine.checkIfModuleStorageNeedUpdate(serverConfig, PROJECT_KEY_JAVA, null);
assertThat(result.needUpdate()).isFalse();
// Change a project setting that is not in the whitelist
setSettings(PROJECT_KEY_JAVA, "sonar.foo", "biz");
result = engine.checkIfModuleStorageNeedUpdate(serverConfig, PROJECT_KEY_JAVA, null);
assertThat(result.needUpdate()).isFalse();
// Change a project setting that *is* in the whitelist
setSettingsMultiValue(PROJECT_KEY_JAVA, "sonar.exclusions", "**/*.foo");
result = engine.checkIfModuleStorageNeedUpdate(serverConfig, PROJECT_KEY_JAVA, null);
assertThat(result.needUpdate()).isTrue();
assertThat(result.changelog()).containsOnly("Project settings updated");
}
use of org.sonarsource.sonarlint.core.client.api.connected.ServerConfiguration in project sonarlint-core by SonarSource.
the class ConnectedSonarLintEngineImpl method update.
@Override
public UpdateResult update(ServerConfiguration serverConfig, @Nullable ProgressMonitor monitor) {
checkNotNull(serverConfig);
setLogging(null);
return withRwLock(() -> {
stop(false);
changeState(State.UPDATING);
List<SonarAnalyzer> analyzers;
try {
analyzers = runInConnectedContainer(serverConfig, container -> container.update(new ProgressWrapper(monitor)));
} finally {
start();
}
return new UpdateResult(getHandler().getGlobalStorageStatus(), analyzers);
});
}
use of org.sonarsource.sonarlint.core.client.api.connected.ServerConfiguration in project sonarlint-core by SonarSource.
the class ConnectedSonarLintEngineImpl method checkIfModuleStorageNeedUpdate.
@Override
public StorageUpdateCheckResult checkIfModuleStorageNeedUpdate(ServerConfiguration serverConfig, String moduleKey, @Nullable ProgressMonitor monitor) {
checkNotNull(serverConfig);
checkNotNull(moduleKey);
return withReadLock(() -> runInConnectedContainer(serverConfig, container -> container.checkForUpdate(moduleKey, new ProgressWrapper(monitor))));
}
use of org.sonarsource.sonarlint.core.client.api.connected.ServerConfiguration 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);
}
Aggregations