]> source.dussan.org Git - sonarqube.git/commitdiff
Fix some quality flaws
authorJulien HENRY <julien.henry@sonarsource.com>
Tue, 1 Jul 2014 14:40:43 +0000 (16:40 +0200)
committerJulien HENRY <julien.henry@sonarsource.com>
Tue, 1 Jul 2014 14:41:04 +0000 (16:41 +0200)
sonar-batch/src/main/java/org/sonar/batch/scan/AnalyzerContextAdaptor.java
sonar-core/src/test/java/org/sonar/core/component/ComponentKeysTest.java
sonar-plugin-api/src/main/java/org/sonar/api/measures/RuleMeasure.java

index d92769f308cc5489d920d506130c3975bb8536e0..8b883db44832a1693f871604fd1113500e5e3df0 100644 (file)
@@ -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
index b2248c80ee601c8e359d37b1c9a2d8bc1f662cf2..2e372c4261cc184ce3d449f6baaf40f7ff93b22f 100644 (file)
@@ -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
index 4f966e2bab6eed6944de8000e9965ca3d2221bb3..e6c114e5b3151bf827ba41bf64b49356f6faebbb 100644 (file)
@@ -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;