Skip to content

Commit

Permalink
Run pmd checks from pre-commit hooks. (#2694)
Browse files Browse the repository at this point in the history
Add pmd cache.

Signed-off-by: Jakub Dardzinski <[email protected]>
  • Loading branch information
JDarDagran authored May 28, 2024
1 parent 9f1a8de commit 6967b4a
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 0 deletions.
1 change: 1 addition & 0 deletions .circleci/continue_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1001,6 +1001,7 @@ jobs:
name: Run pre-commit
command: |
. venv/bin/activate
SKIP= && [ -n "${CI}" ] && export SKIP="pmd"
pre-commit run --show-diff-on-failure --all-files
always_run:
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -169,3 +169,6 @@ __pycache__

# Dev
changes.txt

# pre-commit pmd hook cache
.pmd_cache
8 changes: 8 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,11 @@ repos:
entry: python ./.pre_commit/check-redactions.py
always_run: true
pass_filenames: false
- id: pmd
name: pmd
description: "Runs the PMD static code analyzer."
language: docker_image
entry: -v ./.pmd_cache:/opt/.pmd_cache --entrypoint .pre_commit/run-pmd.sh cimg/openjdk:8.0
files: ^client/java/src/.*\.java$|^integration/spark/spark-interfaces-scala/.*\.java$
exclude: ".*test.*"
require_serial: true
43 changes: 43 additions & 0 deletions .pre_commit/run-pmd.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/bin/bash

set -e

PMD_RELEASE="https://github.com/pmd/pmd/releases/download/pmd_releases%2F6.46.0/pmd-bin-6.46.0.zip"

cd /opt/.pmd_cache

# check if there is a pmd folder
if [ ! -d "pmd" ]; then
wget -nc -O pmd.zip "$PMD_RELEASE" > /dev/null 2>&1 \
&& unzip pmd.zip > /dev/null 2>&1 \
&& rm pmd.zip > /dev/null 2>&1 \
&& mv pmd-bin* pmd > /dev/null 2>&1 \
&& chmod -R +x pmd > /dev/null 2>&1
fi

idx=1
for (( i=1; i <= "$#"; i++ )); do
if [[ ${!i} == *.java ]]; then
idx=${i}
break
fi
done

# add default ruleset if not specified
if [[ ! $pc_args == *"-R "* ]]; then
pc_args="$pc_args -R /src/client/java/pmd-openlineage.xml"
fi

# populate list of files to analyse
files=""
prefix="/src/"
for arg in "${@:idx}"; do
files="$files $prefix$arg"
done

# Remove leading space (optional)
files="${files:1}"
eol=$'\n'
echo "${files// /$eol}" > /tmp/list

./pmd/bin/run.sh pmd -f textcolor -min 5 --file-list /tmp/list $pc_args

0 comments on commit 6967b4a

Please sign in to comment.