diff options
author | Simon Brandhof <simon.brandhof@sonarsource.com> | 2014-06-04 16:26:19 +0200 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@sonarsource.com> | 2014-06-04 16:26:28 +0200 |
commit | e35c7a6d9aaf8bfc8a5e28b573ea2ecf42434c59 (patch) | |
tree | 7bd66e8dda8ec6e9531f71d8cca17ec454b6f738 | |
parent | a7a3c8ad4ebc217db744f6dcde43d7604e9e53bf (diff) | |
download | sonarqube-e35c7a6d9aaf8bfc8a5e28b573ea2ecf42434c59.tar.gz sonarqube-e35c7a6d9aaf8bfc8a5e28b573ea2ecf42434c59.zip |
SONAR-5007 clear preview cache on rule changes
-rw-r--r-- | sonar-server/src/main/java/org/sonar/server/qualityprofile/RuleActivator.java | 40 |
1 files changed, 16 insertions, 24 deletions
diff --git a/sonar-server/src/main/java/org/sonar/server/qualityprofile/RuleActivator.java b/sonar-server/src/main/java/org/sonar/server/qualityprofile/RuleActivator.java index 9e89b4f0111..960cdc38021 100644 --- a/sonar-server/src/main/java/org/sonar/server/qualityprofile/RuleActivator.java +++ b/sonar-server/src/main/java/org/sonar/server/qualityprofile/RuleActivator.java @@ -87,21 +87,12 @@ public class RuleActivator implements ServerComponent { List<ActiveRuleChange> activate(RuleActivation activation) { DbSession dbSession = db.openSession(false); try { - List<ActiveRuleChange> changes = activate(dbSession, activation); - if (!changes.isEmpty()) { - log.write(dbSession, changes); - dbSession.commit(); - previewCache.reportGlobalModification(); - } - return changes; + return activate(dbSession, activation); } finally { dbSession.close(); } } - /** - * Activate the rule WITHOUT committing db session - */ List<ActiveRuleChange> activate(DbSession dbSession, RuleActivation activation) { RuleActivationContext context = contextFactory.create(activation.getKey(), dbSession); List<ActiveRuleChange> changes = Lists.newArrayList(); @@ -147,7 +138,11 @@ public class RuleActivator implements ServerComponent { // Execute the cascade on the child if NOT overrides changes.addAll(cascadeActivation(dbSession, activation)); - log.write(dbSession, changes); + if (!changes.isEmpty()) { + log.write(dbSession, changes); + dbSession.commit(); + previewCache.reportGlobalModification(); + } return changes; } @@ -232,20 +227,11 @@ public class RuleActivator implements ServerComponent { */ List<ActiveRuleChange> deactivate(ActiveRuleKey key) { DbSession dbSession = db.openSession(false); - List<ActiveRuleChange> changes = Lists.newArrayList(); try { - changes.addAll(this.deactivate(key, dbSession)); - if (!changes.isEmpty()) { - log.write(dbSession, changes); - dbSession.commit(); - } - } finally - - { + return deactivate(key, dbSession); + } finally { dbSession.close(); } - - return changes; } /** @@ -280,6 +266,12 @@ public class RuleActivator implements ServerComponent { changes.addAll(cascadeDeactivation(activeRuleKey, dbSession, true)); } + if (!changes.isEmpty()) { + log.write(dbSession, changes); + dbSession.commit(); + previewCache.reportGlobalModification(); + } + return changes; } @@ -313,7 +305,7 @@ public class RuleActivator implements ServerComponent { ActiveRuleKey key = ActiveRuleKey.of(profileKey, rule.key()); RuleActivation activation = new RuleActivation(key); activation.setSeverity(severity); - for (ActiveRuleChange active : this.activate(dbSession, activation)) { + for (ActiveRuleChange active : activate(dbSession, activation)) { results.put("activated", active.getKey().ruleKey().toString()); } } else { @@ -337,7 +329,7 @@ public class RuleActivator implements ServerComponent { for (Rule rule : result.getHits()) { ActiveRuleKey key = ActiveRuleKey.of(profile, rule.key()); - for (ActiveRuleChange deActive : this.deactivate(key, dbSession)) { + for (ActiveRuleChange deActive : deactivate(key, dbSession)) { results.put("deactivated", deActive.getKey().ruleKey().toString()); } } |