Monday, November 23, 2020

Create Sonar Plugin - Plugin class

We create a plugin class implementing org.sonar.api.Plugin.

Implement "define" contract and register all classes as extensions. Plugin class is the entry point.

Below is the sample code for FooPlugin class.

You can see that, you need to implement all other specialized classes before registering as extensions.

---------------------------------------------------------------------------------------------------


package com.plugin.sonar;

import com.plugin.sonar.language.foo.FooLanguage;
import com.plugin.sonar.language.foo.FooLanguageProperties;
import com.plugin.sonar.language.foo.FooQualityProfile;
import com.plugin.sonar.scanner.FooScanner;
import com.plugin.sonar.util.Extractor;
import com.plugin.sonar.language.foo.FooRulesDefinition;
import org.sonar.api.Plugin;
import org.sonar.api.utils.log.Logger;
import org.sonar.api.utils.log.Loggers;

public class FooPlugin implements Plugin {

private static final Logger LOG = Loggers.get(FooPlugin.class);

public void define(Context context) {
LOG.info("defining all extensions for Foo Language plugin");
context.addExtensions(FooLanguage.class, FooRulesDefinition.class)
.addExtensions(FooQualityProfile.class, FooLanguageProperties.getProperties());
context.addExtension(FooScanner.class);
context.addExtension(Extractor.class);
}
}

No comments:

Post a Comment