2 * Sonar, open source software quality management tool.
3 * Copyright (C) 2008-2012 SonarSource
4 * mailto:contact AT sonarsource DOT com
6 * Sonar is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 3 of the License, or (at your option) any later version.
11 * Sonar is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with Sonar; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
20 package org.sonar.plugins.core.sensors;
22 import com.google.common.collect.ImmutableList;
23 import org.sonar.api.batch.DecoratorContext;
24 import org.sonar.api.batch.DependsUpon;
25 import org.sonar.api.measures.CoreMetrics;
26 import org.sonar.api.measures.MeasureUtils;
27 import org.sonar.api.measures.Metric;
29 import java.util.List;
31 public final class AllTestsLineCoverageDecorator extends AbstractCoverageDecorator {
33 public List<Metric> dependsUponMetrics() {
34 return ImmutableList.of(CoreMetrics.MERGED_UNCOVERED_LINES, CoreMetrics.MERGED_LINES_TO_COVER, CoreMetrics.NEW_MERGED_UNCOVERED_LINES,
35 CoreMetrics.NEW_MERGED_LINES_TO_COVER);
39 protected Metric getGeneratedMetric() {
40 return CoreMetrics.MERGED_LINE_COVERAGE;
44 protected Long countElements(DecoratorContext context) {
45 return MeasureUtils.getValueAsLong(context.getMeasure(CoreMetrics.MERGED_LINES_TO_COVER), 0L);
49 protected long countCoveredElements(DecoratorContext context) {
50 long uncoveredLines = MeasureUtils.getValueAsLong(context.getMeasure(CoreMetrics.MERGED_UNCOVERED_LINES), 0L);
51 long lines = MeasureUtils.getValueAsLong(context.getMeasure(CoreMetrics.MERGED_LINES_TO_COVER), 0L);
53 return lines - uncoveredLines;
57 protected Metric getGeneratedMetricForNewCode() {
58 return CoreMetrics.NEW_MERGED_LINE_COVERAGE;
62 protected Long countElementsForNewCode(DecoratorContext context, int periodIndex) {
63 return MeasureUtils.getVariationAsLong(context.getMeasure(CoreMetrics.NEW_MERGED_LINES_TO_COVER), periodIndex);
67 protected long countCoveredElementsForNewCode(DecoratorContext context, int periodIndex) {
68 long uncoveredLines = MeasureUtils.getVariationAsLong(context.getMeasure(CoreMetrics.NEW_MERGED_UNCOVERED_LINES), periodIndex, 0L);
69 long lines = MeasureUtils.getVariationAsLong(context.getMeasure(CoreMetrics.NEW_MERGED_LINES_TO_COVER), periodIndex, 0L);
71 return lines - uncoveredLines;