Quantcast

[sonar-dev] custom plugin to raise issues

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[sonar-dev] custom plugin to raise issues

timwebster9
Hi,

I'm trying to write a plugin that will do the following:

  1. Obtain project files of a specified type (non-java).
  2. For each file, perform an operation with it.
  3. If a problem occurs with said operation, raise an issue on that file.
The idea is the maintainer of that file will get the issue that was raised, and deal with the problem.

I've started down the path of writing a sensor that does all this, and it all works fine, except for when I get to the bit about raising the issue.

To raise an issue you need a rule.  For a rule to exist you need a language.  For the language you need a quality profile, and then the rule needs to be registered.

Before I get to the next bit, it's worth thinking about if I really need all that stuff...I'm not sure I do, at least not from a technical standpoint.  I'm not analyzing a new language or anything like that.

In my plugin I created a new language, a new rule (with @Rule annotation), a new repository for the language and loaded the rule with RulesDefinitionAnnotationLoader.  I then created a quality profile through the GUI.

The problem is the rule I created for the language doesn't show up in SonarQube.   I just get a 'rule XXX doesn't exist' error when I try to raise an issue with it.  It also doesn't show up on the 'rules' GUI page.  The new repository is there but the rule isn't.

It's also not in the rules database table.  I guess it's not getting registered for some reason.

I also tried with a manual rule, and I get the same error when I try to raise an issue with it in the plugin.  The rule does exist and I'm using the correct key as far as I can tell.

I've looked at a bunch of other plugins and I'm doing pretty much exactly what they are doing.  I've also got another plugin for custom Java rules and that all works OK. 

So:
  • does anyone think there is a better way to accomplish what I'm trying to do?  
  • If not, any ideas why my rule is not getting registered in the server?

thanks,

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[sonar-dev] Re: custom plugin to raise issues

timwebster9
Hi,

Really sorry to pester and ask twice, but does anyone have any ideas about the problem below?

This is quite important for us in that there are several 'checks' that we currently do that are similar to the one described below, and I would prefer to do them with SonarQube plugins.  If for whatever reason it isn't going to work it would be better if I know sooner rather than later.

To reiterate - does this seem like a decent use case for SonarQube?  And if so, any hints as to why I can't seem to get the rules to persist?  Or is there another way to raise an issue without it being associated with languages, etc...





On Sun, May 17, 2015 at 1:59 PM, Tim Webster <[hidden email]> wrote:
Hi,

I'm trying to write a plugin that will do the following:

  1. Obtain project files of a specified type (non-java).
  2. For each file, perform an operation with it.
  3. If a problem occurs with said operation, raise an issue on that file.
The idea is the maintainer of that file will get the issue that was raised, and deal with the problem.

I've started down the path of writing a sensor that does all this, and it all works fine, except for when I get to the bit about raising the issue.

To raise an issue you need a rule.  For a rule to exist you need a language.  For the language you need a quality profile, and then the rule needs to be registered.

Before I get to the next bit, it's worth thinking about if I really need all that stuff...I'm not sure I do, at least not from a technical standpoint.  I'm not analyzing a new language or anything like that.

In my plugin I created a new language, a new rule (with @Rule annotation), a new repository for the language and loaded the rule with RulesDefinitionAnnotationLoader.  I then created a quality profile through the GUI.

The problem is the rule I created for the language doesn't show up in SonarQube.   I just get a 'rule XXX doesn't exist' error when I try to raise an issue with it.  It also doesn't show up on the 'rules' GUI page.  The new repository is there but the rule isn't.

It's also not in the rules database table.  I guess it's not getting registered for some reason.

I also tried with a manual rule, and I get the same error when I try to raise an issue with it in the plugin.  The rule does exist and I'm using the correct key as far as I can tell.

I've looked at a bunch of other plugins and I'm doing pretty much exactly what they are doing.  I've also got another plugin for custom Java rules and that all works OK. 

So:
  • does anyone think there is a better way to accomplish what I'm trying to do?  
  • If not, any ideas why my rule is not getting registered in the server?

thanks,


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[sonar-dev] Re: custom plugin to raise issues

timwebster9
In reply to this post by timwebster9
FYI I figured out the problem - my language key on the language implementation was in uppercase.  I changed it to lowercase and it worked (the rules were persisted).




On Sun, May 17, 2015 at 1:59 PM, Tim Webster <[hidden email]> wrote:
Hi,

I'm trying to write a plugin that will do the following:

  1. Obtain project files of a specified type (non-java).
  2. For each file, perform an operation with it.
  3. If a problem occurs with said operation, raise an issue on that file.
The idea is the maintainer of that file will get the issue that was raised, and deal with the problem.

I've started down the path of writing a sensor that does all this, and it all works fine, except for when I get to the bit about raising the issue.

To raise an issue you need a rule.  For a rule to exist you need a language.  For the language you need a quality profile, and then the rule needs to be registered.

Before I get to the next bit, it's worth thinking about if I really need all that stuff...I'm not sure I do, at least not from a technical standpoint.  I'm not analyzing a new language or anything like that.

In my plugin I created a new language, a new rule (with @Rule annotation), a new repository for the language and loaded the rule with RulesDefinitionAnnotationLoader.  I then created a quality profile through the GUI.

The problem is the rule I created for the language doesn't show up in SonarQube.   I just get a 'rule XXX doesn't exist' error when I try to raise an issue with it.  It also doesn't show up on the 'rules' GUI page.  The new repository is there but the rule isn't.

It's also not in the rules database table.  I guess it's not getting registered for some reason.

I also tried with a manual rule, and I get the same error when I try to raise an issue with it in the plugin.  The rule does exist and I'm using the correct key as far as I can tell.

