@codacy/tools-pmd-7
v0.2.0
Published
PMD 7 adapter — CLI-mode multi-language static analyzer
Readme
@codacy/tools-pmd-7
Table of Contents
Overview
Multi-language static analysis tool using the PMD CLI. Uses the CLI execution strategy -- spawns the PMD shell script via spawnTool() and parses its JSON output.
| Property | Value |
|----------|-------|
| Tool ID | PMD7 |
| Codacy UUID | ed7e8287-707d-485a-a0cb-e211004432c2 |
| Strategy | CLI |
| Languages | Java, Javascript, Kotlin, Swift, PLSQL, XML, Apex, Velocity, VisualForce, JSP |
| Binary | pmd (shell script from PMD distribution zip) |
| File patterns | **/*.java, **/*.js, **/*.jsx, **/*.kt, **/*.kts, **/*.swift, **/*.sql, **/*.pls, **/*.plb, **/*.pkb, **/*.pks, **/*.xml, **/*.pom, **/*.wsdl, **/*.xsl, **/*.cls, **/*.trigger, **/*.vm, **/*.page, **/*.component, **/*.jsp |
Updating patterns
# Re-fetch pattern metadata from the Codacy API
pnpm prefetch
# Commit the result
git add src/patterns.jsonPattern IDs follow the format PMD7_category_{lang}_{categoryDir}_{RuleName}, e.g. PMD7_category_java_errorprone_EmptyCatchBlock.
Updating the PMD version
- Update
PMD_VERSIONinsrc/adapter.ts - Update
PMD_DOWNLOAD_URLandPMD_EXTRACTED_DIRconstants accordingly - Run
pnpm prefetchto check for new/removed rules - Run
pnpm testto verify compatibility - If the major version changes, create a new adapter package (
pmd-8/)
Development
pnpm build # Build with tsup
pnpm test # Run tests (requires Java + PMD in PATH or installed)To install PMD locally for testing, download from https://github.com/pmd/pmd/releases and add bin/ to your PATH. Java 8+ is required.
Notes for maintainers
- PMD requires Java 8+ as a runtime. The adapter uses
ensureJre()from@codacy/toolingto download Adoptium Temurin JDK 17 if no suitable Java is found on the system. - The PMD distribution is downloaded as a zip from GitHub releases and extracted to
toolInstallDir/pmd-bin-{version}/. - The
JAVA_HOMEenvironment variable is set when invoking PMD if using a non-system Java binary. - PMD's JSON output format provides
beginline/begincolumn/endline/endcolumn, all 1-based. No offset conversion needed. - PMD priority (1-5, 1=highest) maps to numeric confidence: 1-2 -> 3 (high), 3 -> 2 (medium), 4-5 -> 1 (low).
- Pattern ID to rule reference mapping:
PMD7_category_java_errorprone_EmptyCatchBlock->category/java/errorprone.xml/EmptyCatchBlock. - Config file detection supports
ruleset.xmlandapex-ruleset.xmlin the repository root. - When patterns are specified, a generated ruleset XML is written to the generated config dir and passed via
-R. - When no patterns or local config is specified, PMD runs with the built-in
rulesets/java/quickstart.xml. - The
--no-fail-on-violationflag ensures PMD exits 0 even when violations are found. - The
--file-listoption is used to pass target files via a temp file rather than command-line arguments, avoiding argument length limits. - Processing errors (unparseable files) are mapped to
AnalysisErrorwith level "warning". - Configuration errors (invalid rules) are mapped to
AnalysisErrorwith level "warning".
