]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-1988 Description of rule parameters should be optional
authorsimonbrandhof <simon.brandhof@gmail.com>
Tue, 23 Nov 2010 22:11:55 +0000 (22:11 +0000)
committersimonbrandhof <simon.brandhof@gmail.com>
Tue, 23 Nov 2010 22:11:55 +0000 (22:11 +0000)
sonar-core/src/main/java/org/sonar/jpa/entity/SchemaMigration.java
sonar-server/src/main/webapp/WEB-INF/config/environment.rb
sonar-server/src/main/webapp/WEB-INF/db/migrate/160_nullable_rule_parameter_description.rb [new file with mode: 0644]
tests/integration/sonar-it-reference-plugin/src/main/java/itests/ITestsPlugin.java
tests/integration/sonar-it-reference-plugin/src/main/java/itests/rules/RuleWithoutDefinition.java [new file with mode: 0644]
tests/integration/sonar-it-reference-plugin/src/main/java/itests/rules/SampleRules.java [new file with mode: 0644]

index 5a6ec38be20be8c8364ba5fd610b61ad3f946e91..1b9b642960d423debe67468f2db2249ce40fe181 100644 (file)
@@ -30,7 +30,7 @@ import java.sql.Statement;
 public class SchemaMigration {
 
   public final static int VERSION_UNKNOWN = -1;
-  public static final int LAST_VERSION = 152
+  public static final int LAST_VERSION = 160
 
   public final static String TABLE_NAME = "schema_migrations";
 
index 1f4acf43ec26b12497c790567d935223fa116ecb..8c1197f98f28b85ae81703000cb64d21a1a524e7 100644 (file)
@@ -135,6 +135,16 @@ module JdbcSpec
 
       tp
     end
+
+    def change_column_null(table_name, column_name, null, default = nil)
+      column = column_for(table_name, column_name)
+
+      unless null || default.nil?
+        execute("UPDATE #{quote_table_name(table_name)} SET #{quote_column_name(column_name)}=#{quote(default)} WHERE #{quote_column_name(column_name)} IS NULL")
+      end
+
+      change_column table_name, column_name, column.sql_type, :null => null
+    end
   end
   
   # wrong column types on oracle 10g timestamp and datetimes
@@ -187,6 +197,15 @@ module JdbcSpec
     def quote_table_name(name) #:nodoc:
       quote_column_name(name).gsub('.', '`.`')
     end
+
+
+    # see http://jira.codehaus.org/browse/JRUBY-4719
+    def change_column_null(table_name, column_name, null, default = nil)
+      unless null || default.nil?
+        execute("UPDATE #{quote_table_name(table_name)} SET #{quote_column_name(column_name)}=#{quote(default)} WHERE #{quote_column_name(column_name)} IS NULL")
+      end
+      execute("ALTER TABLE #{quote_table_name(table_name)} ALTER COLUMN #{quote_column_name(column_name)} #{'NOT ' unless null}NULL")
+    end
   end
 
   module PostgreSQL
@@ -215,6 +234,15 @@ module JdbcSpec
       end
       @connection.columns_internal(table_name, name, schema_name)
     end
+
+
+    # see http://jira.codehaus.org/browse/JRUBY-3608
+    def change_column_null(table_name, column_name, null, default = nil)
+      unless null || default.nil?
+        execute("UPDATE #{quote_table_name(table_name)} SET #{quote_column_name(column_name)}=#{quote(default)} WHERE #{quote_column_name(column_name)} IS NULL")
+      end
+      execute("ALTER TABLE #{quote_table_name(table_name)} ALTER #{quote_column_name(column_name)} #{null ? 'DROP' : 'SET'} NOT NULL")
+    end
   end
 end
 
diff --git a/sonar-server/src/main/webapp/WEB-INF/db/migrate/160_nullable_rule_parameter_description.rb b/sonar-server/src/main/webapp/WEB-INF/db/migrate/160_nullable_rule_parameter_description.rb
new file mode 100644 (file)
index 0000000..2b9fcde
--- /dev/null
@@ -0,0 +1,25 @@
+#
+# 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
+#
+class NullableRuleParameterDescription < ActiveRecord::Migration
+
+  def self.up
+    change_column_null(:rules_parameters, :description, true)
+  end
+end
\ No newline at end of file
index 73c30c51ca9aac6f0cc2ec9e6573f65764ea9bb5..f416f5dcf7fdfb2f8b299dcb5bfe23bdff5f6a47 100644 (file)
@@ -24,6 +24,7 @@ import itests.languages.LanguageWithoutRulesEngine;
 import itests.page.GwtSamplePage;\r
 import itests.page.RubyApiTestsPage;\r
 import itests.resourcetab.SampleResourceTab;\r
+import itests.rules.SampleRules;\r
 import itests.ws.RubyWebService;\r
 import org.sonar.api.Plugin;\r
 \r
@@ -50,7 +51,7 @@ public class ITestsPlugin implements Plugin {
     extensions.add(SampleSensor.class);\r
     extensions.add(LanguageWithoutRulesEngine.class);\r
     extensions.add(ServerSideExtensionUsingExternalDependency.class);\r
-\r
+    extensions.add(SampleRules.class);\r
 \r
     // web\r
     extensions.add(SampleResourceTab.class);\r
diff --git a/tests/integration/sonar-it-reference-plugin/src/main/java/itests/rules/RuleWithoutDefinition.java b/tests/integration/sonar-it-reference-plugin/src/main/java/itests/rules/RuleWithoutDefinition.java
new file mode 100644 (file)
index 0000000..44f0091
--- /dev/null
@@ -0,0 +1,27 @@
+/*
+ * 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 itests.rules;
+
+import org.sonar.check.IsoCategory;
+import org.sonar.check.Rule;
+
+@Rule(key="no_description", name="No description", isoCategory = IsoCategory.Maintainability)
+public class RuleWithoutDefinition {
+}
diff --git a/tests/integration/sonar-it-reference-plugin/src/main/java/itests/rules/SampleRules.java b/tests/integration/sonar-it-reference-plugin/src/main/java/itests/rules/SampleRules.java
new file mode 100644 (file)
index 0000000..1e7f9d2
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ * 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 itests.rules;
+
+import org.sonar.api.resources.Java;
+import org.sonar.api.rules.AnnotationRuleParser;
+import org.sonar.api.rules.Rule;
+import org.sonar.api.rules.RuleRepository;
+
+import java.util.Arrays;
+import java.util.List;
+
+public class SampleRules extends RuleRepository {
+
+  private AnnotationRuleParser ruleParser;
+
+  public SampleRules(AnnotationRuleParser ruleParser) {
+    super("it", Java.KEY);
+    setName("Integration tests");
+    this.ruleParser = ruleParser;
+  }
+
+  @Override
+  public List<Rule> createRules() {
+    return ruleParser.parse("it", Arrays.<Class>asList(RuleWithoutDefinition.class));
+  }
+}