import java.util.Collections;
import java.util.Comparator;
-import java.util.List;
public class ViolationsViewer extends Page {
public static final String GWT_ID = "org.sonar.plugins.core.violationsviewer.ViolationsViewer";
}
private void loadRulePriorities() {
- final ResourceQuery query = ResourceQuery.createForResource(resource, Metrics.VIOLATIONS)
- .setExcludeRulePriorities(false);
+ final ResourceQuery query = ResourceQuery.createForResource(resource, Metrics.BLOCKER_VIOLATIONS,
+ Metrics.CRITICAL_VIOLATIONS, Metrics.MAJOR_VIOLATIONS, Metrics.MINOR_VIOLATIONS, Metrics.INFO_VIOLATIONS)
+ .setExcludeRulePriorities(true);
Sonar.getInstance().find(query, new AbstractCallback<Resource>(loading) {
@Override
protected void doOnResponse(Resource resource) {
final Grid grid = new Grid(1, 10);
header.setWidget(0, 0, grid);
- List<Measure> measures = resource.getMeasures();
- displayRulePriority(grid, 0, "BLOCKER", measures);
- displayRulePriority(grid, 2, "CRITICAL", measures);
- displayRulePriority(grid, 4, "MAJOR", measures);
- displayRulePriority(grid, 6, "MINOR", measures);
- displayRulePriority(grid, 8, "INFO", measures);
+ displayRulePriority(grid, 0, "BLOCKER", resource.getMeasure(Metrics.BLOCKER_VIOLATIONS));
+ displayRulePriority(grid, 2, "CRITICAL", resource.getMeasure(Metrics.CRITICAL_VIOLATIONS));
+ displayRulePriority(grid, 4, "MAJOR", resource.getMeasure(Metrics.MAJOR_VIOLATIONS));
+ displayRulePriority(grid, 6, "MINOR", resource.getMeasure(Metrics.MINOR_VIOLATIONS));
+ displayRulePriority(grid, 8, "INFO", resource.getMeasure(Metrics.INFO_VIOLATIONS));
}
- private void displayRulePriority(final Grid grid, final int column, final String priority, final List<Measure> measures) {
+ private void displayRulePriority(final Grid grid, final int column, final String priority, final Measure measure) {
String value = "0";
- for (Measure measure : measures) {
- if (priority.equals(measure.getRulePriority())) {
- value = measure.getFormattedValue();
- filterBox.addItem(priority + " (" + value + ")", priority);
- if (priority.equals(defaultFilter)) {
- filterBox.setSelectedIndex(filterBox.getItemCount() - 1);
- }
- continue;
+ if (measure != null) {
+ value = measure.getFormattedValue();
+ filterBox.addItem(priority + " (" + value + ")", priority);
+ if (priority.equals(defaultFilter)) {
+ filterBox.setSelectedIndex(filterBox.getItemCount() - 1);
}
}
+
grid.setHTML(0, column, Icons.forPriority(priority).getHTML());
grid.setHTML(0, column + 1, value);
grid.getCellFormatter().setStyleName(0, column, "thin metric right");
private void saveViolationsByPriority(DecoratorContext context) {
for (RulePriority priority : RulePriority.values()) {
- Collection<Measure> children = context.getChildrenMeasures(MeasuresFilters.rulePriority(CoreMetrics.VIOLATIONS, priority));
+ Metric metric = getMetricForPriority(priority);
+ Collection<Measure> children = context.getChildrenMeasures(MeasuresFilters.metric(metric));
double sum = MeasureUtils.sum(true, children) + priorities.count(priority);
- context.saveMeasure(RuleMeasure.createForPriority(CoreMetrics.VIOLATIONS, priority, sum));
- context.saveMeasure(new Measure(getMetricForPriority(priority), sum));
+ context.saveMeasure(new Measure(metric, sum));
}
}
decorator.decorate(resource, context);
- verify(context).saveMeasure(argThat(new IsRuleMeasure(CoreMetrics.VIOLATIONS, null, RulePriority.BLOCKER, 0.0)));
- verify(context).saveMeasure(argThat(new IsRuleMeasure(CoreMetrics.VIOLATIONS, null, RulePriority.CRITICAL, 2.0)));
- verify(context).saveMeasure(argThat(new IsRuleMeasure(CoreMetrics.VIOLATIONS, null, RulePriority.MAJOR, 1.0)));
- verify(context).saveMeasure(argThat(new IsRuleMeasure(CoreMetrics.VIOLATIONS, null, RulePriority.MINOR, 1.0)));
- verify(context).saveMeasure(argThat(new IsRuleMeasure(CoreMetrics.VIOLATIONS, null, RulePriority.INFO, 0.0)));
-
verify(context).saveMeasure(argThat(new IsMeasure(CoreMetrics.BLOCKER_VIOLATIONS, 0.0)));
verify(context).saveMeasure(argThat(new IsMeasure(CoreMetrics.CRITICAL_VIOLATIONS, 2.0)));
verify(context).saveMeasure(argThat(new IsMeasure(CoreMetrics.MAJOR_VIOLATIONS, 1.0)));
public class SchemaMigration {
public final static int VERSION_UNKNOWN = -1;
- public static final int LAST_VERSION = 163;
+ public static final int LAST_VERSION = 164;
public final static String TABLE_NAME = "schema_migrations";
end
def violations
- @metric = select_metric(params[:metric], 'violations')
+ @rule=Rule.by_key_or_id(params[:rule])
+
+ if @rule.nil? && params[:priority]
+ @metric = Metric::by_key("#{params[:priority].downcase}_violations")
+ @priority_id=Sonar::RulePriority.id(params[:priority])
+ else
+ @metric = Metric::by_key('violations')
+ @priority_id=nil
+ end
# selected resources
if params[:rids]
@selected_rids=@selected_rids.map{|r|r.to_i}
- # options
- @rule=Rule.by_key_or_id(params[:rule])
- @priority_id = (params[:priority] ? Sonar::RulePriority.id(params[:priority]) : nil)
-
- options={}
- options[:rule_priority_id]=@priority_id
+ # options for Drilldown
+ options={:exclude_zero_value => true}
if @rule
params[:rule]=@rule.key # workaround for SONAR-1767 : the javascript hash named "rp" in the HTML source must contain the rule key, but not the rule id
options[:rule_id]=@rule.id
def initialize(snapshot, metric, scope, selected_resource_ids, options)
@scope=scope
@snapshot = snapshot
- order='project_measures.value'
+
+ value_column = (options[:variation_index] ? "variation_value_#{options[:variation_index]}" : 'value')
+ order="project_measures.#{value_column}"
if metric.direction<0
order += ' DESC'
end
conditions='snapshots.root_snapshot_id=:root_sid AND snapshots.islast=:islast AND snapshots.scope=:scope AND snapshots.path LIKE :path AND project_measures.metric_id=:metric_id'
- if metric.key=='violations'
- conditions += ' AND project_measures.value>0'
+ if options[:exclude_zero_value]
+ conditions += " AND project_measures.#{value_column}<>0"
end
- values={
+ condition_values={
:root_sid => (snapshot.root_snapshot_id || snapshot.id),
:islast=>true,
:scope => scope,
if options[:rule_id]
conditions += ' AND project_measures.rule_id=:rule'
- values[:rule]=options[:rule_id]
+ condition_values[:rule]=options[:rule_id]
else
- conditions += ' AND project_measures.rule_id IS NULL'
+ conditions += ' AND project_measures.rule_id IS NULL AND project_measures.rule_priority IS NULL '
end
- if options[:rule_priority_id]
- conditions += ' AND project_measures.rule_priority=:priority'
- values[:priority]=options[:rule_priority_id]
- elsif options[:rule_id].nil?
- conditions += ' AND project_measures.rule_priority IS NULL'
- end
if options[:characteristic]
conditions += ' AND project_measures.characteristic_id=:characteristic_id'
- values[:characteristic_id]=options[:characteristic].id
+ condition_values[:characteristic_id]=options[:characteristic].id
else
conditions += ' AND project_measures.characteristic_id IS NULL'
end
@measures=ProjectMeasure.find(:all,
- :select => 'project_measures.id,project_measures.metric_id,project_measures.value,project_measures.text_value,project_measures.alert_status,project_measures.snapshot_id',
+ :select => "project_measures.id,project_measures.metric_id,project_measures.#{value_column},project_measures.text_value,project_measures.alert_status,project_measures.snapshot_id",
:joins => :snapshot,
- :conditions => [conditions,values],
+ :conditions => [conditions, condition_values],
:order => order,
:limit => 200)
-<tr class="<%= css -%> <%= 'selected' if @priority_id==priority_id -%>">
+<tr class="<%= css -%> <%= 'selected' if Sonar::RulePriority.to_s(priority_id)==params[:priority] -%>">
<td><%= image_tag "priority/#{priority_id}.png" %></td>
- <td>
- <%= link_to label,
- {:controller => 'drilldown', :action => 'violations', :id => @project.id, :priority => Sonar::RulePriority.to_s(priority_id)} %>
-
- </td>
- <td style="padding-left: 10px;" align="right">
- <% measure = measures.select{|m| m.rule_priority==priority_id}.first %>
- <%= format_measure(measure) -%>
- </td>
- <td align="left">
- <%= barchart(:width => 60, :percent => (measure ? (100 * measure.value / max).to_i : 0), :color => '#777') if max>0 %>
- </td>
+ <td><%= link_to label, {:controller => 'drilldown', :action => 'violations', :id => @project.id, :priority => Sonar::RulePriority.to_s(priority_id)} %></td>
+ <td style="padding-left: 10px;" align="right">
+ <%= format_measure(measure) -%>
+ </td>
+ <td align="left">
+ <%= barchart(:width => 60, :percent => (measure ? (100 * measure.value / max).to_i : 0), :color => '#777') if max>0 %>
+ </td>
</tr>
\ No newline at end of file
<tr>
<td align="left" width="1%" nowrap class="column first">
- <%
- rule_priority_measures = @snapshot.rule_priority_measures(Metric::VIOLATIONS)
+ <%
max = 0
- rule_priority_measures.each do |m|
- max = m.value if m.value and m.value>max
- end
+ blocker_violations=@snapshot.measure('blocker_violations')
+ critical_violations=@snapshot.measure('critical_violations')
+ major_violations=@snapshot.measure('major_violations')
+ minor_violations=@snapshot.measure('minor_violations')
+ info_violations=@snapshot.measure('info_violations')
+
+ [blocker_violations, critical_violations, major_violations, minor_violations, info_violations].each do |m|
+ max = m.value if m && m.value && m.value>max
+ end
%>
<h3>Severity</h3>
<table class="spacedicon" style="border: 1px solid #ccc;">
- <%= render :partial => 'rule_priority', :locals => {:label => 'Blocker', :css => 'even', :priority_id => Sonar::RulePriority::PRIORITY_BLOCKER, :max => max, :measures => rule_priority_measures }%>
- <%= render :partial => 'rule_priority', :locals => {:label => 'Critical', :css => 'odd', :priority_id => Sonar::RulePriority::PRIORITY_CRITICAL, :max => max, :measures => rule_priority_measures }%>
- <%= render :partial => 'rule_priority', :locals => {:label => 'Major', :css => 'even', :priority_id => Sonar::RulePriority::PRIORITY_MAJOR, :max => max, :measures => rule_priority_measures }%>
- <%= render :partial => 'rule_priority', :locals => {:label => 'Minor', :css => 'odd', :priority_id => Sonar::RulePriority::PRIORITY_MINOR, :max => max, :measures => rule_priority_measures }%>
- <%= render :partial => 'rule_priority', :locals => {:label => 'Info', :css => 'even', :priority_id => Sonar::RulePriority::PRIORITY_INFO, :max => max, :measures => rule_priority_measures }%>
+ <%= render :partial => 'rule_priority', :locals => {:label => 'Blocker', :css => 'even', :priority_id => Sonar::RulePriority::PRIORITY_BLOCKER, :max => max, :measure => blocker_violations }%>
+ <%= render :partial => 'rule_priority', :locals => {:label => 'Critical', :css => 'odd', :priority_id => Sonar::RulePriority::PRIORITY_CRITICAL, :max => max, :measure => critical_violations }%>
+ <%= render :partial => 'rule_priority', :locals => {:label => 'Major', :css => 'even', :priority_id => Sonar::RulePriority::PRIORITY_MAJOR, :max => max, :measure => major_violations }%>
+ <%= render :partial => 'rule_priority', :locals => {:label => 'Minor', :css => 'odd', :priority_id => Sonar::RulePriority::PRIORITY_MINOR, :max => max, :measure => minor_violations }%>
+ <%= render :partial => 'rule_priority', :locals => {:label => 'Info', :css => 'even', :priority_id => Sonar::RulePriority::PRIORITY_INFO, :max => max, :measure => info_violations }%>
</table>
</td>
<td class="column" align="left" style="white-space: normal;">
<div class="scrollable">
<table class="spacedicon" width="100%" id="col_rules">
<%
- rule_measures=@snapshot.rule_measures(Metric.by_key(Metric::VIOLATIONS), @priority_id)
+ rule_measures=@snapshot.rule_measures(Metric.by_key('violations'), @priority_id)
max=0
rule_index=0
rule_measures.each { |m| max=m.value if m.value>max }
<% if @priority_id %>
<%= Sonar::RulePriority.to_s(@priority_id) %> <%= link_to 'clear', {:overwrite_params => {:priority => nil}} %>
<% else %>
-Any <%= @filter %>
+Any severity
<% end %> »
<% if @rule %>
<%= h @rule.name %> <%= link_to 'clear', {:overwrite_params => {:rule => nil}} %>
--- /dev/null
+#
+# Sonar, entreprise quality control tool.
+# Copyright (C) 2009 SonarSource SA
+# mailto:contact AT sonarsource DOT com
+#
+# Sonar is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 3 of the License, or (at your option) any later version.
+#
+# Sonar is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with Sonar; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+#
+
+#
+# Sonar 2.5
+#
+class DeleteMeasuresOnViolationsAndPriority < ActiveRecord::Migration
+
+ def self.up
+ puts "If the following step fails, please execute the SQL request 'DELETE FROM PROJECT_MEASURES WHERE RULE_ID IS NULL AND RULE_PRIORITY IS NOT NULL' and restart Sonar."
+ ProjectMeasure.delete_all('rule_id is null and rule_priority is not null')
+ end
+
+end