summaryrefslogtreecommitdiffstats
path: root/sonar-server
diff options
context:
space:
mode:
authorsimonbrandhof <simon.brandhof@gmail.com>2011-03-17 15:01:38 +0100
committersimonbrandhof <simon.brandhof@gmail.com>2011-03-17 15:01:38 +0100
commit46385881103f7b54c3be4d11fccfb3b3e7a4cf7a (patch)
tree0a821788b599910b4f5bff9f9a226a2d9943146f /sonar-server
parent0bf0c415cef549b3a644d251ba59003166c25af2 (diff)
downloadsonarqube-46385881103f7b54c3be4d11fccfb3b3e7a4cf7a.tar.gz
sonarqube-46385881103f7b54c3be4d11fccfb3b3e7a4cf7a.zip
The coverage tab must display block of codes, filtered by lines to cover,uncovered lines, branches to cover and uncovered branches
Diffstat (limited to 'sonar-server')
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/controllers/resource_controller.rb101
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/views/resource/_options.html.erb17
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/views/resource/_tabs.html.erb2
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/views/resource/index.html.erb47
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<line.conditions && line.after(to)}
+ end
end
render :action => '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<to
+ line.flag_as_hidden() if !line.after(to)
end
end
end
end
+ def filter_lines(&block)
+ @lines.each_with_index do |line,index|
+ if yield(line)
+ for i in index-4...index
+ @lines[i].flag_as_highlight_context() if i>=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? %>
<td class="<%= 'first' if first -%>">
<select id="period" name="period" onchange="applyOptions()">
<option value="">Time changes...</option>
@@ -61,7 +61,20 @@
</td>
<td class="<%= 'first' if first -%>"><%= render :partial => 'rules_filter' -%></td>
- <% end %>
+ <% first=false
+ end %>
+
+ <% if @display_coverage %>
+ <td class="<%= 'first' if first -%>">
+ <select id="coverage_filter" name="coverage_filter" onchange="applyOptions()">
+ <option value="lines_to_cover" <%= 'selected' if @coverage_filter=='lines_to_cover' -%>>Lines to cover</option>
+ <option value="uncovered_lines" <%= 'selected' if @coverage_filter=='uncovered_lines' -%>>Uncovered lines</option>
+ <option value="conditions_to_cover" <%= 'selected' if @coverage_filter=='conditions_to_cover' -%>>Branches to cover</option>
+ <option value="uncovered_conditions" <%= 'selected' if @coverage_filter=='uncovered_conditions' -%>>Uncovered branches</option>
+ </select>
+ </td>
+ <% first=false
+ end %>
</tr>
</table>
</form>
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 %>
<script>function loadTab(url) {$('resource-loading').show();document.location.href=url;return false;}</script>
<% @extensions.each do |extension| %>
- <li><a href="#" onClick="loadTab('<%= url_for(:overwrite_params => {:tab => extension.getId()}) -%>')" class="<%= 'selected' if @extension.getId()==extension.getId() -%>"><%= extension.getTitle() -%></a></li>
+ <li><a href="#" onClick="loadTab('<%= url_for(:overwrite_params => {:tab => extension.getId(), :metric => nil}) -%>')" class="<%= 'selected' if @extension.getId()==extension.getId() -%>"><%= extension.getTitle() -%></a></li>
<% end %>
<% end %>
<li>
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
%>
<tr>
<%
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)}"
%>
- <td class="scm revision"><span class="date"><a href="#" title="<%= title -%>" alt="<%= title -%>"><%= l(line.date) if line.date -%></a></span> <span class="author"><%= h(line.author) -%></span></td>
+ <td class="scm revision"><span class="date"><a href="#" title="<%= title -%>" alt="<%= title -%>"><%= Java::OrgSonarApiUtils::DateUtils.formatDate(line.datetime) if line.datetime -%></a></span> <span class="author"><%= h(line.author) -%></span></td>
<% else %>
<td class="scm"></td>
<% end %>
<td class="lid <%= ' section' if line.violations? -%>" id="L<%= index+1 -%>"><a name="L<%= index+1 -%>" href="#L<%= index+1 -%>"><%= index + 1 -%></a></td>
<% if @display_coverage %>
+ <% if line.highlighted? %>
<td class="ind <%= hits_status -%>"><%= line.hits -%></td>
<td class="ind <%= conditions_status -%>">
<% if line.deprecated_conditions_label -%>
@@ -83,6 +86,10 @@
<%= line.covered_conditions -%>/<%= line.conditions -%>
<% end %>
</td>
+ <% else %>
+ <td class="ind"> </td>
+ <td class="ind"> </td>
+ <% end %>
<% end %>
<td class="line <%= status -%>">
<pre><%= line.source -%></pre>