XtianGIS
XtianGIS

Reputation: 1006

Does SonarQube 5.6 executes Decorators in plugins developed with sonar-plugin-api version 4.5.2?

I installed sonarqube 5.6, and download the C# plugin.

I decide to extend the C# plugin, so I proceed to download the code of the plugin installed (version 5.3.2).

The C# plugin project has a reference to sonar-plugin-api version 4.5.2

I add new metrics that require to be calculated for the project level, therefore, and following the documentation, I create a Decorator.

public class CSharpMyDecorator implements Decorator{
    private static final Logger LOG = LoggerFactory.getLogger(CSharpMyDecorator.class);

    @Override
    public boolean shouldExecuteOnProject(Project arg0) {
        // TODO Auto-generated method stub
        return true;
    }

    @Override
    public void decorate(Resource resource, DecoratorContext context) {

        LOG.info(resource.getName() + " Is Project: " + Scopes.isProject(resource) +" Is project not Module:" + Qualifiers.isProject(resource, false));


        if (Scopes.isProject(resource) && Qualifiers.isProject(resource, false)) {
            double files = 0d;
            double percentage = 0d;
            LOG.info("files: "+context.getMeasure(CoreMetrics.FILES).getValue());

            for (Measure measure : context.getChildrenMeasures(MyMetrics.FILES_DONT_PASS_FUNCTION_THRESHOLD)) {
                files += measure.getValue();
            }

            percentage = files / context.getMeasure(CoreMetrics.FILES).getValue();
            context.saveMeasure(MyMetrics.PERC_FILES_DONT_PASS_FUNCTION_THRESHOLD, percentage);
        }

    }

}

I add the class in the plugin :

public class CSharpPlugin extends SonarPlugin {

  public static final String LANGUAGE_KEY = "cs";
  public static final String LANGUAGE_NAME = "C#";

  public static final String FILE_SUFFIXES_KEY = "sonar.cs.file.suffixes";
  public static final String FILE_SUFFIXES_DEFVALUE = ".cs";

  public static final String CSHARP_WAY_PROFILE = "Sonar way";

  public static final String REPOSITORY_KEY = "csharpsquid";
  public static final String REPOSITORY_NAME = "SonarQube";

  public static final String IGNORE_HEADER_COMMENTS = "sonar.cs.ignoreHeaderComments";
  public static final String NUMBER_FUNCTION_THRESHOLD = "sonar.cs.numberFunctionThreshold";
  public static final String NUMBER_LOC_THRESHOLD = "sonar.cs.numberLocThreshold";

  @Override
  public List getExtensions() {
    ImmutableList.Builder builder = ImmutableList.builder();

    builder.add(
      CSharp.class,
      CSharpSonarRulesDefinition.class,
      CSharpSonarWayProfile.class,
      CSharpCommonRulesEngine.class,
      CSharpCommonRulesDecorator.class,
      CSharpSourceCodeColorizer.class,
      RuleRunnerExtractor.class,
      CSharpSensor.class,
      CSharpCPDMapping.class,
      SonarLintProfileExporter.class,
      SonarLintFakeProfileImporter.class,
      RoslynProfileExporter.class,
      MyMetrics.class,
      CSharpMyDecorator.class
      );

    builder.addAll(CSharpFxCopProvider.extensions());
    builder.addAll(CSharpCodeCoverageProvider.extensions());
    builder.addAll(CSharpUnitTestResultsProvider.extensions());
    builder.addAll(CSharpMsBuildIntegrationProvider.extensions());
    builder.addAll(RoslynProfileExporter.sonarLintRepositoryProperties());

    return builder.build();
  }

}

When I execute the analysis, neither the metrics are created, nor the measure are stored.

Reviewing the Log generated (I enabled the verbose option), I do not found any reference to the Decorators execution. Not even the LOG entries expected from the code in the Decorator.

I am using the MSBuild.SonarQube.Runner.exe version 2.0

Why the decorators are not called? is it an issue with the version of the SonarQube?

Upvotes: 1

Views: 114

Answers (1)

Simon Brandhof
Simon Brandhof

Reputation: 5136

The extension point Decorator was dropped in version 5.2 as it was not designed for one of the most wanted features of series 5.x : isolating scanners from database.

More details can be found at http://docs.sonarqube.org/display/DEV/API+Changes and in the group https://groups.google.com/forum/#!forum/sonarqube.

Upvotes: 1

Related Questions