diff options
author | Julien Lancelot <julien.lancelot@gmail.com> | 2013-03-08 17:47:06 +0100 |
---|---|---|
committer | Julien Lancelot <julien.lancelot@gmail.com> | 2013-03-08 17:47:06 +0100 |
commit | 887511087786db6ad4e338ec31822fd21bd39848 (patch) | |
tree | 833b0246b940ec2159636acbc434a860f61a70ff | |
parent | 1cea549f87284f5705ebe575f911adf0cdaf34f3 (diff) | |
download | sonarqube-887511087786db6ad4e338ec31822fd21bd39848.tar.gz sonarqube-887511087786db6ad4e338ec31822fd21bd39848.zip |
SONAR-3879 Provide the ability to flag a rule as 'Deprecated' or 'Beta'
7 files changed, 88 insertions, 19 deletions
diff --git a/plugins/sonar-core-plugin/src/main/resources/org/sonar/l10n/core.properties b/plugins/sonar-core-plugin/src/main/resources/org/sonar/l10n/core.properties index ebd13865b40..849d65b72c6 100644 --- a/plugins/sonar-core-plugin/src/main/resources/org/sonar/l10n/core.properties +++ b/plugins/sonar-core-plugin/src/main/resources/org/sonar/l10n/core.properties @@ -52,6 +52,7 @@ descending=Descending description=Description directories=Directories directory=Directory +disabled=Disabled display=Display download_verb=Download edit=Edit @@ -1451,6 +1452,8 @@ rules_configuration.rule_overriding_from_profile_x=Rule overrides parent definit rules_configuration.original_value=Original value rules_configuration.original_severity=Original severity rules_configuration.repository=Repository +rules_configuration.status_filters=Status filters +rules_configuration.available_rules=Available rules #------------------------------------------------------------------------------ diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/rules/XMLRuleParserTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/rules/XMLRuleParserTest.java index 14213c64f7a..c683949ef55 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/rules/XMLRuleParserTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/rules/XMLRuleParserTest.java @@ -51,7 +51,7 @@ public class XMLRuleParserTest { assertThat(rule.getSeverity(), Is.is(RulePriority.BLOCKER)); assertThat(rule.getCardinality(), Is.is(Cardinality.MULTIPLE)); assertThat(rule.getConfigKey(), is("Checker/TreeWalker/LocalVariableName")); - assertThat(rule.getStatus(), is(Status.NORMAL.name())); + assertThat(rule.getStatus(), nullValue()); assertThat(rule.getParams().size(), is(2)); RuleParam prop = rule.getParam("ignore"); 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 948dabab2d3..f982ec8ca31 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 @@ -25,6 +25,7 @@ class RulesConfigurationController < ApplicationController STATUS_ACTIVE = "ACTIVE" STATUS_INACTIVE = "INACTIVE" + ANY_SELECTION = [] RULE_PRIORITIES = Sonar::RulePriority.as_options.reverse @@ -39,30 +40,26 @@ class RulesConfigurationController < ApplicationController require_parameters :id @profile = Profile.find(params[:id]) - add_breadcrumbs ProfilesController::ROOT_BREADCRUMB, Api::Utils.language_name(@profile.language), {:name => @profile.name, :url => {:controller => 'rules_configuration', :action => 'index', :id => @profile.id}} + add_breadcrumbs ProfilesController::ROOT_BREADCRUMB, Api::Utils.language_name(@profile.language), + {:name => @profile.name, :url => {:controller => 'rules_configuration', :action => 'index', :id => @profile.id}} init_params() @select_plugins = ANY_SELECTION + java_facade.getRuleRepositoriesByLanguage(@profile.language).collect { |repo| [repo.getName(true), repo.getKey()] }.sort @select_priority = ANY_SELECTION + RULE_PRIORITIES @select_activation = [[message('any'), 'any'], [message('active'), STATUS_ACTIVE], [message('inactive'), STATUS_INACTIVE]] - @select_inheritance = [[message('any'), 'any'], [message('rules_configuration.not_inherited'), 'NOT'], [message('rules_configuration.inherited'), 'INHERITED'], [message('rules_configuration.overrides'), 'OVERRIDES']] + @select_inheritance = [[message('any'), 'any'], [message('rules_configuration.not_inherited'), 'NOT'], [message('rules_configuration.inherited'), 'INHERITED'], + [message('rules_configuration.overrides'), 'OVERRIDES']] + @select_status = ANY_SELECTION + [[message('beta'), Rule::STATUS_BETA], [message('deprecated'), Rule::STATUS_DEPRECATED], [message('disabled'), Rule::STATUS_DISABLED]] @rules = Rule.search(java_facade, { - :profile => @profile, :status => @activation, :priorities => @priorities, :inheritance => @inheritance, + :profile => @profile, :activation => @activation, :priorities => @priorities, :inheritance => @inheritance, :status => @status, :plugins => @plugins, :searchtext => @searchtext, :include_parameters_and_notes => true, :language => @profile.language}) unless @searchtext.blank? - if @activation==STATUS_ACTIVE - @hidden_inactives=Rule.search(java_facade, { - :profile => @profile, :status => STATUS_INACTIVE, :priorities => @priorities, - :plugins => @plugins, :language => @profile.language, :searchtext => @searchtext, :include_parameters_and_notes => false}).size - - elsif @activation==STATUS_INACTIVE - @hidden_actives=Rule.search(java_facade, { - :profile => @profile, :status => STATUS_ACTIVE, :priorities => @priorities, - :plugins => @plugins, :language => @profile.language, :searchtext => @searchtext, :include_parameters_and_notes => false}).size - end + @hidden_inactives = Rule.search(java_facade, { + :profile => @profile, :activation => @activation==STATUS_ACTIVE ? STATUS_INACTIVE : STATUS_ACTIVE, :priorities => @priorities, :status => @status, + :plugins => @plugins, :language => @profile.language, :searchtext => @searchtext, :include_parameters_and_notes => false}).size end @pagination = Api::Pagination.new(params) @@ -379,6 +376,7 @@ class RulesConfigurationController < ApplicationController @plugins=filter_any(params[:plugins]) || [''] @activation=params[:rule_activation] || STATUS_ACTIVE @inheritance=params[:inheritance] || 'any' + @status=params[:status] @searchtext=params[:searchtext] 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 116256d9ff9..ce8f4607f69 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 @@ -21,6 +21,10 @@ class Rule < ActiveRecord::Base MANUAL_REPOSITORY_KEY = 'manual' + STATUS_BETA = "BETA" + STATUS_DEPRECATED = "DEPRECATED" + STATUS_DISABLED = "DISABLED" + validates_presence_of :name, :description, :plugin_name validates_presence_of :plugin_rule_key, :if => 'name.present?' @@ -63,6 +67,18 @@ class Rule < ActiveRecord::Base !parent_id.nil? end + def disabled? + !enabled + end + + def deprecated? + enabled && status == STATUS_DEPRECATED + end + + def beta? + enabled && status == STATUS_BETA + end + def <=>(other) return -1 if other.nil? return 1 if other.name.nil? @@ -238,11 +254,19 @@ class Rule < ActiveRecord::Base end - # options :language => nil, :plugins => [], :searchtext => '', :profile => nil, :priorities => [], :status => + # options :language => nil, :plugins => [], :searchtext => '', :profile => nil, :priorities => [], :activation => '', :status => [] def self.search(java_facade, options={}) conditions = ['enabled=:enabled'] values = {:enabled => true} + status = options[:status] + if status && !status.empty? + values[:enabled] = !status.include?(STATUS_DISABLED) + + conditions << "status IN (:status)" + values[:status] = status + end + plugins=nil if remove_blank(options[:plugins]) plugins = options[:plugins] @@ -297,8 +321,8 @@ class Rule < ActiveRecord::Base inheritance = options[:inheritance] if profile - inactive = (options[:status]=='INACTIVE') - active = (options[:status]=='ACTIVE') + inactive = (options[:activation]=='INACTIVE') + active = (options[:activation]=='ACTIVE') rules = rules.reject do |rule| active_rule = profile.active_by_rule_id(rule.id) diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/rules_configuration/_rule.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/rules_configuration/_rule.html.erb index cc4c945f10a..8b596b6d949 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/rules_configuration/_rule.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/rules_configuration/_rule.html.erb @@ -29,11 +29,21 @@ </td> <td class="left"> - <div class="h3"><%= link_to_function("#{h rule.name}", nil, :class => "") do |page| + <div class="h3 rule-title"><%= link_to_function("#{h rule.name}", nil, :class => "") do |page| page.toggle "desc_#{rule.id}" end %></div> + <div class="rule-status"> + <% if rule.beta? %> + <div class="status-beta"><%= message('beta') %></div> + <% elsif rule.deprecated? %> + <div class="status-deprecated"><%= message('deprecated') %></div> + <% elsif rule.disabled? %> + <div class="status-disabled"><%= message('disabled') %></div> + <% end %> + </div> + <div id="desc_<%= rule.id -%>" class="rule_detail" style="<%= 'display:none' -%>"> <a name="rule<%= rule.id -%>"></a> 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 b77b5c18f79..49c7d2377d5 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 @@ -55,6 +55,10 @@ <span class="note"><%= message('activation') -%></span><br/> <%= select_tag "rule_activation", options_for_select(@select_activation, @activation), :id => 'search_activation', :size => 6 %> </div> + <div class="rule-search top"> + <span class="note"><%= message('rules_configuration.status_filters') -%></span><br/> + <%= select_tag "status", options_for_select(@select_status, @status), :id => 'search_status', :multiple => true, :size => 6 %> + </div> <% if @profile.inherited? %> <div class="rule-search top"> <span class="note"><%= message('inheritance') -%></span><br/> @@ -154,4 +158,9 @@ minimumResultsForSearch: <%= (@select_inheritance.size + 1).to_s %> }); + $j('#search_status').select2({ + width: '120px', + placeholder: "<%= message('rules_configuration.available_rules') -%>" + }); + </script>
\ No newline at end of file diff --git a/sonar-server/src/main/webapp/stylesheets/style.css b/sonar-server/src/main/webapp/stylesheets/style.css index 2fd55768dbb..8646a25211d 100644 --- a/sonar-server/src/main/webapp/stylesheets/style.css +++ b/sonar-server/src/main/webapp/stylesheets/style.css @@ -2391,9 +2391,34 @@ textarea.width100 { } -/* Rules search styles for rules configuration page */ +/* ------------------- Rule styles ------------------- */ + .rule-search { display: inline-block; line-height: 16px; padding: 4px 2px; } + +.rule-title { + display: inline-block; +} + +.rule-status { + display: inline-block; + margin-left: 10px; + float: right; + background-color: #e7e7e7; + padding: 3px; +} + +.rule-status .status-beta { + color: #5e8790; +} + +.rule-status .status-deprecated { + color: #906947; +} + +.rule-status .status-disabled { + color: #904553; +} |