]> source.dussan.org Git - sonarqube.git/commitdiff
Improve the web services 'violations' and 'reviews'
authorsimonbrandhof <simon.brandhof@gmail.com>
Thu, 5 May 2011 15:19:26 +0000 (17:19 +0200)
committersimonbrandhof <simon.brandhof@gmail.com>
Thu, 5 May 2011 15:19:26 +0000 (17:19 +0200)
SONAR-2249 always use unix newline (LF) in violation messages
SONAR-2382 always use unix newlines (LF) in review comments (plain output)
SONAR-2382 use upper-case constants for output parameter
SONAR-2382 replace the XML node <user> by <author>

sonar-server/src/main/webapp/WEB-INF/app/controllers/api/reviews_controller.rb
sonar-server/src/main/webapp/WEB-INF/app/controllers/api/violations_controller.rb
sonar-server/src/main/webapp/WEB-INF/app/models/api/utils.rb
sonar-server/src/main/webapp/WEB-INF/app/models/review.rb
sonar-server/src/main/webapp/WEB-INF/app/models/review_comment.rb
sonar-server/src/main/webapp/WEB-INF/app/models/rule_failure.rb
sonar-ws-client/src/main/java/org/sonar/wsclient/services/ReviewQuery.java

index b178a345f5c21fc3af67ee2c9842c500a06ecb08..4638eafc9c3b061d6bc578b2ada9ac7ade0edabd 100644 (file)
@@ -23,7 +23,7 @@ require 'json'
 class Api::ReviewsController < Api::ApiController
 
   def index
-    convert_markdown=(params[:output]=='html')
+    convert_markdown=(params[:output]=='HTML')
     reviews=select_authorized(:user, Review.search(params), :project)
     
     respond_to do |format|
index a22223d549d774cc7f2ae8d44809e9c30aec76a0..02be1887f6202a4eb164f51477db2f1905e5567e 100644 (file)
@@ -93,13 +93,13 @@ class Api::ViolationsController < Api::ResourceRestController
 
   def rest_to_json(rule_failures)
     include_review=(params['include_review']=='true')
-    convert_markdown=(params[:output]=='html')
+    convert_markdown=(params[:output]=='HTML')
     JSON(rule_failures.collect{|rule_failure| rule_failure.to_json(include_review, convert_markdown)})
   end
 
   def rest_to_xml(rule_failures)
     include_review=(params['include_review']=='true')
-    convert_markdown=(params[:output]=='html')
+    convert_markdown=(params[:output]=='HTML')
     xml = Builder::XmlMarkup.new(:indent => 0)
     xml.instruct!
     xml.violations do
index 5aeb88e1d02176aaff0f791975c07d6eec82d2e6..a007048931b76cbb72e66bdf28f9a1e0e66a27a4 100644 (file)
@@ -47,4 +47,8 @@ class Api::Utils
     # See http://jira.codehaus.org/browse/SONAR-2282
     input.split(/\r?\n|\r/, -1)
   end
+
+  def self.convert_string_to_unix_newlines(input)
+    split_newlines(input).join('\n')
+  end
 end
index 6d5af84149259a475dc6c569c3dca8d954e8e408..dbfa303a2db1e7b186656fbd1e85a56c6e3240cc 100644 (file)
@@ -143,7 +143,7 @@ class Review < ActiveRecord::Base
       xml.id(id.to_i)
       xml.createdAt(Api::Utils.format_datetime(created_at))
       xml.updatedAt(Api::Utils.format_datetime(updated_at))
-      xml.user(user.login)
+      xml.author(user.login)
       xml.assignee(assignee.login) if assignee
       xml.title(title)
       xml.type(review_type)
@@ -159,7 +159,7 @@ class Review < ActiveRecord::Base
             if convert_markdown 
               xml.text(comment.html_text)
             else
-              xml.text(comment.review_text)
+              xml.text(comment.plain_text)
             end
           end
         end
@@ -189,7 +189,7 @@ class Review < ActiveRecord::Base
       comments << {
         'author' => comment.user.login,
         'updatedAt' => Api::Utils.format_datetime(comment.updated_at),
-        'text' => convert_markdown ? comment.html_text : comment.review_text
+        'text' => convert_markdown ? comment.html_text : comment.plain_text
       }
     end
     json['comments'] = comments
index 214f1afa4f9471fe262be47f8a3e6465ed035ca0..b8059c19b07017bfe0529f1d6260c58089058db1 100644 (file)
@@ -29,6 +29,10 @@ class ReviewComment < ActiveRecord::Base
     Api::Utils.markdown_to_html(review_text)
   end
 
+  def plain_text
+    Api::Utils.convert_string_to_unix_newlines(review_text)
+  end
+
   private
 
   def comment_should_not_be_blank
index 9842e8dfbb74fcf806b6bc21d3ae4f2d9fb32ffc..eda6220717f18a32ef4a636e37105658aec9665d 100644 (file)
@@ -36,7 +36,14 @@ class RuleFailure < ActiveRecord::Base
           end
         end
   end
-  
+
+  def plain_message
+    @plain_message ||=
+        begin
+          Api::Utils.convert_string_to_unix_newlines(message)
+        end
+  end
+
   def html_message
     @html_message ||=
       begin
@@ -46,7 +53,7 @@ class RuleFailure < ActiveRecord::Base
 
   def to_json(include_review=false, convert_markdown=false)
     json = {}
-    json['message'] = message
+    json['message'] = plain_message if plain_message
     json['line'] = line if line && line>=1
     json['priority'] = Sonar::RulePriority.to_s(failure_level).upcase
     json['switchedOff']=true if switched_off?
@@ -70,7 +77,7 @@ class RuleFailure < ActiveRecord::Base
 
   def to_xml(xml=Builder::XmlMarkup.new(:indent => 0), include_review=false, convert_markdown=false)
     xml.violation do
-      xml.message(message)
+      xml.message(plain_message) if plain_message
       xml.line(line) if line && line>=1
       xml.priority(Sonar::RulePriority.to_s(failure_level))
       xml.switchedOff(true) if switched_off?
index 5914e4d3de1047a97d826c4402da21e12dca5fa9..dda32f50a08492b0d6d6ecdfc2bf366d2285fe58 100644 (file)
@@ -26,6 +26,9 @@ public class ReviewQuery extends Query<Review> {
 
   public static final String BASE_URL = "/api/reviews";
 
+  public static final String OUTPUT_PLAIN = "PLAIN";
+  public static final String OUTPUT_HTML = "HTML";
+
   private String reviewType;
   private Long id;
   private Long[] ids;
@@ -195,9 +198,6 @@ public class ReviewQuery extends Query<Review> {
     return output;
   }
 
-  /**
-   * @param output the output to set
-   */
   public ReviewQuery setOutput(String output) {
     this.output = output;
     return this;