diff options
author | simonbrandhof <simon.brandhof@gmail.com> | 2010-12-07 16:17:50 +0000 |
---|---|---|
committer | simonbrandhof <simon.brandhof@gmail.com> | 2010-12-07 16:17:50 +0000 |
commit | 0cd519b35d499f60fceec66f08dc7ca80301f127 (patch) | |
tree | 8c9a547da0ee1ce5c1bf20e9d139f1f705b42bec | |
parent | c1cfffea2098a53ab078deb9bebe47b627c389cf (diff) | |
download | sonarqube-0cd519b35d499f60fceec66f08dc7ca80301f127.tar.gz sonarqube-0cd519b35d499f60fceec66f08dc7ca80301f127.zip |
SONAR-1937 add the field 'age' to violations web service + display the select box to filter violations by period
11 files changed, 68 insertions, 60 deletions
diff --git a/plugins/sonar-core-gwt/src/main/java/org/sonar/plugins/core/violationsviewer/client/ViolationsPanel.java b/plugins/sonar-core-gwt/src/main/java/org/sonar/plugins/core/violationsviewer/client/ViolationsPanel.java index 772325dfa83..14cf189a9f0 100644 --- a/plugins/sonar-core-gwt/src/main/java/org/sonar/plugins/core/violationsviewer/client/ViolationsPanel.java +++ b/plugins/sonar-core-gwt/src/main/java/org/sonar/plugins/core/violationsviewer/client/ViolationsPanel.java @@ -139,13 +139,16 @@ public class ViolationsPanel extends SourcePanel { @Override public String getColumn4() { + String age = ""; + if (violation.getAge()!=null && violation.getAge()>0) { + age = " <span class='note'>(" + violation.getAge() + " days)</span>"; + } return "<div class=\"warn\">" + Icons.forPriority(violation.getPriority()).getHTML() + "</img> " - + Utils.formatDate(violation.getCreatedAt()) + " <a href=\"" + Links.urlForRule(violation.getRuleKey(), false) + "\" onclick=\"window.open(this.href,'rule','height=800,width=900,scrollbars=1,resizable=1');return false;\" title=\"" + violation.getRuleKey() + "\"><b>" + Utils.escapeHtml(violation.getRuleName()) + "</b></a> : " - + Utils.escapeHtml(violation.getMessage()) + "</div>"; + + Utils.escapeHtml(violation.getMessage()) + age + "</div>"; } } diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/TimeMachineConfigurationPersister.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/TimeMachineConfigurationPersister.java index f119344ba32..d7f586d3993 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/TimeMachineConfigurationPersister.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/TimeMachineConfigurationPersister.java @@ -40,9 +40,11 @@ public final class TimeMachineConfigurationPersister implements BatchExtension { public void start() { List<PastSnapshot> variationSnapshots = configuration.getProjectPastSnapshots(); for (PastSnapshot variationSnapshot : variationSnapshots) { + projectSnapshot = session.reattach(Snapshot.class, projectSnapshot.getId()); projectSnapshot.setVariationMode(variationSnapshot.getIndex(), variationSnapshot.getMode()); projectSnapshot.setVariationModeParam(variationSnapshot.getIndex(), variationSnapshot.getModeParameter()); session.save(projectSnapshot); } + session.commit(); } } diff --git a/sonar-gwt-api/src/main/java/org/sonar/wsclient/gwt/unmarshallers/ViolationUnmarshaller.java b/sonar-gwt-api/src/main/java/org/sonar/wsclient/gwt/unmarshallers/ViolationUnmarshaller.java index 7dc2efae3a5..d5fff51f259 100644 --- a/sonar-gwt-api/src/main/java/org/sonar/wsclient/gwt/unmarshallers/ViolationUnmarshaller.java +++ b/sonar-gwt-api/src/main/java/org/sonar/wsclient/gwt/unmarshallers/ViolationUnmarshaller.java @@ -29,8 +29,9 @@ public class ViolationUnmarshaller extends AbstractUnmarshaller<Violation> { Violation violation = new Violation(); violation.setMessage(JsonUtils.getString(json, "message")); violation.setLine(JsonUtils.getInteger(json, "line")); - violation.setPriority(JsonUtils.getString(json, "priority")); + violation.setSeverity(JsonUtils.getString(json, "priority")); violation.setCreatedAt(JsonUtils.getDate(json, "createdAt")); + violation.setAge(JsonUtils.getInteger(json, "age")); JSONObject rule = (JSONObject) json.get("rule"); if (rule != null) { diff --git a/sonar-server/src/main/webapp/WEB-INF/app/helpers/drilldown_helper.rb b/sonar-server/src/main/webapp/WEB-INF/app/helpers/drilldown_helper.rb index 43576d79496..7820bc17503 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/helpers/drilldown_helper.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/helpers/drilldown_helper.rb @@ -18,6 +18,7 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 # module DrilldownHelper + include DashboardHelper def measure_or_variation_value(measure) if measure diff --git a/sonar-server/src/main/webapp/WEB-INF/app/models/rule_failure.rb b/sonar-server/src/main/webapp/WEB-INF/app/models/rule_failure.rb index 181b4332bf3..3b4e73b4de7 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/models/rule_failure.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/models/rule_failure.rb @@ -23,21 +23,34 @@ class RuleFailure < ActiveRecord::Base belongs_to :rule belongs_to :snapshot + def age_in_days + if created_at + ((snapshot.created_at - created_at)/(60 * 60 * 24)).to_i + else + nil + end + end + def to_hash_json json = {} json['message'] = message json['line'] = line if line json['priority'] = Sonar::RulePriority.to_s(failure_level).upcase - json['createdAt'] = format_datetime(created_at) if created_at + if created_at + json['createdAt'] = format_datetime(created_at) + json['age'] = age_in_days + end json['rule'] = { :key => rule.key, - :name => rule.name} + :name => rule.name + } json['resource'] = { :key => snapshot.project.key, :name => snapshot.project.name, :scope => snapshot.project.scope, :qualifier => snapshot.project.qualifier, - :language => snapshot.project.language} + :language => snapshot.project.language + } json end @@ -46,7 +59,10 @@ class RuleFailure < ActiveRecord::Base xml.message(message) xml.line(line) if line xml.priority(Sonar::RulePriority.to_s(failure_level)) - xml.createdAt(format_datetime(created_at)) if created_at + if created_at + xml.createdAt(format_datetime(created_at)) + xml.age(age_in_days) + end xml.rule do xml.key(rule.key) xml.name(rule.name) diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/dashboard/_header.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/dashboard/_header.html.erb index 6e60e64b5d6..331bea8eb7c 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/dashboard/_header.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/dashboard/_header.html.erb @@ -17,10 +17,9 @@ <div id="snapshot_title" class="page_title"> <h4> <% - version_event=@snapshot.event(EventCategory::KEY_VERSION) profile_measure=@snapshot.measure(Metric::PROFILE) %> - <%= link_to_favourite(@project) -%> <%= "#{version_event.fullname} - " if version_event %> <%= l @snapshot.created_at %> + <%= link_to_favourite(@project) -%> Version <%= @snapshot.version -%> - <%= l @snapshot.created_at %> <% if profile_measure %> - Profile <%= link_to profile_measure.data, :controller => '/rules_configuration', :action => 'index', :id => profile_measure.value.to_i %><% end %> - Compare to <form method="GET" action="<%= url_for :only_path=>true, :overwrite_params => {:var => nil} -%>" style="display: inline"> @@ -29,6 +28,8 @@ <%= variation_select_option(@snapshot, 1) -%> <%= variation_select_option(@snapshot, 2) -%> <%= variation_select_option(@snapshot, 3) -%> + <%= variation_select_option(@snapshot, 4) -%> + <%= variation_select_option(@snapshot, 5) -%> </select> </form> </h4> diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/drilldown/violations.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/drilldown/violations.html.erb index 2a5b503eeca..b59824efa91 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/drilldown/violations.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/drilldown/violations.html.erb @@ -1,4 +1,23 @@ -<%= render :partial => 'project/snapshot_title' -%> +<div id="snapshot_title" class="page_title"> +<h4> +<% + profile_measure=@snapshot.measure(Metric::PROFILE) + %> +<%= link_to_favourite(@project) -%> Version <%= @snapshot.version -%> - <%= l @snapshot.created_at %> +<% if profile_measure %> - Profile <%= link_to profile_measure.data, :controller => '/rules_configuration', :action => 'index', :id => profile_measure.value.to_i %><% end %> +- <form method="GET" action="<%= url_for :only_path=>true, :overwrite_params => {:var => nil} -%>" style="display: inline"> + <select id="select-comparison" name="var" onchange="submit()" class="small"> + <option value="">All violations</option> + <%= variation_select_option(@snapshot, 1) -%> + <%= variation_select_option(@snapshot, 2) -%> + <%= variation_select_option(@snapshot, 3) -%> + <%= variation_select_option(@snapshot, 4) -%> + <%= variation_select_option(@snapshot, 5) -%> + </select> + </form> +</h4> +</div> + <%= render :partial => 'gwt/base', :locals => {:resource => @highlighted_resource, :popup => false, :metric => 'violations'} %> <%= render :partial => 'gwt/resource_viewers', :locals => {:resource => @project} %> diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/project/_snapshot_title.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/project/_snapshot_title.html.erb index c5a57fb1533..cecfecef2e3 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/project/_snapshot_title.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/project/_snapshot_title.html.erb @@ -5,7 +5,7 @@ version_event=@snapshot.event(EventCategory::KEY_VERSION) profile_measure=@snapshot.measure(Metric::PROFILE) %> -<%= link_to_favourite(@project) -%> <%= "#{version_event.fullname} - " if version_event %> <%= l @snapshot.created_at %> +<%= link_to_favourite(@project) -%> Version <%= "#{@snapshot.version} -%> - <%= l @snapshot.created_at %> <% if profile_measure %> - profile <%= link_to profile_measure.data, :controller => '/rules_configuration', :action => 'index', :id => profile_measure.value.to_i %><% end %> </h4> </div> diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/project/index.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/project/index.html.erb index 4789e49b0f8..e69de29bb2d 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/project/index.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/project/index.html.erb @@ -1,49 +0,0 @@ -<div id='dashboard'> -<%= render :partial => 'project/snapshot_title' %> -<table><tr> - <td width="390px" valign="top" style="padding: 0 4px 0 0"> - - </td> - <td width="390px" valign="top" style="padding: 0 0 0 4px"> - -<% @widgets.each do |widget| - begin - widget_body=render :inline => widget.getTarget().getTemplate() - rescue => error - logger.error("Can not render widget #{widget.getId()}: " + error) - logger.error(error.backtrace.join("\n")) - widget_body="<p>Can not render widget #{widget.getTitle()}. See logs.</p>" - end - if widget_body.include? '<' -%> -<div id="<%= widget.getId() -%>" class="widget"> -<%= widget_body %> -<div class="clear"></div> -</div> -<% else %> -<div id="<%= widget.getId() -%>" ></div> -<% end -end %> - </td> -</tr></table> -<script type="text/javascript"> - function selectReviewMetric(){ - $$('.review_description_update').each(function(element) { - element.hide(); - }); - review = $('review_metric_id').value; - $('review_description_'+review).show(); - $('review_value_'+review).show(); - } - - function selectEventCateg(){ - $$('#event_cat_desc .comments').each(function(elt) { - elt.hide(); - }); - selected_categ = $('event_category').value; - if (selected_categ!=null && selected_categ!='') { - $('event_cat_desc_'+selected_categ).show(); - } - } -</script> -</div>
\ No newline at end of file diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/Violation.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/Violation.java index ff0c3f22ce9..c984d15a3bf 100644 --- a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/Violation.java +++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/Violation.java @@ -33,6 +33,7 @@ public class Violation extends Model { private String resourceScope = null; private String resourceQualifier = null; private Date createdAt = null; + private Integer age = null; public String getMessage() { return message; @@ -136,6 +137,18 @@ public class Violation extends Model { /** * @since 2.5 */ + public Integer getAge() { + return age; + } + + public Violation setAge(Integer age) { + this.age = age; + return this; + } + + /** + * @since 2.5 + */ public Date getCreatedAt() { return createdAt; } diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/ViolationUnmarshaller.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/ViolationUnmarshaller.java index 258e5938570..c0c5aa538cc 100644 --- a/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/ViolationUnmarshaller.java +++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/ViolationUnmarshaller.java @@ -31,6 +31,7 @@ public class ViolationUnmarshaller extends AbstractUnmarshaller<Violation> { violation.setLine(JsonUtils.getInteger(json, "line")); violation.setSeverity(JsonUtils.getString(json, "priority")); violation.setCreatedAt(JsonUtils.getDateTime(json, "createdAt")); + violation.setAge(JsonUtils.getInteger(json, "age")); JSONObject rule = (JSONObject) json.get("rule"); if (rule != null) { |