Skip to content

Replace PMD used by the engine

Robert Sösemann edited this page Jul 14, 2016 · 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.

Build PMD

  1. Download and unpack the desired PMD release to a folder

  2. Replace the /pmd-dist/pom.xml with this lean version which only contains Apex related jars. This is required to keep the engine's Docker file as small as possible.

     <?xml version="1.0" encoding="UTF-8"?>
     <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
         <modelVersion>4.0.0</modelVersion>
         <artifactId>pmd-dist</artifactId>
         <name>PMD Distribution Packages</name>
         <packaging>pom</packaging>
    
         <parent>
             <groupId>net.sourceforge.pmd</groupId>
             <artifactId>pmd</artifactId>
             <version>5.5.1-SNAPSHOT</version>
         </parent>
    
         <properties>
             <config.basedir>${basedir}/../pmd-core</config.basedir>
         </properties>
    
         <build>
             <plugins>
                 <plugin>
                     <artifactId>maven-assembly-plugin</artifactId>
                     <configuration>
                         <appendAssemblyId>false</appendAssemblyId>
                         <attach>false</attach>
                         <archiverConfig>
                             <defaultDirectoryMode>493</defaultDirectoryMode> <!-- 0755 -->
                         </archiverConfig>
                     </configuration>
                     <executions>
                         <execution>
                             <id>build-bin-dist</id>
                             <phase>package</phase>
                             <goals>
                                 <goal>single</goal>
                             </goals>
                             <configuration>
                                 <finalName>pmd-bin-${project.version}</finalName>
                                 <descriptors>
                                     <descriptor>src/main/assembly/bin.xml</descriptor>
                                 </descriptors>
                             </configuration>
                         </execution>
                         <execution>
                             <id>build-src-dist</id>
                             <phase>package</phase>
                             <goals>
                                 <goal>single</goal>
                             </goals>
                             <configuration>
                                 <finalName>pmd-src-${project.version}</finalName>
                                 <descriptors>
                                     <descriptor>src/main/assembly/src.xml</descriptor>
                                 </descriptors>
                             </configuration>
                         </execution>
                     </executions>
                 </plugin>
             </plugins>
         </build>
         <dependencies>
             <dependency>
                 <groupId>net.sourceforge.pmd</groupId>
                 <artifactId>pmd-core</artifactId>
                 <version>${project.version}</version>
             </dependency>
         </dependencies>
    
         <profiles>
             <profile>
                 <id>jdk8-modules</id>
                 <activation>
                     <jdk>1.8</jdk>
                 </activation>
                 <dependencies>
                     <dependency>
                         <groupId>net.sourceforge.pmd</groupId>
                         <artifactId>pmd-apex</artifactId>
                         <version>${project.version}</version>
                     </dependency>
                 </dependencies>
             </profile>
         </profiles>
     </project>
    
  3. Install Maven in order to execute mvn commands in your CLI.

  4. Check if you have a valid ${user.home}/.m2/toolchains.xml containing valid JDK paths. Read the official PMD README for more details. Our toolchains.xml von MacOSX looks like this:

     <?xml version="1.0" encoding="UTF8"?>
     <toolchains>
       <!-- place this file in ${user.home}/.m2/toolchains.xml -->
       <toolchain>
         <type>jdk</type>
         <provides>
           <version>1.7</version>
         </provides>
         <configuration>
           <jdkHome>/Library/Java/JavaVirtualMachines/jdk1.7.0_75.jdk/Contents/Home</jdkHome>
         </configuration>
       </toolchain>
    
       <toolchain>
         <type>jdk</type>
         <provides>
           <version>1.8</version>
         </provides>
         <configuration>
           <jdkHome>/Library/Java/JavaVirtualMachines/jdk1.8.0_74.jdk/Contents/Home</jdkHome>
         </configuration>
       </toolchain>
     </toolchains>
    
  5. To build PMD navigate with your CLI to the root directory of PMD and execute mvn clean package

  6. If the build fails you have to have a deeper look into the debug log to find and fix the root cause. Most of the time a test fails or the toolchains.xml file is invalid.

Update the PMD version of the engine

  1. After your build succeeds navigate to /pmd/pmd-dist/target directory.

  2. Unzip the generated pmd-bin-*.*.*-SNAPSHOT.zip.

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

  4. Replace the content of /codeclimate-apexmetrics/lib/pmd with the content of your unzipped pmd-bin-*.*.*-SNAPSHOT directory.

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 directory inside your git directory and execute

     docker build -t codeclimate/codeclimate-apexmetrics .
    
  3. Check if there is a codeclimate/codeclimate-apexmetrics image by executing

     docker images
    
  4. Download and unzip the following Open source repositories

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

    CODECLIMATE_DEBUG=1 codeclimate analyze --dev
    

    If an error occurs try to understand the root cause and fix it. If the analysis is successful you can go on.

  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.

Clone this wiki locally