Ejemplo n.º 1
0
  /** {@inheritDoc} */
  public void decorate(Resource resource, DecoratorContext context) {

    if (ResourceUtils.isProject(resource)) {

      Collection<Measure> childMeasures =
          context.getChildrenMeasures(CodesizeMetrics.CODE_COUNTERS);

      if (!childMeasures.isEmpty()) {
        Measure projectMeasure = context.getMeasure(CodesizeMetrics.CODE_COUNTERS);
        final PropertiesBuilder<String, Integer> counters =
            new PropertiesBuilder<String, Integer>(CodesizeMetrics.CODE_COUNTERS);
        if (projectMeasure != null) {
          Map<String, Integer> map = KeyValueFormat.parseStringInt(projectMeasure.getData());
          counters.addAll(map);
        }

        for (Measure childMeasure : childMeasures) {
          Map<String, Integer> childcounters =
              KeyValueFormat.parseStringInt(childMeasure.getData());
          for (Entry<String, Integer> entry : childcounters.entrySet()) {
            String key = entry.getKey();
            Integer value = entry.getValue();
            if (counters.getProps().containsKey(key)) {
              counters.add(key, value + counters.getProps().get(key));
            } else {
              counters.add(key, value);
            }
          }
        }

        if (projectMeasure != null) {
          projectMeasure.setData(counters.buildData());
        } else {
          context.saveMeasure(counters.build());
        }
      }
    }
  }