aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/UnitTestDecorator.java2
-rw-r--r--plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/UnitTestDecoratorTest.java8
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/index/Bucket.java4
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/index/MeasurePersister.java5
4 files changed, 17 insertions, 2 deletions
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/UnitTestDecorator.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/UnitTestDecorator.java
index 6ee37e94669..6fca0264d7d 100644
--- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/UnitTestDecorator.java
+++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/UnitTestDecorator.java
@@ -46,7 +46,7 @@ public class UnitTestDecorator implements Decorator {
}
public boolean shouldDecorateResource(Resource resource, DecoratorContext context) {
- return context.getMeasure(CoreMetrics.TESTS) == null && (ResourceUtils.isUnitTestClass(resource) || !ResourceUtils.isEntity(resource));
+ return ResourceUtils.isUnitTestClass(resource) || !ResourceUtils.isEntity(resource);
}
public void decorate(Resource resource, DecoratorContext context) {
diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/UnitTestDecoratorTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/UnitTestDecoratorTest.java
index d1b23f797f7..4f52830b5de 100644
--- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/UnitTestDecoratorTest.java
+++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/UnitTestDecoratorTest.java
@@ -20,6 +20,7 @@
package org.sonar.plugins.core.sensors;
import org.junit.Before;
+import org.junit.Ignore;
import org.junit.Test;
import org.sonar.api.batch.DecoratorContext;
import org.sonar.api.measures.CoreMetrics;
@@ -33,7 +34,11 @@ import static org.fest.assertions.Assertions.assertThat;
import static org.hamcrest.Matchers.closeTo;
import static org.mockito.Matchers.doubleThat;
import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.*;
+import static org.mockito.Mockito.atLeastOnce;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyNoMoreInteractions;
+import static org.mockito.Mockito.when;
public class UnitTestDecoratorTest {
@@ -85,6 +90,7 @@ public class UnitTestDecoratorTest {
}
@Test
+ @Ignore("Hack for SONAR-5212")
public void doNotDecorateIfTestsMeasureAlreadyExists() {
Project project = mock(Project.class);
when(context.getMeasure(CoreMetrics.TESTS)).thenReturn(new Measure());
diff --git a/sonar-batch/src/main/java/org/sonar/batch/index/Bucket.java b/sonar-batch/src/main/java/org/sonar/batch/index/Bucket.java
index 551c25327f3..af6a87ae8a6 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/index/Bucket.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/index/Bucket.java
@@ -22,6 +22,7 @@ package org.sonar.batch.index;
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.ListMultimap;
import com.google.common.collect.Lists;
+import org.sonar.api.measures.CoreMetrics;
import org.sonar.api.measures.Measure;
import org.sonar.api.measures.MeasuresFilter;
import org.sonar.api.measures.MeasuresFilters;
@@ -87,6 +88,9 @@ public final class Bucket {
if (index > -1) {
if (metricMeasures.get(index) == measure) {
add = false;
+ } else if (measure.getMetric().equals(CoreMetrics.TESTS)) {
+ // Hack for SONAR-5212
+ measuresByMetric.remove(measure.getMetric().getKey(), metricMeasures.get(index));
} else {
throw new SonarException("Can not add twice the same measure on " + resource + ": " + measure);
}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/index/MeasurePersister.java b/sonar-batch/src/main/java/org/sonar/batch/index/MeasurePersister.java
index 564ee82ec72..8e61a931bd0 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/index/MeasurePersister.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/index/MeasurePersister.java
@@ -28,6 +28,7 @@ import org.slf4j.LoggerFactory;
import org.sonar.api.database.model.MeasureMapper;
import org.sonar.api.database.model.MeasureModel;
import org.sonar.api.database.model.Snapshot;
+import org.sonar.api.measures.CoreMetrics;
import org.sonar.api.measures.Measure;
import org.sonar.api.measures.RuleMeasure;
import org.sonar.api.resources.Resource;
@@ -73,6 +74,10 @@ public final class MeasurePersister {
public void saveMeasure(Resource resource, Measure measure) {
if (shouldSaveLater(measure)) {
+ if (measure.getMetric().equals(CoreMetrics.TESTS) && unsavedMeasuresByResource.get(resource).contains(measure)) {
+ // Hack for SONAR-5212
+ unsavedMeasuresByResource.remove(resource, measure);
+ }
unsavedMeasuresByResource.put(resource, measure);
return;
}