Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Example of structure :

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

...

Info

Widgets can be manually tested with the URL : http://<server>/widget?id=<widget id>.

If you're testing a project-level widget, you'll need to add a project to the URL, like so : http://<server>/widget?id=<widget id>&resource=<project key>.

The width can be set with the property widget_width. The default value is 350px.

...

The development mode reloads Ruby changes on the fly. It allows to lets you edit code and immediately display your widget at the same timechanges.

To enable the development mode on a widget :

  1. Install SonarSonarQube
  2. Edit the method RubyRailsWidget#getTemplatePath() in order to return the absolute path but not the to the widget file, rather than 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

...

Info

Ruby on Rails applications are supported since Sonar 3SonarQube3.0.

Ruby on Rails applications allow plugins to extend the Sonar SonarQube webapp with a complete MVC stack : controllers, helpers, models and views. Contrary to Unlike widgets, it does not require you 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.

...

Controller URLs are not isolated from the core URLs used by SonarSonarQube. 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

Code Block
titleSample code for first_foomy_console_controller.rb :
languageruby
class MyConsoleController < ApplicationController

  # this is an administration console
  SECTION=Navigation::SECTION_CONFIGURATION

  before_filter :admin_required
  
  # GET http://<server>/my_console/index
  def index
    # automatically renders the file ../views/my_console/index.html.erb
  end
end

...

The development mode reloads Ruby changes on the fly. It allows you 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 you to restart the server.

To enable the development mode on an application :

  1. Install SonarSonarQube
  2. Install the plugin by copying the initial JAR file to /extensions/plugins
  3. Edit the Enable the development mode :
    1. If SonarQube 3.x : 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.
    2. If SonarQube 4.x : edit conf/sonar.properties and add the line sonar.web.dev=true
  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 :

    Code Block
    #config.plugin_paths << "#{Java::OrgSonarServerUi::JRubyFacade.getInstance().getServerHome()}/temp/ror"
    config.plugin_paths << '/absolute/path/to/sonar-foo-plugin/src/main/resources/org/sonar/ror'
  5. Start server

...

Info
iconfalse

The Java extension point org.sonar.api.web.RubyRailsWebservice is still supported but is useless since Sonar SonarQube 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 :

...

Info

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 http://chart.apis.google.com/chart?<params>  by http://<sonar>/gchart?<params>.

TBD : protovis.js.

Language packs

See Internationalization