]> source.dussan.org Git - sonarqube.git/commitdiff
Fix quality flaws
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Tue, 14 Oct 2014 12:09:39 +0000 (14:09 +0200)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Wed, 15 Oct 2014 11:29:07 +0000 (13:29 +0200)
server/sonar-server/src/main/java/org/sonar/server/db/migrations/v45/AddMissingCustomRuleParametersMigration.java
sonar-batch/src/main/java/org/sonar/batch/ProjectConfigurator.java
sonar-batch/src/main/java/org/sonar/batch/debt/SqaleRatingDecorator.java

index 4df912365da4dc761001d9e8e8dbb3d1f8fbc1c2..8d59d4d4d9ffc0b0d65c0c9fcab96c9d5fb0bc25 100644 (file)
@@ -83,21 +83,7 @@ public class AddMissingCustomRuleParametersMigration implements DatabaseMigratio
       for (Integer templateRuleId : templateRuleParamsByRuleId.keySet()) {
         for (RuleParameter templateRuleParam : templateRuleParamsByRuleId.get(templateRuleId)) {
           // Each custom rule should have this parameter
-          for (Integer customRuleId : customRuleIdsByTemplateRuleId.get(templateRuleId)) {
-            if (!hasParameter(templateRuleParam.getName(), customRuleParamsByRuleId.get(customRuleId))) {
-              // Insert new custom rule parameter
-              mapper.insertRuleParameter(new RuleParameter()
-                .setRuleId(customRuleId)
-                .setRuleTemplateId(templateRuleId)
-                .setName(templateRuleParam.getName())
-                .setDescription(templateRuleParam.getDescription())
-                .setType(templateRuleParam.getType())
-              );
-
-              // Update updated at date of custom rule in order to allow E/S indexation
-              mapper.updateRuleUpdateAt(customRuleId, new Date(system.now()));
-            }
-          }
+          insertCustomRuleParameterIfNotAlreadyExisting(templateRuleParam, templateRuleId, customRuleIdsByTemplateRuleId, customRuleParamsByRuleId, session);
         }
       }
 
@@ -107,6 +93,27 @@ public class AddMissingCustomRuleParametersMigration implements DatabaseMigratio
     }
   }
 
+  private void insertCustomRuleParameterIfNotAlreadyExisting(RuleParameter templateRuleParam, Integer templateRuleId,
+    Multimap<Integer, Integer> customRuleIdsByTemplateRuleId,
+    Multimap<Integer, RuleParameter> customRuleParamsByRuleId,
+    DbSession session) {
+    for (Integer customRuleId : customRuleIdsByTemplateRuleId.get(templateRuleId)) {
+      if (!hasParameter(templateRuleParam.getName(), customRuleParamsByRuleId.get(customRuleId))) {
+        // Insert new custom rule parameter
+        session.getMapper(Migration45Mapper.class).insertRuleParameter(new RuleParameter()
+          .setRuleId(customRuleId)
+          .setRuleTemplateId(templateRuleId)
+          .setName(templateRuleParam.getName())
+          .setDescription(templateRuleParam.getDescription())
+          .setType(templateRuleParam.getType())
+          );
+
+        // Update updated at date of custom rule in order to allow E/S indexation
+        session.getMapper(Migration45Mapper.class).updateRuleUpdateAt(customRuleId, new Date(system.now()));
+      }
+    }
+  }
+
   private boolean hasParameter(final String parameter, Collection<RuleParameter> customRuleParams) {
     return Iterables.any(customRuleParams, new Predicate<RuleParameter>() {
       @Override
index a77827817c70e5051f5e1e703bfcaf814d928f89..0d32ff92dc95c7a4dc70df64fe652441a80586f3 100644 (file)
@@ -91,7 +91,8 @@ public class ProjectConfigurator implements BatchComponent {
         throw new IllegalArgumentException(
           "'sonar.projectDate' property cannot be older than the date of the last known quality snapshot on this project. Value: '" +
             settings.getString(CoreProperties.PROJECT_DATE_PROPERTY) + "'. " +
-            "Latest quality snapshot: '" + DateUtils.formatDateTime(lastSnapshot.getCreatedAt()) + "'. This property may only be used to rebuild the past in a chronological order.");
+            "Latest quality snapshot: '" + DateUtils.formatDateTime(lastSnapshot.getCreatedAt())
+            + "'. This property may only be used to rebuild the past in a chronological order.");
       }
     }
   }
index 46dc7bbea3d870a9e314ba44a4e9395ac11bbfb5..2d18f1f54c0c937a1c3812df322668ad2db5d36b 100644 (file)
@@ -141,10 +141,10 @@ public final class SqaleRatingDecorator implements Decorator {
   }
 
   protected double computeDensity(double debt, double developmentCost) {
-    if (Double.doubleToRawLongBits(developmentCost) != 0L) {
+    if (developmentCost != 0d) {
       return debt / developmentCost;
     }
-    return 0f;
+    return 0d;
   }
 
 }