From: simonbrandhof Date: Tue, 21 Dec 2010 22:32:44 +0000 (+0000) Subject: do not persist measures with null value, null variations and "best-value" metric X-Git-Tag: 2.6~259 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=4d2ccd83150e1e769e67fb71bd4d519c6913cd6e;p=sonarqube.git do not persist measures with null value, null variations and "best-value" metric --- diff --git a/sonar-batch/src/main/java/org/sonar/batch/DefaultTimeMachine.java b/sonar-batch/src/main/java/org/sonar/batch/DefaultTimeMachine.java index d15de3d2e6b..8c22431ce83 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/DefaultTimeMachine.java +++ b/sonar-batch/src/main/java/org/sonar/batch/DefaultTimeMachine.java @@ -149,8 +149,10 @@ public class DefaultTimeMachine implements TimeMachine { measure.setVariation1(model.getVariationValue1()); measure.setVariation2(model.getVariationValue2()); measure.setVariation3(model.getVariationValue3()); + measure.setVariation4(model.getVariationValue4()); + measure.setVariation5(model.getVariationValue5()); measure.setUrl(model.getUrl()); measure.setCharacteristic(model.getCharacteristic()); return measure; } -} +} \ No newline at end of file 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 19d118db5ca..39737571315 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 @@ -90,12 +90,11 @@ public final class MeasurePersister { !(ResourceUtils.isEntity(resource) && isBestValueMeasure(measure, metric)); } - private static boolean isBestValueMeasure(Measure measure, Metric metric) { + static boolean isBestValueMeasure(Measure measure, Metric metric) { return measure.getId() == null && metric.isOptimizedBestValue() == Boolean.TRUE && metric.getBestValue() != null && - measure.getValue() != null & - NumberUtils.compare(metric.getBestValue(), measure.getValue()) == 0 && + (measure.getValue()==null || NumberUtils.compare(metric.getBestValue(), measure.getValue()) == 0) && measure.getAlertStatus() == null && measure.getDescription() == null && measure.getTendency() == null && diff --git a/sonar-batch/src/test/java/org/sonar/batch/index/MeasurePersisterTest.java b/sonar-batch/src/test/java/org/sonar/batch/index/MeasurePersisterTest.java index c14b147d84d..90d597908c5 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/index/MeasurePersisterTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/index/MeasurePersisterTest.java @@ -201,6 +201,11 @@ public class MeasurePersisterTest extends AbstractDbUnitTestCase { duplicatedLines.setVariation1(-3.0); assertThat(MeasurePersister.shouldPersistMeasure(file, duplicatedLines), is(true)); + } + @Test + public void nullValueAndNullVariationsShouldBeConsideredAsBestValue() { + Measure measure = new Measure(CoreMetrics.NEW_VIOLATIONS_KEY); + assertThat(MeasurePersister.isBestValueMeasure(measure, CoreMetrics.NEW_VIOLATIONS), is(true)); } }