]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-2804 Starting to refactor code for merged coverage
authorDavid Gageot <david@gageot.net>
Wed, 3 Oct 2012 07:44:37 +0000 (09:44 +0200)
committerDavid Gageot <david@gageot.net>
Wed, 3 Oct 2012 07:47:03 +0000 (09:47 +0200)
13 files changed:
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/AllTestsBranchCoverageDecorator.java
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/AllTestsCoverageDecorator.java
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/AllTestsLineCoverageDecorator.java
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/BranchCoverageDecorator.java
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/CoverageDecorator.java
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/ItBranchCoverageDecorator.java
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/ItCoverageDecorator.java
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/ItLineCoverageDecorator.java
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/LineCoverageDecorator.java
plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/AllTestsCoverageDecoratorTest.java
plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/CoverageDecoratorTest.java
plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/ItCoverageDecoratorTest.java
plugins/sonar-jacoco-plugin/src/main/java/org/sonar/plugins/jacoco/JaCoCoAllTestsSensor.java

index 7949cc91e893dc6f89afd28dfdb75df86419dafd..bdc66eae8dfe362dfc94380d83e9a7df10b932a7 100644 (file)
  */
 package org.sonar.plugins.core.sensors;
 
+import com.google.common.collect.ImmutableList;
 import org.sonar.api.batch.DecoratorContext;
 import org.sonar.api.batch.DependsUpon;
 import org.sonar.api.measures.CoreMetrics;
 import org.sonar.api.measures.MeasureUtils;
 import org.sonar.api.measures.Metric;
 
