-
Notifications
You must be signed in to change notification settings - Fork 18
Replace PMD used by the engine
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
-
Download and unpack the desired PMD release to a folder
-
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>
-
Install Maven in order to execute
mvn
commands in your CLI. -
Check if you have a valid
${user.home}/.m2/toolchains.xml
containing valid JDK paths. Read the official PMD README for more details. Ourtoolchains.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>
-
To build PMD navigate with your CLI to the root directory of PMD and execute mvn clean package
-
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
-
After your build succeeds navigate to
/pmd/pmd-dist/target
directory. -
Unzip the generated
pmd-bin-*.*.*-SNAPSHOT.zip
. -
Fork the Apex Metrics engine and connect the repository to your Eclipse and import it as a general project in Eclipse.
-
Replace the content of
/codeclimate-apexmetrics/lib/pmd
with the content of your unzippedpmd-bin-*.*.*-SNAPSHOT
directory.
Build and test your custom engine locally
First you need to install Docker and the Code Climate CLI.
-
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 executeeval "$(docker-machine env default)"
. Here is why. -
Navigate into your
codeclimate-apexmetrics
directory inside your git directory and executedocker build -t codeclimate/codeclimate-apexmetrics .
-
Check if there is a
codeclimate/codeclimate-apexmetrics
image by executingdocker images
-
Download and unzip the following Open source repositories
-
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.
-
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.