aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-web/src
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@sonarsource.com>2016-07-01 16:16:38 +0200
committerSimon Brandhof <simon.brandhof@sonarsource.com>2016-07-04 10:25:07 +0200
commit479c7533db672c2e4b96e8fdcc41142570c39069 (patch)
tree4a47e27a4dd796e7b00649b0df2ed24ece5aea31 /server/sonar-web/src
parent1cc993f6dae7a22df577faa7101d06dc6c594974 (diff)
downloadsonarqube-479c7533db672c2e4b96e8fdcc41142570c39069.tar.gz
sonarqube-479c7533db672c2e4b96e8fdcc41142570c39069.zip
Revert "SONAR-7858 Stop support of XML response in web services"
This reverts commit 8d277d413f1739763f32d893c7eb9740bcac6c57.
Diffstat (limited to 'server/sonar-web/src')
-rw-r--r--server/sonar-web/src/main/webapp/WEB-INF/app/controllers/api/api_controller.rb6
-rw-r--r--server/sonar-web/src/main/webapp/WEB-INF/app/controllers/api/components_controller.rb6
-rw-r--r--server/sonar-web/src/main/webapp/WEB-INF/app/controllers/api/events_controller.rb38
-rw-r--r--server/sonar-web/src/main/webapp/WEB-INF/app/controllers/api/favourites_controller.rb41
-rw-r--r--server/sonar-web/src/main/webapp/WEB-INF/app/controllers/api/issues_controller.rb23
-rw-r--r--server/sonar-web/src/main/webapp/WEB-INF/app/controllers/api/profiles_controller.rb39
-rw-r--r--server/sonar-web/src/main/webapp/WEB-INF/app/controllers/api/projects_controller.rb36
-rw-r--r--server/sonar-web/src/main/webapp/WEB-INF/app/controllers/api/properties_controller.rb26
-rw-r--r--server/sonar-web/src/main/webapp/WEB-INF/app/controllers/api/resources_controller.rb102
-rw-r--r--server/sonar-web/src/main/webapp/WEB-INF/app/controllers/api/rest_controller.rb6
-rw-r--r--server/sonar-web/src/main/webapp/WEB-INF/app/controllers/api/server_controller.rb18
-rw-r--r--server/sonar-web/src/main/webapp/WEB-INF/app/controllers/api/tests_controller.rb12
-rw-r--r--server/sonar-web/src/main/webapp/WEB-INF/app/controllers/api/updatecenter_controller.rb18
-rw-r--r--server/sonar-web/src/main/webapp/WEB-INF/app/controllers/api/user_properties_controller.rb26
-rw-r--r--server/sonar-web/src/main/webapp/WEB-INF/app/models/metric.rb15
-rw-r--r--server/sonar-web/src/main/webapp/WEB-INF/app/models/project_link.rb8
-rw-r--r--server/sonar-web/src/main/webapp/WEB-INF/app/models/property.rb9
-rw-r--r--server/sonar-web/src/main/webapp/WEB-INF/app/models/rule.rb26
-rw-r--r--server/sonar-web/src/main/webapp/WEB-INF/app/models/rules_parameter.rb11
-rw-r--r--server/sonar-web/src/main/webapp/WEB-INF/app/models/widget_property.rb8
20 files changed, 444 insertions, 30 deletions
diff --git a/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/api/api_controller.rb b/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/api/api_controller.rb
index fea19b175de..dca3fc1bf57 100644
--- a/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/api/api_controller.rb
+++ b/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/api/api_controller.rb
@@ -119,7 +119,11 @@ class Api::ApiController < ApplicationController
end
def render_response(status, message)
- render :json => error_to_json(status, message), :status => status
+ respond_to do |format|
+ format.json { render :json => error_to_json(status, message), :status => status }
+ format.xml { render :xml => error_to_xml(status, message), :status => status }
+ format.text { render :text => message, :status => status }
+ end
end
def error_to_json(status, message=nil)
diff --git a/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/api/components_controller.rb b/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/api/components_controller.rb
index 24e4a86acd7..cdf63cd52a8 100644
--- a/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/api/components_controller.rb
+++ b/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/api/components_controller.rb
@@ -77,7 +77,11 @@ class Api::ComponentsController < Api::ApiController
end
json['results']=json_results
- render :json => jsonp(json)
+ respond_to do |format|
+ format.json { render :json => jsonp(json) }
+ format.xml { render :xml => xml_not_supported }
+ format.text { render :text => text_not_supported }
+ end
end
private
diff --git a/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/api/events_controller.rb b/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/api/events_controller.rb
index dec487de655..4269dee6bb5 100644
--- a/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/api/events_controller.rb
+++ b/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/api/events_controller.rb
@@ -67,7 +67,11 @@ class Api::EventsController < Api::ApiController
events=Event.find(:all, :conditions => [conditions.join(' AND '), values], :order => 'event_date DESC')
- render :json => jsonp(events_to_json(events))
+ respond_to do |format|
+ format.json { render :json => jsonp(events_to_json(events)) }
+ format.xml { render :xml => events_to_xml(events) }
+ format.text { render :text => text_not_supported }
+ end
rescue ApiException => e
render_error(e.msg, e.code)
@@ -85,7 +89,11 @@ class Api::EventsController < Api::ApiController
event=Event.find(params[:id])
load_resource_by_uuid(:user, event.component_uuid)
- render :json => jsonp(events_to_json([event]))
+ respond_to do |format|
+ format.json { render :json => jsonp(events_to_json([event])) }
+ format.xml { render :xml => events_to_xml([event]) }
+ format.text { render :text => text_not_supported }
+ end
rescue ActiveRecord::RecordNotFound => e
render_error(e.message, 404)
@@ -156,7 +164,12 @@ class Api::EventsController < Api::ApiController
event_to_return = event if snapshot.component_uuid = @resource.uuid
end
- render :json => jsonp(events_to_json([event_to_return]))
+
+ respond_to do |format|
+ format.json { render :json => jsonp(events_to_json([event_to_return])) }
+ format.xml { render :xml => events_to_xml([event_to_return]) }
+ format.text { render :text => text_not_supported }
+ end
rescue ApiException => e
render_error(e.msg, e.code)
@@ -260,4 +273,23 @@ class Api::EventsController < Api::ApiController
hash
end
+ def events_to_xml(events, xml=Builder::XmlMarkup.new(:indent => 0))
+ xml.events do
+ events.each do |event|
+ event_to_xml(event, xml)
+ end
+ end
+ end
+
+ def event_to_xml(event, xml=Builder::XmlMarkup.new(:indent => 0))
+ xml.event do
+ xml.id(event.id.to_s)
+ xml.name(event.name) if event.name
+ xml.resourceKey(event.resource.key) if event.resource
+ xml.category(event.category)
+ xml.date(Api::Utils.format_datetime(event.event_date)) if event.event_date
+ xml.description(event.description) if event.description
+ end
+ end
+
end
diff --git a/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/api/favourites_controller.rb b/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/api/favourites_controller.rb
index 91fb49f92e8..b92914e4723 100644
--- a/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/api/favourites_controller.rb
+++ b/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/api/favourites_controller.rb
@@ -29,7 +29,11 @@ class Api::FavouritesController < Api::ApiController
# curl http://localhost:9000/api/favourites -v -u admin:admin
#
def index
- render :json => jsonp(favourites_to_json(current_user.favourites))
+ respond_to do |format|
+ format.json { render :json => jsonp(favourites_to_json(current_user.favourites)) }
+ format.xml { render :xml => favourites_to_xml(current_user.favourites) }
+ format.text { render :text => text_not_supported }
+ end
end
#
@@ -39,7 +43,11 @@ class Api::FavouritesController < Api::ApiController
def create
favourite=current_user.add_favourite(params[:key])
if favourite
- render :json => jsonp(favourites_to_json([favourite]))
+ respond_to do |format|
+ format.json { render :json => jsonp(favourites_to_json([favourite])) }
+ format.xml { render :xml => favourites_to_xml([favourite]) }
+ format.text { render :text => text_not_supported }
+ end
else
render_error('Favourite not found', 404)
end
@@ -75,4 +83,33 @@ class Api::FavouritesController < Api::ApiController
hash
end
+ def favourites_to_xml(favourites, xml=Builder::XmlMarkup.new(:indent => 0))
+ xml.favourites do
+ favourites.each do |f|
+ xml.favourite do
+ xml.id(f.id)
+ xml.key(f.key)
+ xml.name(f.name)
+ xml.lname(f.long_name) if f.long_name
+ xml.branch(f.branch) if f.branch
+ xml.scope(f.scope)
+ xml.qualifier(f.qualifier)
+ xml.lang(f.language) if f.language
+ end
+ end
+ end
+ end
+
+ def favourite_to_xml(favourite, xml=Builder::XmlMarkup.new(:indent => 0))
+ xml.favourite do
+ xml.id(f.id)
+ xml.key(f.key)
+ xml.name(f.name)
+ xml.lname(f.long_name) if f.long_name
+ xml.branch(f.branch) if f.branch
+ xml.scope(f.scope)
+ xml.qualifier(f.qualifier)
+ xml.lang(f.language) if f.language
+ end
+ end
end
diff --git a/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/api/issues_controller.rb b/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/api/issues_controller.rb
index 69b67f1dd39..62d75c2c884 100644
--- a/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/api/issues_controller.rb
+++ b/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/api/issues_controller.rb
@@ -37,7 +37,10 @@ class Api::IssuesController < Api::ApiController
hash = {}
hash[:changelog] = Issue.changelog_to_hash(changelog)
- render :json => jsonp(hash)
+ respond_to do |format|
+ format.json { render :json => jsonp(hash) }
+ format.xml { render :xml => hash.to_xml(:skip_types => true, :root => 'sonar') }
+ end
end
#
@@ -78,7 +81,11 @@ class Api::IssuesController < Api::ApiController
hash = result_to_hash(result)
hash[:comment] = Issue.comment_to_hash(result.get) if result.get
- render :json => jsonp(hash), :status => result.httpStatus
+ respond_to do |format|
+ # if the request header "Accept" is "*/*", then the default format is the first one (json)
+ format.json { render :json => jsonp(hash), :status => result.httpStatus }
+ format.xml { render :xml => hash.to_xml(:skip_types => true, :root => 'sonar', :status => http_status) }
+ end
end
#
@@ -117,7 +124,11 @@ class Api::IssuesController < Api::ApiController
hash = result_to_hash(result)
hash[:comment] = Issue.comment_to_hash(result.get) if result.get
- render :json => jsonp(hash), :status => result.httpStatus
+ respond_to do |format|
+ # if the request header "Accept" is "*/*", then the default format is the first one (json)
+ format.json { render :json => jsonp(hash), :status => result.httpStatus }
+ format.xml { render :xml => hash.to_xml(:skip_types => true, :root => 'sonar', :status => result.httpStatus) }
+ end
end
#
@@ -174,7 +185,11 @@ class Api::IssuesController < Api::ApiController
:issues => result.issuesNotChanged().map { |issue| issue.key() }
}
- render :json => jsonp(hash), :status => 200
+ respond_to do |format|
+ # if the request header "Accept" is "*/*", then the default format is the first one (json)
+ format.json { render :json => jsonp(hash), :status => 200 }
+ format.xml { render :xml => hash.to_xml(:skip_types => true, :root => 'sonar', :status => 200) }
+ end
end
protected
diff --git a/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/api/profiles_controller.rb b/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/api/profiles_controller.rb
index e2176ae3243..892ec9e3eb4 100644
--- a/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/api/profiles_controller.rb
+++ b/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/api/profiles_controller.rb
@@ -75,7 +75,11 @@ class Api::ProfilesController < Api::ApiController
:language => profile.language,
:default => default_profile_by_language[profile.language].name == profile.name
} }
- render :json => jsonp(json)
+ respond_to do |format|
+ format.json { render :json => jsonp(json) }
+ format.xml { render :xml => xml_not_supported }
+ format.text { render :text => text_not_supported }
+ end
end
# GET /api/profiles?language=<language>[&name=<name>]
@@ -93,7 +97,11 @@ class Api::ProfilesController < Api::ApiController
@active_rules=filter_rules()
- render :json => jsonp(to_json)
+ respond_to do |format|
+ format.json { render :json => jsonp(to_json) }
+ format.xml { render :xml => to_xml }
+ format.text { render :text => text_not_supported }
+ end
end
private
@@ -156,4 +164,31 @@ class Api::ProfilesController < Api::ApiController
[result]
end
+ def to_xml
+ xml = Builder::XmlMarkup.new(:indent => 0)
+ xml.instruct!
+
+ xml.profile do
+ xml.name(@profile.name)
+ xml.language(@profile.language)
+ xml.parent(@profile.parent_kee) if @profile.parent_kee.present?
+ xml.default(@profile.default_profile?)
+
+ @active_rules.each do |active_rule|
+ xml.rule do
+ xml.key(active_rule.rule.plugin_rule_key)
+ xml.repo(active_rule.rule.plugin_name)
+ xml.severity(active_rule.priority_text)
+ xml.inheritance(active_rule.inheritance) if active_rule.inheritance
+ active_rule.active_rule_parameters.each do |param|
+ xml.param do
+ xml.key(param.name)
+ xml.value(param.value)
+ end
+ end
+ end
+ end
+ end
+ end
+
end
diff --git a/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/api/projects_controller.rb b/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/api/projects_controller.rb
index 4383a4c4115..bace6cd3b69 100644
--- a/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/api/projects_controller.rb
+++ b/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/api/projects_controller.rb
@@ -39,7 +39,11 @@ class Api::ProjectsController < Api::ApiController
@show_description=(params[:desc]=='true')
@projects=load_projects
@snapshots_by_puuid=load_snapshots_by_project
- render :json => jsonp(to_json)
+ respond_to do |format|
+ format.json{ render :json => jsonp(to_json) }
+ format.xml { render :xml => to_xml }
+ format.text { render :text => text_not_supported }
+ end
rescue Exception => e
logger.error("Fails to execute #{request.url} : #{e.message}")
@@ -62,7 +66,10 @@ class Api::ProjectsController < Api::ApiController
id = Internal.component_api.createComponent(params[:key], params[:branch], params[:name], nil)
result = Project.find(id.to_i)
- render :json => jsonp(to_json_hash(result))
+ respond_to do |format|
+ format.json { render :json => jsonp(to_json_hash(result)) }
+ format.xml { render :xml => to_xml_hash(result) }
+ end
end
private
@@ -166,4 +173,29 @@ class Api::ProjectsController < Api::ApiController
}.reject!{|k,v| v.nil?}
end
+ def to_xml
+ xml = Builder::XmlMarkup.new(:indent => 0)
+ xml.projects do
+ @projects.each do |project|
+ to_xml_hash(project, xml)
+ end
+ end
+ end
+
+ def to_xml_hash(project, xml=Builder::XmlMarkup.new(:indent => 0))
+ xml.project(:id => project.id.to_s, :key => project.key) do
+ xml.name(project.name(true))
+ xml.scope(project.scope)
+ xml.qualifier(project.qualifier)
+ xml.desc(project.description) if @show_description && project.description
+
+ if @snapshots_by_puuid && @snapshots_by_puuid[project.uuid]
+ @snapshots_by_puuid[project.id].sort{|s1,s2| s2.version <=> s1.version}.each do |snapshot|
+ attributes={:sid => snapshot.id.to_s, :last => snapshot.last?}
+ attributes[:date]=Api::Utils.format_datetime(snapshot.created_at) if snapshot.created_at
+ xml.version(snapshot.version, attributes)
+ end
+ end
+ end
+ end
end
diff --git a/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/api/properties_controller.rb b/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/api/properties_controller.rb
index f1c682f41ad..0c69c45098a 100644
--- a/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/api/properties_controller.rb
+++ b/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/api/properties_controller.rb
@@ -58,7 +58,10 @@ class Api::PropertiesController < Api::ApiController
# apply security
properties = properties.select{|prop| allowed?(prop.key)}
- render :json => jsonp(to_json(properties))
+ respond_to do |format|
+ format.json { render :json => jsonp(to_json(properties)) }
+ format.xml { render :xml => to_xml(properties) }
+ end
end
# GET /api/properties/<key>[?resource=<resource>]
@@ -79,10 +82,17 @@ class Api::PropertiesController < Api::ApiController
unless prop
# for backward-compatibility with versions <= 2.14 : keep status 200
message = "Property not found: #{key}"
- render :json => error_to_json(404, message), :status => 200
+ return respond_to do |format|
+ format.json { render :json => error_to_json(404, message), :status => 200 }
+ format.xml { render :xml => error_to_xml(404, message), :status => 200 }
+ format.text { render :text => message, :status => 200 }
+ end
end
access_denied unless allowed?(key)
- render :json => jsonp(to_json([prop]))
+ respond_to do |format|
+ format.json { render :json => jsonp(to_json([prop])) }
+ format.xml { render :xml => to_xml([prop]) }
+ end
end
# curl -u admin:admin -v -X POST http://localhost:9000/api/properties/foo?value=bar[&resource=<resource>]
@@ -135,6 +145,16 @@ class Api::PropertiesController < Api::ApiController
properties.collect { |property| property.to_hash_json }
end
+ def to_xml(properties)
+ xml = Builder::XmlMarkup.new(:indent => 0)
+ xml.instruct!
+ xml.properties do
+ properties.each do |property|
+ property.to_xml(xml)
+ end
+ end
+ end
+
def allowed?(property_key)
!property_key.end_with?('.secured') || is_admin? || (property_key.include?(".license") && logged_in?)
end
diff --git a/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/api/resources_controller.rb b/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/api/resources_controller.rb
index f9f6b1ea7b1..3462125a2bc 100644
--- a/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/api/resources_controller.rb
+++ b/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/api/resources_controller.rb
@@ -92,7 +92,11 @@ class Api::ResourcesController < Api::ApiController
json = {:total => total, :page => page, :page_size => page_size, :data => resources.map { |r| {:id => r.id, :key => r.key, :nm => r.name(true), :q => r.qualifier} }}
end
- render :json => jsonp(json)
+ respond_to do |format|
+ format.json { render :json => jsonp(json) }
+ format.xml { render :xml => xml_not_supported }
+ format.text { render :text => text_not_supported }
+ end
end
def index
@@ -228,7 +232,11 @@ class Api::ResourcesController < Api::ApiController
# ---------- FORMAT RESPONSE
objects={:sorted_components => sorted_components, :components_by_uuid => components_by_uuid, :measures_by_component_uuid => measures_by_component_uuid, :params => params}
- render :json => jsonp(to_json(objects))
+ respond_to do |format|
+ format.json { render :json => jsonp(to_json(objects)) }
+ format.xml { render :xml => to_xml(objects) }
+ format.text { render :text => text_not_supported }
+ end
rescue ApiException => e
render_error(e.msg, e.code)
end
@@ -264,6 +272,23 @@ class Api::ResourcesController < Api::ApiController
result
end
+ def to_xml(objects)
+ components = objects[:sorted_components]
+ components_by_uuid = objects[:components_by_uuid]
+ measures_by_component_uuid = objects[:measures_by_component_uuid]
+ params = objects[:params]
+
+ xml = Builder::XmlMarkup.new(:indent => 0)
+ xml.instruct!
+
+ xml.resources do
+ components.each do |component|
+ measures = measures_by_component_uuid[component.uuid]
+ resource_to_xml(xml, component, measures, params)
+ end
+ end
+ end
+
def component_to_json(component, measures, options={})
verbose=(options[:verbose]=='true')
include_alerts=(options[:includealerts]=='true')
@@ -340,4 +365,77 @@ class Api::ResourcesController < Api::ApiController
json
end
+ def resource_to_xml(xml, component, measures, options={})
+ verbose=(options[:verbose]=='true')
+ include_alerts=(options[:includealerts]=='true')
+ include_trends=(options[:includetrends]=='true')
+ include_descriptions=(options[:includedescriptions]=='true')
+
+ xml.resource do
+ xml.id(component.id)
+ xml.key(component.key)
+ xml.name(component.name)
+ xml.lname(component.long_name) if component.long_name
+ xml.branch(component.branch) if component.branch
+ xml.scope(component.scope)
+ xml.qualifier(component.qualifier)
+ xml.lang(component.language) if component.language
+ xml.version(snapshot.version) if snapshot.version
+ xml.date(Api::Utils.format_datetime(snapshot.created_at))
+ xml.creationDate(Api::Utils.format_datetime(resource.created_at))
+ xml.description(resource.description) if include_descriptions && resource.description
+
+ if include_trends && component.last_snapshot
+ xml.period1(component.last_snapshot.period1_mode) if component.last_snapshot.period1_mode
+ xml.period1_param(component.last_snapshot.period1_param) if component.last_snapshot.period1_param
+ xml.period1_date(Api::Utils.format_datetime(component.last_snapshot.period1_date)) if component.last_snapshot.period1_date
+
+ xml.period2(component.last_snapshot.period2_mode) if component.last_snapshot.period2_mode
+ xml.period2_param(component.last_snapshot.period2_param) if component.last_snapshot.period2_param
+ xml.period2_date(Api::Utils.format_datetime(component.last_snapshot.period2_date)) if component.last_snapshot.period2_date
+
+ xml.period3(component.last_snapshot.period3_mode) if component.last_snapshot.period3_mode
+ xml.period3_param(component.last_snapshot.period3_param) if component.last_snapshot.period3_param
+ xml.period3_date(Api::Utils.format_datetime(component.last_snapshot.period3_date)) if component.last_snapshot.period3_date
+
+ xml.period4(component.last_snapshot.period4_mode) if component.last_snapshot.period4_mode
+ xml.period4_param(component.last_snapshot.period4_param) if component.last_snapshot.period4_param
+ xml.period4_date(Api::Utils.format_datetime(component.last_snapshot.period4_date)) if component.last_snapshot.period4_date
+
+ xml.period5(component.last_snapshot.period5_mode) if component.last_snapshot.period5_mode
+ xml.period5_param(component.last_snapshot.period5_param) if component.last_snapshot.period5_param
+ xml.period5_date(Api::Utils.format_datetime(component.last_snapshot.period5_date)) if component.last_snapshot.period5_date
+ end
+
+ if measures
+ measures.select { |measure| !measure.metric.key.start_with?('new_') || include_trends }.each do |measure|
+ xml.msr do
+ xml.key(measure.metric.name)
+ xml.name(measure.metric.short_name) if verbose
+ xml.val(measure.value.to_f) if measure.value
+ xml.frmt_val(measure.formatted_value) if measure.value
+ xml.data(measure.data) if measure.data
+ xml.description(measure.description) if include_descriptions && measure.description
+ xml.url(measure.url) if include_descriptions && measure.url
+ if include_alerts
+ xml.alert(measure.alert_status) if measure.alert_status
+ xml.alert_text(measure.alert_text) if measure.alert_text
+ end
+ if include_trends
+ xml.var1(measure.variation_value_1.to_f) if measure.variation_value_1
+ xml.fvar1(measure.format_numeric_value(measure.variation_value_1.to_f)) if measure.variation_value_1
+ xml.var2(measure.variation_value_2.to_f) if measure.variation_value_2
+ xml.fvar2(measure.format_numeric_value(measure.variation_value_2.to_f)) if measure.variation_value_2
+ xml.var3(measure.variation_value_3.to_f) if measure.variation_value_3
+ xml.fvar3(measure.format_numeric_value(measure.variation_value_3.to_f)) if measure.variation_value_3
+ xml.var4(measure.variation_value_4.to_f) if measure.variation_value_4
+ xml.fvar4(measure.format_numeric_value(measure.variation_value_4.to_f)) if measure.variation_value_4
+ xml.var5(measure.variation_value_5.to_f) if measure.variation_value_5
+ xml.fvar5(measure.format_numeric_value(measure.variation_value_5.to_f)) if measure.variation_value_5
+ end
+ end
+ end
+ end
+ end
+ end
end
diff --git a/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/api/rest_controller.rb b/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/api/rest_controller.rb
index 525dd58f8e6..8bec1e4a2d0 100644
--- a/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/api/rest_controller.rb
+++ b/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/api/rest_controller.rb
@@ -65,7 +65,11 @@ class Api::RestController < ApplicationController
end
def rest_render(objects)
- render :json => rest_to_jsonp(objects)
+ respond_to do |format|
+ format.json{ render :json => rest_to_jsonp(objects) }
+ format.xml { render :xml => rest_to_xml(objects) }
+ format.text { render :text => rest_to_text(objects) }
+ end
end
def rest_to_jsonp(objects)
diff --git a/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/api/server_controller.rb b/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/api/server_controller.rb
index da39edf0766..c5c45639eb6 100644
--- a/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/api/server_controller.rb
+++ b/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/api/server_controller.rb
@@ -34,7 +34,11 @@ class Api::ServerController < Api::ApiController
def index
hash={:id => Java::OrgSonarServerPlatform::Platform.getServer().getId(), :version => Java::OrgSonarServerPlatform::Platform.getServer().getVersion()}
complete_with_status(hash)
- render :json => jsonp(hash)
+ respond_to do |format|
+ format.json{ render :json => jsonp(hash) }
+ format.xml { render :xml => hash.to_xml(:skip_types => true, :root => 'server') }
+ format.text { render :text => text_not_supported}
+ end
end
def setup
@@ -60,7 +64,11 @@ class Api::ServerController < Api::ApiController
hash[:message]=manager.message if manager.message
hash[:startedAt]=manager.migration_start_time if manager.migration_start_time
- render :json => jsonp(hash)
+ respond_to do |format|
+ format.json{ render :json => jsonp(hash) }
+ format.xml { render :xml => hash.to_xml(:skip_types => true, :root => 'setup') }
+ format.text { render :text => hash[:status] }
+ end
rescue => e
hash={
# deprecated fields
@@ -71,7 +79,11 @@ class Api::ServerController < Api::ApiController
:message => e.message,
:state => manager.status
}
- render :json => jsonp(hash)
+ respond_to do |format|
+ format.json{ render :json => jsonp(hash) }
+ format.xml { render :xml => hash.to_xml(:skip_types => true, :root => 'setup') }
+ format.text { render :text => hash[:status] }
+ end
end
end
diff --git a/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/api/tests_controller.rb b/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/api/tests_controller.rb
index 522ba2d1f5b..b5ade1556e6 100644
--- a/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/api/tests_controller.rb
+++ b/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/api/tests_controller.rb
@@ -70,7 +70,11 @@ class Api::TestsController < Api::ApiController
end
json.delete_if { |k, v| v.nil? }
- render :json => jsonp(json)
+ respond_to do |format|
+ format.json { render :json => jsonp(json) }
+ format.xml { render :xml => xml_not_supported }
+ format.text { render :text => text_not_supported }
+ end
end
end
@@ -117,6 +121,10 @@ class Api::TestsController < Api::ApiController
end
json.delete_if { |k, v| v.nil? }
- render :json => jsonp(json)
+ respond_to do |format|
+ format.json { render :json => jsonp(json) }
+ format.xml { render :xml => xml_not_supported }
+ format.text { render :text => text_not_supported }
+ end
end
end
diff --git a/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/api/updatecenter_controller.rb b/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/api/updatecenter_controller.rb
index 51f3b415297..c6e83dfe35b 100644
--- a/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/api/updatecenter_controller.rb
+++ b/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/api/updatecenter_controller.rb
@@ -27,7 +27,11 @@ class Api::UpdatecenterController < Api::ApiController
# curl http://localhost:9000/api/updatecenter/installed_plugins -v
#
def installed_plugins
- render :json => jsonp(plugins_to_json(user_plugins()))
+ respond_to do |format|
+ format.json { render :json => jsonp(plugins_to_json(user_plugins())) }
+ format.xml { render :xml => plugins_to_xml(user_plugins()) }
+ format.text { render :text => text_not_supported }
+ end
end
private
@@ -48,6 +52,18 @@ class Api::UpdatecenterController < Api::ApiController
hash
end
+ def plugins_to_xml(plugins, xml=Builder::XmlMarkup.new(:indent => 0))
+ xml.plugins do
+ plugins.each do |plugin|
+ xml.plugin do
+ xml.key(plugin.getKey())
+ xml.name(plugin.getName())
+ xml.version(plugin.getVersion().getName())
+ end
+ end
+ end
+ end
+
def user_plugins
java_facade.getPluginInfos().to_a.sort
end
diff --git a/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/api/user_properties_controller.rb b/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/api/user_properties_controller.rb
index fae02b8f73a..d25c2d23010 100644
--- a/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/api/user_properties_controller.rb
+++ b/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/api/user_properties_controller.rb
@@ -31,7 +31,11 @@ class Api::UserPropertiesController < Api::ApiController
#
def index
properties = current_user.properties
- render :json => jsonp(properties_to_json(properties))
+ respond_to do |format|
+ format.json { render :json => jsonp(properties_to_json(properties)) }
+ format.xml { render :xml => properties_to_xml(properties) }
+ format.text { render :text => text_not_supported }
+ end
end
#
@@ -41,7 +45,11 @@ class Api::UserPropertiesController < Api::ApiController
def show
property = Property.by_key(params[:id], nil, current_user.id)
if property
- render :json => jsonp(properties_to_json([property]))
+ respond_to do |format|
+ format.json { render :json => jsonp(properties_to_json([property])) }
+ format.xml { render :xml => properties_to_xml([property]) }
+ format.text { render :text => text_not_supported }
+ end
else
render_error('Not found', 404)
end
@@ -59,7 +67,11 @@ class Api::UserPropertiesController < Api::ApiController
begin
Property.clear(key, nil, current_user.id)
property=Property.create(:prop_key => key, :text_value => value, :user_id => current_user.id)
- render :json => jsonp(properties_to_json([property]))
+ respond_to do |format|
+ format.json { render :json => jsonp(properties_to_json([property])) }
+ format.xml { render :xml => properties_to_xml([property]) }
+ format.text { render :text => text_not_supported }
+ end
rescue Exception => e
render_error(e.message, 500)
@@ -95,4 +107,12 @@ class Api::UserPropertiesController < Api::ApiController
json
end
+ def properties_to_xml(properties, xml=Builder::XmlMarkup.new(:indent => 0))
+ xml.properties do
+ properties.each do |p|
+ p.to_xml(xml)
+ end
+ end
+ end
+
end
diff --git a/server/sonar-web/src/main/webapp/WEB-INF/app/models/metric.rb b/server/sonar-web/src/main/webapp/WEB-INF/app/models/metric.rb
index 54f0ff96ea3..204c8f49b83 100644
--- a/server/sonar-web/src/main/webapp/WEB-INF/app/models/metric.rb
+++ b/server/sonar-web/src/main/webapp/WEB-INF/app/models/metric.rb
@@ -281,6 +281,21 @@ class Metric < ActiveRecord::Base
end
end
+ def to_xml(options={})
+ xml = Builder::XmlMarkup.new
+ xml.metric do
+ xml.key(name)
+ xml.name(short_name)
+ xml.description(description)
+ xml.domain(domain)
+ xml.qualitative(qualitative)
+ xml.direction(direction)
+ xml.user_managed(self.user_managed)
+ xml.val_type(val_type)
+ xml.hidden(hidden)
+ end
+ end
+
HUMANIZED_ATTRIBUTES = {
:name => "key",
:short_name => "name",
diff --git a/server/sonar-web/src/main/webapp/WEB-INF/app/models/project_link.rb b/server/sonar-web/src/main/webapp/WEB-INF/app/models/project_link.rb
index ba01d3d08ec..1a11f230c4b 100644
--- a/server/sonar-web/src/main/webapp/WEB-INF/app/models/project_link.rb
+++ b/server/sonar-web/src/main/webapp/WEB-INF/app/models/project_link.rb
@@ -65,6 +65,14 @@ class ProjectLink < ActiveRecord::Base
{'type' => link_type, 'name' => name, 'url' => href}
end
+ def to_xml(xml)
+ xml.link do
+ xml.type(link_type)
+ xml.name(name)
+ xml.url(href)
+ end
+ end
+
def <=>(other)
if name.nil?
-1
diff --git a/server/sonar-web/src/main/webapp/WEB-INF/app/models/property.rb b/server/sonar-web/src/main/webapp/WEB-INF/app/models/property.rb
index 64a54f49eac..a66e0e452d5 100644
--- a/server/sonar-web/src/main/webapp/WEB-INF/app/models/property.rb
+++ b/server/sonar-web/src/main/webapp/WEB-INF/app/models/property.rb
@@ -137,6 +137,15 @@ class Property < ActiveRecord::Base
java_definition && (java_definition.multi_values? || !java_definition.fields.blank?)
end
+ def to_xml(xml=Builder::XmlMarkup.new(:indent => 0))
+ xml.property do
+ xml.key(prop_key)
+ xml.value { xml.cdata!(value.to_s) }
+ Property.string_to_array_value(value.to_s).each { |v| xml.values { xml.cdata!(v) } } if multi_values?
+ end
+ xml
+ end
+
def java_definition
@java_definition ||= Property.property_def(key)
end
diff --git a/server/sonar-web/src/main/webapp/WEB-INF/app/models/rule.rb b/server/sonar-web/src/main/webapp/WEB-INF/app/models/rule.rb
index 1661b76911e..a5bd31ca656 100644
--- a/server/sonar-web/src/main/webapp/WEB-INF/app/models/rule.rb
+++ b/server/sonar-web/src/main/webapp/WEB-INF/app/models/rule.rb
@@ -206,6 +206,32 @@ class Rule < ActiveRecord::Base
json
end
+ def to_xml(profile, xml)
+ xml.rule do
+ xml.title(name)
+ xml.key(key)
+ xml.config_key(config_key)
+ xml.plugin(plugin_name)
+ xml.description { xml.cdata!(description) } if description
+ active_rule = nil
+ if profile
+ active_rule = profile.active_by_rule_id(id)
+ if active_rule
+ xml.priority(active_rule.priority_text)
+ xml.status('ACTIVE')
+ else
+ xml.priority(priority_text)
+ xml.status("INACTIVE")
+ end
+ else
+ xml.priority(priority_text)
+ end
+ parameters.each do |parameter|
+ parameter.to_xml(active_rule, xml)
+ end
+ end
+ end
+
def to_csv(profile)
csv = [name.strip, plugin_rule_key, plugin_name]
if profile
diff --git a/server/sonar-web/src/main/webapp/WEB-INF/app/models/rules_parameter.rb b/server/sonar-web/src/main/webapp/WEB-INF/app/models/rules_parameter.rb
index 8f9fb439cc3..c1785dc0d13 100644
--- a/server/sonar-web/src/main/webapp/WEB-INF/app/models/rules_parameter.rb
+++ b/server/sonar-web/src/main/webapp/WEB-INF/app/models/rules_parameter.rb
@@ -35,6 +35,17 @@ class RulesParameter < ActiveRecord::Base
json
end
+ def to_xml(active_rule, xml)
+ xml.param do
+ xml.name(name)
+ xml.description { xml.cdata!(description) } if description
+ if active_rule
+ active_parameter = active_rule.active_param_by_param_id(id)
+ xml.value(active_parameter.value) if active_parameter
+ end
+ end
+ end
+
def <=>(other)
name <=> other.name
end
diff --git a/server/sonar-web/src/main/webapp/WEB-INF/app/models/widget_property.rb b/server/sonar-web/src/main/webapp/WEB-INF/app/models/widget_property.rb
index 998e51906ed..00220919af8 100644
--- a/server/sonar-web/src/main/webapp/WEB-INF/app/models/widget_property.rb
+++ b/server/sonar-web/src/main/webapp/WEB-INF/app/models/widget_property.rb
@@ -57,6 +57,14 @@ class WidgetProperty < ActiveRecord::Base
{:key => key, :value => text_value}
end
+ def to_xml(xml=Builder::XmlMarkup.new(:indent => 0))
+ xml.property do
+ xml.key(prop_key)
+ xml.value { xml.cdata!(text_value) }
+ end
+ xml
+ end
+
def self.text_to_value(text, type)
PropertyType.text_to_value(text, type);
end