]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-1937 add the field 'age' to violations web service + display the select box...
authorsimonbrandhof <simon.brandhof@gmail.com>
Tue, 7 Dec 2010 16:17:50 +0000 (16:17 +0000)
committersimonbrandhof <simon.brandhof@gmail.com>
Tue, 7 Dec 2010 16:17:50 +0000 (16:17 +0000)
plugins/sonar-core-gwt/src/main/java/org/sonar/plugins/core/violationsviewer/client/ViolationsPanel.java
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/TimeMachineConfigurationPersister.java
sonar-gwt-api/src/main/java/org/sonar/wsclient/gwt/unmarshallers/ViolationUnmarshaller.java
sonar-server/src/main/webapp/WEB-INF/app/helpers/drilldown_helper.rb
sonar-server/src/main/webapp/WEB-INF/app/models/rule_failure.rb
sonar-server/src/main/webapp/WEB-INF/app/views/dashboard/_header.html.erb
sonar-server/src/main/webapp/WEB-INF/app/views/drilldown/violations.html.erb
sonar-server/src/main/webapp/WEB-INF/app/views/project/_snapshot_title.html.erb
sonar-server/src/main/webapp/WEB-INF/app/views/project/index.html.erb
sonar-ws-client/src/main/java/org/sonar/wsclient/services/Violation.java
sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/ViolationUnmarshaller.java

index 772325dfa836a5f7488d0d43d50a3120adff568a..14cf189a9f0132cdac94cf2fc63241e14c8bdd62 100644 (file)
@@ -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>";
     }
   }
 
index f119344ba32d78e7089230b9826912aa91685174..d7f586d3993caa75aa4678621409f0a517d9e690 100644 (file)
@@ -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();
   }
 }
index 7dc2efae3a5d3d3e48dbf3d57237c19e8769c245..d5fff51f259590e9e7a2fadb146bdfce8547124c 100644 (file)
@@ -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) {
index 43576d79496fb23deb23fd5d80e8d0660da7abd9..7820bc175032bb24a81bd2f2962d3496748a379c 100644 (file)
@@ -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
index 181b4332bf31f8afab40c7e363ad1664b26037a1..3b4e73b4de7b8bccda3b620d380bc1744be84707 100644 (file)
@@ -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)
index 6e60e64b5d6ec2e7e66e41ab2591989136e3b7cc..331bea8eb7ceb7be7112bf43e97dcf5fec57cd5d 100644 (file)
   <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>
index 2a5b503eeca40691b59341a4175df9d1bde197ec..b59824efa91d8770b05a9c14c75b2cb84121b2eb 100644 (file)
@@ -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} %>
 
index c5a57fb1533b6b1f3b122f5e632cf5068d5984e8..cecfecef2e3951e4e1874408503e29cb0acdd5b8 100644 (file)
@@ -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>
index 4789e49b0f8f740353e39487a5b22067e53fb87f..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 100644 (file)
@@ -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
index ff0c3f22ce9289b329f96519d2613275be6e138d..c984d15a3bf4b3e13b80f014c670e633f83e7d60 100644 (file)
@@ -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;
@@ -133,6 +134,18 @@ public class Violation extends Model {
     return this;
   }
 
+  /**
+   * @since 2.5
+   */
+  public Integer getAge() {
+    return age;
+  }
+
+  public Violation setAge(Integer age) {
+    this.age = age;
+    return this;
+  }
+
   /**
    * @since 2.5
    */
index 258e5938570a2db796ac1f1cd867971178a471ca..c0c5aa538cc732cd52b64a9e29e0c1342d4b2a09 100644 (file)
@@ -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) {