public interface Plugin
The JAR manifest must declare the name of the implementation class in the property Plugin-Class.
This property is automatically set by sonar-packaging-maven-plugin when building plugin.
Example of implementation
package com.mycompany.sonarqube;
public class MyPlugin implements Plugin {
@Override
public void define(Context context) {
context.addExtensions(MySensor.class, MyRules.class);
if (context.getSonarQubeVersion().isGreaterThanOrEqual(SonarQubeVersion.V5_6)) {
// Extension which supports only versions 5.6 and greater
// See org.sonar.api.SonarQubeVersion for more details.
context.addExtension(MyNewExtension.class);
}
}
}
Example of pom.xml
<project>
...
<packaging>sonar-plugin</packaging>
<build>
<plugins>
<plugin>
<groupId>org.sonarsource.sonar-packaging-maven-plugin</groupId>
<artifactId>sonar-packaging-maven-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<pluginClass>com.mycompany.sonarqube.MyPlugin</pluginClass>
</configuration>
</plugin>
</plugins>
</build>
</project>
Example of test
MyPlugin underTest = new MyPlugin();
@Test
public void test_plugin_extensions_compatible_with_5_5() {
Plugin.Context context = new Plugin.Context(SonarQubeVersion.V5_5);
underTest.define(context);
assertThat(context.getExtensions()).hasSize(4);
}
| Modifier and Type | Interface and Description |
|---|---|
static class |
Plugin.Context |
| Modifier and Type | Method and Description |
|---|---|
void |
define(Plugin.Context context)
This method is executed at runtime when:
Web Server starts
Compute Engine starts
Scanner starts
|
void define(Plugin.Context context)
Copyright © 2009–2017 SonarSource. All rights reserved.