aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@sonarsource.com>2014-04-10 17:51:28 +0200
committerJulien Lancelot <julien.lancelot@sonarsource.com>2014-04-10 17:51:36 +0200
commit14dcfc4c94b47fe38489a30725eddb6b12814084 (patch)
treec1b2f29a848aa53a31fab371324944f5477f252a
parent16e3e24652fbcc70741310fe1ebdb9227bb66053 (diff)
downloadsonarqube-14dcfc4c94b47fe38489a30725eddb6b12814084.tar.gz
sonarqube-14dcfc4c94b47fe38489a30725eddb6b12814084.zip
Fix quality flaws
-rw-r--r--sonar-server/src/main/java/org/sonar/server/db/migrations/MassUpdater.java11
-rw-r--r--sonar-server/src/main/java/org/sonar/server/rule/DeprecatedRulesDefinition.java33
2 files changed, 24 insertions, 20 deletions
diff --git a/sonar-server/src/main/java/org/sonar/server/db/migrations/MassUpdater.java b/sonar-server/src/main/java/org/sonar/server/db/migrations/MassUpdater.java
index a6e861e4202..0a603ab3a4a 100644
--- a/sonar-server/src/main/java/org/sonar/server/db/migrations/MassUpdater.java
+++ b/sonar-server/src/main/java/org/sonar/server/db/migrations/MassUpdater.java
@@ -123,13 +123,10 @@ public class MassUpdater {
@VisibleForTesting
static String convertSelectSql(String selectSql, Database db){
- // Replace ${_true}
- selectSql = selectSql.replace("${_true}", db.getDialect().getTrueSqlValue());
-
- // Replace ${_false}
- selectSql = selectSql.replace("${_false}", db.getDialect().getFalseSqlValue());
-
- return selectSql;
+ String newSelectSql = selectSql;
+ newSelectSql = newSelectSql.replace("${_true}", db.getDialect().getTrueSqlValue());
+ newSelectSql = newSelectSql.replace("${_false}", db.getDialect().getFalseSqlValue());
+ return newSelectSql;
}
}
diff --git a/sonar-server/src/main/java/org/sonar/server/rule/DeprecatedRulesDefinition.java b/sonar-server/src/main/java/org/sonar/server/rule/DeprecatedRulesDefinition.java
index b5a822d3209..dc57c863c73 100644
--- a/sonar-server/src/main/java/org/sonar/server/rule/DeprecatedRulesDefinition.java
+++ b/sonar-server/src/main/java/org/sonar/server/rule/DeprecatedRulesDefinition.java
@@ -40,6 +40,7 @@ import org.sonar.server.debt.DebtModelXMLExporter;
import org.sonar.server.debt.DebtRulesXMLImporter;
import javax.annotation.CheckForNull;
+import javax.annotation.Nullable;
import java.io.Reader;
import java.util.Collection;
@@ -117,23 +118,29 @@ public class DeprecatedRulesDefinition implements RulesDefinition {
LOG.warn(String.format("'%s:%s' is a rule template, it should not define technical debt. Its debt definition will be ignored.", repoKey, ruleKey));
} else {
newRule.setDebtSubCharacteristic(ruleDebt.subCharacteristicKey());
- String function = ruleDebt.function();
- String coefficient = ruleDebt.coefficient();
- String offset = ruleDebt.offset();
-
- if (DebtRemediationFunction.Type.LINEAR.name().equals(function) && coefficient != null) {
- newRule.setDebtRemediationFunction(newRule.debtRemediationFunctions().linear(coefficient));
- } else if (DebtRemediationFunction.Type.CONSTANT_ISSUE.name().equals(function) && offset != null) {
- newRule.setDebtRemediationFunction(newRule.debtRemediationFunctions().constantPerIssue(offset));
- } else if (DebtRemediationFunction.Type.LINEAR_OFFSET.name().equals(function) && coefficient != null && offset != null) {
- newRule.setDebtRemediationFunction(newRule.debtRemediationFunctions().linearWithOffset(coefficient, offset));
- } else {
- throw new IllegalArgumentException(String.format("Debt definition on rule '%s:%s' is invalid", repoKey, ruleKey));
- }
+ newRule.setDebtRemediationFunction(remediationFunction(DebtRemediationFunction.Type.valueOf(ruleDebt.function()),
+ ruleDebt.coefficient(),
+ ruleDebt.offset(),
+ newRule.debtRemediationFunctions(),
+ repoKey, ruleKey
+ ));
}
}
}
+ private DebtRemediationFunction remediationFunction(DebtRemediationFunction.Type function, @Nullable String coefficient, @Nullable String offset,
+ DebtRemediationFunctions functions, String repoKey, String ruleKey) {
+ if (DebtRemediationFunction.Type.LINEAR.equals(function) && coefficient != null) {
+ return functions.linear(coefficient);
+ } else if (DebtRemediationFunction.Type.CONSTANT_ISSUE.equals(function) && offset != null) {
+ return functions.constantPerIssue(offset);
+ } else if (DebtRemediationFunction.Type.LINEAR_OFFSET.equals(function) && coefficient != null && offset != null) {
+ return functions.linearWithOffset(coefficient, offset);
+ } else {
+ throw new IllegalArgumentException(String.format("Debt definition on rule '%s:%s' is invalid", repoKey, ruleKey));
+ }
+ }
+
@CheckForNull
private String ruleName(String repositoryKey, org.sonar.api.rules.Rule rule) {
String name = i18n.getName(repositoryKey, rule.getKey());