aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>2015-06-23 10:28:54 +0200
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>2015-06-23 11:29:38 +0200
commit7fe7ecde39df4755d153ace94ff60433df24cf03 (patch)
treec09ad6e14d5a3ce12617f4c243fcd8656e695632
parent0bb8ab47ee7b9b00322d9a1f95fde78a8f775801 (diff)
downloadsonarqube-7fe7ecde39df4755d153ace94ff60433df24cf03.tar.gz
sonarqube-7fe7ecde39df4755d153ace94ff60433df24cf03.zip
SONAR-6646 empty measure must not be persisted
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/computation/step/PersistMeasuresStep.java15
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistMeasuresStepTest.java19
2 files changed, 32 insertions, 2 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/step/PersistMeasuresStep.java b/server/sonar-server/src/main/java/org/sonar/server/computation/step/PersistMeasuresStep.java
index d9868cd1181..46a21ac6b90 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/computation/step/PersistMeasuresStep.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/computation/step/PersistMeasuresStep.java
@@ -27,6 +27,7 @@ import com.google.common.collect.Multimap;
import java.util.Collection;
import java.util.List;
import java.util.Map;
+import javax.annotation.Nonnull;
import org.sonar.api.measures.CoreMetrics;
import org.sonar.core.measure.db.MeasureDto;
import org.sonar.core.persistence.DbSession;
@@ -108,13 +109,23 @@ public class PersistMeasuresStep implements ComputationStep {
}
Metric metric = metricRepository.getByKey(metricKey);
- Predicate<Measure> notBestValueOptimization = Predicates.not(BestValueOptimization.from(metric, component));
- for (Measure measure : from(measures.getValue()).filter(notBestValueOptimization)) {
+ Predicate<Measure> notBestValueOptimized = Predicates.not(BestValueOptimization.from(metric, component));
+ for (Measure measure : from(measures.getValue()).filter(NonEmptyMeasure.INSTANCE).filter(notBestValueOptimized)) {
MeasureDto measureDto = MeasureToMeasureDto.INSTANCE.toMeasureDto(measure, metric, componentId, snapshotId);
dbClient.measureDao().insert(session, measureDto);
}
}
}
+
+ }
+
+ private enum NonEmptyMeasure implements Predicate<Measure> {
+ INSTANCE;
+
+ @Override
+ public boolean apply(@Nonnull Measure input) {
+ return input.getValueType() != Measure.ValueType.NO_VALUE || input.hasVariations() || input.getData() != null;
+ }
}
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistMeasuresStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistMeasuresStepTest.java
index c491c9dfb39..ac7cb109e20 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistMeasuresStepTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistMeasuresStepTest.java
@@ -213,6 +213,25 @@ public class PersistMeasuresStepTest extends BaseStepTest {
assertThat(retrieveDtos()).isEmpty();
}
+ @Test
+ public void empty_values_are_not_persisted() {
+ reportReader.putMeasures(FILE_REF, Arrays.asList(
+ BatchReport.Measure.newBuilder()
+ .setValueType(MeasureValueType.STRING)
+ .setMetricKey(STRING_METRIC_KEY)
+ .build(),
+ BatchReport.Measure.newBuilder()
+ .setValueType(MeasureValueType.DOUBLE)
+ .setMetricKey(DOUBLE_METRIC_KEY)
+ .build()
+ ));
+
+ sut.execute();
+ session.commit();
+
+ assertThat(retrieveDtos()).isEmpty();
+ }
+
private ComponentDto addComponent(String key) {
ComponentDto componentDto = new ComponentDto().setKey(key).setUuid(Uuids.create());
dbClient.componentDao().insert(session, componentDto);