Search in sources :

Example 46 with Measure

use of org.sonar.server.computation.task.projectanalysis.measure.Measure in project sonarqube by SonarSource.

the class QualityGateMeasuresStep method updateMeasures.

private void updateMeasures(Component project, Set<Condition> conditions, QualityGateDetailsDataBuilder builder) {
    Multimap<Metric, Condition> conditionsPerMetric = conditions.stream().collect(Collectors.index(Condition::getMetric, java.util.function.Function.identity()));
    for (Map.Entry<Metric, Collection<Condition>> entry : conditionsPerMetric.asMap().entrySet()) {
        Metric metric = entry.getKey();
        Optional<Measure> measure = measureRepository.getRawMeasure(project, metric);
        if (!measure.isPresent()) {
            continue;
        }
        MetricEvaluationResult metricEvaluationResult = evaluateQualityGate(measure.get(), entry.getValue());
        String text = evaluationResultTextConverter.asText(metricEvaluationResult.condition, metricEvaluationResult.evaluationResult);
        builder.addLabel(text);
        Measure updatedMeasure = Measure.updatedMeasureBuilder(measure.get()).setQualityGateStatus(new QualityGateStatus(metricEvaluationResult.evaluationResult.getLevel(), text)).create();
        measureRepository.update(project, metric, updatedMeasure);
        builder.addEvaluatedCondition(metricEvaluationResult);
    }
}
Also used : EvaluatedCondition(org.sonar.server.computation.task.projectanalysis.measure.qualitygatedetails.EvaluatedCondition) Condition(org.sonar.server.computation.task.projectanalysis.qualitygate.Condition) QualityGateStatus(org.sonar.server.computation.task.projectanalysis.measure.QualityGateStatus) Measure(org.sonar.server.computation.task.projectanalysis.measure.Measure) Collection(java.util.Collection) Metric(org.sonar.server.computation.task.projectanalysis.metric.Metric) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap)

Aggregations

Measure (org.sonar.server.computation.task.projectanalysis.measure.Measure)46 Test (org.junit.Test)35 Metric (org.sonar.server.computation.task.projectanalysis.metric.Metric)30 EvaluatedCondition (org.sonar.server.computation.task.projectanalysis.measure.qualitygatedetails.EvaluatedCondition)8 Condition (org.sonar.server.computation.task.projectanalysis.qualitygate.Condition)8 QualityGate (org.sonar.server.computation.task.projectanalysis.qualitygate.QualityGate)7 QualityGateDetailsData (org.sonar.server.computation.task.projectanalysis.measure.qualitygatedetails.QualityGateDetailsData)5 FileAttributes (org.sonar.server.computation.task.projectanalysis.component.FileAttributes)3 QualityGateStatus (org.sonar.server.computation.task.projectanalysis.measure.QualityGateStatus)3 MetricType (org.sonar.server.computation.task.projectanalysis.metric.Metric.MetricType)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 Collection (java.util.Collection)1 Map (java.util.Map)1 CustomMeasureDto (org.sonar.db.measure.custom.CustomMeasureDto)1 ReportComponent (org.sonar.server.computation.task.projectanalysis.component.ReportComponent)1 VisitorsCrawler (org.sonar.server.computation.task.projectanalysis.component.VisitorsCrawler)1 ScmInfo (org.sonar.server.computation.task.projectanalysis.scm.ScmInfo)1