Custom Plugin Development - Sensor extended class not executed

[sonarqube-community-10.6.0.92116]
My New/Custom developed SQL (*.sql) Sonar Plugin is not being detected/activated when I run analysis on new project that has .sql scripts.

I can see my new Quality Profile and new Rules in Sonar but not being run when I run code analysis. i.e., SQLComplianceSensor.execute(SensorContext context) was never called. (I see no debug messages in the log files)

I followed all the steps listed in developing a new plugin section of the documentation.
How do I debug or detect why and where I’m missing the plugin detection?
I see my new SQL language (AbstractLanguage extension) debug message in log.
Here is my plugin context extensions addition:

context.addExtensions(SQLLanguage.class, SQLComplianceSensor.class, SQLQualityProfile.class,
SQLComplianceRulesDefinition.class, SQLComplianceCheckRegistrar.class);

Question: Does this extension classes addition order has any significance?

  1. SQLLanguage.java
    public final class SQLLanguage extends AbstractLanguage {
    …

  2. SQLComplianceSensor.java

public class SQLComplianceSensor implements Sensor {
…

  1. SQLQualityProfile.java

public class SQLQualityProfile implements BuiltInQualityProfilesDefinition {
…

  1. SQLComplianceRulesDefinition.java

public class SQLComplianceRulesDefinition implements RulesDefinition {
…

  1. SQLComplianceCheckRegistrar.java

public class SQLComplianceCheckRegistrar implements CheckRegistrar {
…

Do I have to sign my Plugin Jar before I deploy to sonar extensions/plugins folder?

Appreciate your input and feedback!!

Hi,

You’ve presumably declared a new language(?). What file extensions does that language ‘claim’? And are those file extensions present in the project you’re testing on?

 
Ann

Thank you, Ann.

Yes, I declared SQL as my new language. I do have multiple .sql files in my project. Is there a good example or documentation on implementing a new language? Most of the SSLR examples are outdated libraries or implemented with complex grammar or too many interfaces to implement. To answer your second question, yes - my project do have multiple .sql files.

Hi,

I can only point you to our open source analyzers in Sonar ¡ GitHub

 
Ann

Hi Ann,

Quick clarification. Do we have to write Grammar and Tree visitors as listed in Supporting new languages? Cannot we write a simple parser that does all and invoke from scanner?

I noticed all my custom rules and profiles are being created, but when I test run new project with SQL script file in the project, my sensor or my plugin rules are not triggered.

On a different note, My newly added language is not listed under Languages list from Admin page, but under Rule Profiles I see a language SQL.

(Supporting new languages)

Supporting new languages

The steps to cover a new programming language are:

  1. Write the grammar. This is the hardest part.
  2. Write a parser (a parser simply parses an input based on your grammar to yield a parse tree).
  3. Test your grammar, to ensure it is able to parse real-life language files.
  4. Write a few parse tree visitors. Some visitors will compute metrics such as executable lines, while others will enforce coding rules. A dozen or so visitors are sufficient for an initial release.

Thank you for you response and support.

Hi,

I think both of these are unrelated to how you’re analyzing the language, and indicate that your plugin isn’t being registered properly. I would back to to working on just that, using whether or not the language shows up as your indicator of whether or not it’s working.

 
Ann

Thank you, Ann. I’ll continue my investigation on Plugin scanner detection and post my progress.

1 Like

Hi Ann,

Could you please confirm that, I’m on the right track and why my new PL/SQL or SQL language sensor is not triggered when I validate a new project? I tried to validate local project using maven option.

Here are the key Plugin calls -
PlSqlPlugin class:
context.addExtensions(Arrays.asList(
PropertyDefinition.builder(FILE_SUFFIXES_KEY)
.name(“File Suffixes”)
.description(“Comma-separated list of suffixes of PL/SQL files to analyze.”)
.category(“PL/SQL”)
.onQualifiers(Qualifiers.PROJECT)
.defaultValue(“sql,pkg,pks,pkb”)
.build(),

    PlSql.class,
    PlSqlProfile.class,
    PlSqlSquidSensor.class, <== Missing log entries for instantiation or any other calls
    PlSqlRuleRepository.class,
    PlSqlCpdMapping.class, <== Missing log entries for instantiation or any other calls
    SonarComponents.class)); <== Missing log entries for instantiation or any other calls

Here are the log entries:
2024.10.24 11:12:26 INFO web[o.s.p.PlSqlPlugin] PlSqlPlugin define() started
2024.10.24 11:12:26 INFO web[o.s.p.PlSqlPlugin] PlSqlPlugin define() completed

2024.10.24 11:12:28 INFO web[o.s.plsqlopen.PlSql] PlSql() completed

2024.10.24 11:12:33 INFO web[o.s.p.PlSqlRuleRepository] PlSqlRuleRepository() started
2024.10.24 11:12:33 INFO web[o.s.p.PlSqlRuleRepository] PlSqlRuleRepository() ended

2024.10.24 11:12:58 INFO web[o.s.p.PlSqlProfile] PlSqlProfile define() started
2024.10.24 11:12:58 INFO web[o.s.p.PlSqlProfile] PlSqlProfile define() completed

2024.10.24 11:13:00 INFO web[o.s.s.q.RegisterQualityProfiles] Update profile plsql/Sonar way

I see no log entries for Sensor, CpdMapping or SonarComponents even when I check/validated project.

I appreciate any guidence on why the sensor is not triggered on SQL files?

Thanks,
S.

Hi,

This really isn’t my area of expertise, and since you’re trying to craft a plugin for a language we support commercially I can’t ask any of the developers to help you. I can only advise you to work from our open source analyzers.

 
Ann