[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:
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?
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.
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.
The steps to cover a new programming language are:
Write the grammar. This is the hardest part.
Write a parser (a parser simply parses an input based on your grammar to yield a parse tree).
Test your grammar, to ensure it is able to parse real-life language files.
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.
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.
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?
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.