ZPA CLI
ZPA CLI analyzes PL/SQL and Oracle SQL from a terminal or a CI pipeline, without a SonarQube plugin. It runs the same analyzer and built-in rules as the SonarQube plugin and writes findings to the console, to JSON, or to a file that SonarQube Cloud and SonarQube Server can import.
Download
3.3.0
Includes ZPA 4.3.0. Full changelog
Extract the archive and run bin/zpa-cli (bin\zpa-cli.bat on Windows). The archives with a bundled Java runtime need no
Java installation.
Quick start
Analyze every supported file under the current directory and print the findings:
zpa-cli --sources .
Fail a CI job when the analysis finds an issue of major severity or higher:
zpa-cli --sources . --fail-on major
The command exits with code 1 when the threshold is met, so the CI step fails.
Options
| Option | Description | Default |
|---|---|---|
--sources | Required. Root folder of the project sources. | |
--files | Analyze and report only these files (paths relative to --sources). See Project context. | all files under --sources |
--fail-on | Exit with code 1 when a finding reaches this level: none, any, info, minor, major, critical, blocker or syntax. | none |
--output-format | console, json or sq-generic-issue-import. | console |
--output-file | Write the report to this file instead of the standard output. | |
--config | Rule configuration file. See Rules and configuration. | |
--extensions | Comma-separated file extensions to analyze. | sql,pkg,pks,pkb,fun,pcd,tgg,prc,tpb,trg,typ,tab,tps |
--forms-metadata | Oracle Forms metadata file. | |
--oracle-url, --oracle-user, --oracle-schemas… | Read table, view and synonym definitions from an Oracle database. See Database metadata. | |
--compilation-schema, --schema-paths | Schema in which the units compile. See Compilation schema. | |
--ccflags | PLSQL_CCFLAGS the code is compiled with, e.g. 'debug:TRUE, level:2'. See Conditional compilation. | |
--database-version | Database version the code is compiled for, e.g. 19 or 12.2. See Conditional compilation. | |
--syntax-only | Only check that the files parse; skip the coding rules. Implies --fail-on syntax. | |
--stdin-filename | File name used for code read from standard input. See Reference. | stdin.sql |
Project context
--sources defines the whole project: ZPA reads declarations from every supported file under it, so rules can resolve
packages and types declared in other files. --files only narrows which files are analyzed and reported, which is useful
to check the files changed in a pull request while keeping the full project context:
zpa-cli --sources . --files src/packages/customer.pks src/packages/customer.pkb
Conditional compilation
Without --ccflags or --database-version, $IF conditions are not evaluated: the CLI analyzes the first branch of
each $IF and skips branches that only contain $ERROR. With either option, it selects the branches the database would
compile, as described in Conditional compilation. The
options apply in every mode, including --syntax-only and standard input.
zpa-cli --sources . --database-version 19 --ccflags 'debug:FALSE'
Send results to SonarQube Cloud or SonarQube Server
Generate a report in SonarQube's generic issue format:
zpa-cli --sources . --output-format sq-generic-issue-import --output-file zpa-issues.json
Then import it with SonarScanner through the sonar.externalIssuesReportPaths property:
sonar-scanner \
-Dsonar.projectKey=myproject \
-Dsonar.sources=. \
-Dsonar.externalIssuesReportPaths=zpa-issues.json
The report includes each rule's name, description, severity and clean code attribute, in the format introduced by SonarQube Server 10.3. This is the way to use ZPA with SonarQube Cloud or with SonarQube editions where the ZPA Plugin for SonarQube is not available.
Rules and configuration
Without --config, the CLI runs the rules that are active by default (see the rule catalog).
A configuration file lets you turn rules on or off and change their severity. It must follow the
JSON schema; the
example configuration lists every built-in rule.
To run custom rules, copy the plugin .jar to a plugins folder in the CLI
installation directory, next to bin. The CLI loads every plugin found there.
Reference
JSON output
--output-format json writes a UTF-8 document to the standard output (or to --output-file); log messages go to the
standard error, so the output can be piped.
{
"schemaVersion" : 1,
"validation" : { "passed" : false, "threshold" : "major" },
"diagnostics" : [ {
"kind" : "RULE",
"file" : "src/close_order.sql",
"range" : { "startLine" : 7, "startColumn" : 5, "endLine" : 7, "endColumn" : 20 },
"rule" : "zpa:ComparisonWithNull",
"severity" : "BLOCKER",
"message" : "Fix this comparison or change to \"IS NULL\"."
} ]
}
validation.passedmatches the exit code:truefor0,falsefor1.kindisRULEfor coding rules andSYNTAXfor parse errors.fileis relative to--sources. Lines start at 1 and columns at 0;endColumnis exclusive. Unknown positions arenull.
Exit codes
| Code | Meaning |
|---|---|
0 | Analysis completed and no finding reached the --fail-on threshold. |
1 | A finding reached the --fail-on threshold. |
2 | Invalid arguments, files or configuration, for example a target outside --sources or a missing password environment variable. |
3 | Execution failure, such as a failed database connection or an internal error. |
Reading code from standard input
With --syntax-only, the CLI can check code read from standard input. Pass - to --files and give the code a file
name inside --sources with a supported extension:
cat generated.sql | zpa-cli --sources . --files - --stdin-filename src/generated.pkb --syntax-only
Standard input is not supported in a full analysis.