]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-2218 fix rule filter in violations tab
authorsimonbrandhof <simon.brandhof@gmail.com>
Wed, 2 Mar 2011 14:19:32 +0000 (15:19 +0100)
committersimonbrandhof <simon.brandhof@gmail.com>
Wed, 2 Mar 2011 14:19:32 +0000 (15:19 +0100)
sonar-server/src/main/webapp/WEB-INF/app/controllers/browse_controller.rb
sonar-server/src/main/webapp/WEB-INF/app/views/browse/_rules_filter.html.erb
sonar-server/src/main/webapp/WEB-INF/app/views/browse/index.html.erb

index bacf6c73325bba3e6ca98cec6d5c8311a7d09b6e..4a1642a57ea1d835c4f4cfa42f1045d05a34cd5a 100644 (file)
@@ -125,6 +125,16 @@ class BrowseController < ApplicationController
       end
     end
 
+    if @snapshot.measure('conditions_by_line').nil?
+      deprecated_branches_by_line=load_distribution('branch_coverage_hits_data')
+      deprecated_branches_by_line.each_pair do |line_id,label|
+        line=@lines[line_id-1]
+        if line
+          line.deprecated_conditions_label=label
+        end
+      end
+    end
+
     filter_lines_by_date()
     render :action => 'index'
   end
@@ -161,8 +171,7 @@ class BrowseController < ApplicationController
       end
     end
 
-    @violations=RuleFailure.find(:all, :include => 'rule', :conditions => [conditions] + values, :order => 'failure_level DESC')
-    @violations.each do |violation|
+    RuleFailure.find(:all, :include => 'rule', :conditions => [conditions] + values, :order => 'failure_level DESC').each do |violation|
       # sorted by severity => from blocker to info
       if violation.line && violation.line>0
         @lines[violation.line-1].add_violation(violation)
@@ -207,7 +216,7 @@ class BrowseController < ApplicationController
   end
 
   class Line
-    attr_accessor :source, :revision, :author, :datetime, :violations, :hits, :conditions, :covered_conditions, :hidden
+    attr_accessor :source, :revision, :author, :datetime, :violations, :hits, :conditions, :covered_conditions, :hidden, :deprecated_conditions_label
 
     def initialize(source)
       @source=source
@@ -234,6 +243,22 @@ class BrowseController < ApplicationController
     def date
       @datetime ? @datetime.to_date : nil
     end
+
+    def deprecated_conditions_label=(label)
+      if label
+        @deprecated_conditions_label=label
+          if label=='0%'
+            @conditions=2
+            @covered_conditions=0
+          elsif label=='100%'
+            @conditions=2
+            @covered_conditions=2
+          else
+            @conditions=2
+            @covered_conditions=1
+        end
+      end
+    end
   end
 
   
index cd37ea4255eca7ebd8c2de39819ee6784dea11ee..ea36a4da8d1dd697e053ea1ad4c65ee53fc5ecc5 100644 (file)
@@ -7,14 +7,12 @@
 
    rule_counts={}
    rules=[]
-
-   @violations.each do |violation|
-     count=(rule_counts[violation.rule_id]||0) +1
-     rule_counts[violation.rule_id]=count
-     rules<<violation.rule
+   rule_measures=ProjectMeasure.find(:all, :include => 'rule', :conditions => ['metric_id=? AND snapshot_id=? AND rule_id IS NOT NULL AND characteristic_id IS NULL', Metric.by_key('violations').id, @snapshot.id])
+   rule_measures.each do |rule_measure|
+     rule_counts[rule_measure.rule_id]=rule_measure.value.to_i
+     rules<<rule_measure.rule
    end
 
-
    rule_options=[]
    rules.uniq.sort_by{|rule| rule.name}.each do |rule|
      rule_options<<["#{h rule.name} (#{rule_counts[rule.id]})", rule.key]
index da557c0651c8fa3a24dde535b32717b34fb48d66..d4b5f7db9052aa97a0feabd9b644ac2558463090 100644 (file)
 
     <% if @display_coverage  %>
       <td class="ind <%= hits_status -%>"><%= line.hits -%></td>
-      <td class="ind <%= conditions_status -%>"><% if line.conditions && line.conditions>0 %><%= line.covered_conditions -%>/<%= line.conditions -%><% end %></td>
+      <td class="ind <%= conditions_status -%>">
+        <% if line.deprecated_conditions_label -%>
+          <%= line.deprecated_conditions_label -%>
+        <% elsif line.conditions && line.conditions>0 -%>
+          <%= line.covered_conditions -%>/<%= line.conditions -%>
+        <% end %>
+      </td>
     <% end %>
     <td class="line <%= status -%>"><%= line.source -%></td>
   </tr>