-import java.util.Arrays;
 import java.util.List;
 
 public final class AllTestsBranchCoverageDecorator extends AbstractCoverageDecorator {
-
   @DependsUpon
   public List<Metric> dependsUponMetrics() {
-    return Arrays.asList(CoreMetrics.MERGED_UNCOVERED_CONDITIONS, CoreMetrics.MERGED_CONDITIONS_TO_COVER,
+    return ImmutableList.of(CoreMetrics.MERGED_UNCOVERED_CONDITIONS, CoreMetrics.MERGED_CONDITIONS_TO_COVER,
         CoreMetrics.NEW_MERGED_UNCOVERED_CONDITIONS, CoreMetrics.NEW_MERGED_CONDITIONS_TO_COVER);
   }
 
@@ -50,6 +49,7 @@ public final class AllTestsBranchCoverageDecorator extends AbstractCoverageDecor
   protected long countCoveredElements(DecoratorContext context) {
     long uncoveredConditions = MeasureUtils.getValueAsLong(context.getMeasure(CoreMetrics.MERGED_UNCOVERED_CONDITIONS), 0L);
     long conditions = MeasureUtils.getValueAsLong(context.getMeasure(CoreMetrics.MERGED_CONDITIONS_TO_COVER), 0L);
+
     return conditions - uncoveredConditions;
   }
 
@@ -67,6 +67,7 @@ public final class AllTestsBranchCoverageDecorator extends AbstractCoverageDecor
   protected long countCoveredElementsForNewCode(DecoratorContext context, int periodIndex) {
     long uncoveredConditions = MeasureUtils.getVariationAsLong(context.getMeasure(CoreMetrics.NEW_MERGED_UNCOVERED_CONDITIONS), periodIndex, 0L);
     long conditions = MeasureUtils.getVariationAsLong(context.getMeasure(CoreMetrics.NEW_MERGED_CONDITIONS_TO_COVER), periodIndex, 0L);
+
     return conditions - uncoveredConditions;
   }
 }
index f83d32911403c1d9c299378cd3c8c5df23d5591b..5cd791570c83562f2e3c9c0b25961399948271d3 100644 (file)
  */
 package org.sonar.plugins.core.sensors;
 
+import com.google.common.collect.ImmutableList;
 import org.sonar.api.batch.DecoratorContext;
 import org.sonar.api.batch.DependsUpon;
 import org.sonar.api.measures.CoreMetrics;
 import org.sonar.api.measures.MeasureUtils;
 import org.sonar.api.measures.Metric;
 
-import java.util.Arrays;
 import java.util.Collection;
 
 public final class AllTestsCoverageDecorator extends AbstractCoverageDecorator {
-
   @DependsUpon
   public Collection<Metric> usedMetrics() {
-    return Arrays.asList(CoreMetrics.MERGED_LINES_TO_COVER, CoreMetrics.MERGED_UNCOVERED_LINES, CoreMetrics.NEW_MERGED_LINES_TO_COVER,
+    return ImmutableList.of(CoreMetrics.MERGED_LINES_TO_COVER, CoreMetrics.MERGED_UNCOVERED_LINES, CoreMetrics.NEW_MERGED_LINES_TO_COVER,
         CoreMetrics.NEW_MERGED_UNCOVERED_LINES, CoreMetrics.MERGED_CONDITIONS_TO_COVER, CoreMetrics.MERGED_UNCOVERED_CONDITIONS,
         CoreMetrics.NEW_MERGED_CONDITIONS_TO_COVER, CoreMetrics.NEW_MERGED_UNCOVERED_CONDITIONS);
   }
@@ -46,6 +45,7 @@ public final class AllTestsCoverageDecorator extends AbstractCoverageDecorator {
   protected Long countElements(DecoratorContext context) {
     long lines = MeasureUtils.getValueAsLong(context.getMeasure(CoreMetrics.MERGED_LINES_TO_COVER), 0L);
     long conditions = MeasureUtils.getValueAsLong(context.getMeasure(CoreMetrics.MERGED_CONDITIONS_TO_COVER), 0L);
+
     return lines + conditions;
   }
 
@@ -55,10 +55,10 @@ public final class AllTestsCoverageDecorator extends AbstractCoverageDecorator {
     long lines = MeasureUtils.getValueAsLong(context.getMeasure(CoreMetrics.MERGED_LINES_TO_COVER), 0L);
     long uncoveredConditions = MeasureUtils.getValueAsLong(context.getMeasure(CoreMetrics.MERGED_UNCOVERED_CONDITIONS), 0L);
     long conditions = MeasureUtils.getValueAsLong(context.getMeasure(CoreMetrics.MERGED_CONDITIONS_TO_COVER), 0L);
+
     return lines + conditions - uncoveredConditions - uncoveredLines;
   }
 
-
   @Override
   protected Metric getGeneratedMetricForNewCode() {
     return CoreMetrics.NEW_MERGED_COVERAGE;
@@ -67,11 +67,13 @@ public final class AllTestsCoverageDecorator extends AbstractCoverageDecorator {
   @Override
   protected Long countElementsForNewCode(DecoratorContext context, int periodIndex) {
     Long newLinesToCover = MeasureUtils.getVariationAsLong(context.getMeasure(CoreMetrics.NEW_MERGED_LINES_TO_COVER), periodIndex);
-    if (newLinesToCover != null) {
-      long newConditionsToCover = MeasureUtils.getVariationAsLong(context.getMeasure(CoreMetrics.NEW_MERGED_CONDITIONS_TO_COVER), periodIndex, 0L);
-      return newLinesToCover + newConditionsToCover;
+    if (newLinesToCover == null) {
+      return null;
     }
-    return null;
+
+    long newConditionsToCover = MeasureUtils.getVariationAsLong(context.getMeasure(CoreMetrics.NEW_MERGED_CONDITIONS_TO_COVER), periodIndex, 0L);
+
+    return newLinesToCover + newConditionsToCover;
   }
 
   @Override
@@ -80,6 +82,7 @@ public final class AllTestsCoverageDecorator extends AbstractCoverageDecorator {
     long newUncoveredLines = MeasureUtils.getVariationAsLong(context.getMeasure(CoreMetrics.NEW_MERGED_UNCOVERED_LINES), periodIndex, 0L);
     long newUncoveredConditions = MeasureUtils.getVariationAsLong(context.getMeasure(CoreMetrics.NEW_MERGED_UNCOVERED_CONDITIONS), periodIndex, 0L);
     long newConditions = MeasureUtils.getVariationAsLong(context.getMeasure(CoreMetrics.NEW_MERGED_CONDITIONS_TO_COVER), periodIndex, 0L);
+
     return newLines + newConditions - newUncoveredConditions - newUncoveredLines;
   }
-}
\ No newline at end of file
+}
index 969cc1cae1b84a3769e644ddc56577568e5771c6..e815cdc3244392aa3190f54ee9e00667c71d2101 100644 (file)
  */
 package org.sonar.plugins.core.sensors;
 
+import com.google.common.collect.ImmutableList;
 import org.sonar.api.batch.DecoratorContext;
 import org.sonar.api.batch.DependsUpon;
 import org.sonar.api.measures.CoreMetrics;
 import org.sonar.api.measures.MeasureUtils;
 import org.sonar.api.measures.Metric;
 
-import java.util.Arrays;
 import java.util.List;
 
 public final class AllTestsLineCoverageDecorator extends AbstractCoverageDecorator {
   @DependsUpon
   public List<Metric> dependsUponMetrics() {
-    return Arrays.asList(CoreMetrics.MERGED_UNCOVERED_LINES, CoreMetrics.MERGED_LINES_TO_COVER, CoreMetrics.NEW_MERGED_UNCOVERED_LINES,
+    return ImmutableList.of(CoreMetrics.MERGED_UNCOVERED_LINES, CoreMetrics.MERGED_LINES_TO_COVER, CoreMetrics.NEW_MERGED_UNCOVERED_LINES,
         CoreMetrics.NEW_MERGED_LINES_TO_COVER);
   }
 
@@ -49,10 +49,10 @@ public final class AllTestsLineCoverageDecorator extends AbstractCoverageDecorat
   protected long countCoveredElements(DecoratorContext context) {
     long uncoveredLines = MeasureUtils.getValueAsLong(context.getMeasure(CoreMetrics.MERGED_UNCOVERED_LINES), 0L);
     long lines = MeasureUtils.getValueAsLong(context.getMeasure(CoreMetrics.MERGED_LINES_TO_COVER), 0L);
+
     return lines - uncoveredLines;
   }
 
-
   @Override
   protected Metric getGeneratedMetricForNewCode() {
     return CoreMetrics.NEW_MERGED_LINE_COVERAGE;
@@ -67,6 +67,7 @@ public final class AllTestsLineCoverageDecorator extends AbstractCoverageDecorat
   protected long countCoveredElementsForNewCode(DecoratorContext context, int periodIndex) {
     long uncoveredLines = MeasureUtils.getVariationAsLong(context.getMeasure(CoreMetrics.NEW_MERGED_UNCOVERED_LINES), periodIndex, 0L);
     long lines = MeasureUtils.getVariationAsLong(context.getMeasure(CoreMetrics.NEW_MERGED_LINES_TO_COVER), periodIndex, 0L);
+
     return lines - uncoveredLines;
   }
 }
index 71cfb25905283c2aaeadef2bdda10685ceb383ec..72f32ea49d305482ebcd75593d0d54564aabc864 100644 (file)
  */
 package org.sonar.plugins.core.sensors;
 
+import com.google.common.collect.ImmutableList;
 import org.sonar.api.batch.DecoratorContext;
 import org.sonar.api.batch.DependsUpon;
 import org.sonar.api.measures.CoreMetrics;
 import org.sonar.api.measures.MeasureUtils;
 import org.sonar.api.measures.Metric;
 
-import java.util.Arrays;
 import java.util.List;
 
 public final class BranchCoverageDecorator extends AbstractCoverageDecorator {
-
   @DependsUpon
   public List<Metric> dependsUponMetrics() {
-    return Arrays.asList(CoreMetrics.UNCOVERED_CONDITIONS, CoreMetrics.CONDITIONS_TO_COVER,
+    return ImmutableList.of(CoreMetrics.UNCOVERED_CONDITIONS, CoreMetrics.CONDITIONS_TO_COVER,
         CoreMetrics.NEW_UNCOVERED_CONDITIONS, CoreMetrics.NEW_CONDITIONS_TO_COVER);
   }
 
@@ -50,6 +49,7 @@ public final class BranchCoverageDecorator extends AbstractCoverageDecorator {
   protected long countCoveredElements(DecoratorContext context) {
     long uncoveredConditions = MeasureUtils.getValueAsLong(context.getMeasure(CoreMetrics.UNCOVERED_CONDITIONS), 0L);
     long conditions = MeasureUtils.getValueAsLong(context.getMeasure(CoreMetrics.CONDITIONS_TO_COVER), 0L);
+
     return conditions - uncoveredConditions;
   }
 
@@ -67,6 +67,7 @@ public final class BranchCoverageDecorator extends AbstractCoverageDecorator {
   protected long countCoveredElementsForNewCode(DecoratorContext context, int periodIndex) {
     long uncoveredConditions = MeasureUtils.getVariationAsLong(context.getMeasure(CoreMetrics.NEW_UNCOVERED_CONDITIONS), periodIndex, 0L);
     long conditions = MeasureUtils.getVariationAsLong(context.getMeasure(CoreMetrics.NEW_CONDITIONS_TO_COVER), periodIndex, 0L);
+
     return conditions - uncoveredConditions;
   }
 }
index 4a781d8c220f278b36fb5c9c801989a8279d1419..b02c3ebea30d540f1bea87ad3fa2b903643e50ef 100644 (file)
  */
 package org.sonar.plugins.core.sensors;
 
+import com.google.common.collect.ImmutableList;
 import org.sonar.api.batch.DecoratorContext;
 import org.sonar.api.batch.DependsUpon;
 import org.sonar.api.measures.CoreMetrics;
 import org.sonar.api.measures.MeasureUtils;
 import org.sonar.api.measures.Metric;
 
-import java.util.Arrays;
 import java.util.Collection;
 
 public final class CoverageDecorator extends AbstractCoverageDecorator {
-
   @DependsUpon
   public Collection<Metric> usedMetrics() {
-    return Arrays.asList(CoreMetrics.LINES_TO_COVER, CoreMetrics.UNCOVERED_LINES, CoreMetrics.NEW_LINES_TO_COVER,
-        CoreMetrics.NEW_UNCOVERED_LINES, CoreMetrics.CONDITIONS_TO_COVER, CoreMetrics.UNCOVERED_CONDITIONS,
-        CoreMetrics.NEW_CONDITIONS_TO_COVER, CoreMetrics.NEW_UNCOVERED_CONDITIONS);
+    return ImmutableList.of(CoreMetrics.LINES_TO_COVER, CoreMetrics.UNCOVERED_LINES, CoreMetrics.NEW_LINES_TO_COVER,
+      CoreMetrics.NEW_UNCOVERED_LINES, CoreMetrics.CONDITIONS_TO_COVER, CoreMetrics.UNCOVERED_CONDITIONS,
+      CoreMetrics.NEW_CONDITIONS_TO_COVER, CoreMetrics.NEW_UNCOVERED_CONDITIONS);
   }
 
   @Override
@@ -46,6 +45,7 @@ public final class CoverageDecorator extends AbstractCoverageDecorator {
   protected Long countElements(DecoratorContext context) {
     long lines = MeasureUtils.getValueAsLong(context.getMeasure(CoreMetrics.LINES_TO_COVER), 0L);
     long conditions = MeasureUtils.getValueAsLong(context.getMeasure(CoreMetrics.CONDITIONS_TO_COVER), 0L);
+
     return lines + conditions;
   }
 
@@ -55,10 +55,10 @@ public final class CoverageDecorator extends AbstractCoverageDecorator {
     long lines = MeasureUtils.getValueAsLong(context.getMeasure(CoreMetrics.LINES_TO_COVER), 0L);
     long uncoveredConditions = MeasureUtils.getValueAsLong(context.getMeasure(CoreMetrics.UNCOVERED_CONDITIONS), 0L);
     long conditions = MeasureUtils.getValueAsLong(context.getMeasure(CoreMetrics.CONDITIONS_TO_COVER), 0L);
+
     return lines + conditions - uncoveredConditions - uncoveredLines;
   }
 
-
   @Override
   protected Metric getGeneratedMetricForNewCode() {
     return CoreMetrics.NEW_COVERAGE;
@@ -67,11 +67,13 @@ public final class CoverageDecorator extends AbstractCoverageDecorator {
   @Override
   protected Long countElementsForNewCode(DecoratorContext context, int periodIndex) {
     Long newLinesToCover = MeasureUtils.getVariationAsLong(context.getMeasure(CoreMetrics.NEW_LINES_TO_COVER), periodIndex);
-    if (newLinesToCover != null) {
-      long newConditionsToCover = MeasureUtils.getVariationAsLong(context.getMeasure(CoreMetrics.NEW_CONDITIONS_TO_COVER), periodIndex, 0L);
-      return newLinesToCover + newConditionsToCover;
+    if (newLinesToCover == null) {
+      return null;
     }
-    return null;
+
+    long newConditionsToCover = MeasureUtils.getVariationAsLong(context.getMeasure(CoreMetrics.NEW_CONDITIONS_TO_COVER), periodIndex, 0L);
+
+    return newLinesToCover + newConditionsToCover;
   }
 
   @Override
@@ -80,6 +82,7 @@ public final class CoverageDecorator extends AbstractCoverageDecorator {
     long newUncoveredLines = MeasureUtils.getVariationAsLong(context.getMeasure(CoreMetrics.NEW_UNCOVERED_LINES), periodIndex, 0L);
     long newUncoveredConditions = MeasureUtils.getVariationAsLong(context.getMeasure(CoreMetrics.NEW_UNCOVERED_CONDITIONS), periodIndex, 0L);
     long newConditions = MeasureUtils.getVariationAsLong(context.getMeasure(CoreMetrics.NEW_CONDITIONS_TO_COVER), periodIndex, 0L);
+
     return newLines + newConditions - newUncoveredConditions - newUncoveredLines;
   }
-}
\ No newline at end of file
+}
index 5ed3d0d826edde2b92313115b59a3cd0ad7b1838..1761b2b4b4b684457689a1cd0a1aad460f994f1a 100644 (file)
  */
 package org.sonar.plugins.core.sensors;
 
+import com.google.common.collect.ImmutableList;
 import org.sonar.api.batch.DecoratorContext;
 import org.sonar.api.batch.DependsUpon;
 import org.sonar.api.measures.CoreMetrics;
 import org.sonar.api.measures.MeasureUtils;
 import org.sonar.api.measures.Metric;
 
-import java.util.Arrays;
 import java.util.List;
 
 public final class ItBranchCoverageDecorator extends AbstractCoverageDecorator {
 
   @DependsUpon
   public List<Metric> dependsUponMetrics() {
-    return Arrays.asList(CoreMetrics.IT_UNCOVERED_CONDITIONS, CoreMetrics.IT_CONDITIONS_TO_COVER,
+    return ImmutableList.of(CoreMetrics.IT_UNCOVERED_CONDITIONS, CoreMetrics.IT_CONDITIONS_TO_COVER,
         CoreMetrics.NEW_IT_UNCOVERED_CONDITIONS, CoreMetrics.NEW_IT_CONDITIONS_TO_COVER);
   }
 
@@ -50,6 +50,7 @@ public final class ItBranchCoverageDecorator extends AbstractCoverageDecorator {
   protected long countCoveredElements(DecoratorContext context) {
     long uncoveredConditions = MeasureUtils.getValueAsLong(context.getMeasure(CoreMetrics.IT_UNCOVERED_CONDITIONS), 0L);
     long conditions = MeasureUtils.getValueAsLong(context.getMeasure(CoreMetrics.IT_CONDITIONS_TO_COVER), 0L);
+
     return conditions - uncoveredConditions;
   }
 
@@ -67,6 +68,7 @@ public final class ItBranchCoverageDecorator extends AbstractCoverageDecorator {
   protected long countCoveredElementsForNewCode(DecoratorContext context, int periodIndex) {
     long uncoveredConditions = MeasureUtils.getVariationAsLong(context.getMeasure(CoreMetrics.NEW_IT_UNCOVERED_CONDITIONS), periodIndex, 0L);
     long conditions = MeasureUtils.getVariationAsLong(context.getMeasure(CoreMetrics.NEW_IT_CONDITIONS_TO_COVER), periodIndex, 0L);
+
     return conditions - uncoveredConditions;
   }
 }
index 290612594e9cff24b03d45248f582bba7af33b81..318c5382faff5b23a3d7c833746de988de8891b0 100644 (file)
  */
 package org.sonar.plugins.core.sensors;
 
+import com.google.common.collect.ImmutableList;
 import org.sonar.api.batch.DecoratorContext;
 import org.sonar.api.batch.DependsUpon;
 import org.sonar.api.measures.CoreMetrics;
 import org.sonar.api.measures.MeasureUtils;
 import org.sonar.api.measures.Metric;
 
-import java.util.Arrays;
 import java.util.Collection;
 
 public final class ItCoverageDecorator extends AbstractCoverageDecorator {
-
   @DependsUpon
   public Collection<Metric> usedMetrics() {
-    return Arrays.asList(CoreMetrics.IT_LINES_TO_COVER, CoreMetrics.IT_UNCOVERED_LINES, CoreMetrics.NEW_IT_LINES_TO_COVER,
+    return ImmutableList.of(CoreMetrics.IT_LINES_TO_COVER, CoreMetrics.IT_UNCOVERED_LINES, CoreMetrics.NEW_IT_LINES_TO_COVER,
         CoreMetrics.NEW_IT_UNCOVERED_LINES, CoreMetrics.IT_CONDITIONS_TO_COVER, CoreMetrics.IT_UNCOVERED_CONDITIONS,
         CoreMetrics.NEW_IT_CONDITIONS_TO_COVER, CoreMetrics.NEW_IT_UNCOVERED_CONDITIONS);
   }
@@ -46,6 +45,7 @@ public final class ItCoverageDecorator extends AbstractCoverageDecorator {
   protected Long countElements(DecoratorContext context) {
     long lines = MeasureUtils.getValueAsLong(context.getMeasure(CoreMetrics.IT_LINES_TO_COVER), 0L);
     long conditions = MeasureUtils.getValueAsLong(context.getMeasure(CoreMetrics.IT_CONDITIONS_TO_COVER), 0L);
+
     return lines + conditions;
   }
 
@@ -55,10 +55,10 @@ public final class ItCoverageDecorator extends AbstractCoverageDecorator {
     long lines = MeasureUtils.getValueAsLong(context.getMeasure(CoreMetrics.IT_LINES_TO_COVER), 0L);
     long uncoveredConditions = MeasureUtils.getValueAsLong(context.getMeasure(CoreMetrics.IT_UNCOVERED_CONDITIONS), 0L);
     long conditions = MeasureUtils.getValueAsLong(context.getMeasure(CoreMetrics.IT_CONDITIONS_TO_COVER), 0L);
+
     return lines + conditions - uncoveredConditions - uncoveredLines;
   }
 
-
   @Override
   protected Metric getGeneratedMetricForNewCode() {
     return CoreMetrics.NEW_IT_COVERAGE;
@@ -67,11 +67,12 @@ public final class ItCoverageDecorator extends AbstractCoverageDecorator {
   @Override
   protected Long countElementsForNewCode(DecoratorContext context, int periodIndex) {
     Long newLinesToCover = MeasureUtils.getVariationAsLong(context.getMeasure(CoreMetrics.NEW_IT_LINES_TO_COVER), periodIndex);
-    if (newLinesToCover != null) {
-      long newConditionsToCover = MeasureUtils.getVariationAsLong(context.getMeasure(CoreMetrics.NEW_IT_CONDITIONS_TO_COVER), periodIndex, 0L);
-      return newLinesToCover + newConditionsToCover;
+    if (newLinesToCover == null) {
+      return null;
     }
-    return null;
+
+    long newConditionsToCover = MeasureUtils.getVariationAsLong(context.getMeasure(CoreMetrics.NEW_IT_CONDITIONS_TO_COVER), periodIndex, 0L);
+    return newLinesToCover + newConditionsToCover;
   }
 
   @Override
@@ -80,6 +81,7 @@ public final class ItCoverageDecorator extends AbstractCoverageDecorator {
     long newUncoveredLines = MeasureUtils.getVariationAsLong(context.getMeasure(CoreMetrics.NEW_IT_UNCOVERED_LINES), periodIndex, 0L);
     long newUncoveredConditions = MeasureUtils.getVariationAsLong(context.getMeasure(CoreMetrics.NEW_IT_UNCOVERED_CONDITIONS), periodIndex, 0L);
     long newConditions = MeasureUtils.getVariationAsLong(context.getMeasure(CoreMetrics.NEW_IT_CONDITIONS_TO_COVER), periodIndex, 0L);
+
     return newLines + newConditions - newUncoveredConditions - newUncoveredLines;
   }
-}
\ No newline at end of file
+}
index 73fa9c15d946412d2732550cf8e1ac967bb86b4c..8812685e3151e9dfb0ab855e6d9dcecba0d55457 100644 (file)
  */
 package org.sonar.plugins.core.sensors;
 
+import com.google.common.collect.ImmutableList;
 import org.sonar.api.batch.DecoratorContext;
 import org.sonar.api.batch.DependsUpon;
 import org.sonar.api.measures.CoreMetrics;
 import org.sonar.api.measures.MeasureUtils;
 import org.sonar.api.measures.Metric;
 
-import java.util.Arrays;
 import java.util.List;
 
 public final class ItLineCoverageDecorator extends AbstractCoverageDecorator {
-
   @DependsUpon
   public List<Metric> dependsUponMetrics() {
-    return Arrays.asList(CoreMetrics.IT_UNCOVERED_LINES, CoreMetrics.IT_LINES_TO_COVER, CoreMetrics.NEW_IT_UNCOVERED_LINES,
+    return ImmutableList.of(CoreMetrics.IT_UNCOVERED_LINES, CoreMetrics.IT_LINES_TO_COVER, CoreMetrics.NEW_IT_UNCOVERED_LINES,
         CoreMetrics.NEW_IT_LINES_TO_COVER);
   }
 
@@ -50,10 +49,10 @@ public final class ItLineCoverageDecorator extends AbstractCoverageDecorator {
   protected long countCoveredElements(DecoratorContext context) {
     long uncoveredLines = MeasureUtils.getValueAsLong(context.getMeasure(CoreMetrics.IT_UNCOVERED_LINES), 0L);
     long lines = MeasureUtils.getValueAsLong(context.getMeasure(CoreMetrics.IT_LINES_TO_COVER), 0L);
+
     return lines - uncoveredLines;
   }
 
-
   @Override
   protected Metric getGeneratedMetricForNewCode() {
     return CoreMetrics.NEW_IT_LINE_COVERAGE;
@@ -68,6 +67,7 @@ public final class ItLineCoverageDecorator extends AbstractCoverageDecorator {
   protected long countCoveredElementsForNewCode(DecoratorContext context, int periodIndex) {
     long uncoveredLines = MeasureUtils.getVariationAsLong(context.getMeasure(CoreMetrics.NEW_IT_UNCOVERED_LINES), periodIndex, 0L);
     long lines = MeasureUtils.getVariationAsLong(context.getMeasure(CoreMetrics.NEW_IT_LINES_TO_COVER), periodIndex, 0L);
+
     return lines - uncoveredLines;
   }
 }
index f4e1dfa9443f5aa7115347158ca03caf3514141f..7d42a8de76031f85d788fc8e4520dca0eee07c35 100644 (file)
  */
 package org.sonar.plugins.core.sensors;
 
+import com.google.common.collect.ImmutableList;
 import org.sonar.api.batch.DecoratorContext;
 import org.sonar.api.batch.DependsUpon;
 import org.sonar.api.measures.CoreMetrics;
 import org.sonar.api.measures.MeasureUtils;
 import org.sonar.api.measures.Metric;
 
-import java.util.Arrays;
 import java.util.List;
 
 public final class LineCoverageDecorator extends AbstractCoverageDecorator {
-
   @DependsUpon
   public List<Metric> dependsUponMetrics() {
-    return Arrays.asList(CoreMetrics.UNCOVERED_LINES, CoreMetrics.LINES_TO_COVER, CoreMetrics.NEW_UNCOVERED_LINES,
+    return ImmutableList.of(CoreMetrics.UNCOVERED_LINES, CoreMetrics.LINES_TO_COVER, CoreMetrics.NEW_UNCOVERED_LINES,
         CoreMetrics.NEW_LINES_TO_COVER);
   }
 
@@ -50,10 +49,10 @@ public final class LineCoverageDecorator extends AbstractCoverageDecorator {
   protected long countCoveredElements(DecoratorContext context) {
     long uncoveredLines = MeasureUtils.getValueAsLong(context.getMeasure(CoreMetrics.UNCOVERED_LINES), 0L);
     long lines = MeasureUtils.getValueAsLong(context.getMeasure(CoreMetrics.LINES_TO_COVER), 0L);
+
     return lines - uncoveredLines;
   }
 
-
   @Override
   protected Metric getGeneratedMetricForNewCode() {
     return CoreMetrics.NEW_LINE_COVERAGE;
@@ -68,6 +67,7 @@ public final class LineCoverageDecorator extends AbstractCoverageDecorator {
   protected long countCoveredElementsForNewCode(DecoratorContext context, int periodIndex) {
     long uncoveredLines = MeasureUtils.getVariationAsLong(context.getMeasure(CoreMetrics.NEW_UNCOVERED_LINES), periodIndex, 0L);
     long lines = MeasureUtils.getVariationAsLong(context.getMeasure(CoreMetrics.NEW_LINES_TO_COVER), periodIndex, 0L);
+
     return lines - uncoveredLines;
   }
 }
index 0a51ab09c5e6f3ffa3dfa34711bb47fd5426bd22..b5c4ef15c8a8b3754b55f53e114b3b9e0ce06951 100644 (file)
@@ -24,9 +24,12 @@ import org.junit.Test;
 import org.sonar.api.batch.DecoratorContext;
 import org.sonar.api.measures.CoreMetrics;
 import org.sonar.api.measures.Measure;
+import org.sonar.api.measures.Metric;
 import org.sonar.api.resources.Project;
 import org.sonar.api.resources.Scopes;
 
+import java.util.Collection;
+
 import static org.fest.assertions.Assertions.assertThat;
 import static org.mockito.Matchers.anyDouble;
 import static org.mockito.Matchers.eq;
@@ -44,6 +47,15 @@ public class AllTestsCoverageDecoratorTest {
     when(project.getScope()).thenReturn(Scopes.PROJECT);
   }
 
+  @Test
+  public void should_use_metrics() {
+    Collection<Metric> metrics = decorator.usedMetrics();
+
+    assertThat(metrics).containsOnly(CoreMetrics.MERGED_LINES_TO_COVER, CoreMetrics.MERGED_UNCOVERED_LINES, CoreMetrics.NEW_MERGED_LINES_TO_COVER,
+        CoreMetrics.NEW_MERGED_UNCOVERED_LINES, CoreMetrics.MERGED_CONDITIONS_TO_COVER, CoreMetrics.MERGED_UNCOVERED_CONDITIONS,
+        CoreMetrics.NEW_MERGED_CONDITIONS_TO_COVER, CoreMetrics.NEW_MERGED_UNCOVERED_CONDITIONS);
+  }
+
   @Test
   public void noCoverageWhenStaticAnalysis() {
     when(project.getAnalysisType()).thenReturn(Project.AnalysisType.STATIC);
index 2821f94c407763539b66e2bad29816d2cd4bdaa8..0a9a0a9ddb4171128ec347ec269b5a4fa29405dd 100644 (file)
@@ -24,9 +24,12 @@ import org.junit.Test;
 import org.sonar.api.batch.DecoratorContext;
 import org.sonar.api.measures.CoreMetrics;
 import org.sonar.api.measures.Measure;
+import org.sonar.api.measures.Metric;
 import org.sonar.api.resources.Project;
 import org.sonar.api.resources.Scopes;
 
+import java.util.Collection;
+
 import static org.fest.assertions.Assertions.assertThat;
 import static org.mockito.Mockito.anyDouble;
 import static org.mockito.Mockito.eq;
@@ -44,6 +47,15 @@ public class CoverageDecoratorTest {
     when(project.getScope()).thenReturn(Scopes.PROJECT);
   }
 
+  @Test
+  public void should_use_metrics() {
+    Collection<Metric> metrics = decorator.usedMetrics();
+
+    assertThat(metrics).containsOnly(CoreMetrics.LINES_TO_COVER, CoreMetrics.UNCOVERED_LINES, CoreMetrics.NEW_LINES_TO_COVER,
+        CoreMetrics.NEW_UNCOVERED_LINES, CoreMetrics.CONDITIONS_TO_COVER, CoreMetrics.UNCOVERED_CONDITIONS,
+        CoreMetrics.NEW_CONDITIONS_TO_COVER, CoreMetrics.NEW_UNCOVERED_CONDITIONS);
+  }
+
   @Test
   public void noCoverageWhenStaticAnalysis() {
     when(project.getAnalysisType()).thenReturn(Project.AnalysisType.STATIC);
index 76e1538615058b5b8dbe8058cd7194d47857067a..1fc2089a376bf135a1970bc6eb4258580de6297b 100644 (file)
@@ -24,9 +24,12 @@ import org.junit.Test;
 import org.sonar.api.batch.DecoratorContext;
 import org.sonar.api.measures.CoreMetrics;
 import org.sonar.api.measures.Measure;
+import org.sonar.api.measures.Metric;
 import org.sonar.api.resources.Project;
 import org.sonar.api.resources.Scopes;
 
+import java.util.Collection;
+
 import static org.fest.assertions.Assertions.assertThat;
 import static org.mockito.Matchers.anyDouble;
 import static org.mockito.Matchers.eq;
@@ -44,6 +47,15 @@ public class ItCoverageDecoratorTest {
     when(project.getScope()).thenReturn(Scopes.PROJECT);
   }
 
+  @Test
+  public void should_use_metrics() {
+    Collection<Metric> metrics = decorator.usedMetrics();
+
+    assertThat(metrics).containsOnly(CoreMetrics.IT_LINES_TO_COVER, CoreMetrics.IT_UNCOVERED_LINES, CoreMetrics.NEW_IT_LINES_TO_COVER,
+        CoreMetrics.NEW_IT_UNCOVERED_LINES, CoreMetrics.IT_CONDITIONS_TO_COVER, CoreMetrics.IT_UNCOVERED_CONDITIONS,
+        CoreMetrics.NEW_IT_CONDITIONS_TO_COVER, CoreMetrics.NEW_IT_UNCOVERED_CONDITIONS);
+  }
+
   @Test
   public void noCoverageWhenStaticAnalysis() {
     when(project.getAnalysisType()).thenReturn(Project.AnalysisType.STATIC);
index 57e4cb84dfa43ebd1b63a9c57ff7e4f8f4d59648..d37b7357380e9a70a050dec3657cf5ac80e48f51 100644 (file)
@@ -31,7 +31,6 @@ import org.sonar.api.measures.CoreMetrics;
 import org.sonar.api.measures.Measure;
 import org.sonar.api.resources.JavaFile;
 import org.sonar.api.resources.Project;
-import org.sonar.api.resources.ProjectFileSystem;
 import org.sonar.api.utils.SonarException;
 
 import java.io.BufferedInputStream;
@@ -47,11 +46,9 @@ public class JaCoCoAllTestsSensor implements Sensor {
   private static final String MERGED_EXEC = "target/merged.exec";
 
   private final JacocoConfiguration configuration;
-  private final ProjectFileSystem projectFileSystem;
 
-  public JaCoCoAllTestsSensor(JacocoConfiguration configuration, ProjectFileSystem projectFileSystem) {
+  public JaCoCoAllTestsSensor(JacocoConfiguration configuration) {
     this.configuration = configuration;
-    this.projectFileSystem = projectFileSystem;
   }
 
   public boolean shouldExecuteOnProject(Project project) {
@@ -60,32 +57,32 @@ public class JaCoCoAllTestsSensor implements Sensor {
   }
 
   public void analyse(Project project, SensorContext context) {
-    mergeReports();
+    mergeReports(project);
+
     new AllTestsAnalyzer().analyse(project, context);
   }
 
-  private void mergeReports() {
-    String reportUTs = configuration.getReportPath();
-    String reportITs = configuration.getItReportPath();
-    String reportAllTests = MERGED_EXEC;
+  private void mergeReports(Project project) {
+    File baseDir = project.getFileSystem().getBasedir();
 
-    File baseDir = projectFileSystem.getBasedir();
-    File destFile = new File(baseDir, reportAllTests);
+    File reportUTs = new File(baseDir, configuration.getReportPath());
+    File reportITs = new File(baseDir, configuration.getItReportPath());
+    File reportAllTests = new File(baseDir, MERGED_EXEC);
 
-    final SessionInfoStore infoStore = new SessionInfoStore();
-    final ExecutionDataStore dataStore = new ExecutionDataStore();
+    SessionInfoStore infoStore = new SessionInfoStore();
+    ExecutionDataStore dataStore = new ExecutionDataStore();
 
-    loadSourceFiles(infoStore, dataStore, new File(baseDir, reportUTs), new File(baseDir, reportITs));
+    loadSourceFiles(infoStore, dataStore, reportUTs, reportITs);
 
     BufferedOutputStream outputStream = null;
     try {
-      outputStream = new BufferedOutputStream(new FileOutputStream(destFile));
+      outputStream = new BufferedOutputStream(new FileOutputStream(reportAllTests));
       ExecutionDataWriter dataWriter = new ExecutionDataWriter(outputStream);
 
       infoStore.accept(dataWriter);
       dataStore.accept(dataWriter);
     } catch (IOException e) {
-      throw new SonarException(String.format("Unable to write merged file %s", destFile.getAbsolutePath()), e);
+      throw new SonarException(String.format("Unable to write merged file %s", reportAllTests.getAbsolutePath()), e);
     } finally {
       Closeables.closeQuietly(outputStream);
     }
@@ -122,14 +119,14 @@ public class JaCoCoAllTestsSensor implements Sensor {
     @Override
     protected void saveMeasures(SensorContext context, JavaFile resource, Collection<Measure> measures) {
       for (Measure measure : measures) {
-        Measure mergedMeasure = convertForIT(measure);
+        Measure mergedMeasure = convertForAllTests(measure);
         if (mergedMeasure != null) {
           context.saveMeasure(resource, mergedMeasure);
         }
       }
     }
 
-    private Measure convertForIT(Measure measure) {
+    private Measure convertForAllTests(Measure measure) {
       if (CoreMetrics.LINES_TO_COVER.equals(measure.getMetric())) {
         return new Measure(CoreMetrics.MERGED_LINES_TO_COVER, measure.getValue());
       } else if (CoreMetrics.UNCOVERED_LINES.equals(measure.getMetric())) {