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 10 Next »

Widgets

TBD

Applications

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/
                      • first_foo_controller.rb
                      • second_foo_controller.rb
                    • helpers/
                      • first_foo_helper.rb
                    • views/
                      • first_foo/
                        • index.html.erb
                      • second_foo/
                        • index.html.erb
                        • _foo_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 : https://github.com/SonarSource/sonar/tree/master/sonar-server/src/main/webapp/WEB-INF/app/controllers

Sample code for first_foo_controller.rb :

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 :

  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

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.

  • No labels