Sonar Xml custom rules not triggering

363 views
Skip to first unread message

mohankris...@gmail.com

unread,
Feb 7, 2017, 8:58:21 PM2/7/17
to SonarQube
Hi All,

I am able write the XML custom rules through Sonar UI, but created rule not triggering.
additionally have to any settings or any configurations.
Please suggest to resolve the issue.

Thanks,
Mohan

yves.dubo...@sonarsource.com

unread,
Feb 9, 2017, 3:22:45 AM2/9/17
to SonarQube, mohankris...@gmail.com
Hello Mohan,

I assume you created an XPath rule using the XML analyzer. The functionality is supposed to work smoothly. Kindly provide:
- the version of SonarQube
- the version of the XML plugin
- the details of your rule
- a sample of an XML file for which you expect an issue to be raised

Did you activate your rule?

Best regards,

Yves Dubois-Pèlerin
SonarSource team

mohankris...@gmail.com

unread,
Feb 9, 2017, 4:46:03 AM2/9/17
to SonarQube, mohankris...@gmail.com
Hi Team,

            Thank you for your prompt response,
                
               Version of SonarQube = 6.2
               Version of the XML plugin = 1.4.1

Sample XML : 
               

       <?xml version="1.0" encoding="ISO-8859-1"?>
<items xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="items.xsd">

<collectiontypes>
<collectiontype code="CountriesCollection" elementtype="Country" autocreate="true" generate="true"
type="list" />
</collectiontypes>

<enumtypes>
<enumtype code="NAModStatus" autocreate="false" generate="false">
<value code="OBSOLETE" />
<value code="USEUP" />
</enumtype>
<enumtype code="SourceSysId" autocreate="true" generate="true" dynamic="true">
<value code="E1PD812" />
</enumtype>
<enumtype code="OrderStatus" autocreate="false" generate="true">
<value code="SUBMITTED" />
<value code="IN_PROGRESS" />
</enumtype>
</items>

Condition : I am writing rule for if root element name is other than "items", it should throw the error message.
Xpath :  not(/name(/*) = 'item')

Please let me know for more details.

Thanks,
Mohan.

 

yves.dubo...@sonarsource.com

unread,
Feb 10, 2017, 4:50:38 AM2/10/17
to SonarQube, mohankris...@gmail.com
Hello Mohan,

In your example I made two small fixes: I appended "s" to "item" in your XPath expression and I added a closing </enumtypes> markup in your XML sample file. Then indeed I came up with a defect of the XML analyzer has a problem: the name() XPath function is not supported. I created a JIRA ticket for this.

A workaround for you would be to use a different XPath expression, viz.:
count(items)=0
I hope this helps.

Thanks for reporting the error!

mohankris...@gmail.com

unread,
Feb 13, 2017, 2:39:56 AM2/13/17
to SonarQube, mohankris...@gmail.com
Hi All,

Thank you for your help.

:)

Thanks,
Mohan
Reply all
Reply to author
Forward
0 new messages