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

Getting started

The Sonar forge

Tempted to go ahead and write your own plugin ? No obligation, but you might want to share it with the Sonar community. In that case, subscribe and send an email to the Sonar development mailing list. You will then benefit from the Sonar plugins forge to publish the plugin, have access to Subversion to store the source code and to JIRA to file your issues.

When you utilize the forge, we request that you respect the following principles :

  1. A plugin is built with Maven 2.
  2. When you create a plugin called 'foo', it should be stored in the directory 'foo'. Maven groupId is 'org.codehaus.sonar-plugins' and artifactId is  'sonar-foo-plugin'.
  3. Add the plugin as a module of ../pom.xml
  4. After creation, send an email to the dev mailing for it to be added to Continuous Integration server (Bamboo)
  5. The copyright belongs to whoever wrote the plugin, however the license should be business friendly (see #Define plugin license)

Create a plugin project

As a prerequisite to write a plugin, you are going to need to have the Java Development Kit version 5 or higher Maven version 2.0.9 or higher installed.

You can execute an archetype in order to generate the skeleton of your plugin :

[ARCHETYPE_ID] can either be 'sonar-basic-plugin-archetype' for a vanilla plugin or 'sonar-gwt-plugin-archetype' for a plugin with Google Web Toolkit extensions.

Example :

Define plugin license

Starting from Sonar plugins parent version 4 we are using maven-license-plugin for checking and for managing license headers in source files.

Here is a brief description of how we recommend to use this plugin :

  1. Define licenses, inceptionYear and organization in your pom.xml file :
  2. Place license-header.txt to your src directory (example of this file can be found here).
  3. Add/update headers of your source files :

For detailed instructions on how to use this plugin see plugin homepage.

Plugin structure

A Sonar plugin is a set of POJOs that implement one or more Sonar extension points. Those extension points are interfaces or abstract classes that model an aspect of the system and define contracts of what needs to be implemented. POJOs are then placed in a container that implements the Plugin extension point.

Sonar must then have a way to retrieve the plugin class. For this, the plugin class must be declared in the JAR manifest. Maven can handle this stuff by adding this in your pom.xml file :

A plugin is packaged in a JAR file that must be deployed into the directory $SONAR_HOME/extensions/plugins before starting the server.

  • No labels