aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-server
diff options
context:
space:
mode:
authorsimonbrandhof <simon.brandhof@gmail.com>2010-09-08 09:47:57 +0000
committersimonbrandhof <simon.brandhof@gmail.com>2010-09-08 09:47:57 +0000
commit39b5479f0e61ceb731990eefa8df81306eb6f571 (patch)
tree1ec08114fbbc2899aaf636663bb4045b3688c0b7 /sonar-server
parent88495df471775df6f4f725e63bf25d151f584893 (diff)
downloadsonarqube-39b5479f0e61ceb731990eefa8df81306eb6f571.tar.gz
sonarqube-39b5479f0e61ceb731990eefa8df81306eb6f571.zip
SONAR-1137 When no rule engine exist on a language, all other rules are shown on the screen
Diffstat (limited to 'sonar-server')
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/controllers/api/rules_controller.rb11
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/controllers/profiles_controller.rb7
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/controllers/rules_configuration_controller.rb40
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/models/rule.rb38
4 files changed, 52 insertions, 44 deletions
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 42c08aa35e0..e17fd55fb73 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
@@ -26,12 +26,9 @@ class Api::RulesController < Api::RestController
set_backward_compatibility_params
language = params[:language] || ''
options= {}
- if params[:plugins].blank?
- options[:plugins] = java_facade.getRuleRepositoriesByLanguage(language).collect { |repo| repo.getKey() }
- else
- options[:plugins] = params[:plugins].split(',')
- end
+ options[:plugins]=params[:plugins].split(',') if params[:plugins]
+ options[:language]=language
options[:categories]=params[:categories].split(',') if params[:categories]
options[:priorities]=params[:priorities].split(',') if params[:priorities]
options[:status]=params[:status]
@@ -45,11 +42,11 @@ class Api::RulesController < Api::RestController
rest_render([])
else
options[:profile]=profile
- rules = Rule.search(options)
+ rules = Rule.search(java_facade, options)
rest_render(rules, profile)
end
else
- rules = Rule.search(options)
+ rules = Rule.search(java_facade, options)
rest_render(rules)
end
end
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/profiles_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/profiles_controller.rb
index 273b5887698..a097835caae 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/profiles_controller.rb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/profiles_controller.rb
@@ -258,14 +258,15 @@ class ProfilesController < ApplicationController
end
def flash_validation_messages(messages)
+ # only 4 messages are kept each time to avoid cookie overflow.
if messages.hasErrors()
- flash[:error]=messages.getErrors().map{|m| m.getLabel()}.join('<br/>')
+ flash[:error]=messages.getErrors()[0...4].map{|m| m.getLabel()}.join('<br/>')
end
if messages.hasWarnings()
- flash[:warning]=messages.getWarnings().map{|m| m.getLabel()}.join('<br/>')
+ flash[:warning]=messages.getWarnings()[0...4].map{|m| m.getLabel()}.join('<br/>')
end
if messages.hasInfos()
- flash[:notice]=messages.getInfos().map{|m| m.getLabel()}.join('<br/>')
+ flash[:notice]=messages.getInfos()[0...4].map{|m| m.getLabel()}.join('<br/>')
end
end
end
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 949402c6a34..2d546a25d2a 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
@@ -56,23 +56,20 @@ class RulesConfigurationController < ApplicationController
@select_priority = ANY_SELECTION + RULE_PRIORITIES
@select_status = [['Any',''], ["Active", STATUS_ACTIVE], ["Inactive", STATUS_INACTIVE]]
- if @plugins.include?('')
- plugins_to_search = java_facade.getRuleRepositoriesByLanguage(@profile.language).collect { |repo| repo.getKey() }
- else
- plugins_to_search = @plugins
- end
-
- @rules = Rule.search(:profile => @profile, :categories => @categories,
- :status => @status, :priorities => @priorities, :plugins => plugins_to_search, :searchtext => @searchtext, :include_parameters => true)
+ @rules = Rule.search(java_facade, {
+ :profile => @profile, :categories => @categories, :status => @status, :priorities => @priorities,
+ :plugins => @plugins, :searchtext => @searchtext, :include_parameters => true, :language => @profile.language})
unless @searchtext.blank?
if @status==STATUS_ACTIVE
- @hidden_inactives=Rule.search(:profile => @profile, :categories => @categories,
- :status => STATUS_INACTIVE, :priorities => @priorities, :plugins => plugins_to_search, :searchtext => @searchtext, :include_parameters => false).size
+ @hidden_inactives=Rule.search(java_facade, {
+ :profile => @profile, :categories => @categories, :status => STATUS_INACTIVE, :priorities => @priorities,
+ :plugins => @plugins, :language => @profile.language, :searchtext => @searchtext, :include_parameters => false}).size
elsif @status==STATUS_INACTIVE
- @hidden_actives=Rule.search(:profile => @profile, :categories => @categories,
- :status => STATUS_ACTIVE, :priorities => @priorities, :plugins => plugins_to_search, :searchtext => @searchtext, :include_parameters => false).size
+ @hidden_actives=Rule.search(java_facade, {
+ :profile => @profile, :categories => @categories, :status => STATUS_ACTIVE, :priorities => @priorities,
+ :plugins => @plugins, :language => @profile.language, :searchtext => @searchtext, :include_parameters => false}).size
end
end
@@ -316,19 +313,18 @@ class RulesConfigurationController < ApplicationController
def init_params
@id = params[:id]
- @priorities = params[:priorities] || ['']
- @plugins = params[:plugins] || ['']
- @categories=params[:categories] || ['']
+ @priorities = filter_any(params[:priorities]) || ['']
+ @plugins=filter_any(params[:plugins]) || ['']
+ @categories=filter_any(params[:categories]) || ['']
@status=params[:rule_status] || STATUS_ACTIVE
@searchtext=params[:searchtext]
end
-
- def unselect_any_if_necessary(array)
- array = array - [''] if array.size > 1 and array.include?("")
+
+ def filter_any(array)
+ if array && array.size>1 && array.include?('')
+ array=[''] #keep only 'any'
+ end
array
end
-
- def array_for_search(array)
- array ? array - [''] : nil
- end
+
end
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 32035959970..6af4f028a07 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
@@ -30,7 +30,7 @@ class Rule < ActiveRecord::Base
def parameters
rules_parameters
end
-
+
def parameter(name)
result=nil
parameters.each do |param|
@@ -69,13 +69,13 @@ class Rule < ActiveRecord::Base
def editable?
!parent_id.nil?
end
-
+
def <=>(rule)
name<=>rule.name
end
-
+
def self.to_i(key_or_id)
- id=key_or_id.to_i
+ id=key_or_id.to_i
if id<=0 and key_or_id
parts=key_or_id.split(':')
if parts.size==2
@@ -149,21 +149,35 @@ class Rule < ActiveRecord::Base
end
- # options : :categories => [], :plugins => [], :searchtext => '', :profile => nil, :priorities => [], :status =>
- def self.search(options={})
+ # options :language => nil, :categories => [], :plugins => [], :searchtext => '', :profile => nil, :priorities => [], :status =>
+ def self.search(java_facade, options={})
conditions = ['enabled=:enabled']
values = {:enabled => true}
+ plugins=nil
if remove_blank(options[:plugins])
- conditions << "plugin_name IN (:plugin_names)"
- values[:plugin_names] = options[:plugins]
+ plugins = options[:plugins]
+ unless options[:language].blank?
+ plugins = plugins & java_facade.getRuleRepositoriesByLanguage(options[:language]).collect{ |repo| repo.getKey() }
+ end
+ elsif !options[:language].blank?
+ plugins = java_facade.getRuleRepositoriesByLanguage(options[:language]).collect{ |repo| repo.getKey() }
+ end
+
+ if plugins
+ if plugins.empty?
+ conditions << "plugin_name IS NULL"
+ else
+ conditions << "plugin_name IN (:plugin_names)"
+ values[:plugin_names] = plugins
+ end
end
if remove_blank(options[:categories])
conditions << "rules_category_id IN (:category_ids)"
values[:category_ids] = RulesCategory.find(:all, :select => 'id', :conditions => { :name => options[:categories] }).map(&:id)
end
-
+
unless options[:searchtext].blank?
conditions << "(UPPER(rules.name) LIKE :searchtext OR plugin_rule_key = :key)"
searchtext = options[:searchtext].to_s.strip
@@ -177,7 +191,7 @@ class Rule < ActiveRecord::Base
filter(rules, options)
end
-
+
def self.remove_blank(array)
if array
array = array - ['']
@@ -186,7 +200,7 @@ class Rule < ActiveRecord::Base
nil
end
end
-
+
def self.filter(rules, options)
priorities = remove_blank(options[:priorities])
profile = options[:profile]
@@ -205,7 +219,7 @@ class Rule < ActiveRecord::Base
(active_rule and priorities.include?(active_rule.priority_text)) or (active_rule.nil? and priorities.include?(rule.priority_text))
end
end
-
+
elsif priorities
rules = rules.select do |rule|
priorities.include?(rule.priority_text)