diff options
author | Jean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com> | 2014-04-10 17:11:32 +0200 |
---|---|---|
committer | Jean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com> | 2014-04-10 17:11:40 +0200 |
commit | 18fbb41d409fa4b58e298de2d30581d8e1f4a3a8 (patch) | |
tree | 8da95c31da78c25c76e8cf2fc3fb60d11ef71dd9 | |
parent | 0714ae86a68f3230d1819ff02f2e26eb31e114fe (diff) | |
download | sonarqube-18fbb41d409fa4b58e298de2d30581d8e1f4a3a8.tar.gz sonarqube-18fbb41d409fa4b58e298de2d30581d8e1f4a3a8.zip |
Fix quality flaws
5 files changed, 40 insertions, 41 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/qualitygate/ConditionUtils.java b/sonar-batch/src/main/java/org/sonar/batch/qualitygate/ConditionUtils.java index 95c10767ae5..f2e5b36bbe2 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/qualitygate/ConditionUtils.java +++ b/sonar-batch/src/main/java/org/sonar/batch/qualitygate/ConditionUtils.java @@ -66,19 +66,19 @@ class ConditionUtils { } private static boolean isNotEquals(int comparison, ResolvedCondition condition) { - return condition.operator().equals("NE") && comparison == 0; + return "NE".equals(condition.operator()) && comparison == 0; } private static boolean isGreater(int comparison, ResolvedCondition condition) { - return condition.operator().equals("GT") && comparison != 1; + return "GT".equals(condition.operator()) && comparison != 1; } private static boolean isSmaller(int comparison, ResolvedCondition condition) { - return condition.operator().equals("LT") && comparison != -1; + return "LT".equals(condition.operator()) && comparison != -1; } private static boolean isEquals(int comparison, ResolvedCondition condition) { - return condition.operator().equals("EQ") && comparison != 0; + return "EQ".equals(condition.operator()) && comparison != 0; } private static String getValueToEval(ResolvedCondition condition, Metric.Level alertLevel) { diff --git a/sonar-core/src/main/java/org/sonar/core/qualitygate/db/QualityGateConditionDto.java b/sonar-core/src/main/java/org/sonar/core/qualitygate/db/QualityGateConditionDto.java index a64d43af0c8..819d271350a 100644 --- a/sonar-core/src/main/java/org/sonar/core/qualitygate/db/QualityGateConditionDto.java +++ b/sonar-core/src/main/java/org/sonar/core/qualitygate/db/QualityGateConditionDto.java @@ -19,16 +19,15 @@ */ package org.sonar.core.qualitygate.db; +import com.google.common.collect.ImmutableMap; + import com.google.common.collect.ImmutableList; import org.sonar.api.measures.Metric.ValueType; import javax.annotation.CheckForNull; import javax.annotation.Nullable; -import java.util.Collection; -import java.util.Collections; -import java.util.Date; -import java.util.List; +import java.util.*; /** * @since 4.3 @@ -63,6 +62,18 @@ public class QualityGateConditionDto { OPERATOR_EQUALS ); + private static final Map<ValueType, List<String>> OPERATORS_BY_TYPE = ImmutableMap.<ValueType, List<String>>builder() + .put(ValueType.BOOL, BOOLEAN_OPERATORS) + .put(ValueType.LEVEL, LEVEL_OPERATORS) + .put(ValueType.STRING, STRING_OPERATORS) + .put(ValueType.INT, NUMERIC_OPERATORS) + .put(ValueType.FLOAT, NUMERIC_OPERATORS) + .put(ValueType.PERCENT, NUMERIC_OPERATORS) + .put(ValueType.MILLISEC, NUMERIC_OPERATORS) + .put(ValueType.RATING, NUMERIC_OPERATORS) + .put(ValueType.WORK_DUR, NUMERIC_OPERATORS) + .build(); + private long id; private long qualityGateId; @@ -180,30 +191,10 @@ public class QualityGateConditionDto { } public static Collection<String> getOperatorsForType(ValueType metricType) { - Collection<String> operators = Collections.emptySet(); - if (metricType != null) { - switch(metricType) { - case BOOL: - operators = BOOLEAN_OPERATORS; - break; - case LEVEL: - operators = LEVEL_OPERATORS; - break; - case STRING: - operators = STRING_OPERATORS; - break; - case INT: - case FLOAT: - case PERCENT: - case MILLISEC: - case RATING: - case WORK_DUR: - operators = NUMERIC_OPERATORS; - break; - default: - operators = Collections.emptySet(); - } + if (OPERATORS_BY_TYPE.containsKey(metricType)) { + return OPERATORS_BY_TYPE.get(metricType); + } else { + return Collections.emptySet(); } - return operators; } } diff --git a/sonar-server/src/main/java/org/sonar/server/component/DefaultRubyComponentService.java b/sonar-server/src/main/java/org/sonar/server/component/DefaultRubyComponentService.java index 29293d7e326..ace86157de1 100644 --- a/sonar-server/src/main/java/org/sonar/server/component/DefaultRubyComponentService.java +++ b/sonar-server/src/main/java/org/sonar/server/component/DefaultRubyComponentService.java @@ -53,7 +53,7 @@ public class DefaultRubyComponentService implements RubyComponentService { } @Override - public Component<?> findByKey(String key) { + public Component findByKey(String key) { return resourceDao.findByKey(key); } diff --git a/sonar-server/src/main/java/org/sonar/server/qualityprofile/ProfileRuleQuery.java b/sonar-server/src/main/java/org/sonar/server/qualityprofile/ProfileRuleQuery.java index 4d3c0fc5b98..4080b760b33 100644 --- a/sonar-server/src/main/java/org/sonar/server/qualityprofile/ProfileRuleQuery.java +++ b/sonar-server/src/main/java/org/sonar/server/qualityprofile/ProfileRuleQuery.java @@ -105,6 +105,19 @@ public class ProfileRuleQuery { result.addTags(optionalVarargs(params.get(PARAM_TAGS))); } + parseInheritance(params, errors, result); + + parseParams(params, errors, result); + + if (!errors.isEmpty()) { + throw BadRequestException.of("Incorrect rule search parameters", errors); + } else { + result.profileId = RubyUtils.toInteger(params.get(PARAM_PROFILE_ID)); + } + return result; + } + + private static void parseInheritance(Map<String, Object> params, List<BadRequestException.Message> errors, ProfileRuleQuery result) { if (params.containsKey(PARAM_INHERITANCE)) { String inheritance = (String) params.get(PARAM_INHERITANCE); validateInheritance(inheritance, errors); @@ -118,7 +131,9 @@ public class ProfileRuleQuery { } else { result.setAnyInheritance(true); } + } + private static void parseParams(Map<String, Object> params, List<BadRequestException.Message> errors, ProfileRuleQuery result) { if (params.get(PARAM_SORT) != null) { String sort = (String) params.get(PARAM_SORT); Boolean asc = RubyUtils.toBoolean(params.get(PARAM_ASC)); @@ -128,13 +143,6 @@ public class ProfileRuleQuery { result.setAsc(asc); } } - - if (!errors.isEmpty()) { - throw BadRequestException.of("Incorrect rule search parameters", errors); - } else { - result.profileId = RubyUtils.toInteger(params.get(PARAM_PROFILE_ID)); - } - return result; } private static void validatePresenceOf(Map<String, Object> params, List<BadRequestException.Message> errors, String... paramNames) { diff --git a/sonar-server/src/main/java/org/sonar/server/user/DoPrivileged.java b/sonar-server/src/main/java/org/sonar/server/user/DoPrivileged.java index 9e323a63919..edae46ab7ae 100644 --- a/sonar-server/src/main/java/org/sonar/server/user/DoPrivileged.java +++ b/sonar-server/src/main/java/org/sonar/server/user/DoPrivileged.java @@ -53,7 +53,7 @@ public final class DoPrivileged { * Define a task that will be executed using the highest privileges available. The privileged section is restricted * to the execution of the {@link #doPrivileged()} method. */ - public static abstract class Task { + public abstract static class Task { /** * Code placed in this method will be executed in a privileged environment. |