How to create custom rules for Java in SonarQube?

1,173 views
Skip to first unread message

priyan...@gmail.com

unread,
Aug 11, 2017, 8:49:58 AM8/11/17
to SonarQube
I am using SonarQube 6.0 in my project. I need to create custom rules and found the template to create custom rules.
But even though I am not clear about creating custom rule. Help me in creating a new rule in sonar and also need to know about working of the rule.

Thanks in advance.


G. Ann Campbell

unread,
Aug 11, 2017, 9:02:55 AM8/11/17
to SonarQube, priyan...@gmail.com
Hi,

Do you have specific questions that aren't handled by the docs?


Ann

priyan...@gmail.com

unread,
Aug 17, 2017, 5:56:24 AM8/17/17
to SonarQube, priyan...@gmail.com
Thanks Ann.

The steps that are present in document is working fine. Is it possible to create the rule for Java using the template that is available in SonarQube 6.0?
If so, how to do it.

G. Ann Campbell

unread,
Aug 17, 2017, 7:19:27 AM8/17/17
to priyan...@gmail.com, SonarQube
Hi,

There are some template rules in SonarJava, but I believe the XPath template has long since been removed. Coding new rules directly in Java is really your best bet.


Ann



---
G. Ann Campbell | SonarSource
Product Manager
@GAnnCampbell

--
You received this message because you are subscribed to a topic in the Google Groups "SonarQube" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/sonarqube/OnLoniQ1iug/unsubscribe.
To unsubscribe from this group and all its topics, send an email to sonarqube+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sonarqube/b5738340-6e84-4bd0-a4ef-dd8445b419a7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

supers...@gmail.com

unread,
Aug 30, 2017, 2:12:06 PM8/30/17
to SonarQube, priyan...@gmail.com
Hi

I am also trying to create an XPath Custom rule to analyze xml files(check for occurences of certain tags within my XML), and it is not picking those up. So, has support for XPath template been removed? I am using SonarQube 6.5

Thanks
Satish


On Thursday, August 17, 2017 at 6:19:27 AM UTC-5, G. Ann Campbell wrote:
Hi,

There are some template rules in SonarJava, but I believe the XPath template has long since been removed. Coding new rules directly in Java is really your best bet.


Ann



---
G. Ann Campbell | SonarSource
Product Manager
@GAnnCampbell

On Thu, Aug 17, 2017 at 5:56 AM, <priyan...@gmail.com> wrote:
Thanks Ann.

The steps that are present in document is working fine. Is it possible to create the rule for Java using the template that is available in SonarQube 6.0?
If so, how to do it.

On Friday, August 11, 2017 at 6:32:55 PM UTC+5:30, G. Ann Campbell wrote:
Hi,

Do you have specific questions that aren't handled by the docs?


Ann

On Friday, 11 August 2017 08:49:58 UTC-4, priyan...@gmail.com wrote:
I am using SonarQube 6.0 in my project. I need to create custom rules and found the template to create custom rules.
But even though I am not clear about creating custom rule. Help me in creating a new rule in sonar and also need to know about working of the rule.

Thanks in advance.


--
You received this message because you are subscribed to a topic in the Google Groups "SonarQube" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/sonarqube/OnLoniQ1iug/unsubscribe.
To unsubscribe from this group and all its topics, send an email to sonarqube+...@googlegroups.com.

G. Ann Campbell

unread,
Aug 30, 2017, 3:13:53 PM8/30/17
to supers...@gmail.com, SonarQube, Priyanka S
Hi Satish,

XPath rules are still supported in SonarXML, but we no longer provide an SSLR toolkit for XML because there are a number of XPath testers, including several interactive sites, which should help you tune your XPath expression to match the expected XML code.


Ann



---
G. Ann Campbell | SonarSource
Product Manager
@GAnnCampbell

To unsubscribe from this group and all its topics, send an email to sonarqube+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sonarqube/944a42ba-d42a-4d60-840d-c063f0e65a9a%40googlegroups.com.

supers...@gmail.com

unread,
Aug 30, 2017, 3:22:29 PM8/30/17
to SonarQube, supers...@gmail.com, priyan...@gmail.com
Thanks for your very  quick response, Ann. So, if we are trying to define XPath rules to validate certain occurences of meta-data within an XML file and then try to use it to analyze the XML with a SonarScanner, then we wouldnt be able to do that without the SSLR toolkit. right? If that is true, what kind of analysis can be supported on an XML file using Sonar? 

G. Ann Campbell

unread,
Aug 30, 2017, 4:04:09 PM8/30/17
to supers...@gmail.com, SonarQube, Priyanka S
Hi,

Sorry, I confused the issue by introducing the question of an SSLR Toolkit. Let's pretend I didn't. :-)

All you need to do is write your XPath expression (possibly with the help of an XPath tester) to match your target XML. Then use the XPath rule template to create a new rule instance with that XPath expression & you should be good to go.


Ann



---
G. Ann Campbell | SonarSource
Product Manager
@GAnnCampbell

To unsubscribe from this group and all its topics, send an email to sonarqube+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sonarqube/5d97f514-a463-448b-a3aa-34d774dd653e%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages