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
 public class MyPlugin implements Plugin {
   @Override
   public void define(Context context) {
     context.addExtensions(MySensor.class, MyRules.class);
     if (context.getSonarQubeVersion().isGreaterThanOrEqual(Version.create(6, 0))) {
       // Extension which supports only versions 6.0 and greater
       // See org.sonar.api.SonarRuntime 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_6() {
   SonarRuntime runtime = SonarRuntimeImpl.forSonarQube(Version.create(5, 6));
   Plugin.Context context = new Plugin.Context(runtime);
   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–2016 SonarSource. All rights reserved.