From 46385881103f7b54c3be4d11fccfb3b3e7a4cf7a Mon Sep 17 00:00:00 2001 From: simonbrandhof Date: Thu, 17 Mar 2011 15:01:38 +0100 Subject: [PATCH] The coverage tab must display block of codes, filtered by lines to cover,uncovered lines, branches to cover and uncovered branches --- .../app/controllers/resource_controller.rb | 101 ++++++++++++++---- .../app/views/resource/_options.html.erb | 17 ++- .../WEB-INF/app/views/resource/_tabs.html.erb | 2 +- .../WEB-INF/app/views/resource/index.html.erb | 47 ++++---- 4 files changed, 122 insertions(+), 45 deletions(-) diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/resource_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/resource_controller.rb index 672eb3683a4..40c1ccf4614 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/resource_controller.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/resource_controller.rb @@ -90,7 +90,7 @@ class ResourceController < ApplicationController line.author=@authors_by_line[index+1] date_string=@dates_by_line[index+1] - line.datetime=(date_string ? DateTime::strptime(date_string): nil) + line.datetime=(date_string ? Java::OrgSonarApiUtils::DateUtils.parseDateTime(date_string): nil) end end end @@ -110,6 +110,7 @@ class ResourceController < ApplicationController def render_coverage load_sources() @display_coverage=true + @expandable=(@lines!=nil) if @lines @hits_by_line=load_distribution('coverage_line_hits_data') @conditions_by_line=load_distribution('conditions_by_line') @@ -125,6 +126,7 @@ class ResourceController < ApplicationController end if @snapshot.measure('conditions_by_line').nil? + # TODO remove this code when branch_coverage_hits_data is fully removed from CoreMetrics 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] @@ -134,7 +136,28 @@ class ResourceController < ApplicationController end end - filter_lines_by_date() + to=(@period ? Java::JavaUtil::Date.new(@snapshot.period_datetime(@period).to_f * 1000) : nil) + metric=Metric.by_key(params[:coverage_filter]||params[:metric]) + @coverage_filter=(metric ? metric.key : 'coverage') + @filtered=true + 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) + @coverage_filter='lines_to_cover' + filter_lines{|line| line.hits && line.after(to)} + + elsif 'uncovered_lines'==@coverage_filter || 'new_uncovered_lines'==@coverage_filter + @coverage_filter='uncovered_lines' + filter_lines{|line| line.hits && line.hits==0 && line.after(to)} + + elsif 'conditions_to_cover'==@coverage_filter || 'branch_coverage'==@coverage_filter || + 'new_conditions_to_cover'==@coverage_filter || 'new_branch_coverage'==@coverage_filter + @coverage_filter='conditions_to_cover' + filter_lines{|line| line.conditions && line.conditions>0 && line.after(to)} + + elsif 'uncovered_conditions'==@coverage_filter || 'new_uncovered_conditions'==@coverage_filter + @coverage_filter='uncovered_conditions' + filter_lines{|line| line.conditions && line.covered_conditions && line.covered_conditions 'index', :layout => !request.xhr? end @@ -182,22 +205,12 @@ class ResourceController < ApplicationController end if !@expanded && @lines - @lines.each_with_index do |line,index| - if line.violations? - for i in index-4..index+4 - @lines[i].hidden=false if i>=0 && i<@lines.size - end - elsif line.hidden==nil - line.hidden=true - end - end + filter_lines{|line| line.violations?} end render :action => 'index', :layout => !request.xhr? end - - def render_source load_sources() filter_lines_by_date() @@ -208,17 +221,33 @@ class ResourceController < ApplicationController def filter_lines_by_date if @period @filtered=true - to=@snapshot.period_datetime(@period) + to=Java::JavaUtil::Date.new(@snapshot.period_datetime(@period).to_f * 1000) if to @lines.each do |line| - line.hidden=true if line.datetime==nil || line.datetime=0 + end + line.flag_as_highlighted() + for i in index+1..index+4 + @lines[i].flag_as_highlight_context() if i<@lines.size + end + else + line.flag_as_hidden() + end + end + end + class Line - attr_accessor :source, :revision, :author, :datetime, :violations, :hits, :conditions, :covered_conditions, :hidden, :deprecated_conditions_label + attr_accessor :source, :revision, :author, :datetime, :violations, :hits, :conditions, :covered_conditions, :hidden, :highlighted, :deprecated_conditions_label def initialize(source) @source=source @@ -242,8 +271,39 @@ class ResourceController < ApplicationController end end - def date - @datetime ? @datetime.to_date : nil + def after(date) + if date && @datetime + @datetime.after(date) + else + true + end + end + + def flag_as_highlighted + @highlighted=true + @hidden=false + end + + def flag_as_highlight_context + # do not force if highlighted has already been set to true + @highlighted=false if @highlighted.nil? + @hidden=false + end + + def flag_as_hidden + # do not force if it has already been flagged as visible + if @hidden.nil? + @hidden=true + @highlighted=false + end + end + + def hidden? + @hidden==true + end + + def highlighted? + !hidden? && @highlighted==true end def deprecated_conditions_label=(label) @@ -263,14 +323,11 @@ class ResourceController < ApplicationController end end - - - def render_extension() render :action => 'extension', :layout => !request.xhr? end -def render_nothing() + def render_nothing() render :action => 'nothing', :layout => !request.xhr? end end \ No newline at end of file diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/resource/_options.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/resource/_options.html.erb index 1e86caee7c8..3cb70e0395f 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/resource/_options.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/resource/_options.html.erb @@ -33,7 +33,7 @@ <% first=false end %> - <% if @snapshot.project_snapshot.periods? && !@display_violations %> + <% if @scm_available && !@display_violations && @snapshot.project_snapshot.periods? %> + + + + + + + <% first=false + end %> diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/resource/_tabs.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/resource/_tabs.html.erb index bc1af726fb1..a2d0beedaa4 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/resource/_tabs.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/resource/_tabs.html.erb @@ -27,7 +27,7 @@ <% else %> <% @extensions.each do |extension| %> -
  • <%= extension.getTitle() -%>
  • +
  • <%= extension.getTitle() -%>
  • <% end %> <% end %>
  • diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/resource/index.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/resource/index.html.erb index 9036ceba975..56fa8892814 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/resource/index.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/resource/index.html.erb @@ -24,11 +24,10 @@ first_section=true has_displayed_lines=false @lines.each_with_index do |line, index| - if line.hidden + if line.hidden? && !@expanded previous_hidden=true next end - has_displayed_lines=true if previous_hidden && !first_section current_revision=nil @@ -42,39 +41,43 @@ first_section=false status=hits_status=conditions_status='' - 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' + if line.highlighted? + has_displayed_lines=true + 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 line.hits - status=(line.hits>0 ? '' : 'ko') + elsif @display_violations + status="sev#{line.violation_severity}" end - elsif @display_violations - status="sev#{line.violation_severity}" end %> <% if current_revision!=line.revision current_revision=line.revision - title = "Revision #{h(line.revision)} » #{l(line.datetime) if line.datetime}" + title = "Revision #{h(line.revision)}" %> - <%= l(line.date) if line.date -%> <%= h(line.author) -%> + <%= Java::OrgSonarApiUtils::DateUtils.formatDate(line.datetime) if line.datetime -%> <%= h(line.author) -%> <% else %> <% end %> <%= index + 1 -%> <% if @display_coverage %> + <% if line.highlighted? %> <%= line.hits -%> <% if line.deprecated_conditions_label -%> @@ -83,6 +86,10 @@ <%= line.covered_conditions -%>/<%= line.conditions -%> <% end %> + <% else %> + + + <% end %> <% end %>
    <%= line.source -%>
    -- 2.39.5