From 96caf6eac13b66a73d0ee572ad3a361c38e4b53a Mon Sep 17 00:00:00 2001 From: Godin Date: Thu, 16 Dec 2010 00:56:42 +0000 Subject: [PATCH] SONAR-1722: Add DB columns for profiles inheritance --- .../org/sonar/jpa/entity/SchemaMigration.java | 7 ++-- .../shouldAddActiveRulesToProfile-result.xml | 4 +-- .../org/sonar/api/profiles/RulesProfile.java | 8 +++-- .../java/org/sonar/api/rules/ActiveRule.java | 6 ++++ ...69_add_columns_for_profiles_inheritance.rb | 36 +++++++++++++++++++ 5 files changed, 54 insertions(+), 7 deletions(-) create mode 100644 sonar-server/src/main/webapp/WEB-INF/db/migrate/169_add_columns_for_profiles_inheritance.rb 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 ff04ffb27ba..4c0ee4aa224 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 @@ -19,18 +19,19 @@ */ package org.sonar.jpa.entity; -import javax.persistence.*; import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; +import javax.persistence.*; + @Entity -@Table(name = SchemaMigration.TABLE_NAME, uniqueConstraints = {@UniqueConstraint(columnNames = {"version"})}) +@Table(name = SchemaMigration.TABLE_NAME, uniqueConstraints = { @UniqueConstraint(columnNames = { "version" }) }) public class SchemaMigration { public final static int VERSION_UNKNOWN = -1; - public static final int LAST_VERSION = 168; + public static final int LAST_VERSION = 169; public final static String TABLE_NAME = "schema_migrations"; diff --git a/sonar-core/src/test/resources/org/sonar/jpa/dao/RulesDaoTest/shouldAddActiveRulesToProfile-result.xml b/sonar-core/src/test/resources/org/sonar/jpa/dao/RulesDaoTest/shouldAddActiveRulesToProfile-result.xml index 6818bf4c09e..32bf7af86df 100644 --- a/sonar-core/src/test/resources/org/sonar/jpa/dao/RulesDaoTest/shouldAddActiveRulesToProfile-result.xml +++ b/sonar-core/src/test/resources/org/sonar/jpa/dao/RulesDaoTest/shouldAddActiveRulesToProfile-result.xml @@ -1,6 +1,6 @@ - + @@ -10,7 +10,7 @@ - + diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/profiles/RulesProfile.java b/sonar-plugin-api/src/main/java/org/sonar/api/profiles/RulesProfile.java index ccc5e9d2dbd..c71d1ea1835 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/profiles/RulesProfile.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/profiles/RulesProfile.java @@ -29,11 +29,11 @@ import org.sonar.api.rules.ActiveRule; import org.sonar.api.rules.Rule; import org.sonar.api.rules.RulePriority; -import javax.persistence.*; - import java.util.ArrayList; import java.util.List; +import javax.persistence.*; + /** * This class is badly named. It should be "QualityProfile". Indeed it does not relate only to rules but to metric thresholds too. */ @@ -82,6 +82,10 @@ public class RulesProfile implements Cloneable { @OneToMany(mappedBy = "rulesProfile", fetch = FetchType.LAZY) private List projects = new ArrayList(); + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "parent_id", updatable = true, nullable = true) + private RulesProfile parentProfile; + /** * @deprecated use the factory method create() */ diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/rules/ActiveRule.java b/sonar-plugin-api/src/main/java/org/sonar/api/rules/ActiveRule.java index de5db8d61a8..f6f8b0fef30 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/rules/ActiveRule.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/rules/ActiveRule.java @@ -57,6 +57,12 @@ public class ActiveRule implements Cloneable { @OneToMany(mappedBy = "activeRule", fetch = FetchType.LAZY, cascade = { CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REMOVE }) private List activeRuleParams = new ArrayList(); + @Column(name = "inherited", updatable = true, nullable = true) + private Boolean inherited; + + @Column(name = "overrides", updatable = true, nullable = true) + private Boolean overrides; + /** * @deprecated visibility should be reduced to protected or package */ diff --git a/sonar-server/src/main/webapp/WEB-INF/db/migrate/169_add_columns_for_profiles_inheritance.rb b/sonar-server/src/main/webapp/WEB-INF/db/migrate/169_add_columns_for_profiles_inheritance.rb new file mode 100644 index 00000000000..1424404baf8 --- /dev/null +++ b/sonar-server/src/main/webapp/WEB-INF/db/migrate/169_add_columns_for_profiles_inheritance.rb @@ -0,0 +1,36 @@ +# +# Sonar, entreprise quality control 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 +# + +# +# Sonar 2.5 +# +class AddColumnsForProfilesInheritance < ActiveRecord::Migration + + def self.up + add_column 'active_rules', 'inherited', :boolean, :null => true + add_column 'active_rules', 'overrides', :boolean, :null => true + ActiveRule.reset_column_information + ActiveRule.update_all(ActiveRule.sanitize_sql_for_assignment({:inherited => false, :overrides => false})) + + add_column 'rules_profiles', 'parent_id', :integer, :null => true + Profile.reset_column_information + end + +end -- 2.39.5