Ejemplo n.º 1
0
  private void computeViolationsPerRules(DecoratorContext context) {
    Map<RulePriority, Multiset<Rule>> rulesPerSeverity = Maps.newHashMap();
    for (Violation violation : context.getViolations()) {
      Multiset<Rule> rulesBag = initRules(rulesPerSeverity, violation.getSeverity());
      rulesBag.add(violation.getRule());
    }

    for (RulePriority severity : RulePriority.values()) {
      Metric metric = SeverityUtils.severityToViolationMetric(severity);

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

      Multiset<Rule> rulesBag = rulesPerSeverity.get(severity);
      if (rulesBag != null) {
        for (Multiset.Entry<Rule> entry : rulesBag.entrySet()) {
          RuleMeasure measure =
              RuleMeasure.createForRule(metric, entry.getElement(), (double) entry.getCount());
          measure.setSeverity(severity);
          context.saveMeasure(measure);
        }
      }
    }
  }
Ejemplo n.º 2
0
  void compareWithPastMeasures(DecoratorContext context, int index, List<Object[]> pastMeasures) {
    Map<MeasureKey, Object[]> pastMeasuresByKey = Maps.newHashMap();
    for (Object[] pastMeasure : pastMeasures) {
      pastMeasuresByKey.put(new MeasureKey(pastMeasure), pastMeasure);
    }

    // for each measure, search equivalent past measure
    for (Measure measure : context.getMeasures(MeasuresFilters.all())) {
      // compare with past measure
      Integer metricId =
          (measure.getMetric().getId() != null
              ? measure.getMetric().getId()
              : metricFinder.findByKey(measure.getMetric().getKey()).getId());
      Integer characteristicId =
          (measure.getCharacteristic() != null ? measure.getCharacteristic().getId() : null);
      Integer ruleId =
          (measure instanceof RuleMeasure ? ((RuleMeasure) measure).getRule().getId() : null);

      Object[] pastMeasure =
          pastMeasuresByKey.get(new MeasureKey(metricId, characteristicId, ruleId));
      if (updateVariation(measure, pastMeasure, index)) {
        context.saveMeasure(measure);
      }
    }
  }
Ejemplo n.º 3
0
  private void computeViolationsPerSeverities(DecoratorContext context) {
    Multiset<RulePriority> severitiesBag = HashMultiset.create();
    for (Violation violation : context.getViolations()) {
      severitiesBag.add(violation.getSeverity());
    }

    for (RulePriority severity : RulePriority.values()) {
      Metric metric = SeverityUtils.severityToViolationMetric(severity);
      if (context.getMeasure(metric) == null) {
        Collection<Measure> children = context.getChildrenMeasures(MeasuresFilters.metric(metric));
        int sum = MeasureUtils.sum(true, children).intValue() + severitiesBag.count(severity);
        context.saveMeasure(metric, (double) sum);
      }
    }
  }
Ejemplo n.º 4
0
  private double computeTechnicalDebt(
      Metric metric,
      DecoratorContext context,
      TechnicalDebtRequirement requirement,
      Collection<Issue> issues) {
    double value = 0.0;
    if (issues != null) {
      for (Issue issue : issues) {
        value += converter.toDays(((DefaultIssue) issue).technicalDebt());
      }
    }

    for (Measure measure :
        context.getChildrenMeasures(
            MeasuresFilters.characteristic(metric, requirement.toCharacteristic()))) {
      if (measure.getCharacteristic() != null
          && measure.getCharacteristic().equals(requirement.toCharacteristic())
          && measure.getValue() != null) {
        value += measure.getValue();
      }
    }
    return value;
  }