]> source.dussan.org Git - sonarqube.git/blob
5cd791570c83562f2e3c9c0b25961399948271d3
[sonarqube.git] /
1 /*
2  * Sonar, open source software quality management tool.
3  * Copyright (C) 2008-2012 SonarSource
4  * mailto:contact AT sonarsource DOT com
5  *
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.
10  *
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.
15  *
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
19  */
20 package org.sonar.plugins.core.sensors;
21
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;
28
29 import java.util.Collection;
30
31 public final class AllTestsCoverageDecorator extends AbstractCoverageDecorator {
32   @DependsUpon
33   public Collection<Metric> usedMetrics() {
34     return ImmutableList.of(CoreMetrics.MERGED_LINES_TO_COVER, CoreMetrics.MERGED_UNCOVERED_LINES, CoreMetrics.NEW_MERGED_LINES_TO_COVER,
35         CoreMetrics.NEW_MERGED_UNCOVERED_LINES, CoreMetrics.MERGED_CONDITIONS_TO_COVER, CoreMetrics.MERGED_UNCOVERED_CONDITIONS,
36         CoreMetrics.NEW_MERGED_CONDITIONS_TO_COVER, CoreMetrics.NEW_MERGED_UNCOVERED_CONDITIONS);
37   }
38
39   @Override
40   protected Metric getGeneratedMetric() {
41     return CoreMetrics.MERGED_COVERAGE;
42   }
43
44   @Override
45   protected Long countElements(DecoratorContext context) {
46     long lines = MeasureUtils.getValueAsLong(context.getMeasure(CoreMetrics.MERGED_LINES_TO_COVER), 0L);
47     long conditions = MeasureUtils.getValueAsLong(context.getMeasure(CoreMetrics.MERGED_CONDITIONS_TO_COVER), 0L);
48
49     return lines + conditions;
50   }
51
52   @Override
53   protected long countCoveredElements(DecoratorContext context) {
54     long uncoveredLines = MeasureUtils.getValueAsLong(context.getMeasure(CoreMetrics.MERGED_UNCOVERED_LINES), 0L);
55     long lines = MeasureUtils.getValueAsLong(context.getMeasure(CoreMetrics.MERGED_LINES_TO_COVER), 0L);
56     long uncoveredConditions = MeasureUtils.getValueAsLong(context.getMeasure(CoreMetrics.MERGED_UNCOVERED_CONDITIONS), 0L);
57     long conditions = MeasureUtils.getValueAsLong(context.getMeasure(CoreMetrics.MERGED_CONDITIONS_TO_COVER), 0L);
58
59     return lines + conditions - uncoveredConditions - uncoveredLines;
60   }
61
62   @Override
63   protected Metric getGeneratedMetricForNewCode() {
64     return CoreMetrics.NEW_MERGED_COVERAGE;
65   }
66
67   @Override
68   protected Long countElementsForNewCode(DecoratorContext context, int periodIndex) {
69     Long newLinesToCover = MeasureUtils.getVariationAsLong(context.getMeasure(CoreMetrics.NEW_MERGED_LINES_TO_COVER), periodIndex);
70     if (newLinesToCover == null) {
71       return null;
72     }
73
74     long newConditionsToCover = MeasureUtils.getVariationAsLong(context.getMeasure(CoreMetrics.NEW_MERGED_CONDITIONS_TO_COVER), periodIndex, 0L);
75
76     return newLinesToCover + newConditionsToCover;
77   }
78
79   @Override
80   protected long countCoveredElementsForNewCode(DecoratorContext context, int periodIndex) {
81     long newLines = MeasureUtils.getVariationAsLong(context.getMeasure(CoreMetrics.NEW_MERGED_LINES_TO_COVER), periodIndex, 0L);
82     long newUncoveredLines = MeasureUtils.getVariationAsLong(context.getMeasure(CoreMetrics.NEW_MERGED_UNCOVERED_LINES), periodIndex, 0L);
83     long newUncoveredConditions = MeasureUtils.getVariationAsLong(context.getMeasure(CoreMetrics.NEW_MERGED_UNCOVERED_CONDITIONS), periodIndex, 0L);
84     long newConditions = MeasureUtils.getVariationAsLong(context.getMeasure(CoreMetrics.NEW_MERGED_CONDITIONS_TO_COVER), periodIndex, 0L);
85
86     return newLines + newConditions - newUncoveredConditions - newUncoveredLines;
87   }
88 }