]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-1492 Allow notes per quality rule
authorFabrice Bellingard <bellingard@gmail.com>
Fri, 20 Jan 2012 09:56:56 +0000 (10:56 +0100)
committerFabrice Bellingard <bellingard@gmail.com>
Mon, 23 Jan 2012 18:23:18 +0000 (19:23 +0100)
=> DB stuff & Ruby models implemented

13 files changed:
sonar-core/src/main/java/org/sonar/core/persistence/DatabaseUtils.java
sonar-core/src/main/java/org/sonar/jpa/entity/SchemaMigration.java
sonar-core/src/main/resources/org/sonar/core/persistence/rows-derby.sql
sonar-core/src/main/resources/org/sonar/core/persistence/schema-derby.ddl
sonar-server/src/main/webapp/WEB-INF/app/controllers/api/rules_controller.rb
sonar-server/src/main/webapp/WEB-INF/app/controllers/rules_configuration_controller.rb
sonar-server/src/main/webapp/WEB-INF/app/models/active_rule.rb
sonar-server/src/main/webapp/WEB-INF/app/models/active_rule_note.rb [new file with mode: 0644]
sonar-server/src/main/webapp/WEB-INF/app/models/profile.rb
sonar-server/src/main/webapp/WEB-INF/app/models/rule.rb
sonar-server/src/main/webapp/WEB-INF/app/models/rule_note.rb [new file with mode: 0644]
sonar-server/src/main/webapp/WEB-INF/app/views/rules_configuration/_rule.html.erb
sonar-server/src/main/webapp/WEB-INF/db/migrate/252_add_rule_and_active_rule_notes.rb [new file with mode: 0644]

