Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 29 Next »

Table of Contents


Dashboard widgets are implemented as Ruby on Rails views. Widgets must be declared with the Java extension point org.sonar.api.web.Widget.

Example of structure :

  • sonar-foo-plugin/
    • src/
      • main/
        • java/
          • com/
            • foo/
        • resources/
          • com/
            • foo/
              • my_widget.html.erb

Widgets can be manually tested with the URL : http://<server>/widget?id=<widget id>. The width can be set with the property widget_width. The default value is 350px.


Helpers and partials are not supported.

Development mode

The development mode reloads Ruby changes on the fly. It allows to edit code and display widget at the same time.

To enable the development mode on a widget :

  1. Install Sonar
  2. Edit the method RubyRailsWidget#getTemplatePath() in order to return the absolute path but not the class path.
  3. Build the plugin and copy it to /extensions/plugins
  4. Start server
  5. (warning)Do not forget to revert the path before commiting your changes



Ruby on Rails applications are supported since Sonar 3.0.

Ruby on Rails applications allow plugins to extend the Sonar webapp with a complete MVC stack : controllers, helpers, models and views. Contrary to widgets, it does not require to declare a Java component. Ruby sources just have to be stored in the plugin directory : /src/main/resources/org/sonar/ror/<plugin key>. This directory must also contain an empty file named init.rb.

Example for an application provided by the plugin with key 'foo' :

  • sonar-foo-plugin/
    • src/
      • main/
        • resources/
          • org/
            • sonar/
              • ror/
                • foo/
                  • init.rb
                  • app/
                    • controllers/
                      • my_console_controller.rb
                    • helpers/
                      • my_console_helper.rb
                    • views/
                      • my_console/
                        • index.html.erb
                        • _my_partial.html.erb

Controller URLs are not isolated from the core URLs used by Sonar. You have to be careful of potential conflicts and choose controller names different than :

my_console_controller.rb :

Add page to sidebar

By the default the application is not visible. Pages have to be declared with the Java extension point org.sonar.api.web.Page :

Example of

Development mode

The development mode reloads Ruby changes on the fly. It allows to edit code and to directly interact with the application. Only the changes on the files that exist during server startup are supported. Adding a new file requires to restart the server.

To enable the development mode on an application :

  1. Install Sonar
  2. Install the plugin by copying the initial JAR file to /extensions/plugins
  3. Edit the file war/sonar-server/WEB-INF/web.xml and set the context-params rails.env to development and jruby.max.runtimes to 3.
  4. Edit the file war/sonar-server/WEB-INF/config/environment.rb and set the absolute path to your ruby application by replacing the property config.plugin_paths :

  5. Start server

Web services

Web Services are simply packaged as applications. The only differences are that controllers are located in controllers/api/ instead of controllers/, and the class must extend Api::ApiController.

Example of code for controllers/api/my_web_service_controller.rb

The Java extension point org.sonar.api.web.RubyRailsWebservice is still supported but is useless since Sonar 3.0.

Static files

Plugins can provide static files like images, CSS or JS files. They have to be copied in src/main/resources/static and then can by accessible from the public URL :

The URL can be generated from widgets or applications with the Ruby helper function :

Note that the plugin key is logged during the maven build :


Static files are not deployed on the fly when the development mode is enabled. The plugin has to be built and re-installed after changes.

Dynamic charts

Sonar integrates JFreechart Eastwood 1.1.0, a partial implementation of the Google Chart API . To know if a chart is implemented, simply replace<params>  by http://<sonar>/gchart?<params>.

TBD : protovis.js.

Language packs

See Internationalization

  • No labels