diff options
author | simonbrandhof <simon.brandhof@gmail.com> | 2010-11-30 10:24:48 +0000 |
---|---|---|
committer | simonbrandhof <simon.brandhof@gmail.com> | 2010-11-30 10:24:48 +0000 |
commit | 0b875cc83530e92fdf5a22d9d808aee1cc33ea91 (patch) | |
tree | 4d62775c3edb689ce9567a6db14ae6b2892f138a /sonar-batch | |
parent | 0471c891fff652b0c243a20fc68b8563f92c293d (diff) | |
download | sonarqube-0b875cc83530e92fdf5a22d9d808aee1cc33ea91.tar.gz sonarqube-0b875cc83530e92fdf5a22d9d808aee1cc33ea91.zip |
SONAR-249 fix detection of "best value measures" in delayed mode
Diffstat (limited to 'sonar-batch')
-rw-r--r-- | sonar-batch/src/main/java/org/sonar/batch/index/MeasurePersister.java | 46 |
1 files changed, 27 insertions, 19 deletions
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 4b7c47b21fc..ca648c07f42 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 @@ -62,7 +62,8 @@ public final class MeasurePersister { } public void saveMeasure(Project project, Resource resource, Measure measure) { - if (delayedMode && measure.getPersistenceMode().useMemory()) { + boolean saveLater = (measure.getPersistenceMode().useMemory() && delayedMode); + if (saveLater) { unsavedMeasuresByResource.put(resource, measure); } else { @@ -85,30 +86,37 @@ public final class MeasurePersister { static boolean shouldPersistMeasure(Resource resource, Measure measure) { Metric metric = measure.getMetric(); - return measure.getPersistenceMode().useDatabase() && !( - ResourceUtils.isEntity(resource) && - metric.isOptimizedBestValue() == Boolean.TRUE && - metric.getBestValue() != null && - NumberUtils.compare(metric.getBestValue(), measure.getValue()) == 0 && - measure.getAlertStatus()==null && - measure.getDescription()==null && - measure.getTendency()==null && - measure.getUrl()==null && - measure.getData()==null && - (measure.getDiffValue1() == null || NumberUtils.compare(measure.getDiffValue1().doubleValue(), 0.0) == 0) && - (measure.getDiffValue2() == null || NumberUtils.compare(measure.getDiffValue2().doubleValue(), 0.0) == 0) && - (measure.getDiffValue3() == null || NumberUtils.compare(measure.getDiffValue3().doubleValue(), 0.0) == 0)); + return measure.getPersistenceMode().useDatabase() && + !(ResourceUtils.isEntity(resource) && isBestValueMeasure(measure, metric)); + } + + private static boolean isBestValueMeasure(Measure measure, Metric metric) { + return measure.getId() == null && + metric.isOptimizedBestValue() == Boolean.TRUE && + metric.getBestValue() != null && + NumberUtils.compare(metric.getBestValue(), measure.getValue()) == 0 && + measure.getAlertStatus() == null && + measure.getDescription() == null && + measure.getTendency() == null && + measure.getUrl() == null && + measure.getData() == null && + (measure.getDiffValue1() == null || NumberUtils.compare(measure.getDiffValue1().doubleValue(), 0.0) == 0) && + (measure.getDiffValue2() == null || NumberUtils.compare(measure.getDiffValue2().doubleValue(), 0.0) == 0) && + (measure.getDiffValue3() == null || NumberUtils.compare(measure.getDiffValue3().doubleValue(), 0.0) == 0); } public void dump() { LoggerFactory.getLogger(getClass()).debug("{} measures to dump", unsavedMeasuresByResource.size()); Map<Resource, Collection<Measure>> map = unsavedMeasuresByResource.asMap(); for (Map.Entry<Resource, Collection<Measure>> entry : map.entrySet()) { + Resource resource = entry.getKey(); Snapshot snapshot = resourcePersister.getSnapshot(entry.getKey()); for (Measure measure : entry.getValue()) { - MeasureModel model = createModel(measure); - model.setSnapshotId(snapshot.getId()); - model.save(session); + if (shouldPersistMeasure(resource, measure)) { + MeasureModel model = createModel(measure); + model.setSnapshotId(snapshot.getId()); + model.save(session); + } } } @@ -141,9 +149,9 @@ public final class MeasurePersister { RuleMeasure ruleMeasure = (RuleMeasure) measure; merge.setRulesCategoryId(ruleMeasure.getRuleCategory()); merge.setRulePriority(ruleMeasure.getRulePriority()); - if (ruleMeasure.getRule()!=null) { + if (ruleMeasure.getRule() != null) { Rule ruleWithId = ruleFinder.findByKey(ruleMeasure.getRule().getRepositoryKey(), ruleMeasure.getRule().getKey()); - if (ruleWithId!=null) { + if (ruleWithId != null) { merge.setRuleId(ruleWithId.getId()); } else { throw new SonarException("Can not save a measure with unknown rule " + ruleMeasure); |