aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>2013-09-18 14:04:29 +0200
committerJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>2013-09-18 14:04:29 +0200
commit9178edd1d0de1c9421ae464da820257dd8bb4477 (patch)
tree7d8208ba81eb2e8edae019a098c7e5de43e2f5dc
parent469ecd7eb9b89351fd10d7e8d033a5292a683f0e (diff)
downloadsonarqube-9178edd1d0de1c9421ae464da820257dd8bb4477.tar.gz
sonarqube-9178edd1d0de1c9421ae464da820257dd8bb4477.zip
SONAR-766 Filter out generated coverage metrics along with used coverage metrics
-rw-r--r--plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/CoverageMeasurementFilter.java9
-rw-r--r--plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/CoverageMeasurementFilterTest.java2
2 files changed, 9 insertions, 2 deletions
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/CoverageMeasurementFilter.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/CoverageMeasurementFilter.java
index be51f1ef325..268ff4ea64d 100644
--- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/CoverageMeasurementFilter.java
+++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/CoverageMeasurementFilter.java
@@ -19,6 +19,8 @@
*/
package org.sonar.plugins.core.sensors;
+import org.sonar.api.measures.Metric;
+
import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableList.Builder;
@@ -54,13 +56,18 @@ public class CoverageMeasurementFilter implements MeasurementFilter {
@Override
public boolean accept(Resource resource, Measure measure) {
- if (this.decorator.usedMetrics().contains(measure.getMetric())) {
+ if (isCoverageMetric(measure.getMetric())) {
return !hasMatchingPattern(resource);
} else {
return true;
}
}
+ private boolean isCoverageMetric(Metric metric) {
+ return this.decorator.usedMetrics().contains(metric)
+ || this.decorator.generatedMetrics().contains(metric);
+ }
+
private boolean hasMatchingPattern(Resource resource) {
boolean found = false;
Iterator<WildcardPattern> iterator = resourcePatterns.iterator();
diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/CoverageMeasurementFilterTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/CoverageMeasurementFilterTest.java
index 51b06edb60a..57c78c950f2 100644
--- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/CoverageMeasurementFilterTest.java
+++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/CoverageMeasurementFilterTest.java
@@ -66,7 +66,7 @@ public class CoverageMeasurementFilterTest {
public void shouldNotFilterFileBasedOnPattern() {
Resource resource = new File("org/polop/File.php");
Measure coverageMeasure = mock(Measure.class);
- when(coverageMeasure.getMetric()).thenReturn(CoreMetrics.LINES_TO_COVER);
+ when(coverageMeasure.getMetric()).thenReturn(CoreMetrics.COVERAGE);
settings.setProperty(CoverageMeasurementFilter.PROPERTY_COVERAGE_EXCLUSIONS, "org/other/*");
filter.initPatterns();