summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@gmail.com>2013-03-14 08:58:53 +0100
committerJulien Lancelot <julien.lancelot@gmail.com>2013-03-14 08:58:53 +0100
commit5c099b6733143cd647012e0f53d78e1c2698c92b (patch)
tree74d03c4de2dffa71e037ffb9db14fdd94d1bc8dd
parent19b6d3f600d8f028679718d010d24cfccc791979 (diff)
downloadsonarqube-5c099b6733143cd647012e0f53d78e1c2698c92b.tar.gz
sonarqube-5c099b6733143cd647012e0f53d78e1c2698c92b.zip
Fix quality flaws
-rw-r--r--sonar-core/src/main/java/org/sonar/core/rule/DefaultRuleFinder.java11
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/rules/Rule.java3
-rw-r--r--sonar-server/src/main/java/org/sonar/server/startup/RegisterRules.java22
3 files changed, 27 insertions, 9 deletions
diff --git a/sonar-core/src/main/java/org/sonar/core/rule/DefaultRuleFinder.java b/sonar-core/src/main/java/org/sonar/core/rule/DefaultRuleFinder.java
index e7c286d3761..f38d92cadde 100644
--- a/sonar-core/src/main/java/org/sonar/core/rule/DefaultRuleFinder.java
+++ b/sonar-core/src/main/java/org/sonar/core/rule/DefaultRuleFinder.java
@@ -17,6 +17,7 @@
* License along with Sonar; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
*/
+
package org.sonar.core.rule;
import org.apache.commons.lang.StringUtils;
@@ -50,7 +51,8 @@ public class DefaultRuleFinder implements RuleFinder {
session.createQuery("FROM " + Rule.class.getSimpleName() + " r WHERE r.id=:id and r.status<>:status")
.setParameter("id", ruleId)
.setParameter("status", RuleStatus.REMOVED.name()
- ), null);
+ ),
+ null);
}
public Rule findByKey(String repositoryKey, String key) {
@@ -64,12 +66,13 @@ public class DefaultRuleFinder implements RuleFinder {
.setParameter("key", key)
.setParameter("pluginName", repositoryKey)
.setParameter("status", RuleStatus.REMOVED.name()
- ), null);
+ ),
+ null);
}
public final Rule find(RuleQuery query) {
DatabaseSession session = sessionFactory.getSession();
- return (Rule)session.getSingleResult(createHqlQuery(session, query), null);
+ return (Rule) session.getSingleResult(createHqlQuery(session, query), null);
}
@@ -80,7 +83,7 @@ public class DefaultRuleFinder implements RuleFinder {
private Query createHqlQuery(DatabaseSession session, RuleQuery query) {
StringBuilder hql = new StringBuilder().append("from ").append(Rule.class.getSimpleName()).append(" where status<>:status ");
- Map<String,Object> params = new HashMap<String,Object>();
+ Map<String, Object> params = new HashMap<String, Object>();
params.put("status", RuleStatus.REMOVED.name());
if (StringUtils.isNotBlank(query.getRepositoryKey())) {
hql.append("AND pluginName=:repositoryKey ");
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/rules/Rule.java b/sonar-plugin-api/src/main/java/org/sonar/api/rules/Rule.java
index 2a26e0d7e16..fd0bcd66f4f 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/rules/Rule.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/rules/Rule.java
@@ -17,6 +17,7 @@
* License along with Sonar; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
*/
+
package org.sonar.api.rules;
import org.apache.commons.lang.StringUtils;
@@ -252,7 +253,7 @@ public final class Rule {
}
public Boolean isEnabled() {
- return !status.equals("REMOVED");
+ return !"REMOVED".equals(status);
}
public List<RuleParam> getParams() {
diff --git a/sonar-server/src/main/java/org/sonar/server/startup/RegisterRules.java b/sonar-server/src/main/java/org/sonar/server/startup/RegisterRules.java
index d00a336d507..9074d889ac5 100644
--- a/sonar-server/src/main/java/org/sonar/server/startup/RegisterRules.java
+++ b/sonar-server/src/main/java/org/sonar/server/startup/RegisterRules.java
@@ -17,6 +17,7 @@
* License along with Sonar; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
*/
+
package org.sonar.server.startup;
import com.google.common.base.Joiner;
@@ -105,7 +106,8 @@ public final class RegisterRules {
private void disableAllRules(DatabaseSession session) {
// the hardcoded repository "manual" is used for manual violations
- Query query = session.createQuery("UPDATE " + Rule.class.getSimpleName() + " SET status=:status, updated_at=current_timestamp WHERE parent IS NULL AND pluginName<>'manual' AND status<>:status");
+ Query query = session.createQuery(
+ "UPDATE " + Rule.class.getSimpleName() + " SET status=:status, updated_at=current_timestamp WHERE parent IS NULL AND pluginName<>'manual' AND status<>:status");
query.setParameter("status", RuleStatus.REMOVED.name());
query.executeUpdate();
}
@@ -134,11 +136,20 @@ public final class RegisterRules {
}
private void validateRule(Rule rule, String repositoryKey) {
- if (StringUtils.isBlank(rule.getName()) && StringUtils.isBlank(ruleI18nManager.getName(repositoryKey, rule.getKey(), Locale.ENGLISH))) {
+ validateRuleRepositoryName(rule, repositoryKey);
+ validateRuleDescription(rule, repositoryKey);
+ validateStatus(rule);
+ }
+
+ private void validateRuleRepositoryName(Rule rule, String repositoryKey){
+ if (Strings.isNullOrEmpty(rule.getName()) && Strings.isNullOrEmpty(ruleI18nManager.getName(repositoryKey, rule.getKey(), Locale.ENGLISH))) {
throw new SonarException("The following rule (repository: " + repositoryKey + ") must have a name: " + rule);
}
- if (StringUtils.isBlank(rule.getDescription()) && StringUtils.isBlank(ruleI18nManager.getDescription(repositoryKey, rule.getKey(), Locale.ENGLISH))) {
- if (StringUtils.isNotBlank(rule.getName()) && StringUtils.isBlank(ruleI18nManager.getName(repositoryKey, rule.getKey(), Locale.ENGLISH))) {
+ }
+
+ private void validateRuleDescription(Rule rule, String repositoryKey){
+ if (Strings.isNullOrEmpty(rule.getDescription()) && Strings.isNullOrEmpty(ruleI18nManager.getDescription(repositoryKey, rule.getKey(), Locale.ENGLISH))) {
+ if (!Strings.isNullOrEmpty(rule.getName()) && Strings.isNullOrEmpty(ruleI18nManager.getName(repositoryKey, rule.getKey(), Locale.ENGLISH))) {
// specific case
throw new SonarException("No description found for the rule '" + rule.getName() + "' (repository: " + repositoryKey + ") because the entry 'rule."
+ repositoryKey + "." + rule.getKey() + ".name' is missing from the bundle.");
@@ -146,6 +157,9 @@ public final class RegisterRules {
throw new SonarException("The following rule (repository: " + repositoryKey + ") must have a description: " + rule);
}
}
+ }
+
+ private void validateStatus(Rule rule) {
if (!Strings.isNullOrEmpty(rule.getStatus())) {
try {
Status.valueOf(rule.getStatus());