You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

updatecenter_controller.rb 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #
  2. # SonarQube, open source software quality management tool.
  3. # Copyright (C) 2008-2014 SonarSource
  4. # mailto:contact AT sonarsource DOT com
  5. #
  6. # SonarQube is free software; you can redistribute it and/or
  7. # modify it under the terms of the GNU Lesser General Public
  8. # License as published by the Free Software Foundation; either
  9. # version 3 of the License, or (at your option) any later version.
  10. #
  11. # SonarQube is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. # Lesser General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU Lesser General Public License
  17. # along with this program; if not, write to the Free Software Foundation,
  18. # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  19. #
  20. require 'json'
  21. class Api::UpdatecenterController < Api::ApiController
  22. #
  23. # GET /api/updatecenter/installed_plugins
  24. # curl http://localhost:9000/api/updatecenter/installed_plugins -v
  25. #
  26. def installed_plugins
  27. respond_to do |format|
  28. format.json { render :json => jsonp(plugins_to_json(user_plugins())) }
  29. format.xml { render :xml => plugins_to_xml(user_plugins()) }
  30. format.text { render :text => text_not_supported }
  31. end
  32. end
  33. private
  34. def plugins_to_json(plugins=[])
  35. json=[]
  36. plugins.each do |p|
  37. json<<plugin_to_json(p)
  38. end
  39. json
  40. end
  41. def plugin_to_json(plugin)
  42. hash={}
  43. hash['key']=plugin.getKey()
  44. hash['name']=plugin.getName()
  45. hash['version']=plugin.getVersion().getName()
  46. hash
  47. end
  48. def plugins_to_xml(plugins, xml=Builder::XmlMarkup.new(:indent => 0))
  49. xml.plugins do
  50. plugins.each do |plugin|
  51. xml.plugin do
  52. xml.key(plugin.getKey())
  53. xml.name(plugin.getName())
  54. xml.version(plugin.getVersion().getName())
  55. end
  56. end
  57. end
  58. end
  59. def user_plugins
  60. java_facade.getPluginInfos().select{|plugin| !plugin.isCore()}.to_a.sort
  61. end
  62. end