use of org.sonar.ce.task.projectanalysis.measure.Measure in project sonarqube by SonarSource.
the class ConditionEvaluatorTest method fail_when_metric_is_not_supported.
@Test
@UseDataProvider("unsupportedMetricTypes")
public void fail_when_metric_is_not_supported(MetricType metricType) {
Metric metric = createMetric(metricType);
Measure measure = newMeasureBuilder().create("3.14159265358");
assertThatThrownBy(() -> underTest.evaluate(createCondition(metric, LESS_THAN, "1.60217657"), measure)).isInstanceOf(IllegalArgumentException.class).hasMessage(String.format("Conditions on MetricType %s are not supported", metricType));
}
use of org.sonar.ce.task.projectanalysis.measure.Measure in project sonarqube by SonarSource.
the class ConditionEvaluatorTest method test_condition_on_numeric_new_metric.
@Test
@UseDataProvider("numericNewMetricTypes")
public void test_condition_on_numeric_new_metric(MetricType metricType) {
Metric metric = createNewMetric(metricType);
Measure measure = newMeasureBuilder().setVariation(3d).createNoValue();
assertThat(underTest.evaluate(new Condition(metric, GREATER_THAN.getDbValue(), "3"), measure)).hasLevel(OK);
assertThat(underTest.evaluate(new Condition(metric, GREATER_THAN.getDbValue(), "2"), measure)).hasLevel(ERROR);
}
use of org.sonar.ce.task.projectanalysis.measure.Measure in project sonarqube by SonarSource.
the class ConditionEvaluatorTest method test_condition_on_rating.
@Test
public void test_condition_on_rating() {
Metric metric = createMetric(RATING);
Measure measure = newMeasureBuilder().create(4, "D");
assertThat(underTest.evaluate(new Condition(metric, GREATER_THAN.getDbValue(), "4"), measure)).hasLevel(OK).hasValue(4);
assertThat(underTest.evaluate(new Condition(metric, GREATER_THAN.getDbValue(), "2"), measure)).hasLevel(ERROR).hasValue(4);
}
use of org.sonar.ce.task.projectanalysis.measure.Measure in project sonarqube by SonarSource.
the class QualityGateEventsStep method checkQualityGateStatusChange.
private void checkQualityGateStatusChange(Component project, Metric metric, QualityGateStatus rawStatus) {
Optional<Measure> baseMeasure = measureRepository.getBaseMeasure(project, metric);
if (!baseMeasure.isPresent()) {
checkNewQualityGate(project, rawStatus);
return;
}
if (!baseMeasure.get().hasQualityGateStatus()) {
LOGGER.warn(String.format("Previous Quality gate status for project %s is not a supported value. Can not compute Quality Gate event", project.getDbKey()));
checkNewQualityGate(project, rawStatus);
return;
}
QualityGateStatus baseStatus = baseMeasure.get().getQualityGateStatus();
if (baseStatus.getStatus() != rawStatus.getStatus()) {
// The QualityGate status has changed
createEvent(project, rawStatus.getStatus().getLabel(), rawStatus.getText());
boolean isNewKo = rawStatus.getStatus() == Measure.Level.OK;
notifyUsers(project, rawStatus, isNewKo);
}
}
use of org.sonar.ce.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(MoreCollectors.index(Condition::getMetric, java.util.function.Function.identity()));
boolean ignoredConditions = false;
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;
}
final MetricEvaluationResult metricEvaluationResult = evaluateQualityGate(measure.get(), entry.getValue());
final MetricEvaluationResult finalMetricEvaluationResult;
if (smallChangesetQualityGateSpecialCase.appliesTo(project, metricEvaluationResult)) {
finalMetricEvaluationResult = smallChangesetQualityGateSpecialCase.apply(metricEvaluationResult);
ignoredConditions = true;
} else {
finalMetricEvaluationResult = metricEvaluationResult;
}
String text = evaluationResultTextConverter.asText(finalMetricEvaluationResult.condition, finalMetricEvaluationResult.evaluationResult);
builder.addLabel(text);
Measure updatedMeasure = Measure.updatedMeasureBuilder(measure.get()).setQualityGateStatus(new QualityGateStatus(finalMetricEvaluationResult.evaluationResult.getLevel(), text)).create();
measureRepository.update(project, metric, updatedMeasure);
builder.addEvaluatedCondition(finalMetricEvaluationResult);
}
builder.setIgnoredConditions(ignoredConditions);
}
Aggregations