]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-3893 Fixed issue related to coverage data filtering
authorJean-Baptiste Vilain <jean-baptiste.vilain@sonarsource.com>
Wed, 24 Apr 2013 10:18:04 +0000 (12:18 +0200)
committerJean-Baptiste Vilain <jean-baptiste.vilain@sonarsource.com>
Wed, 24 Apr 2013 10:18:04 +0000 (12:18 +0200)
sonar-colorizer/src/main/resources/sonar-colorizer.css
sonar-core/src/main/java/org/sonar/core/source/DecorationDataHolder.java
sonar-core/src/test/java/org/sonar/core/source/DecorationDataHolderTest.java
sonar-core/src/test/java/org/sonar/core/source/HtmlSourceDecoratorTest.java
sonar-server/src/main/webapp/WEB-INF/app/controllers/resource_controller.rb
sonar-server/src/main/webapp/WEB-INF/app/helpers/application_helper.rb
sonar-server/src/main/webapp/WEB-INF/app/helpers/source_helper.rb
sonar-server/src/main/webapp/WEB-INF/app/views/project_reviews/_review.html.erb
sonar-server/src/main/webapp/WEB-INF/app/views/resource/_duplications_source_snippet.html.erb
sonar-server/src/main/webapp/WEB-INF/app/views/shared/_source_coverage.html.erb
sonar-server/src/main/webapp/WEB-INF/app/views/shared/_source_display.erb

index 33813f45051a9830f90e6f7e457622d02c49ea22..7e1b47f87d34326a66e51ee391c8e4effe1855bb 100644 (file)
   font-weight: normal;
 }
 
