Skip to content

Replace PMD used by the engine

Robert Sösemann edited this page Dec 18, 2017 · 18 revisions

The Code Climate engine is a Docker image which basically wraps a custom PMD version. Contributions made to PMD will not be automatically used by the Code Climate engine. You have to locally build a stripped-down (only Apex-relevant jars) version of PMD and add / replace the jars in the engine.

  1. Fork the Apex Metrics engine and connect the repository to your Eclipse and import it as a general project in Eclipse.

  2. Download the latest PMD binary distribution from https://github.com/pmd/pmd/releases

  3. From the lib folder remove all the .jars not required for PMD-Core, PMD-Apex, PMD-Visualforce.

  4. Replace the content of /codeclimate-apexmetrics/lib/pmd with the content of your reduced lib folder.

  5. Make sure that the file /codeclimate-apexmetrics/lib/pmd/bin/run.sh is executable. If it is not use chmod +x run.sh Otherwise the engine will later fail to run as described here: https://github.com/Up2Go/codeclimate-apexmetrics/issues/40.

Build and test your custom engine locally

First you need to install Docker and the Code Climate CLI.

  1. Start Docker deamon (On MacOsX by opening Docker Quickstart Terminal) and check if it is running by executing docker images If you get Cannot connect to the Docker daemon. Is the docker daemon running on this host? you need to execute eval "$(docker-machine env default)". Here is why.

  2. Navigate into your codeclimate-apexmetrics

  3. [OPTIONAL] Delete previous versions of the apexmetric engine with

     docker rmi <Engine Hash>
    
  4. Build the Docker image

     docker build -t codeclimate/codeclimate-apexmetrics .
    
  5. Check if there is a codeclimate/codeclimate-apexmetrics image

     docker images
    
  6. Update the CodeClimate CLI on your machine by executing those commands

     brew update
     brew upgrade codeclimate
    
  7. Download and unzip big open source repos for testing. E.g.:

  1. Run the newly built engine in the root directory of each repository by executing

     codeclimate analyze -e apexmetrics
    

    If the analysis is successful it should show issue output like this. If an error occurs try to understand the root cause and fix it BEFORE you can proceed with the last step!

     ...
     83: The method getInit() has an NCSS line count of 61 [apexmetrics]
     
     == src/classes/TableGridUtils.cls (1 issue) ==
     53: Avoid long parameter lists [apexmetrics]
     
     Analysis complete! Found 22 issues.
    
  2. Commit your changes to your fork and create a Pull Request to merge your changes. You should provide a detailed description of your changes, why you did them and how you tested them. After we checked and merged your pull request we will publish your changes to Code Climate.