From 767f520c9a10f0842bf5bc0084defbf196337230 Mon Sep 17 00:00:00 2001 From: simonbrandhof Date: Tue, 23 Nov 2010 22:11:55 +0000 Subject: [PATCH] SONAR-1988 Description of rule parameters should be optional --- .../org/sonar/jpa/entity/SchemaMigration.java | 2 +- .../main/webapp/WEB-INF/config/environment.rb | 28 ++++++++++++ ...160_nullable_rule_parameter_description.rb | 25 +++++++++++ .../src/main/java/itests/ITestsPlugin.java | 3 +- .../itests/rules/RuleWithoutDefinition.java | 27 ++++++++++++ .../main/java/itests/rules/SampleRules.java | 44 +++++++++++++++++++ 6 files changed, 127 insertions(+), 2 deletions(-) create mode 100644 sonar-server/src/main/webapp/WEB-INF/db/migrate/160_nullable_rule_parameter_description.rb create mode 100644 tests/integration/sonar-it-reference-plugin/src/main/java/itests/rules/RuleWithoutDefinition.java create mode 100644 tests/integration/sonar-it-reference-plugin/src/main/java/itests/rules/SampleRules.java 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 5a6ec38be20..1b9b642960d 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 @@ -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"; diff --git a/sonar-server/src/main/webapp/WEB-INF/config/environment.rb b/sonar-server/src/main/webapp/WEB-INF/config/environment.rb index 1f4acf43ec2..8c1197f98f2 100644 --- a/sonar-server/src/main/webapp/WEB-INF/config/environment.rb +++ b/sonar-server/src/main/webapp/WEB-INF/config/environment.rb @@ -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 index 00000000000..2b9fcde4fde --- /dev/null +++ b/sonar-server/src/main/webapp/WEB-INF/db/migrate/160_nullable_rule_parameter_description.rb @@ -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 diff --git a/tests/integration/sonar-it-reference-plugin/src/main/java/itests/ITestsPlugin.java b/tests/integration/sonar-it-reference-plugin/src/main/java/itests/ITestsPlugin.java index 73c30c51ca9..f416f5dcf7f 100644 --- a/tests/integration/sonar-it-reference-plugin/src/main/java/itests/ITestsPlugin.java +++ b/tests/integration/sonar-it-reference-plugin/src/main/java/itests/ITestsPlugin.java @@ -24,6 +24,7 @@ import itests.languages.LanguageWithoutRulesEngine; import itests.page.GwtSamplePage; import itests.page.RubyApiTestsPage; import itests.resourcetab.SampleResourceTab; +import itests.rules.SampleRules; import itests.ws.RubyWebService; import org.sonar.api.Plugin; @@ -50,7 +51,7 @@ public class ITestsPlugin implements Plugin { extensions.add(SampleSensor.class); extensions.add(LanguageWithoutRulesEngine.class); extensions.add(ServerSideExtensionUsingExternalDependency.class); - + extensions.add(SampleRules.class); // web extensions.add(SampleResourceTab.class); 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 index 00000000000..44f00919cac --- /dev/null +++ b/tests/integration/sonar-it-reference-plugin/src/main/java/itests/rules/RuleWithoutDefinition.java @@ -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 index 00000000000..1e7f9d272f6 --- /dev/null +++ b/tests/integration/sonar-it-reference-plugin/src/main/java/itests/rules/SampleRules.java @@ -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 createRules() { + return ruleParser.parse("it", Arrays.asList(RuleWithoutDefinition.class)); + } +} -- 2.39.5