Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to set existing rules parameters of Checkstyle on Sonarqube from rules xml file #25

Closed
ozlmulg opened this issue Nov 30, 2016 · 5 comments

Comments

@ozlmulg
Copy link

ozlmulg commented Nov 30, 2016

I want to import my checkstyle rules to Sonarqube by setting their parameters according to me. I use Checkstyle Sonar plugin in language Java that my Sonar repository read from rules definition XML file by using RulesDefinitionXmlLoader.

Suppose that I have the following rules XML file to load Sonarqube that contains my custom Checkstyle rules and also LineLength check that is already exists in Checkstyle:

<rules>
    <rule>
        <key>LineLength</key>
        <name>Line Length</name>
        <description>Line Length</description>
        <internalKey>Checker/TreeWalker/LineLength</internalKey>
        <param key="max" name="Max">
            <defaultValue>120</defaultValue>
            <description>Max property with value of '120'</description>
        </param>
    </rule>
    <rule>
        <key>CustomCheck</key>
        <name>CustomCheck</name>
        <description>any custom check</description>
        <internalKey>Checker/TreeWalker/CustomCheck</internalKey>
        <param key="anyParam" name="any">
            <defaultValue>any</defaultValue>
            <description>any param value</description>
        </param>
    </rule>
</rules>

I want to use these rules on Sonarqube. My custom rule and LineLength rule are created on Sonarqube with given parameters. I activated two of them on my used profile. My custom rule successfully works on git pull requests but LineLength check do not works on pull requests. Because there is already LineLength check on Sonarqube that comes from Checkstyle plugin so two LineLength rules seem on the dashboard of Sonarqube. But I want to override existing LineLength check by giving its parameters what I want from my Sonar rule XML file. Note that when I activated two of LineLength rule, two of them successfully works but I do not want to the already existing LineLength rule to work, I want to my LineLength check with my parameters.

@romani
Copy link
Member

romani commented Dec 2, 2016

Can you rename your Check to LineLengthYourCompany?

Naming in the same way is not good and rely on details of loading custom classes and storage them internally.

Try to use fully qualified name.

@ozlmulg
Copy link
Author

ozlmulg commented Dec 2, 2016

@romani Thanks for your answer but LineLength is not a custom check of my company. It is existing com.puppycrawl.tools.checkstyle.checks.sizes.LineLengthCheck check in Checkstyle and I only want to set the parameters of this check according to me on Sonarqube by reading XML rules file. Yes I can do that on dashboard of Sonarqube but thinks that I have lots of rules that are combination of my custom checks and some existing checkstyle checks. How can I easily apply my full XML rule file to Sonarqube?

@romani
Copy link
Member

romani commented Dec 2, 2016

Because there is already LineLength check on Sonarqube that comes from Checkstyle plugin so two LineLength rules seem on the dashboard of Sonarqube.

I mentioned this problem. Please avoid the same simple name of Checks.

How can I easily apply my full XML rule file to Sonarqube?

I do not know :(. You mentioned https://github.com/SonarSource/sonarqube/blob/master/sonar-plugin-api/src/main/java/org/sonar/api/server/rule/RulesDefinitionXmlLoader.java this class , I have never worked with it.
I do not have any automation to suggest you for now. If you find please share.


I am closing this issue as it contain two unrelated problems, you are welcome to open new issues but more certain.

@ozlmulg
Copy link
Author

ozlmulg commented Dec 2, 2016

@romani thanks :(

@romani
Copy link
Member

romani commented Dec 16, 2016

Sonar config could be imported to Sonar during new profile creation - https://github.com/checkstyle/sonar-checkstyle/wiki/How-to-import-existing-checkstyle-config-to-sonar

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants