Search in sources :

Example 1 with Measure

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

the class NewMaintainabilityMeasuresVisitor method initNewDebtRatioCounter.

private void initNewDebtRatioCounter(Component file, Path<Counter> path) {
    // first analysis, no period, no differential value to compute, save processing time and return now
    if (!periodHolder.hasPeriod()) {
        return;
    }
    Optional<Measure> nclocDataMeasure = measureRepository.getRawMeasure(file, this.nclocDataMetric);
    if (!nclocDataMeasure.isPresent()) {
        return;
    }
    Optional<ScmInfo> scmInfoOptional = scmInfoRepository.getScmInfo(file);
    if (!scmInfoOptional.isPresent()) {
        LOG.trace(String.format("No changeset for file %s. Dev cost will be zero.", file.getKey()));
        return;
    }
    ScmInfo scmInfo = scmInfoOptional.get();
    initNewDebtRatioCounter(path.current(), file, nclocDataMeasure.get(), scmInfo);
}
Also used : Measure(org.sonar.server.computation.task.projectanalysis.measure.Measure) ScmInfo(org.sonar.server.computation.task.projectanalysis.scm.ScmInfo)

Example 2 with Measure

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

the class FormulaExecutorComponentVisitor method addNewMeasure.

private void addNewMeasure(Component component, String metricKey, Formula formula, Counter counter) {
    // no new measure can be created by formulas for PROJECT_VIEW components, their measures are the copy
    if (component.getType() == Component.Type.PROJECT_VIEW) {
        return;
    }
    Metric metric = metricRepository.getByKey(metricKey);
    Optional<Measure> measure = formula.createMeasure(counter, new CreateMeasureContextImpl(component, metric));
    if (measure.isPresent()) {
        measureRepository.add(component, metric, measure.get());
    }
}
Also used : Measure(org.sonar.server.computation.task.projectanalysis.measure.Measure) Metric(org.sonar.server.computation.task.projectanalysis.metric.Metric)

Example 3 with Measure

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

the class CustomMeasuresCopyStep method copy.

private void copy(Component component) {
    for (CustomMeasureDto dto : loadCustomMeasures(component)) {
        Metric metric = metricRepository.getById(dto.getMetricId());
        // else metric is not found and an exception is raised
        Measure measure = dtoToMeasure(dto, metric);
        measureRepository.add(component, metric, measure);
    }
}
Also used : Measure(org.sonar.server.computation.task.projectanalysis.measure.Measure) Metric(org.sonar.server.computation.task.projectanalysis.metric.Metric) CustomMeasureDto(org.sonar.db.measure.custom.CustomMeasureDto)

Example 4 with Measure

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

the class QualityGateEventsStep method executeForProject.

private void executeForProject(Component project) {
    Metric metric = metricRepository.getByKey(CoreMetrics.ALERT_STATUS_KEY);
    Optional<Measure> rawStatus = measureRepository.getRawMeasure(project, metric);
    if (!rawStatus.isPresent() || !rawStatus.get().hasQualityGateStatus()) {
        return;
    }
    checkQualityGateStatusChange(project, metric, rawStatus.get().getQualityGateStatus());
}
Also used : Measure(org.sonar.server.computation.task.projectanalysis.measure.Measure) Metric(org.sonar.server.computation.task.projectanalysis.metric.Metric)

Example 5 with Measure

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

the class QualityGateMeasuresStep method addProjectMeasure.

private void addProjectMeasure(Component project, QualityGateDetailsDataBuilder builder) {
    Measure globalMeasure = Measure.newMeasureBuilder().setQualityGateStatus(new QualityGateStatus(builder.getGlobalLevel(), StringUtils.join(builder.getLabels(), ", "))).create(builder.getGlobalLevel());
    Metric metric = metricRepository.getByKey(CoreMetrics.ALERT_STATUS_KEY);
    measureRepository.add(project, metric, globalMeasure);
    String detailMeasureValue = new QualityGateDetailsData(builder.getGlobalLevel(), builder.getEvaluatedConditions()).toJson();
    Measure detailsMeasure = Measure.newMeasureBuilder().create(detailMeasureValue);
    Metric qgDetailsMetric = metricRepository.getByKey(CoreMetrics.QUALITY_GATE_DETAILS_KEY);
    measureRepository.add(project, qgDetailsMetric, detailsMeasure);
}
Also used : QualityGateStatus(org.sonar.server.computation.task.projectanalysis.measure.QualityGateStatus) QualityGateDetailsData(org.sonar.server.computation.task.projectanalysis.measure.qualitygatedetails.QualityGateDetailsData) Measure(org.sonar.server.computation.task.projectanalysis.measure.Measure) Metric(org.sonar.server.computation.task.projectanalysis.metric.Metric)

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