aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-server
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@sonarsource.com>2014-06-18 18:20:21 +0200
committerJulien Lancelot <julien.lancelot@sonarsource.com>2014-06-18 18:20:21 +0200
commita6559a22df82a1686de32e1dc34e5075e8b78cd3 (patch)
tree7e8237ce7bfd6f4ddbb527c7512bb22e6abe1360 /sonar-server
parentaf24ed6c9053df418c224d322c20faf48ffa2d82 (diff)
downloadsonarqube-a6559a22df82a1686de32e1dc34e5075e8b78cd3.tar.gz
sonarqube-a6559a22df82a1686de32e1dc34e5075e8b78cd3.zip
SONAR-5007 Fix display of active rules in Profile inheritance page
Diffstat (limited to 'sonar-server')
-rw-r--r--sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfiles.java14
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/controllers/profiles_controller.rb2
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/helpers/profiles_helper.rb20
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/views/profiles/inheritance.html.erb30
4 files changed, 32 insertions, 34 deletions
diff --git a/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfiles.java b/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfiles.java
index cd688a37511..b6baa8f657f 100644
--- a/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfiles.java
+++ b/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfiles.java
@@ -28,6 +28,7 @@ import org.sonar.server.user.UserSession;
import org.sonar.server.util.Validation;
import javax.annotation.CheckForNull;
+
import java.util.List;
import java.util.Map;
@@ -132,19 +133,6 @@ public class QProfiles implements ServerComponent {
projectOperations.removeAllProjects(profileId, UserSession.get());
}
-
- // PROFILE RULES
- public long countProfileRules(QProfile profile) {
- // TODO
- return -1;
- }
-
- public long countOverridingProfileRules(QProfile profile) {
- // TODO
- return -1;
- //return rules.countProfileRules(ProfileRuleQuery.create(profile.id()).setInheritance(QProfileRule.OVERRIDES));
- }
-
private void checkProfileNameParam(String name) {
if (Strings.isNullOrEmpty(name)) {
throw new BadRequestException("quality_profiles.please_type_profile_name");
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 0be0572ec01..d309b105358 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
@@ -222,6 +222,8 @@ class ProfilesController < ApplicationController
profiles = Internal.quality_profiles.profilesByLanguage(@profile.language()).to_a.reject { |p| p.id == @profile.id() || p.parent() == @profile.name() }
profiles = Api::Utils.insensitive_sort(profiles) { |p| p.name() }
@select_parent = [[message('none'), nil]] + profiles.collect { |profile| [profile.name(), profile.id()] }
+
+ @all_profile_stats = Internal.component(Java::OrgSonarServerQualityprofile::QProfileService.java_class).getAllProfileStats()
end
set_profile_breadcrumbs
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/helpers/profiles_helper.rb b/sonar-server/src/main/webapp/WEB-INF/app/helpers/profiles_helper.rb
index 156f9648351..280eaf1331d 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/helpers/profiles_helper.rb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/helpers/profiles_helper.rb
@@ -23,12 +23,13 @@ module ProfilesHelper
controller.java_facade.getLanguages()
end
- def label_for_rules_count(qProfile)
- profile_rules_count = profile_rules_count(qProfile)
+ def label_for_rules_count(qProfile, all_profile_stats)
+ profile_stat = all_profile_stats[qProfile.key()]
+ profile_rules_count = profile_rules_count(qProfile, profile_stat)
label = "#{profile_rules_count} #{message('rules').downcase}"
- count_overriding = Internal.quality_profiles.countOverridingProfileRules(qProfile).to_i
- if count_overriding>0
+ count_overriding = overriding_rules_count(profile_stat)
+ if count_overriding && count_overriding>0
label += message('quality_profiles.including_x_overriding.suffix', :params => count_overriding)
label += image_tag('overrides.png')
end
@@ -55,7 +56,14 @@ module ProfilesHelper
Internal.quality_profiles.countProjects(qProfile).to_i
end
- def profile_rules_count(qProfile)
- Internal.quality_profiles.countProfileRules(qProfile).to_i
+ def profile_rules_count(qProfile, profile_stat)
+ count = 0
+ count = profile_stat.get('countActiveRules').get(0).getValue() if profile_stat && profile_stat.get('countActiveRules')
+ count
+ end
+
+ def overriding_rules_count(profile_stat)
+ inheritance_stats = Hash[ *profile_stat.get('inheritance').collect { |v| [ v.getKey(), v ] }.flatten ] if profile_stat
+ inheritance_stats['OVERRIDES'].getValue().to_i if inheritance_stats['OVERRIDES']
end
end
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/profiles/inheritance.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/profiles/inheritance.html.erb
index 8ec69c3fe3a..eb6831e481b 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/views/profiles/inheritance.html.erb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/views/profiles/inheritance.html.erb
@@ -7,24 +7,24 @@
<tr>
<td align="center" valign="top">
<div>
- <% @ancestors.reverse.each do |parent| %>
- <a href="<%= url_for :action => 'inheritance', :id => parent.id() -%>"><%= parent.name() -%></a>
- <span class="note">(<%= label_for_rules_count(parent) -%>)</span><br/>
- <%= image_tag 'blue-up.png' -%><br/>
- <% end %>
+ <% @ancestors.reverse.each do |parent| %>
+ <a href="<%= url_for :action => 'inheritance', :id => parent.id() -%>"><%= parent.name() -%></a>
+ <span class="note">(<%= label_for_rules_count(parent, @all_profile_stats) -%>)</span><br/>
+ <%= image_tag 'blue-up.png' -%><br/>
+ <% end %>
- <b><%= @profile.name -%></b> <span class="note">(<%= label_for_rules_count(@profile) -%>)</span><br/>
+ <b><%= @profile.name -%></b> <span class="note">(<%= label_for_rules_count(@profile, @all_profile_stats) -%>)</span><br/>
- <% if @children.size>0 %>
- <%= image_tag 'blue-up.png' -%><br/>
- <% @children.each_with_index do |child,index| %>
- <%= ', ' if index>0 -%>
- <a href="<%= url_for :action => 'inheritance', :id => child.id() -%>"><%= child.name() -%></a>
- <span class="note">(<%= label_for_rules_count(child) -%>)</span>
- <% end %>
- <br/><%= image_tag 'blue-up.png' -%><br/>
- ...
+ <% if @children.size>0 %>
+ <%= image_tag 'blue-up.png' -%><br/>
+ <% @children.each_with_index do |child,index| %>
+ <%= ', ' if index>0 -%>
+ <a href="<%= url_for :action => 'inheritance', :id => child.id() -%>"><%= child.name() -%></a>
+ <span class="note">(<%= label_for_rules_count(child, @all_profile_stats) -%>)</span>
<% end %>
+ <br/><%= image_tag 'blue-up.png' -%><br/>
+ ...
+ <% end %>
</div>
</td>
<% if profiles_administrator? %>