I am a newbie in SonarQube plugin development. I would like to create a rule where the technical dept remediation is given with a the following formula for each issue for that rule: dept = constant_duration * effort where effort is given and different for each issue, constant_duration is specified for the rule.
I managed to create the following RuleDefinition:
public class SodaRuleDefinition
implements RulesDefinition
{
public static final String REPO_KEY = "soda";
public static final String SODA_METHOD_COVERAGE_KEY = "soda-method-coverage";
@Override
public void define(Context context) {
NewRepository repository = context.createRepository(REPO_KEY, Java.KEY);
repository.setName("SoDA");
repository.createRule(SODA_METHOD_COVERAGE_KEY)
.setName("SoDA aggregated method coverage")
.setMarkdownDescription("foo")
.setDebtSubCharacteristic("UNIT_LEVEL")
.setDebtRemediationFunction(
new DefaultDebtRemediationFunction(
DebtRemediationFunction.Type.LINEAR, "1h", null));
repository.done();
}
}
Then in a Sensor class, I created the issue like this:
public class SodaCoverageSensor
implements org.sonar.api.batch.Sensor{
// ...
@Override
public void analyse(Project project, SensorContext sc) {
// ...
sc.newIssue()
.at(new DefaultIssueLocation()
.on(new DefaultInputFile(project.getKey(), resource.getPath()))
.message(String.format("Coverage (%f) is lower than %f.", entry.getValue(), limit)))
.effortToFix(1.0)
.forRule(ruleKey)
.save();
// ...
}
Finally I register all my classes via an Plugin class and activate my rule on the GUI of SonarQube for Sonar way quality profile.
public class SonarQubePlugin
extends org.sonar.api.SonarPlugin{
@Override
public List getExtensions() {
return Arrays.asList(
SodaClassCoverageMetric.class,
SodaCoverageSensor.class,
SodaRuleDefinition.class
);
}
}
Everything works fine, my code executed (I triple checked that), the rule and the issues are created as expected, no error during execution neither in log files. Just the technical dept does not show up on the user interface! I found other issues with the same DebtRemediationFunction.Type.LINEAR
type, which are working just fine.
Any clue, help or recommendation about how to get over this are highly appreciate!