aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@gmail.com>2011-07-26 11:55:44 +0200
committerSimon Brandhof <simon.brandhof@gmail.com>2011-07-26 11:55:44 +0200
commit2ef985b4603128e17ae4228d54b7d16ae58c007f (patch)
treefaf90f0f508a17f6629c598ec8130ab56149ef55
parent60d8f5f0cc60308c5a291f35e39cbccd4e36b888 (diff)
downloadsonarqube-2ef985b4603128e17ae4228d54b7d16ae58c007f.tar.gz
sonarqube-2ef985b4603128e17ae4228d54b7d16ae58c007f.zip
SONAR-2644 Rule name should be optional in XML declaration files
-rw-r--r--sonar-core/src/main/java/org/sonar/jpa/entity/SchemaMigration.java2
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/rules/Rule.java2
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/rules/XMLRuleParser.java3
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/rules/RuleTest.java2
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/rules/XMLRuleParserTest.java12
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/db/migrate/216_set_nullable_rule_name.rb37
-rw-r--r--sonar-testing-harness/src/main/resources/org/sonar/test/persistence/sonar-test.ddl2
7 files changed, 48 insertions, 12 deletions
diff --git a/sonar-core/src/main/java/org/sonar/jpa/entity/SchemaMigration.java b/sonar-core/src/main/java/org/sonar/jpa/entity/SchemaMigration.java
index 592534f56d7..e0ab95f1abd 100644
--- a/sonar-core/src/main/java/org/sonar/jpa/entity/SchemaMigration.java
+++ b/sonar-core/src/main/java/org/sonar/jpa/entity/SchemaMigration.java
@@ -40,7 +40,7 @@ public class SchemaMigration {
- complete the Derby DDL file used for unit tests : sonar-testing-harness/src/main/resources/org/sonar/test/persistence/sonar-test.ddl
*/
- public static final int LAST_VERSION = 215;
+ public static final int LAST_VERSION = 216;
public final static String TABLE_NAME = "schema_migrations";
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));
diff --git a/sonar-server/src/main/webapp/WEB-INF/db/migrate/216_set_nullable_rule_name.rb b/sonar-server/src/main/webapp/WEB-INF/db/migrate/216_set_nullable_rule_name.rb
new file mode 100644
index 00000000000..90d558ff388
--- /dev/null
+++ b/sonar-server/src/main/webapp/WEB-INF/db/migrate/216_set_nullable_rule_name.rb
@@ -0,0 +1,37 @@
+#
+# Sonar, entreprise quality control tool.
+# Copyright (C) 2008-2011 SonarSource
+# 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
+#
+
+#
+# Sonar 2.10
+#
+class SetNullableRuleName < ActiveRecord::Migration
+
+ def self.up
+ add_column(:rules, :temp_name, :string, :limit => 200, :null => true)
+ Rule.reset_column_information
+
+ Rule.update_all('temp_name=name')
+
+ remove_column(:rules, :name)
+ rename_column(:rules, :temp_name, :name)
+ Rule.reset_column_information
+ end
+
+end
diff --git a/sonar-testing-harness/src/main/resources/org/sonar/test/persistence/sonar-test.ddl b/sonar-testing-harness/src/main/resources/org/sonar/test/persistence/sonar-test.ddl
index c9feaaa71f9..864fff1f2a2 100644
--- a/sonar-testing-harness/src/main/resources/org/sonar/test/persistence/sonar-test.ddl
+++ b/sonar-testing-harness/src/main/resources/org/sonar/test/persistence/sonar-test.ddl
@@ -301,7 +301,7 @@ create table QUALITY_MODELS (
create table RULES (
ID INTEGER not null,
- NAME VARCHAR(192) not null,
+ NAME VARCHAR(192),
PLUGIN_RULE_KEY VARCHAR(200) not null,
PLUGIN_NAME VARCHAR(255) not null,
DESCRIPTION CLOB,