aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-server/src/main
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
parente58aaf76c2ed38afe902877c764ef4bbc2f43de6 (diff)
downloadsonarqube-733f89f53adb3364b11420a41aca1280149fbfbd.tar.gz
sonarqube-733f89f53adb3364b11420a41aca1280149fbfbd.zip
SONAR-1722: Allow to override inherited rule
Diffstat (limited to 'sonar-server/src/main')
-rw-r--r--sonar-server/src/main/java/org/sonar/server/configuration/ProfilesManager.java27
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/views/rules_configuration/_rule.html.erb18
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/views/rules_configuration/_rule_param.html.erb3
3 files changed, 35 insertions, 13 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);
+ }
}
}
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/rules_configuration/_rule.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/rules_configuration/_rule.html.erb
index d8e131ce0d8..d612abf3f3f 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/views/rules_configuration/_rule.html.erb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/views/rules_configuration/_rule.html.erb
@@ -1,10 +1,9 @@
<td nowrap valign="top" class="left" x="<%= active_rule.failure_level if active_rule -%>" width="1%">
- <% inherited = active_rule.inherited if active_rule %>
- <% if inherited %>
- Inherited from parent profile.
- <% end %>
+ <% inherited = active_rule.inherited if active_rule
+ overrides = active_rule.overrides if active_rule
+ %>
<form id="levels_<%= rule.id -%>" action="">
- <% enable_modification = is_admin && !profile.provided? && !inherited
+ <% enable_modification = is_admin && !profile.provided?
select_box_id = "levels_select_#{rule.id}"
check_box_id = "levels_check_#{rule.id}"
rule_select_box = "$('#{select_box_id}')"
@@ -18,13 +17,20 @@
:loading => "$('levels_#{rule.id}').replace('<img src=\"#{ApplicationController.root_context}/images/loading.gif\"/>');",
:with => "'level=' + get_level_for_rule(#{rule_select_box},#{rule_check_box})")
%>
- <%= check_box_tag(check_box_id, 'yes', (!active_rule.nil?), :onclick => activate_rule, :disabled => !enable_modification) %>
+ <%= check_box_tag(check_box_id, 'yes', (!active_rule.nil?), :onclick => activate_rule, :disabled => !enable_modification || inherited) %>
<%= select_tag(select_box_id, options_for_select(RulesConfigurationController::RULE_PRIORITIES, (active_rule.nil? ? rule.priority_text : active_rule.priority_text)),
{:onchange => changel_level, :disabled => (!(enable_modification) || active_rule.nil?)}) %>
</form>
</td>
<td valign="top" class="left">
+ <% if inherited %>
+ <% if overrides %>
+ Overrides rule from parent profile.<br/>
+ <% else %>
+ Inherited from parent profile.<br/>
+ <% end %>
+ <% end %>
<%= link_to_function("#{h rule.name}", nil, :class => "") do |page|
page.toggle "desc_#{rule.id}"
end
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/rules_configuration/_rule_param.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/rules_configuration/_rule_param.html.erb
index 15f91b19ed4..c695a0218b7 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/views/rules_configuration/_rule_param.html.erb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/views/rules_configuration/_rule_param.html.erb
@@ -6,8 +6,7 @@
param_value = active_parameter.value unless active_parameter.value.blank?
end
active_rule_id = active_rule.id if active_rule
- inherited = active_rule.inherited if active_rule
- enable_modification = is_admin && !profile.provided? && !inherited
+ enable_modification = is_admin && !profile.provided?
%>
<tr>
<td width="10%" nowrap class="left">