}
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()));
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
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;
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