aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-server/src/main/webapp
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@gmail.com>2012-02-20 10:35:51 +0100
committerSimon Brandhof <simon.brandhof@gmail.com>2012-02-20 10:36:20 +0100
commit1b0a3a26064a45bcd9e2e06c69ea6fc5e49a9939 (patch)
tree21286b9e8343a15667d8abf62ed887accf1495ac /sonar-server/src/main/webapp
parent8143b2c18b7fa996b8ddc8e45db5372481408197 (diff)
downloadsonarqube-1b0a3a26064a45bcd9e2e06c69ea6fc5e49a9939.tar.gz
sonarqube-1b0a3a26064a45bcd9e2e06c69ea6fc5e49a9939.zip
SONAR-3255 Drilling down into violations from SQALE does not land properly
Diffstat (limited to 'sonar-server/src/main/webapp')
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/controllers/drilldown_controller.rb26
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/models/snapshot.rb37
2 files changed, 43 insertions, 20 deletions
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/drilldown_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/drilldown_controller.rb
index 331acca65fd..44e001d1d9a 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/drilldown_controller.rb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/drilldown_controller.rb
@@ -78,6 +78,13 @@ class DrilldownController < ApplicationController
@severity = params[:severity] || params[:priority]
@rule_severity = params[:rule_sev] || @severity
+
+ if @rule && @rule_severity.blank?
+ # workaround for SONAR-3255 : guess the severity
+ @rule_severity=guess_rule_severity(@snapshot, @rule, metric_prefix)
+ end
+
+
if @rule_severity.present?
# Filter resources by severity
@metric = Metric::by_key("#{metric_prefix}#{@rule_severity.downcase}_violations")
@@ -122,11 +129,11 @@ class DrilldownController < ApplicationController
else
# No filter -> loads all the rules
metrics=[
- Metric.by_key("#{metric_prefix}blocker_violations"),
- Metric.by_key("#{metric_prefix}critical_violations"),
- Metric.by_key("#{metric_prefix}major_violations"),
- Metric.by_key("#{metric_prefix}minor_violations"),
- Metric.by_key("#{metric_prefix}info_violations")
+ Metric.by_key("#{metric_prefix}blocker_violations"),
+ Metric.by_key("#{metric_prefix}critical_violations"),
+ Metric.by_key("#{metric_prefix}major_violations"),
+ Metric.by_key("#{metric_prefix}minor_violations"),
+ Metric.by_key("#{metric_prefix}info_violations")
]
@rule_measures = @snapshot.rule_measures(metrics)
end
@@ -190,4 +197,13 @@ class DrilldownController < ApplicationController
return true if snapshot.file?
snapshot.violations.size>0
end
+
+ def guess_rule_severity(snapshot, rule, metric_prefix)
+ Severity::KEYS.each do |severity|
+ if snapshot.rule_measure(Metric.by_key("#{metric_prefix}#{severity.downcase}_violations"), rule)
+ return severity
+ end
+ Severity::MAJOR
+ end
+ end
end
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/models/snapshot.rb b/sonar-server/src/main/webapp/WEB-INF/app/models/snapshot.rb
index 464f783eeab..d600cf6ef3c 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/models/snapshot.rb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/models/snapshot.rb
@@ -98,20 +98,20 @@ class Snapshot < ActiveRecord::Base
def root_snapshot
@root_snapshot ||=
- (root_snapshot_id ? Snapshot.find(root_snapshot_id) : self)
+ (root_snapshot_id ? Snapshot.find(root_snapshot_id) : self)
end
def project_snapshot
@project_snapshot ||=
- begin
- if scope==Project::SCOPE_SET
- self
- elsif parent_snapshot_id
- parent_snapshot.project_snapshot
- else
- nil
- end
+ begin
+ if scope==Project::SCOPE_SET
+ self
+ elsif parent_snapshot_id
+ parent_snapshot.project_snapshot
+ else
+ nil
end
+ end
end
def root?
@@ -189,6 +189,13 @@ class Snapshot < ActiveRecord::Base
end
end
+ def rule_measure(metric, rule)
+ rulemeasures.each do |m|
+ return m if m.metric_id==metric.id && m.rule_id==rule.id
+ end
+ nil
+ end
+
def self.snapshot_by_date(resource_id, date)
if resource_id && date
Snapshot.find(:first, :conditions => ['created_at>=? and created_at<? and project_id=?', date.beginning_of_day, date.end_of_day, resource_id], :order => 'created_at desc')
@@ -245,13 +252,13 @@ class Snapshot < ActiveRecord::Base
def measures_hash
@measures_hash ||=
- begin
- hash = {}
- measures.each do |measure|
- hash[measure.metric_id]=measure
- end
- hash
+ begin
+ hash = {}
+ measures.each do |measure|
+ hash[measure.metric_id]=measure
end
+ hash
+ end
end
end