aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-server
diff options
context:
space:
mode:
authorsimonbrandhof <simon.brandhof@gmail.com>2011-05-05 17:19:26 +0200
committersimonbrandhof <simon.brandhof@gmail.com>2011-05-05 17:19:26 +0200
commit8ee5ce3071082e0fb26f8984bcaa8f5bdb7877d7 (patch)
tree0b98281692ee6e044f90d9ad6e26f90aaeb47e9e /sonar-server
parent1f63c2d10bed4f4505242eedd9ea4d8e7cf155c2 (diff)
downloadsonarqube-8ee5ce3071082e0fb26f8984bcaa8f5bdb7877d7.tar.gz
sonarqube-8ee5ce3071082e0fb26f8984bcaa8f5bdb7877d7.zip
Improve the web services 'violations' and 'reviews'
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>
Diffstat (limited to 'sonar-server')
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/controllers/api/reviews_controller.rb2
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/controllers/api/violations_controller.rb4
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/models/api/utils.rb4
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/models/review.rb6
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/models/review_comment.rb4
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/models/rule_failure.rb13
6 files changed, 24 insertions, 9 deletions
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/api/reviews_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/api/reviews_controller.rb
index b178a345f5c..4638eafc9c3 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/api/reviews_controller.rb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/api/reviews_controller.rb
@@ -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|
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/api/violations_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/api/violations_controller.rb
index a22223d549d..02be1887f62 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/api/violations_controller.rb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/api/violations_controller.rb
@@ -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
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/models/api/utils.rb b/sonar-server/src/main/webapp/WEB-INF/app/models/api/utils.rb
index 5aeb88e1d02..a007048931b 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/models/api/utils.rb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/models/api/utils.rb
@@ -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
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/models/review.rb b/sonar-server/src/main/webapp/WEB-INF/app/models/review.rb
index 6d5af841492..dbfa303a2db 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/models/review.rb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/models/review.rb
@@ -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
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/models/review_comment.rb b/sonar-server/src/main/webapp/WEB-INF/app/models/review_comment.rb
index 214f1afa4f9..b8059c19b07 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/models/review_comment.rb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/models/review_comment.rb
@@ -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
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 9842e8dfbb7..eda6220717f 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
@@ -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?