Sensor or Decorator?
There are two extensions extension points that enables allow plugins to save measures: Sensor and Decorator. A common problem when writing a plugin is to decide which one to use.
You should never directly instantiate classes which implements implement BatchComponent or ServerComponent , because they should be retrieved as an IoC dependency. Otherwise it leads to issues with backward compatibility.
The sonar-dev-maven-plugin allows to lets you start a SonarQubeserver SonarQube server and to deploy the your plugin.
Once the server is launched, hit http://localhost:9000. By default, the in-process database (H2, or Derby prior to SonarQube 3.2) is used but you can specify to use a local MySQL instance instead with the property "-Dsonar.database=mysql". In that case, the sonar schema must exist in the MySQL DB along with the user sonar/sonar (login/password) who which must have all rights on the sonar schema.
Changes on Java code are not reloaded dynamically. You need to rebuild the plugin and to re-execute sonar-dev-maven-plugin.
Debug Java batch
mvnDebug sonar:sonar and attach your IDE to the remote process. Example in Intellij Idea: Run > Edit configurations > Add new configuration > Remote.
Debug a plugin
- Unzip a sonar distribution
- Edit the conf/wrapper.conf file and uncomment the line : wrapper.java.additional.3=-agentlib:jdwp=transport=dt_socket,server=y,address=8000
- Copy your plugin's jar file to extensions/plugins
- Launch SonarQube with the standard command. The following line will appear in the log : Listening for transport dt_socket at address: 8000
- Attach the IDE to the debug process on port 8000
- Set breakpoints in the source code
We've gathered all our debugging tips into this page.
How to Use External Libraries?
A plugin benefits from all the dependencies provided by the API. Execute the following command on your plugin to list them: