Widgets

TBD

Applications

Icon

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.

How to 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 MySample.java

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 :

Install Sonar

Install the plugin by copying the initial JAR file to /extensions/plugins

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.

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 :

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 :

Icon

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.