Search in sources :

Example 1 with Metric

use of org.sonar.server.computation.task.projectanalysis.metric.Metric in project sonarqube by SonarSource.

the class MeasureComputerContextImpl method addMeasure.

@Override
public void addMeasure(String metricKey, double value) {
    Metric metric = metricRepository.getByKey(metricKey);
    validateAddMeasure(metric);
    measureRepository.add(internalComponent, metric, newMeasureBuilder().create(value, metric.getDecimalScale()));
}
Also used : Metric(org.sonar.server.computation.task.projectanalysis.metric.Metric)

Example 2 with Metric

use of org.sonar.server.computation.task.projectanalysis.metric.Metric in project sonarqube by SonarSource.

the class MeasureComputerContextImpl method addMeasure.

@Override
public void addMeasure(String metricKey, long value) {
    Metric metric = metricRepository.getByKey(metricKey);
    validateAddMeasure(metric);
    measureRepository.add(internalComponent, metric, newMeasureBuilder().create(value));
}
Also used : Metric(org.sonar.server.computation.task.projectanalysis.metric.Metric)

Example 3 with Metric

use of org.sonar.server.computation.task.projectanalysis.metric.Metric in project sonarqube by SonarSource.

the class IssueCounter method addMeasuresByPeriod.

private void addMeasuresByPeriod(Component component) {
    if (!periodHolder.hasPeriod()) {
        return;
    }
    Double unresolvedVariations = (double) currentCounters.counterForPeriod().unresolved;
    measureRepository.add(component, metricRepository.getByKey(NEW_VIOLATIONS_KEY), Measure.newMeasureBuilder().setVariation(unresolvedVariations).createNoValue());
    for (Map.Entry<String, String> entry : SEVERITY_TO_NEW_METRIC_KEY.entrySet()) {
        String severity = entry.getKey();
        String metricKey = entry.getValue();
        Multiset<String> bag = currentCounters.counterForPeriod().severityBag;
        Metric metric = metricRepository.getByKey(metricKey);
        measureRepository.add(component, metric, Measure.newMeasureBuilder().setVariation((double) bag.count(severity)).createNoValue());
    }
    // (see call currentCounters.counterForPeriod(period.getIndex()).xxx with xxx as severityBag or typeBag)
    for (Map.Entry<RuleType, String> entry : TYPE_TO_NEW_METRIC_KEY.entrySet()) {
        RuleType type = entry.getKey();
        String metricKey = entry.getValue();
        Multiset<RuleType> bag = currentCounters.counterForPeriod().typeBag;
        Metric metric = metricRepository.getByKey(metricKey);
        measureRepository.add(component, metric, Measure.newMeasureBuilder().setVariation((double) bag.count(type)).createNoValue());
    }
}
Also used : Metric(org.sonar.server.computation.task.projectanalysis.metric.Metric) RuleType(org.sonar.api.rules.RuleType) HashMap(java.util.HashMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 4 with Metric

use of org.sonar.server.computation.task.projectanalysis.metric.Metric 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 5 with Metric

use of org.sonar.server.computation.task.projectanalysis.metric.Metric in project sonarqube by SonarSource.

the class ComputeMeasureVariationsStep method execute.

@Override
public void execute() {
    try (DbSession dbSession = dbClient.openSession(false)) {
        List<Metric> metrics = StreamSupport.stream(metricRepository.getAll().spliterator(), false).filter(isNumeric()).collect(Collectors.toList());
        new DepthTraversalTypeAwareCrawler(new VariationMeasuresVisitor(dbSession, metrics)).visit(treeRootHolder.getRoot());
    }
}
Also used : DbSession(org.sonar.db.DbSession) DepthTraversalTypeAwareCrawler(org.sonar.server.computation.task.projectanalysis.component.DepthTraversalTypeAwareCrawler) Metric(org.sonar.server.computation.task.projectanalysis.metric.Metric)

Aggregations

Metric (org.sonar.server.computation.task.projectanalysis.metric.Metric)47 Measure (org.sonar.server.computation.task.projectanalysis.measure.Measure)30 Test (org.junit.Test)29 MetricImpl (org.sonar.server.computation.task.projectanalysis.metric.MetricImpl)4 ImmutableMap (com.google.common.collect.ImmutableMap)2 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)2 Map (java.util.Map)2 DbSession (org.sonar.db.DbSession)2 QualityGateStatus (org.sonar.server.computation.task.projectanalysis.measure.QualityGateStatus)2 MetricType (org.sonar.server.computation.task.projectanalysis.metric.Metric.MetricType)2 Condition (org.sonar.server.computation.task.projectanalysis.qualitygate.Condition)2 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 RuleType (org.sonar.api.rules.RuleType)1 CustomMeasureDto (org.sonar.db.measure.custom.CustomMeasureDto)1 QualityProfileDto (org.sonar.db.qualityprofile.QualityProfileDto)1 ScannerReport (org.sonar.scanner.protocol.output.ScannerReport)1 Component (org.sonar.server.computation.task.projectanalysis.component.Component)1 DepthTraversalTypeAwareCrawler (org.sonar.server.computation.task.projectanalysis.component.DepthTraversalTypeAwareCrawler)1 EvaluatedCondition (org.sonar.server.computation.task.projectanalysis.measure.qualitygatedetails.EvaluatedCondition)1