Monday, November 23, 2020

Create Sonar Plugin - Basic Class Structure for Sonar Plugin using Java

You can write a sonar Plugin for a langauge using Java.

When you write a plugin there few key components you need to write. Below is the basic structure of classes.

Let's assume you are writting plugin for "Foo" language. 

Here we are calling a third party component which bundled in a executable Jar file. we generate violations in a xml file and show them in SonarQube.

1. class FooPlugin implements Plugin

Plugin class which connects all the component

2. class FooLanguage extends AbstractLanguage

Implement Key and Name for language and some other features

3. class FooRulesDefinition implements RulesDefinition

create repository and define rules for language

4. class FooQualityProfile implements BuiltInQualityProfilesDefinition

Create a quality profile for language. you can set this profile as your default quality profile and also define rules for the profile.

5. class FooLanguageProperties

define properties for the language.

6. class FooScanner implements Sensor

Logic for analysis of the files written language "foo" will be handled/written here. once analysis is done, result/issues will be saved as report in SonarQube.

7. class Extractor

As i explained files will  be analysed using a thirid party jar, we need to extarct that jar from our plugin Jar and also related files need to do the excution. Logic for extraction is written here. 

No comments:

Post a Comment