summaryrefslogtreecommitdiffstats
path: root/sonar-server
diff options
context:
space:
mode:
authorsimonbrandhof <simon.brandhof@gmail.com>2010-12-22 16:59:08 +0000
committersimonbrandhof <simon.brandhof@gmail.com>2010-12-22 16:59:08 +0000
commitda01fe793bd8d7b542e358e0a1a98b4313e60b5d (patch)
treeac6cbc0d9f44fed88a0ea53c9ecf64297f9842ff /sonar-server
parentd7ad68b9d7ffe7b7f666ddb633bb6ee0043e7070 (diff)
downloadsonarqube-da01fe793bd8d7b542e358e0a1a98b4313e60b5d.tar.gz
sonarqube-da01fe793bd8d7b542e358e0a1a98b4313e60b5d.zip
SONAR-1722 add a filter on inheritance field
Diffstat (limited to 'sonar-server')
-rw-r--r--sonar-server/src/main/java/org/sonar/server/startup/DeleteDeprecatedMeasures.java28
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/controllers/api/rules_controller.rb1
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/controllers/rules_configuration_controller.rb20
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/models/active_rule.rb2
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/models/profile.rb4
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/models/rule.rb18
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/views/rules_configuration/index.html.erb8
7 files changed, 67 insertions, 14 deletions
diff --git a/sonar-server/src/main/java/org/sonar/server/startup/DeleteDeprecatedMeasures.java b/sonar-server/src/main/java/org/sonar/server/startup/DeleteDeprecatedMeasures.java
new file mode 100644
index 00000000000..97c6a3f4912
--- /dev/null
+++ b/sonar-server/src/main/java/org/sonar/server/startup/DeleteDeprecatedMeasures.java
@@ -0,0 +1,28 @@
+/*
+ * 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 org.sonar.server.startup;
+
+import org.sonar.jpa.session.DatabaseSessionFactory;
+
+public class DeleteDeprecatedMeasures {
+ public DeleteDeprecatedMeasures(DatabaseSessionFactory sessionFactory) {
+
+ }
+}
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/api/rules_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/api/rules_controller.rb
index 1fc65c297a5..e3d78fba99f 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/api/rules_controller.rb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/api/rules_controller.rb
@@ -33,6 +33,7 @@ class Api::RulesController < Api::RestController
options[:status]=params[:status]
options[:searchtext]=params[:searchtext]
options[:include_parameters]=true
+ options[:inheritance]=params[:inheritance]
if params[:profile]
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/rules_configuration_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/rules_configuration_controller.rb
index 2688bb4b1c8..0d58ca0ac9d 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/rules_configuration_controller.rb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/rules_configuration_controller.rb
@@ -40,13 +40,13 @@ class RulesConfigurationController < ApplicationController
return
end
begin
- @profile = RulesProfile.find(params[:id].to_i)
+ @profile = Profile.find(params[:id].to_i)
rescue
redirect_to :controller => 'profiles'
return
end
else
- @profile = RulesProfile.default_profile
+ @profile = Profile.default_profile
end
init_params()
@@ -54,9 +54,10 @@ class RulesConfigurationController < ApplicationController
@select_plugins = ANY_SELECTION + java_facade.getRuleRepositoriesByLanguage(@profile.language).collect { |repo| [repo.getName(true), repo.getKey()]}.sort
@select_priority = ANY_SELECTION + RULE_PRIORITIES
@select_status = [['Any',''], ["Active", STATUS_ACTIVE], ["Inactive", STATUS_INACTIVE]]
+ @select_inheritance = [['Any',''], ["Not inherited", 'NOT'], ["Inherited", 'INHERITED'], ["Overrides", 'OVERRIDES']]
@rules = Rule.search(java_facade, {
- :profile => @profile, :status => @status, :priorities => @priorities,
+ :profile => @profile, :status => @status, :priorities => @priorities, :inheritance => @inheritance,
:plugins => @plugins, :searchtext => @searchtext, :include_parameters => true, :language => @profile.language})
unless @searchtext.blank?
@@ -96,7 +97,7 @@ class RulesConfigurationController < ApplicationController
#
#
def activate_rule
- profile = RulesProfile.find(params[:id].to_i)
+ profile = Profile.find(params[:id].to_i)
if profile && !profile.provided?
rule=Rule.find(:first, :conditions => {:id => params[:rule_id].to_i, :enabled => true})
priority=params[:level]
@@ -119,7 +120,9 @@ class RulesConfigurationController < ApplicationController
active_rule.save!
java_facade.ruleActivatedOrChanged(profile.id, active_rule.id)
end
- active_rule.reload
+ if active_rule
+ active_rule.reload
+ end
is_admin=true # security has already been checked by controller filters
render :update do |page|
@@ -137,7 +140,7 @@ class RulesConfigurationController < ApplicationController
#
def new
# form to duplicate a rule
- @profile = RulesProfile.find(params[:id].to_i)
+ @profile = Profile.find(params[:id].to_i)
@rule = Rule.find(params[:rule_id])
end
@@ -185,7 +188,7 @@ class RulesConfigurationController < ApplicationController
#
def edit
# form to edit a rule
- @profile = RulesProfile.find(params[:id])
+ @profile = Profile.find(params[:id])
@rule = Rule.find(params[:rule_id])
if !@rule.editable?
redirect_to :action => 'index', :id => params[:id]
@@ -275,7 +278,7 @@ class RulesConfigurationController < ApplicationController
def update_param
is_admin=true # security has already been checked by controller filters
- profile = RulesProfile.find(params[:profile_id].to_i)
+ profile = Profile.find(params[:profile_id].to_i)
rule_param = RulesParameter.find(params[:param_id].to_i)
active_rule = ActiveRule.find(params[:active_rule_id].to_i)
active_param = ActiveRuleParameter.find(params[:id].to_i) if params[:id].to_i > 0
@@ -331,6 +334,7 @@ class RulesConfigurationController < ApplicationController
@priorities = filter_any(params[:priorities]) || ['']
@plugins=filter_any(params[:plugins]) || ['']
@status=params[:rule_status] || STATUS_ACTIVE
+ @inheritance=params[:inheritance] || ''
@searchtext=params[:searchtext]
end
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/models/active_rule.rb b/sonar-server/src/main/webapp/WEB-INF/app/models/active_rule.rb
index 83bce7e376b..f06282f2569 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/models/active_rule.rb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/models/active_rule.rb
@@ -18,7 +18,7 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
#
class ActiveRule < ActiveRecord::Base
- belongs_to :rules_profile, :class_name => 'RulesProfile', :foreign_key => 'profile_id'
+ belongs_to :rules_profile, :class_name => 'Profile', :foreign_key => 'profile_id'
belongs_to :rule
has_many :active_rule_parameters, :dependent => :destroy
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/models/profile.rb b/sonar-server/src/main/webapp/WEB-INF/app/models/profile.rb
index 36207a6dd34..956e93a7f3d 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/models/profile.rb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/models/profile.rb
@@ -44,7 +44,7 @@ class Profile < ActiveRecord::Base
end
def validate_copy(name)
- new_rule_profile = RulesProfile.new(:name => name, :provided => false, :default_profile => false, :language => language)
+ new_rule_profile = Profile.new(:name => name, :provided => false, :default_profile => false, :language => language)
new_rule_profile.valid?
new_rule_profile.errors
end
@@ -81,7 +81,7 @@ class Profile < ActiveRecord::Base
def self.options_for_select
array=[]
- RulesProfile.find(:all, :order => 'name').each do |profile|
+ Profile.find(:all, :order => 'name').each do |profile|
label = profile.name
label = label + ' (active)' if profile.default_profile?
array<<[label, profile.id]
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/models/rule.rb b/sonar-server/src/main/webapp/WEB-INF/app/models/rule.rb
index 8dbd0c37af5..05b12fcda0a 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/models/rule.rb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/models/rule.rb
@@ -198,19 +198,33 @@ class Rule < ActiveRecord::Base
def self.filter(rules, options)
priorities = remove_blank(options[:priorities])
profile = options[:profile]
+ inheritance = options[:inheritance]
+
if profile
inactive = (options[:status]=='INACTIVE')
active = (options[:status]=='ACTIVE')
rules = rules.reject do |rule|
active_rule = profile.active_by_rule_id(rule.id)
- ((inactive and active_rule) or (active and active_rule.nil?))
+ ((inactive && active_rule) || (active && active_rule.nil?))
end
if priorities
rules = rules.select do |rule|
active_rule = profile.active_by_rule_id(rule.id)
- (active_rule and priorities.include?(active_rule.priority_text)) or (active_rule.nil? and priorities.include?(rule.priority_text))
+ (active_rule && priorities.include?(active_rule.priority_text)) || (active_rule.nil? && priorities.include?(rule.priority_text))
+ end
+ end
+
+ if inheritance=='NOT'
+ rules = rules.select do |rule|
+ active_rule = profile.active_by_rule_id(rule.id)
+ (active_rule.nil? || active_rule.inheritance.blank?)
+ end
+ elsif inheritance.present?
+ rules = rules.select do |rule|
+ active_rule = profile.active_by_rule_id(rule.id)
+ (active_rule && active_rule.inheritance==inheritance)
end
end
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/rules_configuration/index.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/rules_configuration/index.html.erb
index 64e9e11abc9..4f8e7d42099 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/views/rules_configuration/index.html.erb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/views/rules_configuration/index.html.erb
@@ -59,6 +59,12 @@
<span class="note">Status</span><br/>
<%= select_tag "rule_status", options_for_select(@select_status, @status), :id => 'search_status', :size => 6 %>
</td>
+ <% if @profile.inherited? %>
+ <td class="left" valign="top" width="1%" nowrap>
+ <span class="note">Inheritance</span><br/>
+ <%= select_tag "inheritance", options_for_select(@select_inheritance, @inheritance), :id => 'search_inheritance', :size => 6 %>
+ </td>
+ <% end %>
<td class="left" valign="top" >
<br/>
<%= submit_tag "Search", :id => 'submit_search' %>
@@ -71,7 +77,7 @@
<ul style="float: right" class="horizontal">
<li class="marginleft10">
<div class="csv">
- <a href="<%= url_for(:controller => 'api/rules', :action => 'index', :language => @profile.language, :profile => @profile.name, :plugins => @plugins.join(','), :status => @status, :searchtext => @searchtext, :priorities => @priorities.join(','), :format => 'csv') -%>" onClick="return downloadCsv()" id="download-link" class="">Download</a>
+ <a href="<%= url_for(:controller => 'api/rules', :action => 'index', :language => @profile.language, :profile => @profile.name, :plugins => @plugins.join(','), :status => @status, :inheritance => @inheritance, :searchtext => @searchtext, :priorities => @priorities.join(','), :format => 'csv') -%>" onClick="return downloadCsv()" id="download-link" class="">Download</a>
</div>
</li>
<% if enable_modification %>