use of org.sonar.api.config.Configuration in project sonarqube by SonarSource.
the class LiveQualityGateComputerImpl method refreshGateStatus.
@Override
public EvaluatedQualityGate refreshGateStatus(ComponentDto project, QualityGate gate, MeasureMatrix measureMatrix, Configuration configuration) {
QualityGateEvaluator.Measures measures = metricKey -> {
Optional<LiveMeasureDto> liveMeasureDto = measureMatrix.getMeasure(project, metricKey);
if (!liveMeasureDto.isPresent()) {
return Optional.empty();
}
MetricDto metric = measureMatrix.getMetricByUuid(liveMeasureDto.get().getMetricUuid());
return Optional.of(new LiveMeasure(liveMeasureDto.get(), metric));
};
EvaluatedQualityGate evaluatedGate = evaluator.evaluate(gate, measures, configuration);
measureMatrix.setValue(project, CoreMetrics.ALERT_STATUS_KEY, evaluatedGate.getStatus().name());
measureMatrix.setValue(project, CoreMetrics.QUALITY_GATE_DETAILS_KEY, QualityGateConverter.toJson(evaluatedGate));
return evaluatedGate;
}
use of org.sonar.api.config.Configuration in project sonarqube by SonarSource.
the class NewIndex method applySettingsConfiguration.
private void applySettingsConfiguration(SettingsConfiguration settingsConfiguration) {
settings.put("index.refresh_interval", refreshInterval(settingsConfiguration));
Configuration config = settingsConfiguration.getConfiguration();
boolean clusterMode = config.getBoolean(CLUSTER_ENABLED.getKey()).orElse(false);
int shards = config.getInt(String.format("sonar.search.%s.shards", index.getName())).orElse(settingsConfiguration.getDefaultNbOfShards());
int replicas = clusterMode ? config.getInt(SEARCH_REPLICAS.getKey()).orElse(1) : 0;
settings.put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, shards);
settings.put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, replicas);
settings.put("index.max_ngram_diff", DefaultIndexSettings.MAXIMUM_NGRAM_LENGTH - DefaultIndexSettings.MINIMUM_NGRAM_LENGTH);
}
use of org.sonar.api.config.Configuration in project sonarqube by SonarSource.
the class ProjectConfigurationFactoryTest method project_settings_override_global_settings.
@Test
public void project_settings_override_global_settings() {
settings.setProperty("key", "value");
ComponentDto project = db.components().insertPrivateProject();
db.properties().insertProperties(null, project.getKey(), project.name(), project.qualifier(), newComponentPropertyDto(project).setKey("key").setValue("value2"));
Configuration projectConfig = underTest.newProjectConfiguration(project.getDbKey(), new DefaultBranchImpl());
assertThat(projectConfig.get("key")).hasValue("value2");
}
use of org.sonar.api.config.Configuration in project sonarqube by SonarSource.
the class WebhookQGChangeEventListenerTest method onIssueChanges_calls_webhook_for_changeEvent_with_webhook_enabled.
@Test
@UseDataProvider("newQGorNot")
public void onIssueChanges_calls_webhook_for_changeEvent_with_webhook_enabled(@Nullable EvaluatedQualityGate newQualityGate) {
ProjectAndBranch projectBranch = insertBranch(BRANCH, "foo");
SnapshotDto analysis = insertAnalysisTask(projectBranch);
Configuration configuration = mock(Configuration.class);
mockPayloadSupplierConsumedByWebhooks();
Map<String, String> properties = new HashMap<>();
properties.put("sonar.analysis.test1", randomAlphanumeric(50));
properties.put("sonar.analysis.test2", randomAlphanumeric(5000));
insertPropertiesFor(analysis.getUuid(), properties);
QGChangeEvent qualityGateEvent = newQGChangeEvent(projectBranch, analysis, configuration, newQualityGate);
mockWebhookEnabled(qualityGateEvent.getProject());
underTest.onIssueChanges(qualityGateEvent, CHANGED_ISSUES_ARE_IGNORED);
ProjectAnalysis projectAnalysis = verifyWebhookCalledAndExtractPayloadFactoryArgument(projectBranch, analysis, qualityGateEvent.getProject());
assertThat(projectAnalysis).isEqualTo(new ProjectAnalysis(new Project(projectBranch.project.getUuid(), projectBranch.project.getKey(), projectBranch.project.getName()), null, new Analysis(analysis.getUuid(), analysis.getCreatedAt(), analysis.getRevision()), new Branch(false, "foo", Branch.Type.BRANCH), newQualityGate, null, properties));
}
use of org.sonar.api.config.Configuration in project sonarqube by SonarSource.
the class WebhookQGChangeEventListenerTest method onIssueChanges_has_no_effect_if_no_webhook_is_configured.
@Test
@UseDataProvider("allCombinationsOfStatuses")
public void onIssueChanges_has_no_effect_if_no_webhook_is_configured(Metric.Level previousStatus, Metric.Level newStatus) {
Configuration configuration1 = mock(Configuration.class);
when(newQualityGate.getStatus()).thenReturn(newStatus);
QGChangeEvent qualityGateEvent = newQGChangeEvent(configuration1, previousStatus, newQualityGate);
mockWebhookDisabled(qualityGateEvent.getProject());
mockedUnderTest.onIssueChanges(qualityGateEvent, CHANGED_ISSUES_ARE_IGNORED);
verify(webHooks).isEnabled(qualityGateEvent.getProject());
verifyZeroInteractions(webhookPayloadFactory, mockedDbClient);
}
Aggregations