aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-batch
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2014-07-01 16:40:43 +0200
committerJulien HENRY <julien.henry@sonarsource.com>2014-07-01 16:41:04 +0200
commitd223c5ded79b36396ad2b4b16dbbe1dd2dc24cd1 (patch)
treedae952a9f10660f4fba3636d64c034023238026e /sonar-batch
parente7b58a71656a61b36449afdd76ba4eaacc44f950 (diff)
downloadsonarqube-d223c5ded79b36396ad2b4b16dbbe1dd2dc24cd1.tar.gz
sonarqube-d223c5ded79b36396ad2b4b16dbbe1dd2dc24cd1.zip
Fix some quality flaws
Diffstat (limited to 'sonar-batch')
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/scan/AnalyzerContextAdaptor.java33
1 files changed, 18 insertions, 15 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/AnalyzerContextAdaptor.java b/sonar-batch/src/main/java/org/sonar/batch/scan/AnalyzerContextAdaptor.java
index d92769f308c..8b883db4483 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/scan/AnalyzerContextAdaptor.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/scan/AnalyzerContextAdaptor.java
@@ -151,24 +151,39 @@ public class AnalyzerContextAdaptor implements AnalyzerContext {
}
Measure measureToSave = new Measure(m);
+ setValueAccordingToMetricType(measure, m, measureToSave);
+ if (measure.inputFile() != null) {
+ Formula formula = measure.metric() instanceof org.sonar.api.measures.Metric ?
+ ((org.sonar.api.measures.Metric) measure.metric()).getFormula() : null;
+ if (formula instanceof SumChildDistributionFormula
+ && !Scopes.isHigherThanOrEquals(Scopes.FILE, ((SumChildDistributionFormula) formula).getMinimumScopeToPersist())) {
+ measureToSave.setPersistenceMode(PersistenceMode.MEMORY);
+ }
+ sensorContext.saveMeasure(measure.inputFile(), measureToSave);
+ } else {
+ sensorContext.saveMeasure(measureToSave);
+ }
+ }
+
+ private void setValueAccordingToMetricType(AnalyzerMeasure<?> measure, org.sonar.api.measures.Metric<?> m, Measure measureToSave) {
switch (m.getType()) {
case BOOL:
measureToSave.setValue(Boolean.TRUE.equals(measure.value()) ? 1.0 : 0.0);
break;
case INT:
case MILLISEC:
- measureToSave.setValue(Double.valueOf(((Integer) measure.value())));
+ measureToSave.setValue(Double.valueOf((Integer) measure.value()));
break;
case FLOAT:
case PERCENT:
case RATING:
- measureToSave.setValue(((Double) measure.value()));
+ measureToSave.setValue((Double) measure.value());
break;
case STRING:
case LEVEL:
case DATA:
case DISTRIB:
- measureToSave.setData(((String) measure.value()));
+ measureToSave.setData((String) measure.value());
break;
case WORK_DUR:
measureToSave.setValue(Double.valueOf((Long) measure.value()));
@@ -182,18 +197,6 @@ public class AnalyzerContextAdaptor implements AnalyzerContext {
throw new UnsupportedOperationException("Unsupported type :" + m.getType());
}
}
- if (measure.inputFile() != null) {
- Formula formula = measure.metric() instanceof org.sonar.api.measures.Metric ?
- ((org.sonar.api.measures.Metric) measure.metric()).getFormula() : null;
- if (formula instanceof SumChildDistributionFormula) {
- if (!Scopes.isHigherThanOrEquals(Scopes.FILE, ((SumChildDistributionFormula) formula).getMinimumScopeToPersist())) {
- measureToSave.setPersistenceMode(PersistenceMode.MEMORY);
- }
- }
- sensorContext.saveMeasure(measure.inputFile(), measureToSave);
- } else {
- sensorContext.saveMeasure(measureToSave);
- }
}
@Override