aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/scan/AnalyzerContextAdaptor.java33
-rw-r--r--sonar-core/src/test/java/org/sonar/core/component/ComponentKeysTest.java5
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/measures/RuleMeasure.java3
3 files changed, 26 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
diff --git a/sonar-core/src/test/java/org/sonar/core/component/ComponentKeysTest.java b/sonar-core/src/test/java/org/sonar/core/component/ComponentKeysTest.java
index b2248c80ee6..2e372c4261c 100644
--- a/sonar-core/src/test/java/org/sonar/core/component/ComponentKeysTest.java
+++ b/sonar-core/src/test/java/org/sonar/core/component/ComponentKeysTest.java
@@ -20,6 +20,8 @@
package org.sonar.core.component;
import org.junit.Test;
+import org.sonar.api.batch.fs.InputFile;
+import org.sonar.api.batch.fs.internal.DefaultInputFile;
import org.sonar.api.resources.Directory;
import org.sonar.api.resources.Library;
import org.sonar.api.resources.Project;
@@ -38,6 +40,9 @@ public class ComponentKeysTest {
Library library = new Library("junit:junit", "4.7");
assertThat(ComponentKeys.createEffectiveKey(project, library)).isEqualTo("junit:junit");
+
+ InputFile file = new DefaultInputFile("foo/Bar.php");
+ assertThat(ComponentKeys.createEffectiveKey("my_project", file)).isEqualTo("my_project:foo/Bar.php");
}
@Test
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/measures/RuleMeasure.java b/sonar-plugin-api/src/main/java/org/sonar/api/measures/RuleMeasure.java
index 4f966e2bab6..e6c114e5b31 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/measures/RuleMeasure.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/measures/RuleMeasure.java
@@ -45,6 +45,9 @@ public class RuleMeasure extends Measure {
this(metric, rule != null ? rule.ruleKey() : null, rulePriority, ruleCategory);
}
+ /**
+ * This constructor is for internal use only. Please use static methods createForXXX().
+ */
public RuleMeasure(Metric metric, @Nullable RuleKey ruleKey, @Nullable RulePriority rulePriority, @Nullable Integer ruleCategory) {
super(metric);
this.ruleKey = ruleKey;