]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-2644 Rule name should be optional in XML declaration files
authorSimon Brandhof <simon.brandhof@gmail.com>
Tue, 26 Jul 2011 09:55:44 +0000 (11:55 +0200)
committerSimon Brandhof <simon.brandhof@gmail.com>
Tue, 26 Jul 2011 09:55:44 +0000 (11:55 +0200)
sonar-core/src/main/java/org/sonar/jpa/entity/SchemaMigration.java
sonar-plugin-api/src/main/java/org/sonar/api/rules/Rule.java
sonar-plugin-api/src/main/java/org/sonar/api/rules/XMLRuleParser.java
sonar-plugin-api/src/test/java/org/sonar/api/rules/RuleTest.java
sonar-plugin-api/src/test/java/org/sonar/api/rules/XMLRuleParserTest.java
sonar-server/src/main/webapp/WEB-INF/db/migrate/216_set_nullable_rule_name.rb [new file with mode: 0644]
sonar-testing-harness/src/main/resources/org/sonar/test/persistence/sonar-test.ddl

index 592534f56d7241484fdcb1740614dcfc8d2f30fa..e0ab95f1abd3e8f8238825bd84170fcc5abea42b 100644 (file)
@@ -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";
 
index 4f1e1462fffd8f2f068373ce0fc7d9d7f2c2ae16..29a3451d37405f0e8de3740a370f894d91c20d4d 100644 (file)
@@ -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)
index bd3b33af3b62aab622a35448f4a519bd2cac5a4b..9e4300fe9a093b5e33d183fedc10c7551b68ec71 100644 (file)
@@ -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 {
index 95d76b48ea0ba5a89d3886664b1b9b6f0eae4c59..8030f7287ee54061419416ce41109c000e87ab69 100644 (file)
@@ -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"));
     }
   }
index bb76ef7a4c4bb440e33b0446ff211d48dc918627..33f9b671f57b9289029d8185f8c755447df9d150 100644 (file)
@@ -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 (file)
index 0000000..90d558f
--- /dev/null
@@ -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
index c9feaaa71f98fc1edb9fbac917113ce8c44ee6af..864fff1f2a2a952d3070a9abf0a63dc41d0d756a 100644 (file)
@@ -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,