<rules_parameters id="1" rule_id="1" name="param1" description="foo" param_type="r"/>
<!-- Active rule created -->
- <active_rules id="1" profile_id="1" rule_id="1" failure_level="2" inherited="[null]" overridden="[null]"/>
+ <active_rules id="1" profile_id="1" rule_id="1" failure_level="2" inherited="0"/>
<!-- Active rule param created -->
<active_rule_parameters id="1" active_rule_id="1" rules_parameter_id="1" value="20"/>
private List<ActiveRuleParam> activeRuleParams = new ArrayList<ActiveRuleParam>();
@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
*
* @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;
}
/**
*
* @since 2.5
*/
- public void setOverridden(Boolean overridden) {
- this.overridden = overridden;
+ public void setInheritanceStatus(ActiveRuleInheritanceStatus status) {
+ this.inherited = status;
}
/**
@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<ActiveRuleParam>(CollectionUtils.collect(getActiveRuleParams(), new Transformer() {
public Object transform(Object input) {
--- /dev/null
+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
+}
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");
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;
}
*/
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;
*/
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)) {
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);
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);
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
}
<td nowrap valign="top" class="left" x="<%= active_rule.failure_level if active_rule -%>" width="1%">
- <% 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
%>
<form id="levels_<%= rule.id -%>" action="">
<% enable_modification = is_admin && !profile.provided?
: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 || 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?)}) %>
</form>
</td>
<td valign="top" class="left">
- <% if inherited %>
- <% if overridden %>
- Overrides rule from parent profile.<br/>
- <%= button_to "Revert", :action => 'revert_rule', :id => profile.id, :active_rule_id => active_rule.id %><br/>
- <% else %>
- Inherited from parent profile.<br/>
- <% end %>
+ <% if inheritance_status == 1 %>
+ Inherited from parent profile.<br/>
+ <% elsif inheritance_status == 2 %>
+ Overrides rule from parent profile.<br/>
+ <%= button_to "Revert", :action => 'revert_rule', :id => profile.id, :active_rule_id => active_rule.id %><br/>
<% end %>
+
<%= link_to_function("#{h rule.name}", nil, :class => "") do |page|
page.toggle "desc_#{rule.id}"
end
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
*/
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;
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);
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<Rule> rules = sonarConfig.getRules();
assertThat(rules.size(), is(1));
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"));
<key><![CDATA[test key]]></key>
<plugin><![CDATA[test plugin]]></plugin>
<level><![CDATA[ERROR]]></level>
+ <inherited><![CDATA[NO]]></inherited>
<params>
<param>
<key><![CDATA[test param key]]></key>
<key><![CDATA[test key]]></key>
<plugin><![CDATA[test plugin]]></plugin>
<level><![CDATA[ERROR]]></level>
- <inherited><![CDATA[true]]></inherited>
- <overridden><![CDATA[true]]></overridden>
+ <inherited><![CDATA[OVERRIDDEN]]></inherited>
<params>
<param>
<key><![CDATA[test param key]]></key>
<key><![CDATA[test key]]></key>
<plugin><![CDATA[test plugin]]></plugin>
<level><![CDATA[MAJOR]]></level>
- <inherited><![CDATA[false]]></inherited>
- <overridden><![CDATA[false]]></overridden>
+ <inherited><![CDATA[NO]]></inherited>
<params>
<param>
<key><![CDATA[test param key]]></key>
<key><![CDATA[test key]]></key>
<plugin><![CDATA[test plugin]]></plugin>
<level><![CDATA[MINOR]]></level>
- <inherited><![CDATA[true]]></inherited>
- <overridden><![CDATA[true]]></overridden>
+ <inherited><![CDATA[OVERRIDDEN]]></inherited>
<params>
<param>
<key><![CDATA[test param key]]></key>
<rules_profiles id="2" provided="false" name="child" default_profile="0" language="java" parent_name="parent"/>
- <active_rules id="1" profile_id="1" rule_id="1" failure_level="2" inherited="false" overridden="false"/>
+ <active_rules id="1" profile_id="1" rule_id="1" failure_level="2" inherited="0"/>
<active_rule_parameters id="1" active_rule_id="1" rules_parameter_id="1" value="30"/>
- <active_rules id="2" profile_id="2" rule_id="1" failure_level="2" inherited="true" overridden="false"/>
+ <active_rules id="2" profile_id="2" rule_id="1" failure_level="2" inherited="1"/>
<active_rule_parameters id="2" active_rule_id="2" rules_parameter_id="1" value="30"/>
</dataset>
<rules_profiles id="2" provided="false" name="child" default_profile="0" language="java" parent_name="parent"/>
- <active_rules id="1" profile_id="1" rule_id="1" failure_level="2" inherited="false" overridden="false"/>
+ <active_rules id="1" profile_id="1" rule_id="1" failure_level="2" inherited="0"/>
<active_rule_parameters id="1" active_rule_id="1" rules_parameter_id="1" value="30"/>
</dataset>
<rules_profiles id="3" provided="false" name="child" default_profile="0" language="java" parent_name="new_parent"/>
- <active_rules id="1" profile_id="1" rule_id="1" failure_level="2" inherited="false" overridden="false"/>
+ <active_rules id="1" profile_id="1" rule_id="1" failure_level="2" inherited="0"/>
- <active_rules id="2" profile_id="2" rule_id="2" failure_level="2" inherited="false" overridden="false"/>
+ <active_rules id="2" profile_id="2" rule_id="2" failure_level="2" inherited="0"/>
- <active_rules id="4" profile_id="3" rule_id="2" failure_level="2" inherited="true" overridden="false"/>
+ <active_rules id="4" profile_id="3" rule_id="2" failure_level="2" inherited="1"/>
</dataset>
<rules_profiles id="3" provided="false" name="child" default_profile="0" language="java" parent_name="parent"/>
- <active_rules id="1" profile_id="1" rule_id="1" failure_level="2" inherited="false" overridden="false"/>
+ <active_rules id="1" profile_id="1" rule_id="1" failure_level="2" inherited="0"/>
- <active_rules id="2" profile_id="2" rule_id="2" failure_level="2" inherited="false" overridden="false"/>
+ <active_rules id="2" profile_id="2" rule_id="2" failure_level="2" inherited="0"/>
- <active_rules id="3" profile_id="3" rule_id="1" failure_level="2" inherited="true" overridden="false"/>
+ <active_rules id="3" profile_id="3" rule_id="1" failure_level="2" inherited="1"/>
</dataset>
<rules_profiles id="2" provided="false" name="child" default_profile="0" language="java" parent_name="parent"/>
- <active_rules id="1" profile_id="1" rule_id="1" failure_level="2" inherited="false" overridden="false"/>
+ <active_rules id="1" profile_id="1" rule_id="1" failure_level="2" inherited="0"/>
</dataset>
<rules_profiles id="2" provided="false" name="child" default_profile="0" language="java" parent_name="parent"/>
- <active_rules id="1" profile_id="1" rule_id="1" failure_level="2" inherited="false" overridden="false"/>
+ <active_rules id="1" profile_id="1" rule_id="1" failure_level="2" inherited="0"/>
- <active_rules id="2" profile_id="2" rule_id="1" failure_level="2" inherited="true" overridden="false"/>
+ <active_rules id="2" profile_id="2" rule_id="1" failure_level="2" inherited="1"/>
</dataset>
<rules_profiles id="2" provided="false" name="child" default_profile="0" language="java" parent_name="[null]"/>
- <active_rules id="1" profile_id="1" rule_id="1" failure_level="2" inherited="false" overridden="false"/>
+ <active_rules id="1" profile_id="1" rule_id="1" failure_level="2" inherited="0"/>
</dataset>
<rules_profiles id="2" provided="false" name="child" default_profile="0" language="java" parent_name="parent"/>
- <active_rules id="1" profile_id="1" rule_id="1" failure_level="2" inherited="false" overridden="false"/>
+ <active_rules id="1" profile_id="1" rule_id="1" failure_level="2" inherited="0"/>
- <active_rules id="2" profile_id="2" rule_id="1" failure_level="2" inherited="true" overridden="false"/>
+ <active_rules id="2" profile_id="2" rule_id="1" failure_level="2" inherited="1"/>
</dataset>
<rules_profiles id="2" provided="false" name="child" default_profile="0" language="java" parent_name="parent"/>
- <active_rules id="1" profile_id="1" rule_id="1" failure_level="2" inherited="false" overridden="false"/>
+ <active_rules id="1" profile_id="1" rule_id="1" failure_level="2" inherited="0"/>
- <active_rules id="2" profile_id="2" rule_id="1" failure_level="2" inherited="true" overridden="false"/>
+ <active_rules id="2" profile_id="2" rule_id="1" failure_level="2" inherited="1"/>
</dataset>
<rules_profiles id="2" provided="false" name="child" default_profile="0" language="java" parent_name="[null]"/>
- <active_rules id="1" profile_id="1" rule_id="1" failure_level="2" inherited="false" overridden="false"/>
+ <active_rules id="1" profile_id="1" rule_id="1" failure_level="2" inherited="0"/>
</dataset>