aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@sonarsource.com>2014-08-13 14:36:10 +0200
committerJulien Lancelot <julien.lancelot@sonarsource.com>2014-08-13 14:36:17 +0200
commit80346c2d8aaff33baf91f94817d9f22d09d94c6d (patch)
tree78a457f43b11c400985133fd8dda21b8ea6df914
parentc31f7f2abf3e622b88e557ba8bf6a425082cd2b8 (diff)
downloadsonarqube-80346c2d8aaff33baf91f94817d9f22d09d94c6d.tar.gz
sonarqube-80346c2d8aaff33baf91f94817d9f22d09d94c6d.zip
Fix quality flaw
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/batch/ProjectReferentialsAction.java2
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/measure/MeasureFilter.java3
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/rule/RegisterRules.java50
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/batch/ProjectReferentialsActionTest.java2
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/debt/SqaleRatingDecorator.java5
-rw-r--r--sonar-core/src/main/java/org/sonar/core/permission/PermissionTemplateDao.java2
6 files changed, 35 insertions, 29 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/batch/ProjectReferentialsAction.java b/server/sonar-server/src/main/java/org/sonar/server/batch/ProjectReferentialsAction.java
index 76b04cf40d6..20172488b7c 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/batch/ProjectReferentialsAction.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/batch/ProjectReferentialsAction.java
@@ -223,7 +223,7 @@ public class ProjectReferentialsAction implements RequestHandler {
private void addActiveRules(ProjectReferentials ref) {
for (org.sonar.batch.protocol.input.QProfile qProfile : ref.qProfiles()) {
for (ActiveRule activeRule : qProfileLoader.findActiveRulesByProfile(qProfile.key())) {
- Rule rule = ruleService.getByKey(activeRule.key().ruleKey());
+ Rule rule = ruleService.getNonNullByKey(activeRule.key().ruleKey());
org.sonar.batch.protocol.input.ActiveRule inputActiveRule = new org.sonar.batch.protocol.input.ActiveRule(
activeRule.key().ruleKey().repository(),
activeRule.key().ruleKey().rule(),
diff --git a/server/sonar-server/src/main/java/org/sonar/server/measure/MeasureFilter.java b/server/sonar-server/src/main/java/org/sonar/server/measure/MeasureFilter.java
index 7454d8ff930..68c07974484 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/measure/MeasureFilter.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/measure/MeasureFilter.java
@@ -98,11 +98,12 @@ public class MeasureFilter {
return userFavourites;
}
+ @CheckForNull
public String getResourceName() {
return resourceName;
}
- public MeasureFilter setResourceName(String s) {
+ public MeasureFilter setResourceName(@Nullable String s) {
this.resourceName = s;
return this;
}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/rule/RegisterRules.java b/server/sonar-server/src/main/java/org/sonar/server/rule/RegisterRules.java
index ff7817ad150..1cf8dc29103 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/rule/RegisterRules.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/rule/RegisterRules.java
@@ -99,29 +99,7 @@ public class RegisterRules implements Startable {
for (RulesDefinition.ExtendedRepository repoDef : getRepositories(context)) {
if (languages.get(repoDef.language()) != null) {
for (RulesDefinition.Rule ruleDef : repoDef.rules()) {
- RuleKey ruleKey = RuleKey.of(ruleDef.repository().key(), ruleDef.key());
-
- RuleDto rule = allRules.containsKey(ruleKey) ? allRules.remove(ruleKey) : createRuleDto(ruleDef, session);
-
- boolean executeUpdate = false;
- if (mergeRule(ruleDef, rule)) {
- executeUpdate = true;
- }
-
- CharacteristicDto subCharacteristic = characteristic(ruleDef, rule.getSubCharacteristicId(), allCharacteristics);
- if (mergeDebtDefinitions(ruleDef, rule, subCharacteristic)) {
- executeUpdate = true;
- }
-
- if (mergeTags(ruleDef, rule)) {
- executeUpdate = true;
- }
-
- if (executeUpdate) {
- dbClient.ruleDao().update(session, rule);
- }
-
- mergeParams(ruleDef, rule, session);
+ registerRule(ruleDef, allRules, allCharacteristics, session);
}
session.commit();
}
@@ -142,6 +120,32 @@ public class RegisterRules implements Startable {
// nothing
}
+ private void registerRule(RulesDefinition.Rule ruleDef, Map<RuleKey, RuleDto> allRules, Map<String, CharacteristicDto> allCharacteristics, DbSession session) {
+ RuleKey ruleKey = RuleKey.of(ruleDef.repository().key(), ruleDef.key());
+
+ RuleDto rule = allRules.containsKey(ruleKey) ? allRules.remove(ruleKey) : createRuleDto(ruleDef, session);
+
+ boolean executeUpdate = false;
+ if (mergeRule(ruleDef, rule)) {
+ executeUpdate = true;
+ }
+
+ CharacteristicDto subCharacteristic = characteristic(ruleDef, rule.getSubCharacteristicId(), allCharacteristics);
+ if (mergeDebtDefinitions(ruleDef, rule, subCharacteristic)) {
+ executeUpdate = true;
+ }
+
+ if (mergeTags(ruleDef, rule)) {
+ executeUpdate = true;
+ }
+
+ if (executeUpdate) {
+ dbClient.ruleDao().update(session, rule);
+ }
+
+ mergeParams(ruleDef, rule, session);
+ }
+
private Map<RuleKey, RuleDto> loadRules(DbSession session) {
Map<RuleKey, RuleDto> rules = new HashMap<RuleKey, RuleDto>();
for (RuleDto rule : dbClient.ruleDao().findByNonManual(session)) {
diff --git a/server/sonar-server/src/test/java/org/sonar/server/batch/ProjectReferentialsActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/batch/ProjectReferentialsActionTest.java
index 75ea4a1fb6f..a2afc2d7a85 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/batch/ProjectReferentialsActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/batch/ProjectReferentialsActionTest.java
@@ -379,7 +379,7 @@ public class ProjectReferentialsActionTest {
Rule rule = mock(Rule.class);
when(rule.name()).thenReturn("Avoid Cycle");
when(rule.internalKey()).thenReturn("squid-1");
- when(ruleService.getByKey(ruleKey)).thenReturn(rule);
+ when(ruleService.getNonNullByKey(ruleKey)).thenReturn(rule);
WsTester.TestRequest request = tester.newGetRequest("batch", "project").setParam("key", projectKey);
request.execute().assertJson(getClass(), "return_active_rules.json");
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 41b2af1fafa..35672b85d2b 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
@@ -122,8 +122,9 @@ public final class SqaleRatingDecorator implements Decorator {
}
double sum = 0d;
for (Measure measure : measures) {
- if (measure.getData() != null) {
- sum += Double.parseDouble(measure.getData());
+ String data = measure.getData();
+ if (data != null) {
+ sum += Double.parseDouble(data);
}
}
return sum;
diff --git a/sonar-core/src/main/java/org/sonar/core/permission/PermissionTemplateDao.java b/sonar-core/src/main/java/org/sonar/core/permission/PermissionTemplateDao.java
index c28804d6d9b..fccb4fa09f4 100644
--- a/sonar-core/src/main/java/org/sonar/core/permission/PermissionTemplateDao.java
+++ b/sonar-core/src/main/java/org/sonar/core/permission/PermissionTemplateDao.java
@@ -249,7 +249,7 @@ public class PermissionTemplateDao implements TaskComponent, ServerComponent {
* Remove a group from all templates (used when removing a group)
*/
public void removeByGroup(Long groupId, SqlSession session) {
- session.getMapper(PermissionTemplateMapper.class).deleteByGroupId(groupId);
+ session.getMapper(PermissionTemplateMapper.class).deleteByGroupId(groupId);
}
private String generateTemplateKee(String name, Date timeStamp) {