use of org.sonarsource.sonarlint.core.serverapi.ServerApi in project sonarlint-core by SonarSource.
the class ConnectedSonarLintEngineImpl method getActiveRuleDetails.
@Override
public CompletableFuture<ConnectedRuleDetails> getActiveRuleDetails(EndpointParams endpoint, HttpClient client, String ruleKey, @Nullable String projectKey) {
var allRulesDefinitionsByKey = analysisContext.get().allRulesDefinitionsByKey;
var ruleDefFromPlugin = allRulesDefinitionsByKey.get(ruleKey);
if (ruleDefFromPlugin != null && (globalConfig.getExtraPluginsPathsByKey().containsKey(ruleDefFromPlugin.getLanguage().getPluginKey()) || projectKey == null)) {
// if no project key, or for rules from extra plugins there will be no rules metadata in the storage
return CompletableFuture.completedFuture(new DefaultRuleDetails(ruleKey, ruleDefFromPlugin.getName(), ruleDefFromPlugin.getHtmlDescription(), ruleDefFromPlugin.getSeverity(), ruleDefFromPlugin.getType(), ruleDefFromPlugin.getLanguage(), ""));
}
if (projectKey != null) {
var analyzerConfiguration = projectStorage.getAnalyzerConfiguration(projectKey);
var storageActiveRule = analyzerConfiguration.getRuleSetByLanguageKey().values().stream().flatMap(s -> s.getRules().stream()).filter(r -> r.getRuleKey().equals(ruleKey)).findFirst();
if (storageActiveRule.isPresent()) {
var activeRuleFromStorage = storageActiveRule.get();
var serverSeverity = activeRuleFromStorage.getSeverity();
if (StringUtils.isNotBlank(activeRuleFromStorage.getTemplateKey())) {
var templateRuleDefFromPlugin = Optional.ofNullable(allRulesDefinitionsByKey.get(activeRuleFromStorage.getTemplateKey())).orElseThrow(() -> new IllegalStateException("Unable to find rule definition for rule template " + activeRuleFromStorage.getTemplateKey()));
return new ServerApi(new ServerApiHelper(endpoint, client)).rules().getRule(ruleKey).thenApply(serverRule -> new DefaultRuleDetails(ruleKey, serverRule.getName(), serverRule.getHtmlDesc(), serverSeverity, templateRuleDefFromPlugin.getType(), templateRuleDefFromPlugin.getLanguage(), serverRule.getHtmlNote()));
} else {
if (ruleDefFromPlugin == null) {
throw new IllegalStateException("Unable to find rule definition for rule " + ruleKey);
}
return new ServerApi(new ServerApiHelper(endpoint, client)).rules().getRule(ruleKey).thenApply(serverRule -> new DefaultRuleDetails(ruleKey, ruleDefFromPlugin.getName(), ruleDefFromPlugin.getHtmlDescription(), serverSeverity != null ? serverSeverity : ruleDefFromPlugin.getSeverity(), ruleDefFromPlugin.getType(), ruleDefFromPlugin.getLanguage(), serverRule.getHtmlNote()));
}
}
}
throw new IllegalStateException("Unable to find rule details for '" + ruleKey + "'");
}
use of org.sonarsource.sonarlint.core.serverapi.ServerApi in project sonarlint-core by SonarSource.
the class ConnectionValidator method validateConnection.
public CompletableFuture<ValidationResult> validateConnection() {
var serverChecker = new ServerVersionAndStatusChecker(helper);
var authChecker = new AuthenticationChecker(helper);
return serverChecker.checkVersionAndStatusAsync().thenApply(check -> {
var validateCredentials = authChecker.validateCredentials();
var organizationKey = helper.getOrganizationKey();
if (validateCredentials.success() && organizationKey.isPresent()) {
var organization = new ServerApi(helper).organization().fetchOrganization(organizationKey.get(), new ProgressMonitor(null));
if (organization.isEmpty()) {
return new DefaultValidationResult(false, "No organizations found for key: " + organizationKey.get());
}
}
return validateCredentials;
}).exceptionally(e -> new DefaultValidationResult(false, e.getCause().getMessage()));
}
use of org.sonarsource.sonarlint.core.serverapi.ServerApi in project sonarlint-core by SonarSource.
the class LocalStorageSynchronizerTests method should_not_synchronize_when_server_is_down.
@Test
void should_not_synchronize_when_server_is_down(@TempDir Path tmpDir) {
mockServer.addStringResponse("/api/system/status", "{\"id\": \"1\", \"status\": \"DOWN\", \"version\": \"1\"}");
var synchronizer = new LocalStorageSynchronizer(Set.of(Language.JS), emptySet(), new PluginsStorage(tmpDir), new ProjectStorage(tmpDir));
synchronizer.synchronize(new ServerApi(mockServer.serverApiHelper()), Set.of("projectKey"), progressMonitor);
var storageFile = tmpDir.resolve("70726f6a6563744b6579/analyzer_config.pb");
assertThat(storageFile).doesNotExist();
}
use of org.sonarsource.sonarlint.core.serverapi.ServerApi in project sonarlint-core by SonarSource.
the class ConnectedModeTest method getProject.
@Test
public void getProject() {
var api = new ServerApi(endpointParams(ORCHESTRATOR), sqHttpClient()).component();
assertThat(api.getProject("foo")).isNotPresent();
assertThat(api.getProject(PROJECT_KEY_RUBY)).isPresent();
}
use of org.sonarsource.sonarlint.core.serverapi.ServerApi in project sonarlint-core by SonarSource.
the class PluginsSynchronizerTests method should_not_synchronize_an_up_to_date_plugin.
@Test
void should_not_synchronize_an_up_to_date_plugin(@TempDir Path tmp) throws Exception {
var dest = tmp.resolve("destDir");
Files.createDirectory(dest);
mockServer.addStringResponse("/api/plugins/installed", "{\"plugins\": [" + "{\"key\": \"java\", \"hash\": \"de5308f43260d357acc97712ce4c5475\", \"filename\": \"sonar-java-plugin-5.13.1.18282.jar\", \"sonarLintSupported\": true}" + "]}");
mockServer.addStringResponse("/api/plugins/download?plugin=java", "content-java");
underTest = new PluginsSynchronizer(Set.of(Language.JAVA), new PluginsStorage(dest), emptySet());
underTest.synchronize(new ServerApi(mockServer.serverApiHelper()), new ProgressMonitor(null));
mockServer.removeResponse("/api/plugins/download?plugin=java");
var anyPluginUpdated = underTest.synchronize(new ServerApi(mockServer.serverApiHelper()), new ProgressMonitor(null));
assertThat(anyPluginUpdated).isFalse();
}
Aggregations