-.highlightable {
-  /*text-decoration: underline;*/
-  /*color: #0000AA;*/
+.sym {
   cursor: hand; cursor: pointer;
 }
 
-.highlightable:hover {
+.sym:hover {
   background-color: #ff8c00;
 }
 
 .highlighted {
-  background-color: yellow;
+  background-color: #B3D4FF;
 }
 
index c40f4af4c36cfb122510a0b9c43ba20180707d49..45b02b9ceb84685c70a11bc7380744b41a0ec5af 100644 (file)
@@ -28,8 +28,8 @@ public class DecorationDataHolder {
 
   private static final String ENTITY_SEPARATOR = ";";
   private static final String FIELD_SEPARATOR = ",";
-  private static final String SYMBOL_PREFIX = "symbol-";
-  private static final String HIGHLIGHTABLE = "highlightable";
+  private static final String SYMBOL_PREFIX = "sym-";
+  private static final String HIGHLIGHTABLE = "sym";
 
   private List<TagEntry> openingTagsEntries;
   private int openingTagsIndex;
index e8af0180faf8bc7fb9e8de18a37b9e7fd34531e7..58520c19da1080f6bfdcfb7d1ab645f978b6f933 100644 (file)
@@ -50,11 +50,11 @@ public class DecorationDataHolderTest {
     assertThat(openingTagsEntries.get(1)).isEqualTo(new TagEntry(0, "cppd"));
     assertThat(openingTagsEntries.get(2)).isEqualTo(new TagEntry(54, "a"));
     assertThat(openingTagsEntries.get(3)).isEqualTo(new TagEntry(69, "k"));
-    assertThat(openingTagsEntries.get(4)).isEqualTo(new TagEntry(80, "symbol-80 highlightable"));
-    assertThat(openingTagsEntries.get(5)).isEqualTo(new TagEntry(90, "symbol-80 highlightable"));
+    assertThat(openingTagsEntries.get(4)).isEqualTo(new TagEntry(80, "sym-80 sym"));
+    assertThat(openingTagsEntries.get(5)).isEqualTo(new TagEntry(90, "sym-80 sym"));
     assertThat(openingTagsEntries.get(6)).isEqualTo(new TagEntry(106, "cppd"));
     assertThat(openingTagsEntries.get(7)).isEqualTo(new TagEntry(114, "k"));
-    assertThat(openingTagsEntries.get(8)).isEqualTo(new TagEntry(140, "symbol-80 highlightable"));
+    assertThat(openingTagsEntries.get(8)).isEqualTo(new TagEntry(140, "sym-80 sym"));
   }
 
   @Test
index 7f918c70db0d9a08aa3c114813a23df231047501..66c732d36d3b0b2ba687e911089cdf323dc69787 100644 (file)
@@ -67,7 +67,7 @@ public class HtmlSourceDecoratorTest extends AbstractDaoTestCase {
       " * Header",
       " */",
       "",
-      "public class <span class=\"symbol-31 highlightable\">HelloWorld</span> {",
+      "public class <span class=\"sym-31 sym\">HelloWorld</span> {",
       "}"
     );
   }
@@ -84,11 +84,11 @@ public class HtmlSourceDecoratorTest extends AbstractDaoTestCase {
       "<span class=\"cppd\"> * Header</span>",
       "<span class=\"cppd\"> */</span>",
       "",
-      "<span class=\"k\">public </span><span class=\"k\">class </span><span class=\"symbol-31 highlightable\">HelloWorld</span> {",
-      "  <span class=\"k\">public</span> <span class=\"k\">void</span> <span class=\"symbol-58 highlightable\">foo</span>() {",
+      "<span class=\"k\">public </span><span class=\"k\">class </span><span class=\"sym-31 sym\">HelloWorld</span> {",
+      "  <span class=\"k\">public</span> <span class=\"k\">void</span> <span class=\"sym-58 sym\">foo</span>() {",
       "  }",
-      "  <span class=\"k\">public</span> <span class=\"k\">void</span> <span class=\"symbol-84 highlightable\">bar</span>() {",
-      "    <span class=\"symbol-58 highlightable\">foo</span>();",
+      "  <span class=\"k\">public</span> <span class=\"k\">void</span> <span class=\"sym-84 sym\">bar</span>() {",
+      "    <span class=\"sym-58 sym\">foo</span>();",
       "  }",
       "}"
     );
index 705f9f4d91eab3c75806a863d180362e080e181d..e7561699aaf93bfec3ac56c4d3eb7b5d8e7f4703 100644 (file)
@@ -192,7 +192,6 @@ class ResourceController < ApplicationController
         if line
           line.index = line_id
           line.covered_lines = @testable ? @testable.countTestCasesOfLine(line_id) : 0
-          puts "covered_lines for line #{line.index} has been set to #{line.covered_lines}"
           line.hits = hits.to_i
           line.conditions = @conditions_by_line[line_id].to_i
           line.covered_conditions = @covered_conditions_by_line[line_id].to_i
@@ -212,7 +211,6 @@ class ResourceController < ApplicationController
 
       to = (@period && @snapshot.period_datetime(@period) ? Java::JavaUtil::Date.new(@snapshot.period_datetime(@period).to_f * 1000) : nil)
       @filtered = true
-      puts "coverage filter is #{@coverage_filter}"
       if ('lines_to_cover'==@coverage_filter || 'coverage'==@coverage_filter || 'line_coverage'==@coverage_filter ||
           'new_lines_to_cover'==@coverage_filter || 'new_coverage'==@coverage_filter || 'new_line_coverage'==@coverage_filter ||
           'it_lines_to_cover'==@coverage_filter || 'it_coverage'==@coverage_filter || 'it_line_coverage'==@coverage_filter ||
@@ -220,9 +218,7 @@ class ResourceController < ApplicationController
           'overall_lines_to_cover'==@coverage_filter || 'overall_coverage'==@coverage_filter || 'overall_line_coverage'==@coverage_filter ||
           'new_overall_lines_to_cover'==@coverage_filter || 'new_overall_coverage'==@coverage_filter || 'new_overall_line_coverage'==@coverage_filter)
         @coverage_filter = "#{it_prefix}lines_to_cover"
-        filtered_lines = filter_lines { |line| line.hits && line.after(to) }
-        puts "filtered lines length : #{filtered_lines.length}"
-        filtered_lines
+        filter_lines { |line| line.hits && line.after(to) }
 
       elsif ('uncovered_lines'==@coverage_filter || 'new_uncovered_lines'==@coverage_filter ||
           'it_uncovered_lines'==@coverage_filter || 'new_it_uncovered_lines'==@coverage_filter ||
index 9e2bc907452633c28e131c678a97af604620454c..a03a4d8fe422c8c5df9e579ebe8bace09438687f 100644 (file)
@@ -795,58 +795,6 @@ module ApplicationHelper
     html
   end
 
-
-  def prepare_colspans(display_violation_form, scm_available, display_coverage)
-
-    colspan=2
-    gray_colspan=1
-    white_colspan=0
-    if display_violation_form
-      colspan+=1
-      gray_colspan+=1
-    end
-    if scm_available
-      colspan+=1
-      gray_colspan+=1
-    end
-    if display_coverage
-      colspan+=2
-      white_colspan+=2
-    end
-
-    {:base => colspan, :gray => gray_colspan, :white => white_colspan}
-  end
-
-
-  def compute_statuses(line, display_coverage, display_violations)
-
-    status=hits_status=conditions_status=''
-
-    if line.displayed?
-      if display_coverage && line.hits
-        hits_status=(line.hits>0 ? 'ok' : 'ko')
-        if line.conditions && line.conditions>0 && line.covered_conditions
-          if line.covered_conditions==0
-            status='ko'
-            conditions_status='ko'
-          elsif line.covered_conditions==line.conditions
-            status=''
-            conditions_status='ok'
-          else
-            conditions_status='warn'
-            status='warn'
-          end
-        elsif line.hits
-          status=(line.hits>0 ? '' : 'ko')
-        end
-      elsif display_violations && line.violations?
-        status="ko"
-      end
-    end
-
-    {:base => status, :hits => hits_status, :conditions => conditions_status}
-  end
-
   def to_date(java_date)
     java_date ? Time.at(java_date.time/1000) : nil
   end
index 7de01cb0f8b5a333bac3d9c60704126ca2e7f918..2b50ec23f6ce5c8a6455adb91f85b6bff662a2f8 100644 (file)
@@ -30,11 +30,11 @@ module SourceHelper
   # - line_range : range (default is complete lines range)
   # - highlighted_lines : range (default is complete lines range)
   #
-  def snapshot_source_to_html(snapshot, options={})
+  def snapshot_html_source(snapshot, options={})
 
     panel = get_html_source_panel(snapshot, options)
 
-    unless panel.nil?
+    if panel
       panel.filter_min_date(options[:min_date]) if options[:min_date]
 
       unless panel.empty?
@@ -75,14 +75,15 @@ module SourceHelper
       panel.html_lines=[]
       html_source_lines = snapshot.highlighting_data || snapshot.source.syntax_highlighted_lines()
       line_range=sanitize_range(options[:line_range], 1..html_source_lines.length)
-      highlighted_lines=sanitize_range(options[:highlighted_lines], 1..html_source_lines.length)
 
       html_source_lines.each_with_index do |source, index|
         if line_range.include?(index+1)
           html_line=HtmlLine.new(source, index+1)
           html_line.revision=revisions_by_line[index+1]
           html_line.author=authors_by_line[index+1]
-          html_line.displayed=highlighted_lines.include?(index+1)
+          if options[:highlighted_lines]
+            html_line.displayed=options[:highlighted_lines].include?(index+1)
+          end
           date_string=dates_by_line[index+1]
           html_line.datetime=(date_string ? Java::OrgSonarApiUtils::DateUtils.parseDateTime(date_string) : nil)
           panel.html_lines<<html_line
@@ -126,12 +127,12 @@ module SourceHelper
   end
 
   class HtmlLine
-    attr_accessor :index, :source, :revision, :author, :datetime, :violations, :issues, :hits, :conditions,
+    attr_accessor :id, :index, :source, :revision, :author, :datetime, :violations, :issues, :hits, :conditions,
                   :covered_conditions, :hidden, :displayed, :deprecated_conditions_label, :covered_lines
 
-    def initialize(source, index)
+    def initialize(source, id)
       @source=source
-      @index=index
+      @id=id
     end
 
     def add_violation(violation)
@@ -181,14 +182,12 @@ module SourceHelper
     def flag_as_displayed
       @displayed=true
       @hidden=false
-      puts "line #{index} will be displayed"
     end
 
     def flag_as_displayed_context
-      # do not force if selected has already been set to true
+      # do not force if displayed has already been set to true
       @displayed=false if @displayed.nil?
       @hidden=false
-      puts "line #{index} will be displayed as context"
     end
 
     def flag_as_hidden
@@ -196,7 +195,6 @@ module SourceHelper
       if @hidden.nil?
         @hidden=true
         @displayed=false
-        puts "line #{index} will be hidden"
       end
     end
 
@@ -205,7 +203,7 @@ module SourceHelper
     end
 
     def displayed?
-      # selected if the @selected has not been set or has been set to true
+      # displayed if the @displayed has not been set or has been set to true
       !hidden? && @displayed!=false
     end
 
index e5f05be2d93fd5fd8a048d9ae4ae4cee311504e7..b5b6174f6e997542c8fe04a7da81df14d392efd1 100644 (file)
 
   <% if review.rule_failure && review.resource_line && review.rule_failure.snapshot && has_role?(:codeviewer, review.project) %>
     <div class="marginbottom10">
-      <%= snapshot_source_to_html(review.rule_failure.snapshot, {:line_range => (review.resource_line-5)..(review.resource_line+5), :highlighted_lines => [review.resource_line]}) -%>
+      <%= snapshot_html_source(review.rule_failure.snapshot, {:line_range => (review.resource_line-5)..(review.resource_line+5), :highlighted_lines => [review.resource_line]}) -%>
     </div>
   <% end %>
 
index 05bde167327c527a335fb216c13afdb6f8759d29..534f1119c26092dd7d74bd8ef7a3986f195ff362 100644 (file)
@@ -25,7 +25,7 @@
     </p>
   <% end %>
 
-  <%= snapshot_source_to_html(resource.last_snapshot, {:line_range => from_line..to_line}) -%>
+  <%= snapshot_html_source(resource.last_snapshot, {:line_range => from_line..to_line}) -%>
 
   <% if lines_count > ResourceHelper::DUPLICATION_SNIPPET_DEFAULT_NB_OF_LINES %>
     <p class="small">
index 17c5d47c5f6bd79eb086717bfd007729a40b7712..988fff23186800264bd278b31ca0364b9c6ae949 100644 (file)
@@ -1,5 +1,4 @@
 <% if line.displayed? && line.covered_lines %>
-  <% puts "displaying coverage info #{line.covered_lines} for line #{line.index}" %>
   <td class="ind <%= statuses[:hits] -%>" title="<%= message('coverage_viewer.line_covered_by_x_tests', {:params => line.covered_lines.to_s}) if line.covered_lines > 0 -%>">
       <% if line.covered_lines > 0 %>
         <a href="<%= ApplicationController.root_context -%>/test/testable/<%= h resource_key -%>?line=<%= index+1 -%>"
index 39cdc562802e07b58bad2a51d2b7794880d19ac9..b368ef4ccb73de9ea6163b8b7f273f4a4a302d2a 100644 (file)
@@ -5,7 +5,7 @@
 <table id="<%= current_display_id %>" class="sources2 code" cellpadding="0" cellspacing="0" border="0">
 
     <script>
-      $j("#<%= current_display_id %>").on("click", "span[class|='symbol']", {id: "<%= current_display_id.to_s() %>"}, highlight_usages);
+      $j("#<%= current_display_id %>").on("click", "span.sym", {id: "<%= current_display_id.to_s() %>"}, highlight_usages);
     </script>
 
         <%
@@ -94,7 +94,7 @@
 
           <% end %>
 
-          <%= render :partial => "shared/source_line_numbers", :locals => {:index => line.index} %>
+          <%= render :partial => "shared/source_line_numbers", :locals => {:index => line.id} %>
 
           <% if display_coverage %>
             <%= render :partial => "shared/source_coverage", :locals => {:line => line, \