<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="0"/>
+ <active_rules id="1" profile_id="1" rule_id="1" failure_level="2" inheritance="[null]"/>
<!-- Active rule param created -->
<active_rule_parameters id="1" active_rule_id="1" rules_parameter_id="1" value="20"/>
@Table(name = "active_rules")
public class ActiveRule implements Cloneable {
+ public static final String INHERITED = "INHERITED";
+ public static final String OVERRIDES = "OVERRIDES";
+
@Id
@Column(name = "id")
@GeneratedValue
@OneToMany(mappedBy = "activeRule", fetch = FetchType.LAZY, cascade = { CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REMOVE })
private List<ActiveRuleParam> activeRuleParams = new ArrayList<ActiveRuleParam>();
- @Column(name = "inherited", updatable = true, nullable = true)
- @Enumerated(EnumType.ORDINAL)
- private ActiveRuleInheritanceStatus inherited = ActiveRuleInheritanceStatus.NO;
+ @Column(name = "inheritance", updatable = true, nullable = true)
+ private String inheritance;
/**
* @deprecated visibility should be reduced to protected or package
*
* @since 2.5
*/
- public ActiveRuleInheritanceStatus getInheritanceStatus() {
- return inherited == null ? ActiveRuleInheritanceStatus.NO : inherited;
+ public String getInheritance() {
+ return inheritance;
}
/**
*
* @since 2.5
*/
- public void setInheritanceStatus(ActiveRuleInheritanceStatus status) {
- this.inherited = status;
+ public void setInheritance(String s) {
+ this.inheritance = s;
+ }
+
+ public boolean isInherited() {
+ return StringUtils.equals(INHERITED, inheritance);
+ }
+
+ public boolean doesOverride() {
+ return StringUtils.equals(OVERRIDES, inheritance);
}
/**
@Override
public Object clone() {
final ActiveRule clone = new ActiveRule(getRulesProfile(), getRule(), getSeverity());
- clone.setInheritanceStatus(getInheritanceStatus());
+ clone.setInheritance(getInheritance());
if (CollectionUtils.isNotEmpty(getActiveRuleParams())) {
clone.setActiveRuleParams(new ArrayList<ActiveRuleParam>(CollectionUtils.collect(getActiveRuleParams(), new Transformer() {
public Object transform(Object input) {
+++ /dev/null
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2009 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * Sonar is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-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", rule.getInheritanceStatus().toString());
+ writeNode(writer, "inheritance", rule.getInheritance());
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);
- if (valuesRule.containsKey("inherited")) {
- activeRule.setInheritanceStatus(ActiveRuleInheritanceStatus.valueOf(valuesRule.get("inherited")));
+ if (valuesRule.containsKey("inheritance")) {
+ activeRule.setInheritance(valuesRule.get("inheritance"));
}
return activeRule;
}
}
private void writeNode(HierarchicalStreamWriter writer, String name, String value) {
- writer.startNode(name);
- writer.setValue(value);
- writer.endNode();
+ if (value != null) {
+ writer.startNode(name);
+ writer.setValue(value);
+ writer.endNode();
+ }
}
private Map<String, String> readNode(HierarchicalStreamReader reader) {
*/
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.getInheritanceStatus() == ActiveRuleInheritanceStatus.INHERITED) {
- parentActiveRule.setInheritanceStatus(ActiveRuleInheritanceStatus.OVERRIDDEN);
+ if (parentActiveRule.isInherited()) {
+ parentActiveRule.setInheritance(ActiveRule.OVERRIDES);
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.getInheritanceStatus() == ActiveRuleInheritanceStatus.OVERRIDDEN) {
+ if (activeRule != null && activeRule.doesOverride()) {
ActiveRule parentActiveRule = getParentProfile(profile).getActiveRule(activeRule.getRule());
removeActiveRule(profile, activeRule);
activeRule = (ActiveRule) parentActiveRule.clone();
activeRule.setRulesProfile(profile);
- activeRule.setInheritanceStatus(ActiveRuleInheritanceStatus.INHERITED);
+ activeRule.setInheritance(ActiveRule.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.getInheritanceStatus() == ActiveRuleInheritanceStatus.INHERITED) {
+ if (activeRule.isInherited()) {
removeActiveRule(profile, activeRule);
} else {
- activeRule.setInheritanceStatus(ActiveRuleInheritanceStatus.OVERRIDDEN);
+ activeRule.setInheritance(ActiveRule.OVERRIDES);
getSession().saveWithoutFlush(activeRule);
return; // no need to change in children
}
}
activeRule = (ActiveRule) parentActiveRule.clone();
activeRule.setRulesProfile(profile);
- activeRule.setInheritanceStatus(ActiveRuleInheritanceStatus.INHERITED);
+ activeRule.setInheritance(ActiveRule.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.getInheritanceStatus() == ActiveRuleInheritanceStatus.INHERITED) {
+ if (activeRule.isInherited()) {
removeActiveRule(profile, activeRule);
} else {
- activeRule.setInheritanceStatus(ActiveRuleInheritanceStatus.NO);
+ activeRule.setInheritance(null);
getSession().saveWithoutFlush(activeRule);
return; // no need to change in children
}
end\r
\r
def inherited?\r
- inherited==1\r
+ inheritance=='INHERITED'\r
end\r
\r
- def overridden?\r
- inherited==2\r
+ def overrides?\r
+ inheritance=='OVERRIDES'\r
end\r
end\r
: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 || (active_rule && (active_rule.inherited? || active_rule.overridden?))) %>
+ <%= check_box_tag(check_box_id, 'yes', (!active_rule.nil?), :onclick => activate_rule, :disabled => !enable_modification || (active_rule && (active_rule.inherited? || active_rule.overrides?))) %>
<%= 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 active_rule %>
<% if active_rule.inherited? %>
- <img src="<%= ApplicationController.root_context -%>/images/relation-vertical-green.png" alt="Inherited from parent" title="Inherited from parent"/>
- <% elsif active_rule.overridden? %>
- <img src="<%= ApplicationController.root_context -%>/images/relation-vertical-red.png" alt="Overrides parent definition" title="Overrides parent definition"/>
+ <img src="<%= ApplicationController.root_context -%>/images/inherited.png" alt="Inherited from parent" title="Inherited from parent"/>
+ <% elsif active_rule.overrides? %>
+ <img src="<%= ApplicationController.root_context -%>/images/overrides.png" alt="Overrides parent definition" title="Overrides parent definition"/>
<% end %>
<% end %>
</form>
<% if rule.editable? %>
<%= button_to "Edit rule", :action => 'edit', :id => profile.id, :rule_id => rule.id %>
<% end %>
- <% if active_rule && active_rule.overridden? %>
+ <% if active_rule && active_rule.overrides? %>
<%= button_to "Revert to parent definition", :action => 'revert_rule', :id => profile.id, :active_rule_id => active_rule.id %><br/>
<% end %>
<% end %>
class AddColumnsForProfilesInheritance < ActiveRecord::Migration
def self.up
- add_column 'active_rules', 'inherited', :integer, :null => true
+ add_column 'active_rules', 'inheritance', :varchar, :limit => 10, :null => true
ActiveRule.reset_column_information
- ActiveRule.update_all(ActiveRule.sanitize_sql_for_assignment({:inherited => 0}))
-
- add_column 'rules_profiles', 'parent_name', :string, :limit => 40, :null => true
+
+ add_column 'rules_profiles', 'parent_name', :string, :limit => 100, :null => true
Profile.reset_column_information
end
import org.apache.commons.lang.CharEncoding;
import org.custommonkey.xmlunit.Diff;
import org.custommonkey.xmlunit.XMLUnit;
+import org.hamcrest.Matchers;
import org.junit.Test;
import org.sonar.api.database.DatabaseSession;
import org.sonar.api.database.configuration.Property;
assertNotNull(testActiveRule.getRule());
assertEquals("test key", testActiveRule.getRule().getKey());
assertEquals("test plugin", testActiveRule.getRule().getRepositoryKey());
- assertThat(testActiveRule.getInheritanceStatus(), is(ActiveRuleInheritanceStatus.NO));
+ assertThat(testActiveRule.getInheritance(), nullValue());
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.getInheritanceStatus(), is(ActiveRuleInheritanceStatus.OVERRIDDEN));
+ assertThat(testActiveRule.getInheritance(), is(ActiveRule.OVERRIDES));
Collection<Rule> rules = sonarConfig.getRules();
assertThat(rules.size(), is(1));
RulesProfile testProfile = profiles.iterator().next();
assertThat(testProfile.getActiveRules().size(), is(1));
ActiveRule activeRule = testProfile.getActiveRules().get(0);
- assertThat(activeRule.getInheritanceStatus(), is(ActiveRuleInheritanceStatus.NO));
+ assertThat(activeRule.getInheritance(), nullValue());
}
@Test
ActiveRule activeRule2 = profile2.activateRule(rule, RulePriority.MINOR);
activeRule2.setParameter("test param key", "test value");
- activeRule2.setInheritanceStatus(ActiveRuleInheritanceStatus.OVERRIDDEN);
+ activeRule2.setInheritance(ActiveRule.OVERRIDES);
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[OVERRIDDEN]]></inherited>
+ <inheritance><![CDATA[OVERRIDES]]></inheritance>
<params>
<param>
<key><![CDATA[test param key]]></key>
<key><![CDATA[test key]]></key>
<plugin><![CDATA[test plugin]]></plugin>
<level><![CDATA[MAJOR]]></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[MINOR]]></level>
- <inherited><![CDATA[OVERRIDDEN]]></inherited>
+ <inheritance><![CDATA[OVERRIDES]]></inheritance>
<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="0"/>
+ <active_rules id="1" profile_id="1" rule_id="1" failure_level="2" inheritance="[null]"/>
<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="1"/>
+ <active_rules id="2" profile_id="2" rule_id="1" failure_level="2" inheritance="INHERITED"/>
<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="0"/>
+ <active_rules id="1" profile_id="1" rule_id="1" failure_level="2" inheritance="[null]"/>
<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="0"/>
+ <active_rules id="1" profile_id="1" rule_id="1" failure_level="2" inheritance="[null]"/>
- <active_rules id="2" profile_id="2" rule_id="2" failure_level="2" inherited="0"/>
+ <active_rules id="2" profile_id="2" rule_id="2" failure_level="2" inheritance="[null]"/>
- <active_rules id="4" profile_id="3" rule_id="2" failure_level="2" inherited="1"/>
+ <active_rules id="4" profile_id="3" rule_id="2" failure_level="2" inheritance="INHERITED"/>
</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="0"/>
+ <active_rules id="1" profile_id="1" rule_id="1" failure_level="2" inheritance="[null]"/>
- <active_rules id="2" profile_id="2" rule_id="2" failure_level="2" inherited="0"/>
+ <active_rules id="2" profile_id="2" rule_id="2" failure_level="2" inheritance="[null]"/>
- <active_rules id="3" profile_id="3" rule_id="1" failure_level="2" inherited="1"/>
+ <active_rules id="3" profile_id="3" rule_id="1" failure_level="2" inheritance="INHERITED"/>
</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="0"/>
+ <active_rules id="1" profile_id="1" rule_id="1" failure_level="2" inheritance="[null]"/>
</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="0"/>
+ <active_rules id="1" profile_id="1" rule_id="1" failure_level="2" inheritance="[null]"/>
- <active_rules id="2" profile_id="2" rule_id="1" failure_level="2" inherited="1"/>
+ <active_rules id="2" profile_id="2" rule_id="1" failure_level="2" inheritance="INHERITED"/>
</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="0"/>
+ <active_rules id="1" profile_id="1" rule_id="1" failure_level="2" inheritance="[null]"/>
</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="0"/>
+ <active_rules id="1" profile_id="1" rule_id="1" failure_level="2" inheritance="[null]"/>
- <active_rules id="2" profile_id="2" rule_id="1" failure_level="2" inherited="1"/>
+ <active_rules id="2" profile_id="2" rule_id="1" failure_level="2" inheritance="INHERITED"/>
</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="0"/>
+ <active_rules id="1" profile_id="1" rule_id="1" failure_level="2" inheritance="[null]"/>
- <active_rules id="2" profile_id="2" rule_id="1" failure_level="2" inherited="1"/>
+ <active_rules id="2" profile_id="2" rule_id="1" failure_level="2" inheritance="INHERITED"/>
</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="0"/>
+ <active_rules id="1" profile_id="1" rule_id="1" failure_level="2" inheritance="[null]"/>
</dataset>