index 814c1ee26e26f39d8e76d6c139163205c3179e62..be14f84242fb53a236aff819e5e9e7435b5dc07e 100644 (file)
@@ -43,6 +43,7 @@ public final class DatabaseUtils {
     "active_filters",
     "active_rules",
     "active_rule_changes",
+    "active_rule_notes",
     "active_rule_parameters",
     "active_rule_param_changes",
     "alerts",
@@ -72,11 +73,12 @@ public final class DatabaseUtils {
     "resource_index",
     "reviews",
     "review_comments",
+    "rule_failures",
+    "rule_notes",
     "rules",
     "rules_categories",
     "rules_parameters",
     "rules_profiles",
-    "rule_failures",
     "schema_migrations",
     "snapshots",
     "snapshot_sources",
index f0f7a12456ab8fd907c844fe4209aa9de120cf61..5efe3e48193ae28608cc8264173dc478e6a15473 100644 (file)
@@ -34,7 +34,7 @@ public class SchemaMigration {
 
   public final static int VERSION_UNKNOWN = -1;
 
-  public static final int LAST_VERSION = 251;
+  public static final int LAST_VERSION = 252;
   public static final int VERSION_2_13 = 241;
 
   public final static String TABLE_NAME = "schema_migrations";
index 8144ad8cb05a3e5c585124f24363a81348a99759..02a2b5895b58eb5663b0a89f8011ac66bdaae13c 100644 (file)
@@ -170,6 +170,7 @@ INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('240');
 INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('241');
 INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('250');
 INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('251');
+INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('252');
 
 INSERT INTO USERS(ID, LOGIN, NAME, EMAIL, CRYPTED_PASSWORD, SALT, CREATED_AT, UPDATED_AT, REMEMBER_TOKEN, REMEMBER_TOKEN_EXPIRES_AT) VALUES (1, 'admin', 'Administrator', '', 'a373a0e667abb2604c1fd571eb4ad47fe8cc0878', '48bc4b0d93179b5103fd3885ea9119498e9d161b', '2011-09-26 22:27:48.0', '2011-09-26 22:27:48.0', null, null);
 ALTER TABLE USERS ALTER COLUMN ID RESTART WITH 2;
index 81491225d86cab1e57489e071a3d7af6a9179cb7..6ddd00a816beb04a07afcbeeca67f2331f9b5921 100644 (file)
@@ -486,6 +486,24 @@ CREATE TABLE "ACTION_PLANS_REVIEWS" (
   "REVIEW_ID" INTEGER
 );
 
+CREATE TABLE "ACTIVE_RULE_NOTES" (
+  "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1),
+  "ACTIVE_RULE_ID" INTEGER,
+  "USER_LOGIN" VARCHAR(40),
+  "DATA" BLOB(2147483647),
+  "CREATED_AT" TIMESTAMP,
+  "UPDATED_AT" TIMESTAMP
+);
+
+CREATE TABLE "RULE_NOTES" (
+  "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1),
+  "RULE_ID" INTEGER,
+  "USER_LOGIN" VARCHAR(40),
+  "DATA" BLOB(2147483647),
+  "CREATED_AT" TIMESTAMP,
+  "UPDATED_AT" TIMESTAMP
+);
+
 
 -- ----------------------------------------------
 -- DDL Statements for indexes
@@ -579,6 +597,10 @@ CREATE INDEX "INDEX_ACTION_PLANS_REVIEWS_ON_ACTION_PLAN_ID" ON "ACTION_PLANS_REV
 
 CREATE INDEX "INDEX_ACTION_PLANS_REVIEWS_ON_REVIEW_ID" ON "ACTION_PLANS_REVIEWS" ("REVIEW_ID");
 
+CREATE INDEX "INDEX_ACTIVE_RULE_NOTES_ON_ACTIVE_RULE_ID" ON "ACTIVE_RULE_NOTES" ("ACTIVE_RULE_ID");
+
+CREATE INDEX "INDEX_RULE_NOTES_ON_ACTIVE_RULE_ID" ON "RULE_NOTES" ("RULE_ID");
+
 
 -- ----------------------------------------------
 -- DDL Statements for keys
@@ -666,3 +688,7 @@ ALTER TABLE "ACTIVE_RULE_PARAMETERS" ADD CONSTRAINT "SQL110927104437560" PRIMARY
 ALTER TABLE "LOADED_TEMPLATES" ADD CONSTRAINT "SQL110927104437650" PRIMARY KEY ("ID");
 
 ALTER TABLE "ACTION_PLANS" ADD CONSTRAINT "SQL110927104447650" PRIMARY KEY ("ID");
+
+ALTER TABLE "ACTIVE_RULE_NOTES" ADD CONSTRAINT "SQL110927104847650" PRIMARY KEY ("ID");
+
+ALTER TABLE "RULE_NOTES" ADD CONSTRAINT "SQL110927184847650" PRIMARY KEY ("ID");
index 6a92fe9a881214c163eea95ea5b97452005156ca..8b66f10adaee03137784f41c2661dd6e04fc86bc 100644 (file)
@@ -32,7 +32,7 @@ class Api::RulesController < Api::RestController
     options[:priorities]=params[:priorities].split(',') if params[:priorities]
     options[:status]=params[:status]
     options[:searchtext]=params[:searchtext]
-    options[:include_parameters]=true
+    options[:include_parameters_and_notes]=true
     options[:inheritance]=params[:inheritance]
     
 
index e372f6f7459389d9599faf3c07c7df58bc80a9d8..4fb539ecf851febe26ab6f60bba30191debac4d7 100644 (file)
@@ -58,18 +58,18 @@ class RulesConfigurationController < ApplicationController
 
     @rules = Rule.search(java_facade, {
         :profile => @profile, :status => @status, :priorities => @priorities, :inheritance => @inheritance,
-        :plugins =>  @plugins, :searchtext => @searchtext, :include_parameters => true, :language => @profile.language})
+        :plugins =>  @plugins, :searchtext => @searchtext, :include_parameters_and_notes => true, :language => @profile.language})
 
     unless @searchtext.blank?
       if @status==STATUS_ACTIVE
         @hidden_inactives=Rule.search(java_facade, {
             :profile => @profile, :status => STATUS_INACTIVE, :priorities => @priorities,
-            :plugins =>  @plugins, :language => @profile.language, :searchtext => @searchtext, :include_parameters => false}).size
+            :plugins =>  @plugins, :language => @profile.language, :searchtext => @searchtext, :include_parameters_and_notes => false}).size
 
       elsif @status==STATUS_INACTIVE
         @hidden_actives=Rule.search(java_facade, {
             :profile => @profile, :status => STATUS_ACTIVE, :priorities => @priorities,
-            :plugins =>  @plugins, :language => @profile.language, :searchtext => @searchtext, :include_parameters => false}).size
+            :plugins =>  @plugins, :language => @profile.language, :searchtext => @searchtext, :include_parameters_and_notes => false}).size
       end
     end
 
index f6cc5f3b62670c5ee3c2f6cbf4c29cd2f3d83703..f2613920847558fd184668475aacf89d0ed694cb 100644 (file)
@@ -21,6 +21,8 @@ class ActiveRule < ActiveRecord::Base
   belongs_to :rules_profile, :class_name => 'Profile', :foreign_key => 'profile_id'
   belongs_to :rule
   has_many :active_rule_parameters, :dependent => :destroy
