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
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')
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]
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
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()
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
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)
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
<% 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>
</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>
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
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 -%>
<%= 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>