I've looked at a bunch of other plugins and I'm doing pretty much exactly what they are doing.  I've also got another plugin for custom Java rules and that all works OK. 

So:
  • does anyone think there is a better way to accomplish what I'm trying to do?  
  • If not, any ideas why my rule is not getting registered in the server?

thanks,


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [sonar-dev] Re: custom plugin to raise issues

Julien HENRY
Hi Tim,

Sorry for late answer but I had no idea of the issue. I'm glad you managed to make it works.

Concerning the fact raising an issue needs a rule that is declared in a quality profile, then this is how SQ works and I don't see how it can change.
But concerning the fact that a rule needs a language, then here this is for historical reasons and this is very likely we will remove this constraint at some point.

++

Julien

2015-05-20 13:40 GMT+02:00 Tim Webster <[hidden email]>:
FYI I figured out the problem - my language key on the language implementation was in uppercase.  I changed it to lowercase and it worked (the rules were persisted).




On Sun, May 17, 2015 at 1:59 PM, Tim Webster <[hidden email]> wrote:
Hi,

I'm trying to write a plugin that will do the following:

  1. Obtain project files of a specified type (non-java).
  2. For each file, perform an operation with it.
  3. If a problem occurs with said operation, raise an issue on that file.
The idea is the maintainer of that file will get the issue that was raised, and deal with the problem.

I've started down the path of writing a sensor that does all this, and it all works fine, except for when I get to the bit about raising the issue.

To raise an issue you need a rule.  For a rule to exist you need a language.  For the language you need a quality profile, and then the rule needs to be registered.

Before I get to the next bit, it's worth thinking about if I really need all that stuff...I'm not sure I do, at least not from a technical standpoint.  I'm not analyzing a new language or anything like that.

In my plugin I created a new language, a new rule (with @Rule annotation), a new repository for the language and loaded the rule with RulesDefinitionAnnotationLoader.  I then created a quality profile through the GUI.

The problem is the rule I created for the language doesn't show up in SonarQube.   I just get a 'rule XXX doesn't exist' error when I try to raise an issue with it.  It also doesn't show up on the 'rules' GUI page.  The new repository is there but the rule isn't.

It's also not in the rules database table.  I guess it's not getting registered for some reason.

I also tried with a manual rule, and I get the same error when I try to raise an issue with it in the plugin.  The rule does exist and I'm using the correct key as far as I can tell.

I've looked at a bunch of other plugins and I'm doing pretty much exactly what they are doing.  I've also got another plugin for custom Java rules and that all works OK. 

So:
  • does anyone think there is a better way to accomplish what I'm trying to do?  
  • If not, any ideas why my rule is not getting registered in the server?

thanks,



Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [sonar-dev] Re: custom plugin to raise issues

timwebster9
Hi Julien,

Thanks for the reply.  yes it all worked out in the end - actually the language restraint comes in handy as it is tied to file types I want to analyze (in this case anyways), so it is not a problem.  But for other cases which I think might come up, it might be overkill.

I also wondered if the problem with the Language key needing to be lowercase is a bug?  The only reason I noticed it was because the rule repository's language in the database had it specified in lowercase - you'd think it wouldn't be case-sensitive?  To be clear - I only specified the Language key in one place (on the implementation) and nowhere else, and the rules were never saved until I changed it to lowercase.



On Fri, May 22, 2015 at 4:59 PM, Julien HENRY <[hidden email]> wrote:
Hi Tim,

Sorry for late answer but I had no idea of the issue. I'm glad you managed to make it works.

Concerning the fact raising an issue needs a rule that is declared in a quality profile, then this is how SQ works and I don't see how it can change.
But concerning the fact that a rule needs a language, then here this is for historical reasons and this is very likely we will remove this constraint at some point.

++

Julien

2015-05-20 13:40 GMT+02:00 Tim Webster <[hidden email]>:
FYI I figured out the problem - my language key on the language implementation was in uppercase.  I changed it to lowercase and it worked (the rules were persisted).




On Sun, May 17, 2015 at 1:59 PM, Tim Webster <[hidden email]> wrote:
Hi,

I'm trying to write a plugin that will do the following:

  1. Obtain project files of a specified type (non-java).
  2. For each file, perform an operation with it.
  3. If a problem occurs with said operation, raise an issue on that file.
The idea is the maintainer of that file will get the issue that was raised, and deal with the problem.

I've started down the path of writing a sensor that does all this, and it all works fine, except for when I get to the bit about raising the issue.

To raise an issue you need a rule.  For a rule to exist you need a language.  For the language you need a quality profile, and then the rule needs to be registered.

Before I get to the next bit, it's worth thinking about if I really need all that stuff...I'm not sure I do, at least not from a technical standpoint.  I'm not analyzing a new language or anything like that.

In my plugin I created a new language, a new rule (with @Rule annotation), a new repository for the language and loaded the rule with RulesDefinitionAnnotationLoader.  I then created a quality profile through the GUI.

The problem is the rule I created for the language doesn't show up in SonarQube.   I just get a 'rule XXX doesn't exist' error when I try to raise an issue with it.  It also doesn't show up on the 'rules' GUI page.  The new repository is there but the rule isn't.

It's also not in the rules database table.  I guess it's not getting registered for some reason.

I also tried with a manual rule, and I get the same error when I try to raise an issue with it in the plugin.  The rule does exist and I'm using the correct key as far as I can tell.

I've looked at a bunch of other plugins and I'm doing pretty much exactly what they are doing.  I've also got another plugin for custom Java rules and that all works OK. 

So:
  • does anyone think there is a better way to accomplish what I'm trying to do?  
  • If not, any ideas why my rule is not getting registered in the server?

thanks,




Loading...