Supporting analysis for a custom language

508 views
Skip to first unread message

brien...@googlemail.com

unread,
Jun 9, 2017, 7:17:35 AM6/9/17
to SonarQube
Hello,

I want to write a SonarQube plugin which adds analysis for sourcecode in a custom language developed by my company.

I have access to a .csv file from an external source, which contains information about warnings and errors which were logged during the compilation of the source files by our custom compile framework.
So essentially, I want to parse this file and visualize its contents in SonarQube by mapping these warnings and errors to the source files.
As far as I understand, in order to do that, the source files need to be imported to SonarQube, which usually happens during compilation.

As my sourcecode is compiled by our custom compile framework, I fear that an import in such fashion is not easily possible.
Is it possible to import sourcecode without actually compiling it? E.g. just point to some text files, which are imported and then tagged with issues by my plugin?

Or is there any other way to achieve my goal?

Thanks!

Julien HENRY

unread,
Jun 9, 2017, 7:39:58 AM6/9/17
to SonarQube, brien...@googlemail.com
Hi,


Le vendredi 9 juin 2017 13:17:35 UTC+2, brien...@googlemail.com a écrit :

As far as I understand, in order to do that, the source files need to be imported to SonarQube, which usually happens during compilation.

This is not correct. SonarQube scanners are responsible to trigger analysis (including uploading source code to the SonarQube server). Most scanners are developed as plugin for popular build tools, but this is for convenience. The SonarQube Scanner is a standalone command line tool that you can use to analyze any project.

To analyze your language, here are the steps:
  1. develop a custom SonarQube plugin that implements few extension points (Language, RuleDefinitions, as well as a Sensor to process your cvs file and import issues)
  2. install this plugin in your SonarQube server
  3. analyze your source code using the SonarQube Scanner
I let you have a look at the documentation, and feel free to come with more specific questions.

++

Julien

brien...@googlemail.com

unread,
Jun 12, 2017, 2:26:32 AM6/12/17
to SonarQube, brien...@googlemail.com
Hi,

thank you very much for your input, with your help I was able to import my code into SQ.
Adding rules to create issues should be pretty straightforward now.

Bastian

brien...@googlemail.com

unread,
Jul 18, 2017, 6:23:34 AM7/18/17
to SonarQube, brien...@googlemail.com
Hi,

I have added some rules by implementing the RulesDefinition extension. Now I want to create a Quality Profile with my plugin and automatically add my rules to it.

I found the following code snippet: https://github.com/SonarSource/sonar-custom-plugin-example/blob/master/src/main/java/org/sonarsource/plugins/example/languages/FooQualityProfile.java
There, a profile is created, and rules are activated for it using the RulesProfile.activateRule method. This works, but org.sonar.api.rules.RulePriority.BLOCKER, MAJOR, MINOR and so on are deprecated (I have to use SQ 5.6.6 LTS)

So I was wondering if there is any other, non-deprecated way to create a quality profile with my own rules from within the plugin?

Thanks,
Bastian

brien...@googlemail.com

unread,
Jul 18, 2017, 9:34:37 AM7/18/17
to SonarQube, brien...@googlemail.com
I was able to create a profile from within the plugin by creating and parsing a profile.xml with a XMLProfileParser.

But this raises a new issue for me. When I install the plugin on a fresh server and start the server up, the profile is created and everything is fine.
Now, I shutdown the server, add a new rule in the plugin and adapt the profile.xml to include this new rule, then install the plugin and restart the server.
Then, the new rule will be added to SQ but the quality profile will not contain the new rule. I can see that ProfileDefinition.createProfile() is being called, and it returns a profile with the new rule included, but obviously this new quality profile is not written to the server.

Is there any way to update the existing profile from within the plugin?


Thanks,
Bastian

Am Freitag, 9. Juni 2017 13:17:35 UTC+2 schrieb brien...@googlemail.com:
Reply all
Reply to author
Forward
0 new messages