From: Julien Lancelot Date: Tue, 14 Oct 2014 12:09:39 +0000 (+0200) Subject: Fix quality flaws X-Git-Tag: 5.0-RC1~696 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=6cde9e5850019be8e90b4dd1ea6c89263b1fcdae;p=sonarqube.git Fix quality flaws --- diff --git a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v45/AddMissingCustomRuleParametersMigration.java b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v45/AddMissingCustomRuleParametersMigration.java index 4df912365da..8d59d4d4d9f 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v45/AddMissingCustomRuleParametersMigration.java +++ b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v45/AddMissingCustomRuleParametersMigration.java @@ -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 customRuleIdsByTemplateRuleId, + Multimap 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 customRuleParams) { return Iterables.any(customRuleParams, new Predicate() { @Override diff --git a/sonar-batch/src/main/java/org/sonar/batch/ProjectConfigurator.java b/sonar-batch/src/main/java/org/sonar/batch/ProjectConfigurator.java index a77827817c7..0d32ff92dc9 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/ProjectConfigurator.java +++ b/sonar-batch/src/main/java/org/sonar/batch/ProjectConfigurator.java @@ -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."); } } } diff --git a/sonar-batch/src/main/java/org/sonar/batch/debt/SqaleRatingDecorator.java b/sonar-batch/src/main/java/org/sonar/batch/debt/SqaleRatingDecorator.java index 46dc7bbea3d..2d18f1f54c0 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/debt/SqaleRatingDecorator.java +++ b/sonar-batch/src/main/java/org/sonar/batch/debt/SqaleRatingDecorator.java @@ -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; } }