summaryrefslogtreecommitdiffstats
path: root/sonar-server/src/main/java
diff options
context:
space:
mode:
authorGodin <mandrikov@gmail.com>2010-12-18 11:23:14 +0000
committerGodin <mandrikov@gmail.com>2010-12-18 11:23:14 +0000
commit733f89f53adb3364b11420a41aca1280149fbfbd (patch)
tree4ecea00cae9f804bd31987a5b5e789dfea8538e1 /sonar-server/src/main/java
parente58aaf76c2ed38afe902877c764ef4bbc2f43de6 (diff)
downloadsonarqube-733f89f53adb3364b11420a41aca1280149fbfbd.tar.gz
sonarqube-733f89f53adb3364b11420a41aca1280149fbfbd.zip
SONAR-1722: Allow to override inherited rule
Diffstat (limited to 'sonar-server/src/main/java')
-rw-r--r--sonar-server/src/main/java/org/sonar/server/configuration/ProfilesManager.java27
1 files changed, 22 insertions, 5 deletions
diff --git a/sonar-server/src/main/java/org/sonar/server/configuration/ProfilesManager.java b/sonar-server/src/main/java/org/sonar/server/configuration/ProfilesManager.java
index 2cf094e8ac0..6d692a6e7b7 100644
--- a/sonar-server/src/main/java/org/sonar/server/configuration/ProfilesManager.java
+++ b/sonar-server/src/main/java/org/sonar/server/configuration/ProfilesManager.java
@@ -87,7 +87,7 @@ public class ProfilesManager extends BaseDao {
// Activate all inherited rules
if (newParent != null) {
for (ActiveRule activeRule : newParent.getActiveRules()) {
- activate(profile, activeRule);
+ activateOrChange(profile, activeRule);
}
}
profile.setParentId(parentId);
@@ -102,8 +102,12 @@ public class ProfilesManager extends BaseDao {
public void activatedOrChanged(int parentProfileId, int activeRuleId) {
List<RulesProfile> children = getChildren(parentProfileId);
ActiveRule parentActiveRule = getSession().getEntity(ActiveRule.class, activeRuleId);
+ if (parentActiveRule.isInherited() && !parentActiveRule.isOverrides()) {
+ parentActiveRule.setOverrides(true);
+ getSession().saveWithoutFlush(parentActiveRule);
+ }
for (RulesProfile child : children) {
- activate(child, parentActiveRule);
+ activateOrChange(child, parentActiveRule);
}
getSession().commit();
}
@@ -120,10 +124,17 @@ public class ProfilesManager extends BaseDao {
getSession().commit();
}
- private void activate(RulesProfile profile, ActiveRule parentActiveRule) {
+ private void activateOrChange(RulesProfile profile, ActiveRule parentActiveRule) {
ActiveRule activeRule = profile.getActiveRule(parentActiveRule.getRule());
if (activeRule != null) {
- removeActiveRule(profile, activeRule);
+ if (activeRule.isInherited() && !activeRule.isOverrides()) {
+ removeActiveRule(profile, activeRule);
+ } else {
+ activeRule.setInherited(true);
+ activeRule.setOverrides(true);
+ getSession().saveWithoutFlush(activeRule);
+ return;
+ }
}
activeRule = (ActiveRule) parentActiveRule.clone();
activeRule.setRulesProfile(profile);
@@ -134,7 +145,13 @@ public class ProfilesManager extends BaseDao {
private void deactivate(RulesProfile profile, Rule rule) {
ActiveRule activeRule = profile.getActiveRule(rule);
if (activeRule != null) {
- removeActiveRule(profile, activeRule);
+ if (activeRule.isInherited() && !activeRule.isOverrides()) {
+ removeActiveRule(profile, activeRule);
+ } else {
+ activeRule.setInherited(false);
+ activeRule.setOverrides(false);
+ getSession().saveWithoutFlush(activeRule);
+ }
}
}