What is PMD?
PMD basically stands for Programming Mistake Detector. It is a source code analyzer that finds common mistakes in your code like- unused variables, if-else statements without braces, naming conventions of methods, SOQL in loops, and many more. It also includes CPD which stands for Copy/Paste Detector, which finds duplicate code in your files and makes you aware to improve to make your code reusable.
Setting up PMD in AutoRABIT
- Log in to your AutoRABIT account.
- From the AutoRABIT home page, hover your mouse over the Admin module and select the option: My Account
- Go to the Plugins section.
- Click on the ApexPMD checkbox under Static Code Analysis.
- If you do have separate Apex PMD rules that you would like to carry out in AutoRABIT, you can upload the same. Click Browse to search for the file in your local machine. Usually, the file is in XML format. Once done, click Upload.
- If the user has not uploaded any rules file, AutoRABIT will use the default Apex PMD rules file. However, you can update some of the fields in it. Download the default rule set in your local machine using the link as seen in the shared screenshot below, editing the content, and uploading it once again.
- Click Save and you are all set with ApexPMD Integration.
Running PMD during CI Job
- Go to the New CI Job screen.
- Select any one of the criteria for your CI job. For example, Deploy from Salesforce Org
- Give the job a descriptive name in the CI Job Name field.
- In the Build section, select your Salesforce Org or Version Control Repo/Branch.
- Select the Run Static Analysis Report checkbox and choose Apex PMD/Lint.
- AutoRABIT allows you to set the criteria for running the ApexPMD SCA tool. This means running for all the apex classes or stating the period from where it will run. Also, you can set the priority, which means if the priority set is not achieved, the current build is unstable. This helps us in reporting the code quality of the developer team. This has nothing to do with the Lint.
- Fill in the remaining fields as per your requirements and click on Save.
- Once the build is triggered for your CI Job, the SCA report can be found under the Build Details section on the CI Job Result page.