1

I am trying to developing sonar plugin. But i couldnt get rule with params. Here my custom rule.

<?xml version="1.0" encoding="UTF-8"?>
<rules>
    <rule>
       <key>custom-rule-key</key>
       <name>custom rule</name>
       <configKey>custom-rule-key</configKey>
       <description>this is custom rule</description>
       <priority>MINOR</priority>
        <param>
           <key>the-param-key</key>
           <tag>style</tag>
           <tag>security</tag>
           <description>
          <![CDATA[the param-description]]>
            </description>
            <defaultValue>42</defaultValue>
        </param>
    </rule>
</rules>

I can see it on sonarqube interface and i can change param value from interface. But as i mentioned, i couldnt reach rule and value of param from code. Do you have any idea? Thanks.

G. Ann - SonarSource Team
  • 22,346
  • 4
  • 40
  • 76
onua
  • 23
  • 1
  • 6

1 Answers1

1

I suppose that you need to load the rule configuration from scanners ("Sensor" extension point). In this case the component org.sonar.api.batch.rule.ActiveRules must be used and injected in your sensor.

Simon Brandhof
  • 5,137
  • 1
  • 21
  • 28
  • I got it with org.sonar.api.profiles.RulesProfile (rulesProfile .getActiveRulesByRepository(" ");) as you said. But Now i need quality profiles. I can get active rules with parameters but i think only rules belogs to default quality profile are coming. How to get active rules by quaility profiles? – onua Sep 22 '16 at 12:16
  • I didn't mention the class RulesProfile but ActiveRules. That's the way to get the effective rules of the Quality profiles associated to the current project. – Simon Brandhof Sep 22 '16 at 13:26
  • when i set sonar.profile in sonar-project.properties file, i can get active rules with this profile. Rulesprofile is injected in sensor. rulesProfile .getActiveRulesByRepository(" "); is working for me. Thank you. – onua Sep 23 '16 at 14:24