Adding custom rules to sonar PMD written using Java Way - pmd

I'm using Sonar v3.5.1 & PMD V4.3 and I want to add custom rules to my PMD runner written in Java.
How should I add new rules to the pmd-rules.xml configuration file, so I can get the custom rules reporting in Sonar?
Any help is appreciated.

This document has everything you need to write a custom rule in Java for PMD v4.3: http://pmd.sourceforge.net/pmd-4.3.0/howtowritearule.html
If it's possible it would also be good to update PMD to the latest 5.x version, configuration will be friendlier.
Let me know if this helped.

Related

How to get eclipse content assist working in XML files

I have started creating the Spring web application where I need to mention the spring classes in the XML configuration files, for ex, the deployment descriptor (web.xml) where I need to mention the DispatcherServlet class of Spring.
What I am looking for is, I want eclipse to show me the list of packages/classes when I type org.springframework..., like we do in the Java editor. I have googled to find out, but no luck. I am sure there would be plugins available. Can any of you please share me on how to fix this?
Since you are working on a spring project, I'd recommend installing the SpringToolSuite (STS). The info page is here: http://spring.io/tools
Since you already have an Eclipse instance that you are working with, you should go with the update sites: http://dist.springsource.com/release/TOOLS/update/e4.4/
(Make sure to use the correct update site for the Eclipse version you are using.)
Not only does STS include all tools for XML editing, but it also includes special tools for editing your Spring application files.

Checkstyle Jenkins - How do I Configure Checkstyle in Jenkins?

I am new to using Jenkins and I recently built a project with it and installed the "Checkstyle" plugin and received a report.
I want to know how I can configure "Checkstyle" to, let's say, ignore whitespaces or other criteria that may come up?
Thank you!
Jenkins simply reads the checkstyle report after it was run in the course of a build, and is extraneous to the question. To configure checkstyle, you want to modify or create checkstyle.xml (the location is configurable via method based your choice of build automation tool, such as maven or gradle. The checkstyle manual has further details on how to accomplish any checks you may desire.

Does Checkstyle provide quickfix possibilities?

I implemented an extension plugin for checkstyle.
Now I have the task to add quickfixes for some checkstyle errors in eclipse.
Example: Add a final modifier if a class is public.
After several hours of research, I decided to ask this question in several forums because I won't be the only one with this wish/problem.
According to the documentation of checkstyle http://checkstyle.sourceforge.net/, the plugin does not provide quickfixes for own implemented checks.
I did some research but I found nothing about how to add quickfixes for own checks.
Now the question: Is there a way to implement own quickfixes for eclipse?
I'm using version 5.6 of the checkstyle API and Eclipse 4.2.
Refer to Extending the eclipse-cs plugin page.
From there you can download a sample Check.
The file is here under the name net.sf.eclipsecs.sample
In src\net\sf\eclipsecs\sample\checks there is one QuickFix Java code and in base directory, in plugin.xml the following line is present, which enables the quickfix.
<!-- This plugin provides custom quickfixes for Checkstyle problems. -->
<extension
point="net.sf.eclipsecs.ui.checkstyleQuickfixProvider">
</extension>
You can download and refer that sample for your query. Extending Check is described nicely there.

How to export FindBugs/PMD/Checkstyle rules from Sonar and import into Netbeans

My company has sonar set up to with various plugins (PMD, FindBugs, CheckStyle), and although it is very useful as is (it runs after every Jenkins build that was triggered by a check-in to SVN), I would like it if I could run these various plugins on my local machine before I check the code in.
We have a set of rules already set up in Sonar, so ideally I would like to be able to export that ruleset, perhaps do some munging of the data, and then import the resulting rules into my IDE (Netbeans 7.0.1) into the respective plugins. Is there any way to do this? I've searched all over and short of going through and manually adding each rule to the various plugins, there doesn't appear to be a way to do this. Is there something I'm missing?
TL;DR (Summary): I'd like to export a profile from sonar and import the rule settings into the PMD, Findbugs, and CheckStyle plugins in Netbeans.
Each Sonar profile publishes it's Checkstyle, FIndbugs and PMD configuration under the permalinks tab.
Assuming you've got Sonar installed locally, the following link shows the configuration files used by the "Sonar Way" profile:
http://localhost:9000/profiles/permalinks/2
You don't need your own Sonar installation. You can get the configuration of any of Sonar's built-in Quality Profiles from Sonar's Nemo site:
There are about a dozen Java Quality Profiles. A commonly used profile - Sonar way with Findbugs - is available at:
http://nemo.sonarsource.org/rules_configuration/index/135
The initial Profile view just lists all the rules. Don't use the "Download" link on that view. That just gives you a CSV listing of the merged rules across all tools. Helpful for review, but not what you're asking for.
To export the tool-specific configuration, select the Permalinks tab/view. Those links return the configuration file in the form expected by each tool. For example, here's the link for the FindBugs XML configuration file:
http://nemo.sonarsource.org/profiles/export?format=findbugs&language=java&name=Sonar%2520way%2520with%2520Findbugs
SonarLint is the newer plugin and it doesn't support Checkstyle/PMD/FindBugs profiles anymore. Everything has to be migrated to squid rules and configured on the SonarQube server under Quality Profiles. You need to connect to the server using connected mode and set your custom quality profile as default so that local analysis would show issues related to your quality profile.
More information about SonarLint Plugin and connected mode can be found at
http://www.sonarlint.org/eclipse/index.html#Connected
Another simple mechanism is to use : Backing up / Restoring a Profile
See : http://docs.sonarqube.org/display/SONAR/Profile+Existence+Edits
Taking backup from an instance(source) will give you a backup.xml file on your local machine and then on another instance(destination) you can restore it.

Netbeans + Checkstyle

Does anyone have experience using checkstyle in netbeans 7? I have the plugin installed, and I have selected my configuration file but I'm not seeing any errors or the promised "annotation". Any suggestions? Is there something I need to do to get it to start working? I have the plugin activated in the plugins menu.
Follow the directions in this article. You might need to restart Netbeans after installing the plugins. Code violations should appear as annotations on the line number gutter.
You can then go to the tools/options/quality/checkstyle tab to set your custom checkstyle configuration files.
Not sure if this is important but make sure that your custom checkstyle.xml uses the Check Configuration 1.3 version.
<!DOCTYPE module PUBLIC "-//Puppy Crawl//DTD Check Configuration 1.3//EN" "http://www.puppycrawl.com/dtds/configuration_1_3.dtd">