Search in sources :

Example 26 with Configuration

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;
}
Also used : BranchDto(org.sonar.db.component.BranchDto) QualityGateConverter(org.sonar.server.qualitygate.QualityGateConverter) QualityGateEvaluator(org.sonar.server.qualitygate.QualityGateEvaluator) OptionalDouble(java.util.OptionalDouble) DbSession(org.sonar.db.DbSession) QualityGateFinder(org.sonar.server.qualitygate.QualityGateFinder) Condition(org.sonar.server.qualitygate.Condition) HashSet(java.util.HashSet) QualityGateConditionDto(org.sonar.db.qualitygate.QualityGateConditionDto) Map(java.util.Map) Configuration(org.sonar.api.config.Configuration) QualityGate(org.sonar.server.qualitygate.QualityGate) BranchType(org.sonar.db.component.BranchType) Collection(java.util.Collection) EvaluatedQualityGate(org.sonar.server.qualitygate.EvaluatedQualityGate) Set(java.util.Set) QualityGateDto(org.sonar.db.qualitygate.QualityGateDto) MoreCollectors.toHashSet(org.sonar.core.util.stream.MoreCollectors.toHashSet) CoreMetrics(org.sonar.api.measures.CoreMetrics) DbClient(org.sonar.db.DbClient) ComponentDto(org.sonar.db.component.ComponentDto) Stream(java.util.stream.Stream) MetricDto(org.sonar.db.metric.MetricDto) LiveMeasureDto(org.sonar.db.measure.LiveMeasureDto) ProjectDto(org.sonar.db.project.ProjectDto) MoreCollectors.uniqueIndex(org.sonar.core.util.stream.MoreCollectors.uniqueIndex) Optional(java.util.Optional) Metric(org.sonar.api.measures.Metric) MetricDto(org.sonar.db.metric.MetricDto) Optional(java.util.Optional) QualityGateEvaluator(org.sonar.server.qualitygate.QualityGateEvaluator) EvaluatedQualityGate(org.sonar.server.qualitygate.EvaluatedQualityGate)

Example 27 with Configuration

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);
}
Also used : Configuration(org.sonar.api.config.Configuration)

Example 28 with Configuration

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");
}
Also used : Configuration(org.sonar.api.config.Configuration) ComponentDto(org.sonar.db.component.ComponentDto) DefaultBranchImpl(org.sonar.ce.task.projectanalysis.component.DefaultBranchImpl) Test(org.junit.Test)

Example 29 with Configuration

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));
}
Also used : Configuration(org.sonar.api.config.Configuration) HashMap(java.util.HashMap) SnapshotDto(org.sonar.db.component.SnapshotDto) QGChangeEvent(org.sonar.server.qualitygate.changeevent.QGChangeEvent) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 30 with Configuration

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);
}
Also used : Configuration(org.sonar.api.config.Configuration) QGChangeEvent(org.sonar.server.qualitygate.changeevent.QGChangeEvent) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Aggregations

Configuration (org.sonar.api.config.Configuration)47 Test (org.junit.Test)40 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)14 ComponentDto (org.sonar.db.component.ComponentDto)12 QGChangeEvent (org.sonar.server.qualitygate.changeevent.QGChangeEvent)7 MapSettings (org.sonar.api.config.internal.MapSettings)5 SnapshotDto (org.sonar.db.component.SnapshotDto)4 PropertyDefinitions (org.sonar.api.config.PropertyDefinitions)3 Encryption (org.sonar.api.config.internal.Encryption)3 Metric (org.sonar.api.measures.Metric)3 DefaultBranchImpl (org.sonar.ce.task.projectanalysis.component.DefaultBranchImpl)3 HashSet (java.util.HashSet)2 DbClient (org.sonar.db.DbClient)2 BranchDto (org.sonar.db.component.BranchDto)2 LiveMeasureDto (org.sonar.db.measure.LiveMeasureDto)2 MetricDto (org.sonar.db.metric.MetricDto)2 ProjectDto (org.sonar.db.project.ProjectDto)2 EvaluatedQualityGate (org.sonar.server.qualitygate.EvaluatedQualityGate)2 QualityGate (org.sonar.server.qualitygate.QualityGate)2 File (java.io.File)1