diff options
author | Simon Brandhof <simon.brandhof@gmail.com> | 2011-07-26 11:55:44 +0200 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@gmail.com> | 2011-07-26 11:55:44 +0200 |
commit | 2ef985b4603128e17ae4228d54b7d16ae58c007f (patch) | |
tree | faf90f0f508a17f6629c598ec8130ab56149ef55 /sonar-plugin-api | |
parent | 60d8f5f0cc60308c5a291f35e39cbccd4e36b888 (diff) | |
download | sonarqube-2ef985b4603128e17ae4228d54b7d16ae58c007f.tar.gz sonarqube-2ef985b4603128e17ae4228d54b7d16ae58c007f.zip |
SONAR-2644 Rule name should be optional in XML declaration files
Diffstat (limited to 'sonar-plugin-api')
4 files changed, 9 insertions, 10 deletions
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/rules/Rule.java b/sonar-plugin-api/src/main/java/org/sonar/api/rules/Rule.java index 4f1e1462fff..29a3451d374 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/rules/Rule.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/rules/Rule.java @@ -47,7 +47,7 @@ public final class Rule { */ public static final RulePriority DEFAULT_PRIORITY = RulePriority.MAJOR; - @Column(name = "name", updatable = true, nullable = false) + @Column(name = "name", updatable = true, nullable = true, length = 200) private String name; @Column(name = "plugin_rule_key", updatable = false, nullable = true, length = 200) diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/rules/XMLRuleParser.java b/sonar-plugin-api/src/main/java/org/sonar/api/rules/XMLRuleParser.java index bd3b33af3b6..9e4300fe9a0 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/rules/XMLRuleParser.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/rules/XMLRuleParser.java @@ -145,9 +145,6 @@ public final class XMLRuleParser implements ServerComponent { if (StringUtils.isEmpty(rule.getKey())) { throw new SonarException("Node <key> is missing in <rule>"); } - if (StringUtils.isEmpty(rule.getName())) { - throw new SonarException("Node <name> is missing in <rule>"); - } } private static void processParameter(Rule rule, SMInputCursor ruleC) throws XMLStreamException { diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/rules/RuleTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/rules/RuleTest.java index 95d76b48ea0..8030f7287ee 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/rules/RuleTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/rules/RuleTest.java @@ -64,7 +64,7 @@ public class RuleTest { public void shouldRemoveNewLineCharactersInNameWithSecondConstructor() { Rule rule; for (String example : getExamplesContainingNewLineCharacter()) { - rule = new Rule(null, null, example, (RulesCategory) null, null); + rule = new Rule(null, null, example, null, null); assertThat(rule.getName(), is("test")); } } diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/rules/XMLRuleParserTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/rules/XMLRuleParserTest.java index bb76ef7a4c4..33f9b671f57 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/rules/XMLRuleParserTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/rules/XMLRuleParserTest.java @@ -20,6 +20,7 @@ package org.sonar.api.rules; import org.hamcrest.core.Is; +import org.hamcrest.core.IsNull; import org.junit.Test; import org.sonar.api.utils.SonarException; import org.sonar.check.Cardinality; @@ -65,9 +66,10 @@ public class XMLRuleParserTest { new XMLRuleParser().parse(new StringReader("<rules><rule><name>Foo</name></rule></rules>")); } - @Test(expected = SonarException.class) - public void failIfMissingRuleName() { - new XMLRuleParser().parse(new StringReader("<rules><rule><key>foo</key></rule></rules>")); + @Test + public void ruleNameShouldBeOptional() { + List<Rule> rules = new XMLRuleParser().parse(new StringReader("<rules><rule><key>foo</key></rule></rules>")); + assertThat(rules.get(0).getName(), nullValue()); } @Test(expected = SonarException.class) @@ -76,7 +78,7 @@ public class XMLRuleParserTest { } @Test - public void utf8Encoding() { + public void testUtf8Encoding() { List<Rule> rules = new XMLRuleParser().parse(getClass().getResourceAsStream("/org/sonar/api/rules/XMLRuleParserTest/utf8.xml")); assertThat(rules.size(), is(1)); Rule rule = rules.get(0); @@ -88,7 +90,7 @@ public class XMLRuleParserTest { } @Test - public void supportDeprecatedFormat() { + public void shouldSupportDeprecatedFormat() { // the deprecated format uses some attributes instead of nodes List<Rule> rules = new XMLRuleParser().parse(getClass().getResourceAsStream("/org/sonar/api/rules/XMLRuleParserTest/deprecated.xml")); assertThat(rules.size(), is(1)); |