Package org.sonar.api.measures

Examples of org.sonar.api.measures.RuleMeasure


  private void saveIssuesPerRules(DecoratorContext context, RulePriority severity, Map<RulePriority, Multiset<RuleKey>> rulesPerSeverity) {
    Metric metric = SeverityUtils.severityToIssueMetric(severity);

    Collection<Measure> children = context.getChildrenMeasures(MeasuresFilters.rules(metric));
    for (Measure child : children) {
      RuleMeasure childRuleMeasure = (RuleMeasure) child;
      RuleKey ruleKey = childRuleMeasure.ruleKey();
      if (ruleKey != null && MeasureUtils.hasValue(childRuleMeasure)) {
        Multiset<RuleKey> rulesBag = initRules(rulesPerSeverity, severity);
        rulesBag.add(ruleKey, childRuleMeasure.getIntValue());
      }
    }

    Multiset<RuleKey> rulesBag = rulesPerSeverity.get(severity);
    if (rulesBag != null) {
      for (Multiset.Entry<RuleKey> entry : rulesBag.entrySet()) {
        RuleMeasure measure = RuleMeasure.createForRule(metric, entry.getElement(), (double) entry.getCount());
        measure.setSeverity(severity);
        context.saveMeasure(measure);
      }
    }
  }
View Full Code Here


      ListMultimap<RuleKey, Issue> issuesPerRuleKeys = ArrayListMultimap.create();
      Set<RuleKey> ruleKeys = Sets.newHashSet();

      Collection<Measure> children = context.getChildrenMeasures(MeasuresFilters.rules(metric));
      for (Measure child : children) {
        RuleMeasure childRuleMeasure = (RuleMeasure) child;
        RuleKey ruleKey = childRuleMeasure.ruleKey();
        if (ruleKey != null) {
          childMeasuresPerRuleKeys.put(ruleKey, childRuleMeasure);
          ruleKeys.add(ruleKey);
        }
      }

      for (Issue issue : issues) {
        if (RulePriority.valueOf(issue.severity()).equals(severity)) {
          ruleKeys.add(issue.ruleKey());
          issuesPerRuleKeys.put(issue.ruleKey(), issue);
        }
      }

      for (RuleKey ruleKey : ruleKeys) {
        RuleMeasure measure = RuleMeasure.createForRule(metric, ruleKey, null);
        measure.setSeverity(severity);
        for (Period period : timeMachineConfiguration.periods()) {
          int variationIndex = period.getIndex();
          double sum = MeasureUtils.sumOnVariation(true, variationIndex, childMeasuresPerRuleKeys.get(ruleKey)) + countIssues(issuesPerRuleKeys.get(ruleKey), period);
          measure.setVariation(variationIndex, sum);
        }
        context.saveMeasure(measure);
      }
    }
  }
View Full Code Here

    }

    // Aggregate rules debt from children (and populate children characteristics debt)
    for (Measure measure : context.getChildrenMeasures(MeasuresFilters.rules(CoreMetrics.TECHNICAL_DEBT))) {
      Long debt = measure.getValue().longValue();
      RuleMeasure ruleMeasure = (RuleMeasure) measure;
      total += computeDebt(debt, ruleMeasure.ruleKey(), ruleDebts, characteristicDebts);
    }

    context.saveMeasure(CoreMetrics.TECHNICAL_DEBT, total.doubleValue());
    saveOnRule(context, ruleDebts);
    for (Characteristic characteristic : model.characteristics()) {
View Full Code Here

  @VisibleForTesting
  void saveRuleMeasure(DecoratorContext context, org.sonar.api.rules.Rule rule, Double value, boolean inMemory) {
    // we need the value on projects (root or module) even if value==0 in order to display correctly the SQALE history chart (see SQALE-122)
    // BUT we don't want to save zero-values for non top-characteristics (see SQALE-147)
    if (value > 0.0) {
      RuleMeasure measure = new RuleMeasure(CoreMetrics.TECHNICAL_DEBT, rule, null, null);
      saveMeasure(context, measure, value, inMemory);
    }
  }
View Full Code Here

    public boolean matches(Object o) {
      if (!(o instanceof RuleMeasure)) {
        return false;
      }
      RuleMeasure m = (RuleMeasure) o;
      return ObjectUtils.equals(metric, m.getMetric()) &&
        ObjectUtils.equals(rule.ruleKey(), m.ruleKey()) &&
        ObjectUtils.equals(var1, m.getVariation1()) &&
        ObjectUtils.equals(var2, m.getVariation2());
    }
View Full Code Here

    assertThat(next.key()[0]).isEqualTo("struts");

    assertThat(cache.byResource(p)).hasSize(1);
    assertThat(cache.byResource(p).iterator().next()).isEqualTo(m);

    RuleMeasure mRule = RuleMeasure.createForPriority(CoreMetrics.CRITICAL_VIOLATIONS, RulePriority.BLOCKER, 1.0);
    mRule.setRuleKey(RuleKey.of("repo", "rule"));
    cache.put(p, mRule);

    assertThat(cache.entries()).hasSize(2);
  }
View Full Code Here

    assertThat(next.key()[0]).isEqualTo("struts");

    assertThat(cache.byResource(p)).hasSize(1);
    assertThat(cache.byResource(p).iterator().next()).isEqualTo(m);

    RuleMeasure mRule = RuleMeasure.createForPriority(CoreMetrics.CRITICAL_VIOLATIONS, RulePriority.BLOCKER, 1.0);
    mRule.setRuleKey(RuleKey.of("repo", "rule"));
    cache.put(p, mRule);

    assertThat(cache.entries()).hasSize(2);
  }
View Full Code Here

    assertThat(cache.byResource(p)).hasSize(0);

    Measure m1 = new Measure(CoreMetrics.NCLOC, 1.0);
    Measure m2 = new Measure(CoreMetrics.NCLOC, 1.0).setCharacteristic(new DefaultCharacteristic().setKey("charac"));
    Measure m3 = new Measure(CoreMetrics.NCLOC, 1.0).setPersonId(2);
    Measure m4 = new RuleMeasure(CoreMetrics.NCLOC, RuleKey.of("repo", "rule"), RulePriority.BLOCKER, null);
    cache.put(p, m1);
    cache.put(p, m2);
    cache.put(p, m3);
    cache.put(p, m4);
View Full Code Here

  @Override
  public boolean matches(Object o) {
    if (!(o instanceof RuleMeasure)) {
      return false;
    }
    RuleMeasure m = (RuleMeasure) o;
    return ObjectUtils.equals(metric, m.getMetric()) &&
      ObjectUtils.equals(rule.ruleKey(), m.ruleKey()) &&
      NumberUtils.compare(value, m.getValue()) == 0;
  }
View Full Code Here

      model.setCharacteristicId(characteristic.id());
    }
    model.setPersonId(measure.getPersonId());
    model.setValue(measure.getValue());
    if (measure instanceof RuleMeasure) {
      RuleMeasure ruleMeasure = (RuleMeasure) measure;
      model.setRulePriority(ruleMeasure.getSeverity());
      RuleKey ruleKey = ruleMeasure.ruleKey();
      if (ruleKey != null) {
        Rule ruleWithId = ruleFinder.findByKey(ruleKey);
        if (ruleWithId == null) {
          throw new IllegalStateException("Can not save a measure with unknown rule " + ruleMeasure);
        }
View Full Code Here

TOP

Related Classes of org.sonar.api.measures.RuleMeasure

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.