From: Godin Date: Tue, 21 Dec 2010 22:45:14 +0000 (+0000) Subject: SONAR-1722: Merge two fields ActiveRule.inherited and ActiveRule.overridden into... X-Git-Tag: 2.6~258 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=2398469a24eb259e8b8de911a373bb49615d761c;p=sonarqube.git SONAR-1722: Merge two fields ActiveRule.inherited and ActiveRule.overridden into one with enum type --- diff --git a/sonar-core/src/test/resources/org/sonar/jpa/dao/RulesDaoTest/shouldAddActiveRulesToProfile-result.xml b/sonar-core/src/test/resources/org/sonar/jpa/dao/RulesDaoTest/shouldAddActiveRulesToProfile-result.xml index 10c18638842..808647dd2aa 100644 --- a/sonar-core/src/test/resources/org/sonar/jpa/dao/RulesDaoTest/shouldAddActiveRulesToProfile-result.xml +++ b/sonar-core/src/test/resources/org/sonar/jpa/dao/RulesDaoTest/shouldAddActiveRulesToProfile-result.xml @@ -10,7 +10,7 @@ - + diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/rules/ActiveRule.java b/sonar-plugin-api/src/main/java/org/sonar/api/rules/ActiveRule.java index badb3bb2492..1ebab335157 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/rules/ActiveRule.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/rules/ActiveRule.java @@ -58,10 +58,8 @@ public class ActiveRule implements Cloneable { private List activeRuleParams = new ArrayList(); @Column(name = "inherited", updatable = true, nullable = true) - private Boolean inherited; - - @Column(name = "overridden", updatable = true, nullable = true) - private Boolean overridden; + @Enumerated(EnumType.ORDINAL) + private ActiveRuleInheritanceStatus inherited = ActiveRuleInheritanceStatus.NO; /** * @deprecated visibility should be reduced to protected or package @@ -94,26 +92,8 @@ public class ActiveRule implements Cloneable { * * @since 2.5 */ - public boolean isInherited() { - return inherited == null ? false : inherited; - } - - /** - * For internal use only. - * - * @since 2.5 - */ - public void setInherited(boolean inherited) { - this.inherited = inherited; - } - - /** - * For internal use only. - * - * @since 2.5 - */ - public boolean isOverridden() { - return overridden == null ? false : overridden; + public ActiveRuleInheritanceStatus getInheritanceStatus() { + return inherited == null ? ActiveRuleInheritanceStatus.NO : inherited; } /** @@ -121,8 +101,8 @@ public class ActiveRule implements Cloneable { * * @since 2.5 */ - public void setOverridden(Boolean overridden) { - this.overridden = overridden; + public void setInheritanceStatus(ActiveRuleInheritanceStatus status) { + this.inherited = status; } /** @@ -279,8 +259,7 @@ public class ActiveRule implements Cloneable { @Override public Object clone() { final ActiveRule clone = new ActiveRule(getRulesProfile(), getRule(), getSeverity()); - clone.setInherited(isInherited()); - clone.setOverridden(isOverridden()); + clone.setInheritanceStatus(getInheritanceStatus()); if (CollectionUtils.isNotEmpty(getActiveRuleParams())) { clone.setActiveRuleParams(new ArrayList(CollectionUtils.collect(getActiveRuleParams(), new Transformer() { public Object transform(Object input) { diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/rules/ActiveRuleInheritanceStatus.java b/sonar-plugin-api/src/main/java/org/sonar/api/rules/ActiveRuleInheritanceStatus.java new file mode 100644 index 00000000000..713c72ea554 --- /dev/null +++ b/sonar-plugin-api/src/main/java/org/sonar/api/rules/ActiveRuleInheritanceStatus.java @@ -0,0 +1,14 @@ +package org.sonar.api.rules; + +/** + * For internal use only. + * + * @since 2.5 + */ +public enum ActiveRuleInheritanceStatus { + /** + * WARNING : DO NOT CHANGE THE ENUMERATION ORDER + * the enum ordinal is used for db persistence + */ + NO, INHERITED, OVERRIDDEN +} diff --git a/sonar-server/src/main/java/org/sonar/server/configuration/ProfilesBackup.java b/sonar-server/src/main/java/org/sonar/server/configuration/ProfilesBackup.java index 85dfbbae810..543606779fb 100644 --- a/sonar-server/src/main/java/org/sonar/server/configuration/ProfilesBackup.java +++ b/sonar-server/src/main/java/org/sonar/server/configuration/ProfilesBackup.java @@ -169,8 +169,7 @@ public class ProfilesBackup implements Backupable { writeNode(writer, "key", rule.getRule().getKey()); writeNode(writer, "plugin", rule.getRule().getRepositoryKey()); writeNode(writer, "level", rule.getSeverity().name()); - writeNode(writer, "inherited", Boolean.toString(rule.isInherited())); - writeNode(writer, "overridden", Boolean.toString(rule.isOverridden())); + writeNode(writer, "inherited", rule.getInheritanceStatus().toString()); if (!rule.getActiveRuleParams().isEmpty()) { writer.startNode("params"); @@ -206,8 +205,7 @@ public class ProfilesBackup implements Backupable { ActiveRule activeRule = new ActiveRule(null, new Rule(valuesRule.get("plugin"), valuesRule.get("key")), RulePriority .valueOf(valuesRule.get("level"))); activeRule.setActiveRuleParams(params); - activeRule.setInherited(Boolean.parseBoolean(valuesRule.get("inherited"))); - activeRule.setOverridden(Boolean.parseBoolean(valuesRule.get("overridden"))); + activeRule.setInheritanceStatus(ActiveRuleInheritanceStatus.valueOf(valuesRule.get("inherited"))); return activeRule; } 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 bae9f3bff68..f17cb5194d9 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 @@ -19,6 +19,8 @@ */ package org.sonar.server.configuration; +import org.sonar.api.rules.ActiveRuleInheritanceStatus; + import org.sonar.api.database.DatabaseSession; import org.sonar.api.database.model.ResourceModel; import org.sonar.api.profiles.RulesProfile; @@ -116,8 +118,8 @@ public class ProfilesManager extends BaseDao { */ public void activatedOrChanged(int parentProfileId, int activeRuleId) { ActiveRule parentActiveRule = getSession().getEntity(ActiveRule.class, activeRuleId); - if (parentActiveRule.isInherited() && !parentActiveRule.isOverridden()) { - parentActiveRule.setOverridden(true); + if (parentActiveRule.getInheritanceStatus() == ActiveRuleInheritanceStatus.INHERITED) { + parentActiveRule.setInheritanceStatus(ActiveRuleInheritanceStatus.OVERRIDDEN); getSession().saveWithoutFlush(parentActiveRule); } for (RulesProfile child : getChildren(parentProfileId)) { @@ -153,13 +155,12 @@ public class ProfilesManager extends BaseDao { public void revert(int profileId, int activeRuleId) { RulesProfile profile = getSession().getEntity(RulesProfile.class, profileId); ActiveRule activeRule = getSession().getEntity(ActiveRule.class, activeRuleId); - if (activeRule != null && activeRule.isInherited() && activeRule.isOverridden()) { + if (activeRule != null && activeRule.getInheritanceStatus() == ActiveRuleInheritanceStatus.OVERRIDDEN) { ActiveRule parentActiveRule = getParentProfile(profile).getActiveRule(activeRule.getRule()); removeActiveRule(profile, activeRule); activeRule = (ActiveRule) parentActiveRule.clone(); activeRule.setRulesProfile(profile); - activeRule.setInherited(true); - activeRule.setOverridden(false); + activeRule.setInheritanceStatus(ActiveRuleInheritanceStatus.INHERITED); profile.getActiveRules().add(activeRule); getSession().saveWithoutFlush(activeRule); @@ -174,19 +175,17 @@ public class ProfilesManager extends BaseDao { private void activateOrChange(RulesProfile profile, ActiveRule parentActiveRule) { ActiveRule activeRule = profile.getActiveRule(parentActiveRule.getRule()); if (activeRule != null) { - if (activeRule.isInherited() && !activeRule.isOverridden()) { + if (activeRule.getInheritanceStatus() == ActiveRuleInheritanceStatus.INHERITED) { removeActiveRule(profile, activeRule); } else { - activeRule.setInherited(true); - activeRule.setOverridden(true); + activeRule.setInheritanceStatus(ActiveRuleInheritanceStatus.OVERRIDDEN); getSession().saveWithoutFlush(activeRule); return; // no need to change in children } } activeRule = (ActiveRule) parentActiveRule.clone(); activeRule.setRulesProfile(profile); - activeRule.setInherited(true); - activeRule.setOverridden(false); + activeRule.setInheritanceStatus(ActiveRuleInheritanceStatus.INHERITED); profile.getActiveRules().add(activeRule); getSession().saveWithoutFlush(activeRule); @@ -198,11 +197,10 @@ public class ProfilesManager extends BaseDao { private void deactivate(RulesProfile profile, Rule rule) { ActiveRule activeRule = profile.getActiveRule(rule); if (activeRule != null) { - if (activeRule.isInherited() && !activeRule.isOverridden()) { + if (activeRule.getInheritanceStatus() == ActiveRuleInheritanceStatus.INHERITED) { removeActiveRule(profile, activeRule); } else { - activeRule.setInherited(false); - activeRule.setOverridden(false); + activeRule.setInheritanceStatus(ActiveRuleInheritanceStatus.NO); getSession().saveWithoutFlush(activeRule); return; // no need to change in children } 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 e8bc6427c82..a1afa263d1b 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,6 +1,9 @@ - <% inherited = active_rule.inherited if active_rule - overridden = active_rule.overridden if active_rule + <% if active_rule.nil? || active_rule.inherited.nil? + inheritance_status = 0 + else + inheritance_status = active_rule.inherited + end %>
<% enable_modification = is_admin && !profile.provided? @@ -17,21 +20,20 @@ :loading => "$('levels_#{rule.id}').replace('');", :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 || inherited) %> + <%= check_box_tag(check_box_id, 'yes', (!active_rule.nil?), :onclick => activate_rule, :disabled => !enable_modification || inheritance_status > 0) %> <%= 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?)}) %>
- <% if inherited %> - <% if overridden %> - Overrides rule from parent profile.
- <%= button_to "Revert", :action => 'revert_rule', :id => profile.id, :active_rule_id => active_rule.id %>
- <% else %> - Inherited from parent profile.
- <% end %> + <% if inheritance_status == 1 %> + Inherited from parent profile.
+ <% elsif inheritance_status == 2 %> + Overrides rule from parent profile.
+ <%= button_to "Revert", :action => 'revert_rule', :id => profile.id, :active_rule_id => active_rule.id %>
<% 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/db/migrate/169_add_columns_for_profiles_inheritance.rb b/sonar-server/src/main/webapp/WEB-INF/db/migrate/169_add_columns_for_profiles_inheritance.rb index 9d99baf7817..c7b238473d9 100644 --- a/sonar-server/src/main/webapp/WEB-INF/db/migrate/169_add_columns_for_profiles_inheritance.rb +++ b/sonar-server/src/main/webapp/WEB-INF/db/migrate/169_add_columns_for_profiles_inheritance.rb @@ -24,10 +24,9 @@ class AddColumnsForProfilesInheritance < ActiveRecord::Migration def self.up - add_column 'active_rules', 'inherited', :boolean, :null => true - add_column 'active_rules', 'overridden', :boolean, :null => true + add_column 'active_rules', 'inherited', :integer, :null => true ActiveRule.reset_column_information - ActiveRule.update_all(ActiveRule.sanitize_sql_for_assignment({:inherited => false, :overridden => false})) + ActiveRule.update_all(ActiveRule.sanitize_sql_for_assignment({:inherited => 0})) add_column 'rules_profiles', 'parent_name', :string, :limit => 40, :null => true Profile.reset_column_information diff --git a/sonar-server/src/test/java/org/sonar/server/configuration/BackupTest.java b/sonar-server/src/test/java/org/sonar/server/configuration/BackupTest.java index 3a2b52029f2..08f75114341 100644 --- a/sonar-server/src/test/java/org/sonar/server/configuration/BackupTest.java +++ b/sonar-server/src/test/java/org/sonar/server/configuration/BackupTest.java @@ -19,6 +19,8 @@ */ package org.sonar.server.configuration; +import org.sonar.api.rules.ActiveRuleInheritanceStatus; + import com.google.common.collect.Lists; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.io.IOUtils; @@ -128,8 +130,7 @@ public class BackupTest { assertNotNull(testActiveRule.getRule()); assertEquals("test key", testActiveRule.getRule().getKey()); assertEquals("test plugin", testActiveRule.getRule().getRepositoryKey()); - assertThat(testActiveRule.isInherited(), is(false)); - assertThat(testActiveRule.isOverridden(), is(false)); + assertThat(testActiveRule.getInheritanceStatus(), is(ActiveRuleInheritanceStatus.NO)); assertEquals(1, testActiveRule.getActiveRuleParams().size()); ActiveRuleParam testActiveRuleParam = testActiveRule.getActiveRuleParams().get(0); @@ -150,8 +151,7 @@ public class BackupTest { assertEquals("test2 name", testProfile.getName()); assertEquals("test name", testProfile.getParentName()); testActiveRule = testProfile.getActiveRules().get(0); - assertThat(testActiveRule.isInherited(), is(true)); - assertThat(testActiveRule.isOverridden(), is(true)); + assertThat(testActiveRule.getInheritanceStatus(), is(ActiveRuleInheritanceStatus.OVERRIDDEN)); Collection rules = sonarConfig.getRules(); assertThat(rules.size(), is(1)); @@ -269,8 +269,7 @@ public class BackupTest { ActiveRule activeRule2 = profile2.activateRule(rule, RulePriority.MINOR); activeRule2.setParameter("test param key", "test value"); - activeRule2.setInherited(true); - activeRule2.setOverridden(true); + activeRule2.setInheritanceStatus(ActiveRuleInheritanceStatus.OVERRIDDEN); profiles.get(0).getAlerts().add(new Alert(null, new Metric("test key"), Alert.OPERATOR_GREATER, "testError", "testWarn")); diff --git a/sonar-server/src/test/resources/org/sonar/server/configuration/BackupTest/backup-restore-valid.xml b/sonar-server/src/test/resources/org/sonar/server/configuration/BackupTest/backup-restore-valid.xml index d271cb729c3..afbcd51f3e1 100644 --- a/sonar-server/src/test/resources/org/sonar/server/configuration/BackupTest/backup-restore-valid.xml +++ b/sonar-server/src/test/resources/org/sonar/server/configuration/BackupTest/backup-restore-valid.xml @@ -42,6 +42,7 @@ + @@ -70,8 +71,7 @@ - - + diff --git a/sonar-server/src/test/resources/org/sonar/server/configuration/BackupTest/backup-valid.xml b/sonar-server/src/test/resources/org/sonar/server/configuration/BackupTest/backup-valid.xml index 7f353a51f67..55e7c52ef69 100644 --- a/sonar-server/src/test/resources/org/sonar/server/configuration/BackupTest/backup-valid.xml +++ b/sonar-server/src/test/resources/org/sonar/server/configuration/BackupTest/backup-valid.xml @@ -44,8 +44,7 @@ - - + @@ -74,8 +73,7 @@ - - + diff --git a/sonar-server/src/test/resources/org/sonar/server/configuration/InheritedProfilesTest/shouldActivateInChildren-result.xml b/sonar-server/src/test/resources/org/sonar/server/configuration/InheritedProfilesTest/shouldActivateInChildren-result.xml index 7a4d2a592b8..3ce3a268197 100644 --- a/sonar-server/src/test/resources/org/sonar/server/configuration/InheritedProfilesTest/shouldActivateInChildren-result.xml +++ b/sonar-server/src/test/resources/org/sonar/server/configuration/InheritedProfilesTest/shouldActivateInChildren-result.xml @@ -9,10 +9,10 @@ - + - + diff --git a/sonar-server/src/test/resources/org/sonar/server/configuration/InheritedProfilesTest/shouldActivateInChildren.xml b/sonar-server/src/test/resources/org/sonar/server/configuration/InheritedProfilesTest/shouldActivateInChildren.xml index 019b5bb6bb3..5df60edae3d 100644 --- a/sonar-server/src/test/resources/org/sonar/server/configuration/InheritedProfilesTest/shouldActivateInChildren.xml +++ b/sonar-server/src/test/resources/org/sonar/server/configuration/InheritedProfilesTest/shouldActivateInChildren.xml @@ -9,7 +9,7 @@ - + diff --git a/sonar-server/src/test/resources/org/sonar/server/configuration/InheritedProfilesTest/shouldChangeParent-result.xml b/sonar-server/src/test/resources/org/sonar/server/configuration/InheritedProfilesTest/shouldChangeParent-result.xml index f887123534a..e1c19620adb 100644 --- a/sonar-server/src/test/resources/org/sonar/server/configuration/InheritedProfilesTest/shouldChangeParent-result.xml +++ b/sonar-server/src/test/resources/org/sonar/server/configuration/InheritedProfilesTest/shouldChangeParent-result.xml @@ -12,10 +12,10 @@ - + - + - + diff --git a/sonar-server/src/test/resources/org/sonar/server/configuration/InheritedProfilesTest/shouldChangeParent.xml b/sonar-server/src/test/resources/org/sonar/server/configuration/InheritedProfilesTest/shouldChangeParent.xml index 7c6bbdb1ab8..958b9a98031 100644 --- a/sonar-server/src/test/resources/org/sonar/server/configuration/InheritedProfilesTest/shouldChangeParent.xml +++ b/sonar-server/src/test/resources/org/sonar/server/configuration/InheritedProfilesTest/shouldChangeParent.xml @@ -12,10 +12,10 @@ - + - + - + diff --git a/sonar-server/src/test/resources/org/sonar/server/configuration/InheritedProfilesTest/shouldDeactivateInChildren-result.xml b/sonar-server/src/test/resources/org/sonar/server/configuration/InheritedProfilesTest/shouldDeactivateInChildren-result.xml index 393ca0e3a7c..e51993058f6 100644 --- a/sonar-server/src/test/resources/org/sonar/server/configuration/InheritedProfilesTest/shouldDeactivateInChildren-result.xml +++ b/sonar-server/src/test/resources/org/sonar/server/configuration/InheritedProfilesTest/shouldDeactivateInChildren-result.xml @@ -7,6 +7,6 @@ - + diff --git a/sonar-server/src/test/resources/org/sonar/server/configuration/InheritedProfilesTest/shouldDeactivateInChildren.xml b/sonar-server/src/test/resources/org/sonar/server/configuration/InheritedProfilesTest/shouldDeactivateInChildren.xml index 9aa8741732b..2d08e30f5a3 100644 --- a/sonar-server/src/test/resources/org/sonar/server/configuration/InheritedProfilesTest/shouldDeactivateInChildren.xml +++ b/sonar-server/src/test/resources/org/sonar/server/configuration/InheritedProfilesTest/shouldDeactivateInChildren.xml @@ -7,8 +7,8 @@ - + - + diff --git a/sonar-server/src/test/resources/org/sonar/server/configuration/InheritedProfilesTest/shouldRemoveParent-result.xml b/sonar-server/src/test/resources/org/sonar/server/configuration/InheritedProfilesTest/shouldRemoveParent-result.xml index c7d7a39b4a8..93223e48dfc 100644 --- a/sonar-server/src/test/resources/org/sonar/server/configuration/InheritedProfilesTest/shouldRemoveParent-result.xml +++ b/sonar-server/src/test/resources/org/sonar/server/configuration/InheritedProfilesTest/shouldRemoveParent-result.xml @@ -7,6 +7,6 @@ - + diff --git a/sonar-server/src/test/resources/org/sonar/server/configuration/InheritedProfilesTest/shouldRemoveParent.xml b/sonar-server/src/test/resources/org/sonar/server/configuration/InheritedProfilesTest/shouldRemoveParent.xml index 9aa8741732b..2d08e30f5a3 100644 --- a/sonar-server/src/test/resources/org/sonar/server/configuration/InheritedProfilesTest/shouldRemoveParent.xml +++ b/sonar-server/src/test/resources/org/sonar/server/configuration/InheritedProfilesTest/shouldRemoveParent.xml @@ -7,8 +7,8 @@ - + - + diff --git a/sonar-server/src/test/resources/org/sonar/server/configuration/InheritedProfilesTest/shouldSetParent-result.xml b/sonar-server/src/test/resources/org/sonar/server/configuration/InheritedProfilesTest/shouldSetParent-result.xml index 9aa8741732b..2d08e30f5a3 100644 --- a/sonar-server/src/test/resources/org/sonar/server/configuration/InheritedProfilesTest/shouldSetParent-result.xml +++ b/sonar-server/src/test/resources/org/sonar/server/configuration/InheritedProfilesTest/shouldSetParent-result.xml @@ -7,8 +7,8 @@ - + - + diff --git a/sonar-server/src/test/resources/org/sonar/server/configuration/InheritedProfilesTest/shouldSetParent.xml b/sonar-server/src/test/resources/org/sonar/server/configuration/InheritedProfilesTest/shouldSetParent.xml index c7d7a39b4a8..93223e48dfc 100644 --- a/sonar-server/src/test/resources/org/sonar/server/configuration/InheritedProfilesTest/shouldSetParent.xml +++ b/sonar-server/src/test/resources/org/sonar/server/configuration/InheritedProfilesTest/shouldSetParent.xml @@ -7,6 +7,6 @@ - +