+  has_one :active_rule_note
+  alias_attribute :note, :active_rule_note
 
   def level
     failure_level
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/models/active_rule_note.rb b/sonar-server/src/main/webapp/WEB-INF/app/models/active_rule_note.rb
new file mode 100644 (file)
index 0000000..45bdfb4
--- /dev/null
@@ -0,0 +1,27 @@
+#
+# Sonar, entreprise quality control tool.
+# Copyright (C) 2008-2012 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
+#
+class ActiveRuleNote < ActiveRecord::Base
+  belongs_to :active_rule
+  alias_attribute :text, :data
+  
+  validates_presence_of :active_rule, :message => "can't be empty"
+  validates_presence_of :user_login, :message => "can't be empty"
+  
+end
index 78691867b8f171db415f02cbcfd88c2df6bb8909..72d5ee07cd5a1260901c3b04038e8806958ec4a4 100644 (file)
@@ -24,7 +24,7 @@ class Profile < ActiveRecord::Base
   has_many :active_rules, :class_name => 'ActiveRule', :foreign_key => 'profile_id', :dependent => :destroy, :include => ['rule']
   has_many :projects, :order => 'name asc'
   has_many :active_rules_with_params, :class_name => 'ActiveRule', :foreign_key => 'profile_id',
-      :include => ['active_rule_parameters']
+      :include => ['active_rule_parameters', 'active_rule_note']
 
   validates_uniqueness_of :name, :scope => :language, :case_sensitive => false
   validates_presence_of :name
index cfaa06e534f074f3a04a828d835252d8843ccbcf..e1a75229ee2e765d65567ed37ee24678f6743127 100644 (file)
@@ -28,6 +28,8 @@ class Rule < ActiveRecord::Base
   has_many :rule_failures
   has_many :active_rules
   belongs_to :parent, :class_name => 'Rule', :foreign_key => 'parent_id'
+  has_one :rule_note
+  alias_attribute :note, :rule_note
 
   def repository_key
     plugin_name
@@ -263,7 +265,7 @@ class Rule < ActiveRecord::Base
       values[:key] = searchtext
     end
 
-    includes=(options[:include_parameters] ? :rules_parameters : nil)
+    includes=(options[:include_parameters_and_notes] ? [:rules_parameters, :rule_note] : nil)
     rules = Rule.find(:all, :include => includes, :conditions => [conditions.join(" AND "), values]).sort
     filter(rules, options)
   end
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/models/rule_note.rb b/sonar-server/src/main/webapp/WEB-INF/app/models/rule_note.rb
new file mode 100644 (file)
index 0000000..c879875
--- /dev/null
@@ -0,0 +1,27 @@
+#
+# Sonar, entreprise quality control tool.
+# Copyright (C) 2008-2012 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
+#
+class RuleNote < ActiveRecord::Base
+  belongs_to :rule
+  alias_attribute :text, :data
+  
+  validates_presence_of :rule, :message => "can't be empty"
+  validates_presence_of :user_login, :message => "can't be empty"
+  
+end
index 120f361320749aa449fbe670c2f22a5ef539d4ef..8ca525c52026cbf0c3466d303ea1aba324fc2763 100644 (file)
@@ -32,9 +32,9 @@
         page.toggle "desc_#{rule.id}"
       end
   %>
-  <br/>
   <div id="desc_<%= rule.id -%>" class="rule_desc" style="display:none">
-    <%= rule.description %>
+    <span class="subtitle"><%= message('key') -%>: <%= rule.plugin_rule_key -%></span>
+    <div style="margin:8px 0px"><%= rule.description %></div>
     <table style="margin: 10px 0">
               <% rule.parameters.each do |parameter|
                 active_parameter = active_rule.active_param_by_param_id(parameter.id) if active_rule
                     :locals => {:parameter => parameter, :active_parameter => active_parameter, :profile => profile, :active_rule => active_rule, :is_admin => is_admin } %>
                   </tbody>
               <% end %>
-              <tr>
-                <td width="10%" nowrap class="left"><%= message('key') -%>: &nbsp;</td>
-                <td class="left"><%= rule.plugin_rule_key -%></td>
-              </tr>
      </table>
       <% if is_admin %>
         <% if rule.template? %>
diff --git a/sonar-server/src/main/webapp/WEB-INF/db/migrate/252_add_rule_and_active_rule_notes.rb b/sonar-server/src/main/webapp/WEB-INF/db/migrate/252_add_rule_and_active_rule_notes.rb
new file mode 100644 (file)
index 0000000..db934a2
--- /dev/null
@@ -0,0 +1,45 @@
+#
+# Sonar, entreprise quality control tool.
+# Copyright (C) 2008-2012 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.14
+#
+class AddRuleAndActiveRuleNotes < ActiveRecord::Migration
+
+  def self.up
+    create_table :active_rule_notes do |t|
+      t.timestamps
+      t.column :active_rule_id,     :integer,     :null => true
+      t.column :user_login,         :string,      :null => true,    :limit => 40
+      t.column :data,               :binary,      :null => true
+    end
+    add_index :active_rule_notes, :active_rule_id
+    
+    
+    create_table :rule_notes do |t|
+      t.timestamps
+      t.column :rule_id,        :integer,     :null => true
+      t.column :user_login,     :string,      :null => true,    :limit => 40
+      t.column :data,           :binary,      :null => true
+    end
+    add_index :rule_notes, :rule_id
+  end
+
+end