Merge branch 'pmd/7.0.x' into pmd7-issue-4176-NonSerializableClass
This commit is contained in:
745 files changed
+6757
-4301
No files matched your search
@@ -1,9 +1,9 @@
|
||||
source 'https://rubygems.org/'
|
||||
|
||||
# bleeding edge from git
|
||||
#gem 'pmdtester', :git => 'https://github.com/pmd/pmd-regression-tester.git', branch: 'master'
|
||||
gem 'pmdtester', :git => 'https://github.com/pmd/pmd-regression-tester.git', branch: 'master'
|
||||
|
||||
gem 'pmdtester'
|
||||
#gem 'pmdtester'
|
||||
gem 'danger'
|
||||
|
||||
# This group is only needed for rendering release notes (docs/render_release_notes.rb)
|
||||
|
||||
+14
-8
@@ -1,3 +1,16 @@
|
||||
GIT
|
||||
remote: https://github.com/pmd/pmd-regression-tester.git
|
||||
revision: 3b26e7fc28203f5ea4f1cb840d990ad7f28b5491
|
||||
branch: master
|
||||
specs:
|
||||
pmdtester (1.5.2.pre.SNAPSHOT)
|
||||
differ (~> 0.1)
|
||||
liquid (~> 5.2)
|
||||
logger-colors (~> 1.0)
|
||||
nokogiri (~> 1.13)
|
||||
rufus-scheduler (~> 3.8)
|
||||
slop (~> 4.6)
|
||||
|
||||
GEM
|
||||
remote: https://rubygems.org/
|
||||
specs:
|
||||
@@ -76,13 +89,6 @@ GEM
|
||||
faraday (>= 1, < 3)
|
||||
sawyer (~> 0.9)
|
||||
open4 (1.3.4)
|
||||
pmdtester (1.5.2)
|
||||
differ (~> 0.1)
|
||||
liquid (~> 5.2)
|
||||
logger-colors (~> 1.0)
|
||||
nokogiri (~> 1.13)
|
||||
rufus-scheduler (~> 3.8)
|
||||
slop (~> 4.6)
|
||||
public_suffix (5.0.0)
|
||||
raabro (1.4.0)
|
||||
racc (1.6.0)
|
||||
@@ -109,7 +115,7 @@ PLATFORMS
|
||||
DEPENDENCIES
|
||||
danger
|
||||
liquid
|
||||
pmdtester
|
||||
pmdtester!
|
||||
rouge
|
||||
safe_yaml
|
||||
|
||||
|
||||
@@ -403,18 +403,9 @@ entries:
|
||||
- title: Apex
|
||||
url: /pmd_languages_apex.html
|
||||
output: web, pdf
|
||||
- title: null
|
||||
- title: Java
|
||||
url: /pmd_languages_java.html
|
||||
output: web, pdf
|
||||
subfolders:
|
||||
- title: Java
|
||||
output: web, pdf
|
||||
subfolderitems:
|
||||
- title: Java Support
|
||||
url: /pmd_languages_java.html
|
||||
output: web, pdf
|
||||
- title: Java Versions
|
||||
url: /pmd_languages_java_versions.html
|
||||
output: web, pdf
|
||||
- title: JSP
|
||||
url: /pmd_languages_jsp.html
|
||||
output: web, pdf
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
{% assign linux_cmd_blob = '' %}
|
||||
{% assign linux_split_cmds = include.linux | newline_to_br | strip_newlines | split: '<br />' %}
|
||||
{% assign raw_output = false %}
|
||||
{% for linux_raw_cmd in linux_split_cmds %}
|
||||
{% assign linux_cmd = linux_raw_cmd | strip | split: ' ' | first %}
|
||||
{% assign linux_tail = linux_raw_cmd | strip | remove_first: linux_cmd %}
|
||||
{% if linux_cmd == nil %}
|
||||
{% assign raw_output = true %}
|
||||
{% endif %}
|
||||
{% if raw_output %}
|
||||
{% capture linux_cmd_blob %}{{linux_cmd_blob}}{{linux_cmd}}{{linux_tail}}
|
||||
{% endcapture %}
|
||||
{% else %}
|
||||
{% capture linux_cmd_blob %}{{linux_cmd_blob}}<span class="gp">~ $ </span><span class="s2">{{linux_cmd}}</span>{{linux_tail}}
|
||||
{% endcapture %}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
|
||||
{% assign windows_cmd_blob = '' %}
|
||||
{% assign windows_split_cmds = include.windows | newline_to_br | strip_newlines | split: '<br />' %}
|
||||
{% assign raw_output = false %}
|
||||
{% for windows_raw_cmd in windows_split_cmds %}
|
||||
{% assign windows_cmd = windows_raw_cmd | strip | split: ' ' | first %}
|
||||
{% assign windows_tail = windows_raw_cmd | strip | remove_first: windows_cmd %}
|
||||
{% if windows_cmd == nil %}
|
||||
{% assign raw_output = true %}
|
||||
{% endif %}
|
||||
{% if raw_output == true %}
|
||||
{% capture windows_cmd_blob %}{{windows_cmd_blob}}{{windows_cmd}}{{windows_tail}}
|
||||
{% endcapture %}
|
||||
{% else %}
|
||||
{% capture windows_cmd_blob %}{{windows_cmd_blob}}<span class="gp">C:\> </span><span class="s2">{{windows_cmd}}</span>{{windows_tail}}
|
||||
{% endcapture %}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
<div class="text-left">
|
||||
<ul class="nav nav-tabs" role="tablist">
|
||||
<li class="nav-item" role="presentation">
|
||||
<a class="nav-link active" id="linux-tab-{{include.id}}" data-toggle="tab" href="#linux-{{include.id}}" role="tab" aria-controls="linux" aria-selected="true">Linux / macOS</a>
|
||||
</li>
|
||||
<li class="nav-item" role="presentation">
|
||||
<a class="nav-link" id="windows-tab-{{include.id}}" data-toggle="tab" href="#windows-{{include.id}}" role="tab" aria-controls="windows" aria-selected="false">Windows</a>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<div class="tab-content border">
|
||||
<div class="tab-pane fade show active" id="linux-{{include.id}}" role="tabpanel" aria-labelledby="linux-tab">
|
||||
<figure class="highlight"><pre><code class="language-bash" data-lang="bash">{{linux_cmd_blob}}</code></pre></figure>
|
||||
</div>
|
||||
<div class="tab-pane fade" id="windows-{{include.id}}" role="tabpanel" aria-labelledby="windows-tab">
|
||||
<figure class="highlight"><pre><code class="language-bash" data-lang="bash">{{windows_cmd_blob}}</code></pre></figure>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
+1
-1
@@ -26,7 +26,7 @@ additional_js:
|
||||
|
||||
**PMD** is a static source code analyzer. It finds common programming flaws like
|
||||
unused variables, empty catch blocks, unnecessary object creation, and
|
||||
so forth. It's mainly concerned with **Java and Apex**, but **supports 12 other
|
||||
so forth. It's mainly concerned with **Java and Apex**, but **supports 14 other
|
||||
languages**.
|
||||
|
||||
PMD features many **built-in checks** (in PMD lingo, *rules*), which are documented
|
||||
|
||||
@@ -19,15 +19,71 @@ This is a {{ site.pmd.release_type }} release.
|
||||
|
||||
### New and noteworthy
|
||||
|
||||
#### CLI improvements
|
||||
#### Revamped Command Line Interface
|
||||
|
||||
The PMD CLI has been enhanced with a progress bar, which interactively displays the
|
||||
PMD now ships with a unified Command Line Interface for both Linux/Unix and Windows. Instead of having a collection of scripts
|
||||
for the different utilities shipped with PMD, a single script `pmd` (`pmd.bat` for Windows) can now launch all
|
||||
utilities using subcommands, e.g. `pmd check`, `pmd designer`. All commands and options are thoroughly documented in the help,
|
||||
with full color support where available. Moreover, efforts were made to provide consistency in the usage of all PMD utilities.
|
||||
|
||||
```shell
|
||||
$ Usage: pmd [-hV] [COMMAND]
|
||||
-h, --help Show this help message and exit.
|
||||
-V, --version Print version information and exit.
|
||||
Commands:
|
||||
check The PMD standard source code analyzer
|
||||
cpd Copy/Paste Detector - find duplicate code
|
||||
designer The PMD visual rule designer
|
||||
cpd-gui GUI for the Copy/Paste Detector
|
||||
Warning: May not support the full CPD feature set
|
||||
ast-dump Experimental: dumps the AST of parsing source code
|
||||
Exit Codes:
|
||||
0 Succesful analysis, no violations found
|
||||
1 An unexpected error occurred during execution
|
||||
2 Usage error, please refer to the command help
|
||||
4 Successful analysis, at least 1 violation found
|
||||
```
|
||||
|
||||
For instance, where you previously would have run
|
||||
```shell
|
||||
run.sh pmd -d src -R ruleset.xml
|
||||
```
|
||||
you should now use
|
||||
```shell
|
||||
pmd check -d src -R ruleset.xml
|
||||
```
|
||||
or even better, omit using `-d` / `--dir` and simply pass the sources at the end of the parameter list
|
||||
|
||||
```shell
|
||||
pmd check -R ruleset.xml src
|
||||
```
|
||||
|
||||
Multiple source directories can passed, such as:
|
||||
```shell
|
||||
pmd check -R ruleset.xml src/main/java src/test/java
|
||||
```
|
||||
|
||||
And the exact same applies to CPD:
|
||||
```shell
|
||||
pmd cpd --minimum-tokens 100 src/main/java
|
||||
```
|
||||
|
||||
Additionally, the CLI for the `check` command has been enhanced with a progress bar, which interactively displays the
|
||||
current progress of the analysis.
|
||||
|
||||
TODO screenshot (take it right before releasing, because other changes to the CLI will occur until then)
|
||||
|
||||
This can be disabled with the `--no-progress` flag.
|
||||
|
||||
|
||||
Finally, we now provide a completion script for Bash/Zsh to further help daily usage.
|
||||
This script can be found under `shell/pmd-completion.sh` in the binary distribution.
|
||||
To use it, edit your `~/.bashrc` / `~/.zshrc` file and add the following line:
|
||||
|
||||
```
|
||||
source *path_to_pmd*/shell/pmd-completion.sh
|
||||
```
|
||||
|
||||
#### Full Antlr support
|
||||
|
||||
Languages backed by an Antlr grammar are now fully supported. This means, it's now possible not only to use Antlr grammars for CPD,
|
||||
@@ -187,9 +243,11 @@ The following previously deprecated rules have been finally removed:
|
||||
* ant
|
||||
* [#4080](https://github.com/pmd/pmd/issues/4080): \[ant] Split off Ant integration into a new submodule
|
||||
* core
|
||||
* [#2234](https://github.com/pmd/pmd/issues/2234): \[core] Consolidate PMD CLI into a single command
|
||||
* [#4035](https://github.com/pmd/pmd/issues/4035): \[core] ConcurrentModificationException in DefaultRuleViolationFactory
|
||||
* cli
|
||||
* [#3828](https://github.com/pmd/pmd/issues/3828): \[core] Progress reporting
|
||||
* [#4079](https://github.com/pmd/pmd/issues/4079): \[cli] Split off CLI implementation into a pmd-cli submodule
|
||||
* apex-design
|
||||
* [#2667](https://github.com/pmd/pmd/issues/2667): \[apex] Integrate nawforce/ApexLink to build robust Unused rule
|
||||
* java-bestpractices
|
||||
|
||||
@@ -9,37 +9,50 @@ permalink: pmd_devdocs_experimental_ast_dump.html
|
||||
## Command line usage
|
||||
|
||||
```shell
|
||||
$ run.sh ast-dump --help
|
||||
Usage: ast-dump [options]
|
||||
Options:
|
||||
--encoding, -e
|
||||
Encoding of the source file.
|
||||
Default: UTF-8
|
||||
--file
|
||||
The file to dump
|
||||
--format, -f
|
||||
The output format.
|
||||
Default: xml
|
||||
--help, -h
|
||||
Display usage.
|
||||
--language, -l
|
||||
Specify the language to use.
|
||||
Default: java
|
||||
--read-stdin, -i
|
||||
Read source from standard input
|
||||
Default: false
|
||||
-P
|
||||
Properties for the renderer.
|
||||
Syntax: -Pkey=value
|
||||
Default: {}
|
||||
|
||||
Available languages: apex ecmascript java jsp modelica plsql pom scala text vf vm wsdl xml xsl
|
||||
Available formats: xml XML format with the same structure as the one used in XPath
|
||||
+ Properties
|
||||
+ singleQuoteAttributes Use single quotes to delimit attribute values (default true)
|
||||
+ lineSeparator Line separator to use. The default is platform-specific. (default \n)
|
||||
+ renderProlog True to output a prolog (default true)
|
||||
+ renderCommonAttributes True to render attributes like BeginLine, EndLine, etc. (default false)
|
||||
$ pmd ast-dump --help
|
||||
Usage: pmd ast-dump [-Dhi] [-e=<encoding>] [-f=<format>] [--file=<file>]
|
||||
[-l=<language>] [-P=<String=String>]...
|
||||
Experimental: dumps the AST of parsing source code
|
||||
-D, -v, --debug, --verbose
|
||||
Debug mode.
|
||||
-e, --encoding=<encoding>
|
||||
Specifies the character set encoding of the source
|
||||
code files
|
||||
-f, --format=<format> The output format.
|
||||
Valid values: xml, text
|
||||
--file=<file> The file to parse and dump.
|
||||
-h, --help Show this help message and exit.
|
||||
-i, --read-stdin Read source from standard input.
|
||||
-l, --language=<language>
|
||||
The source code language.
|
||||
Valid values: apex, ecmascript, html, java, jsp,
|
||||
kotlin, modelica, plsql, pom, scala, swift, vf, vm,
|
||||
wsdl, xml, xsl
|
||||
-P=<String=String> Key-value pair defining a property for the report
|
||||
format.
|
||||
Supported values for each report format:
|
||||
xml:
|
||||
singleQuoteAttributes - Use single quotes to
|
||||
delimit attribute values
|
||||
Default: true
|
||||
lineSeparator - Line separator to use. The default
|
||||
is platform-specific. The values 'CR', 'CRLF',
|
||||
'LF', '\r', '\r\n' and '\n' can be used to
|
||||
represent a carriage return, line feed and their
|
||||
combination more easily.
|
||||
Default: \n
|
||||
renderProlog - True to output a prolog
|
||||
Default: true
|
||||
renderCommonAttributes - True to render attributes
|
||||
like BeginLine, EndLine, etc.
|
||||
Default: false
|
||||
text:
|
||||
onlyAsciiChars - Use only ASCII characters in the
|
||||
structure
|
||||
Default: false
|
||||
maxLevel - Max level on which to recurse. Negative
|
||||
means unbounded
|
||||
Default: -1
|
||||
```
|
||||
|
||||
## Example
|
||||
@@ -50,12 +63,7 @@ public class Foo {
|
||||
int a;
|
||||
}
|
||||
|
||||
$ run.sh ast-dump --format xml --language java --file Foo.java > Foo.xml
|
||||
-------------------------------------------------------------------------------
|
||||
This command line utility is experimental. It might change at any time without
|
||||
prior notice.
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
$ pmd ast-dump --format xml --language java --file Foo.java > Foo.xml
|
||||
$ cat Foo.xml
|
||||
<?xml version='1.0' encoding='UTF-8' ?>
|
||||
<CompilationUnit Image='' PackageName='' declarationsAreInDefaultPackage='true'>
|
||||
|
||||
@@ -41,7 +41,7 @@ In order to analyze a project with PMD that uses preview language features, you'
|
||||
it via the environment variable `PMD_JAVA_OPTS` and select the new language version, e.g. `19-preview`:
|
||||
|
||||
export PMD_JAVA_OPTS=--enable-preview
|
||||
./run.sh pmd -language java -version 19-preview ...
|
||||
pmd check --use-version java-19-preview ...
|
||||
|
||||
Note: we only support preview language features for the latest two java versions.
|
||||
|
||||
|
||||
@@ -1,39 +0,0 @@
|
||||
---
|
||||
title: Supported Java Versions
|
||||
permalink: pmd_languages_java_versions.html
|
||||
---
|
||||
|
||||
## Overview of supported Java language versions
|
||||
|
||||
Usually the latest non-preview Java Version is the default version.
|
||||
|
||||
Java Version |Alias | Supported by PMD since |
|
||||
-------------|------|------------------------|
|
||||
18-preview | | 6.44.0 |
|
||||
18 (default) | | 6.44.0 |
|
||||
17-preview | | 6.37.0 |
|
||||
17 | | 6.37.0 |
|
||||
16 | | 6.32.0 |
|
||||
15 | | 6.27.0 |
|
||||
14 | | 6.22.0 |
|
||||
13 | | 6.18.0 |
|
||||
12 | | 6.13.0 |
|
||||
11 | | 6.6.0 |
|
||||
10 | 1.10 | 6.4.0 |
|
||||
9 | 1.9 | 6.0.0 |
|
||||
8 | 1.8 | 5.1.0 |
|
||||
7 | 1.7 | 5.0.0 |
|
||||
6 | 1.6 | 3.9 |
|
||||
5 | 1.5 | 3.0 |
|
||||
1.4 | | 1.2.2 |
|
||||
1.3 | | 1.0.0 |
|
||||
|
||||
## Using Java preview features
|
||||
|
||||
In order to analyze a project with PMD that uses preview language features, you'll need to enable
|
||||
it via the environment variable `PMD_JAVA_OPTS` and select the new language version, e.g. `18-preview`:
|
||||
|
||||
export PMD_JAVA_OPTS=--enable-preview
|
||||
./run.sh pmd -language java -version 18-preview ...
|
||||
|
||||
Note: we only support preview language features for the latest two java versions.
|
||||
@@ -31,7 +31,7 @@ We'll probably extend the CLI instead of relying on environment variables in a f
|
||||
```
|
||||
PMD_VF_APEXDIRECTORIES=../classes \
|
||||
PMD_VF_OBJECTSDIRECTORIES=../objects \
|
||||
run.sh pmd -d $GITHUB_WORKSPACE/force-app/main/default/pages \
|
||||
pmd check -d $GITHUB_WORKSPACE/force-app/main/default/pages \
|
||||
-R category/vf/security.xml/VfUnescapeEl -f text
|
||||
```
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ Some XML-based file formats do not conventionally use a `.xml` extension. To ass
|
||||
these files with the XML language, you need to use the `--force-language xml` command-line
|
||||
arguments, for instance:
|
||||
```
|
||||
$ ./run.sh pmd -d /home/me/src/xml-file.ext -f text -R ruleset.xml --force-language xml
|
||||
$ pmd check -d /home/me/src/xml-file.ext -f text -R ruleset.xml --force-language xml
|
||||
```
|
||||
Please refer to [PMD CLI reference](pmd_userdocs_cli_reference.html#analyze-other-xml-formats)
|
||||
for more examples.
|
||||
|
||||
@@ -22,13 +22,24 @@ The tool comes with a rather extensive help text, simply running with `--help`!
|
||||
|
||||
{% include custom/cli_option_row.html options="--rulesets,-R"
|
||||
option_arg="refs"
|
||||
description="Comma-separated list of ruleset or rule references."
|
||||
description="Path to a ruleset xml file. The path may reference
|
||||
a resource on the classpath of the application,
|
||||
be a local file system path, or a URL. The option
|
||||
can be repeated, and multiple arguments separated
|
||||
by comma can be provided to a single occurrence
|
||||
of the option."
|
||||
required="yes"
|
||||
%}
|
||||
{% include custom/cli_option_row.html options="--dir,-d"
|
||||
option_arg="path"
|
||||
description="Root directory for the analyzed sources."
|
||||
required="yes"
|
||||
description="Path to a source file, or directory containing
|
||||
source files to analyze. Zip and Jar files are
|
||||
also supported, if they are specified directly
|
||||
(archive files found while exploring a directory
|
||||
are not recursively expanded). This option can be
|
||||
repeated, and multiple arguments can be provided
|
||||
to a single occurrence of the option. One of
|
||||
`--dir`, `--file-list` or `--uri` must be provided."
|
||||
%}
|
||||
{% include custom/cli_option_row.html options="--format,-f"
|
||||
option_arg="format"
|
||||
@@ -58,7 +69,7 @@ The tool comes with a rather extensive help text, simply running with `--help`!
|
||||
with the most up-to-date rule violations.
|
||||
This can greatly improve analysis performance and is **highly recommended**."
|
||||
%}
|
||||
{% include custom/cli_option_row.html options="--debug,--verbose,-D,-V"
|
||||
{% include custom/cli_option_row.html options="--debug,--verbose,-D,-v"
|
||||
description="Debug mode. Prints more log output. See also [Logging](#logging)."
|
||||
%}
|
||||
{% include custom/cli_option_row.html options="--encoding,-e"
|
||||
@@ -67,17 +78,16 @@ The tool comes with a rather extensive help text, simply running with `--help`!
|
||||
The valid values are the standard character sets of `java.nio.charset.Charset`."
|
||||
default="UTF-8"
|
||||
%}
|
||||
{% include custom/cli_option_row.html options="--fail-on-violation"
|
||||
option_arg="bool"
|
||||
{% include custom/cli_option_row.html options="--[no-]fail-on-violation"
|
||||
description="Specifies whether PMD exits with non-zero status if violations are found.
|
||||
By default PMD exits with status 4 if violations are found.
|
||||
Disable this feature with `--fail-on-violation false` to exit with 0 instead and just output the report."
|
||||
default="true"
|
||||
Disable this feature with `--no-fail-on-violation` to exit with 0 instead and just output the report."
|
||||
%}
|
||||
{% include custom/cli_option_row.html options="--file-list"
|
||||
option_arg="filepath"
|
||||
description="Path to file containing a list of files to analyze, one path per line.
|
||||
If this is given, then you don't need to provide `--dir`."
|
||||
description="Path to a file containing a list of files to
|
||||
analyze, one path per line. One of `--dir`,
|
||||
`--file-list` or `--uri` must be provided."
|
||||
%}
|
||||
{% include custom/cli_option_row.html options="--force-language"
|
||||
option_arg="lang"
|
||||
@@ -95,10 +105,9 @@ The tool comes with a rather extensive help text, simply running with `--help`!
|
||||
{% include custom/cli_option_row.html options="--ignore-list"
|
||||
option_arg="filepath"
|
||||
description="Path to file containing a list of files to ignore, one path per line.
|
||||
This option can be combined with `--dir` and `--file-list`.
|
||||
This ignore list takes precedence over any files in the file-list."
|
||||
This option overrides files included by any of `--dir`, `--file-list` and `--uri`."
|
||||
%}
|
||||
{% include custom/cli_option_row.html options="--help,-h,-H"
|
||||
{% include custom/cli_option_row.html options="--help,-h"
|
||||
description="Display help on usage."
|
||||
%}
|
||||
{% include custom/cli_option_row.html options="--use-version"
|
||||
@@ -115,10 +124,13 @@ The tool comes with a rather extensive help text, simply running with `--help`!
|
||||
option_arg="lang"
|
||||
description="Specify the language PMD should use. Used together with `-version`. See also [Supported Languages](#supported-languages)."
|
||||
%}
|
||||
{% include custom/cli_option_row.html options="--minimum-priority,-min"
|
||||
option_arg="num"
|
||||
description="Rule priority threshold; rules with lower priority than configured here won't be used."
|
||||
default="5"
|
||||
{% include custom/cli_option_row.html options="--minimum-priority"
|
||||
option_arg="priority"
|
||||
description="Rule priority threshold; rules with lower priority
|
||||
than configured here won't be used.
|
||||
Valid values (case insensitive): High, Medium High,
|
||||
Medium, Medium Low, Low"
|
||||
default="Low"
|
||||
%}
|
||||
{% include custom/cli_option_row.html options="--no-ruleset-compatibility"
|
||||
description='Disable automatic fixing of invalid rule references. Without the switch, PMD tries to automatically replace rule references that point to moved or renamed rules with the newer location if possible. Disabling it is not recommended.'
|
||||
@@ -127,13 +139,13 @@ The tool comes with a rather extensive help text, simply running with `--help`!
|
||||
description="Explicitly disables incremental analysis. This switch turns off suggestions to use Incremental Analysis,
|
||||
and causes the `--cache` option to be discarded if it is provided."
|
||||
%}
|
||||
{% include custom/cli_option_row.html options="--no-progress"
|
||||
description="Disable progress bar indicator of live analysis progress."
|
||||
{% include custom/cli_option_row.html options="--[no-]progress"
|
||||
description="Enables / disable progress bar indicator of live analysis progress. This ie enabled by default."
|
||||
%}
|
||||
{% include custom/cli_option_row.html options="--property,-P"
|
||||
option_arg="name>=<value"
|
||||
description="Specifies a property for the report renderer. The option can be specified several times."
|
||||
default="[]"
|
||||
description="Specifies a property for the report renderer. The option can be specified several times.
|
||||
<p>Using `--help` will provide a complete list of supported properties for each report format</p>"
|
||||
%}
|
||||
{% include custom/cli_option_row.html options="--report-file,-r"
|
||||
option_arg="path"
|
||||
@@ -145,9 +157,6 @@ The tool comes with a rather extensive help text, simply running with `--help`!
|
||||
{% include custom/cli_option_row.html options="--show-suppressed"
|
||||
description="Causes the suppressed rule violations to be added to the report."
|
||||
%}
|
||||
{% include custom/cli_option_row.html options="--stress,-S"
|
||||
description="Performs a stress test."
|
||||
%}
|
||||
{% include custom/cli_option_row.html options="--suppress-marker"
|
||||
option_arg="marker"
|
||||
description="Specifies the comment token that marks lines which PMD should ignore."
|
||||
@@ -161,16 +170,9 @@ The tool comes with a rather extensive help text, simply running with `--help`!
|
||||
%}
|
||||
{% include custom/cli_option_row.html options="--uri,-u"
|
||||
option_arg="uri"
|
||||
description="Database URI for sources. If this is given, then you don't need to provide `--dir`."
|
||||
description="Database URI for sources. One of `--dir`, `--file-list` or `--uri` must be provided."
|
||||
languages="PLSQL"
|
||||
%}
|
||||
{% include custom/cli_option_row.html options="--version"
|
||||
description="Display current version of PMD and exit without performing any analysis."
|
||||
%}
|
||||
{% include custom/cli_option_row.html options="-version,-v"
|
||||
option_arg="version"
|
||||
description="Specify the version of a language PMD should use. Used together with `-language`. See also [Supported Languages](#supported-languages)."
|
||||
%}
|
||||
</table>
|
||||
|
||||
## Additional Java Runtime Options
|
||||
@@ -180,8 +182,12 @@ if you want to analyze a project, that uses one of OpenJDK's [Preview Language F
|
||||
|
||||
Just set the environment variable `PMD_JAVA_OPTS` before executing PMD, e.g.
|
||||
|
||||
export PMD_JAVA_OPTS="--enable-preview"
|
||||
./run.sh pmd -d ../../../src/main/java/ -f text -R rulesets/java/quickstart.xml
|
||||
{% include cli_example.html
|
||||
id="preview"
|
||||
linux="export PMD_JAVA_OPTS=\"--enable-preview\"
|
||||
pmd check -d src/main/java/ -f text -R rulesets/java/quickstart.xml"
|
||||
windows="set \"PMD_JAVA_OPTS=--enable-preview\"
|
||||
pmd.bat check -d src\main\java\ -f text -R rulesets/java/quickstart.xml" %}
|
||||
|
||||
## Exit Status
|
||||
|
||||
@@ -189,9 +195,10 @@ Please note that if PMD detects any violations, it will exit with status 4 (sinc
|
||||
This behavior has been introduced to ease PMD integration into scripts or hooks, such as SVN hooks.
|
||||
|
||||
<table>
|
||||
<tr><td>0</td><td>Everything is fine, no violations found</td></tr>
|
||||
<tr><td>1</td><td>Couldn't understand command-line parameters or PMD exited with an exception</td></tr>
|
||||
<tr><td>4</td><td>At least one violation has been detected, unless <code>--fail-on-violation false</code> is set.</td></tr>
|
||||
<tr><td>0</td><td>Everything is fine, no violations found.</td></tr>
|
||||
<tr><td>1</td><td>PMD exited with an exception.</td></tr>
|
||||
<tr><td>2</td><td>Usage error. Command-line parameters are invalid or missing.</td></tr>
|
||||
<tr><td>4</td><td>At least one violation has been detected, unless <code>--no-fail-on-violation</code> is set.</td></tr>
|
||||
</table>
|
||||
|
||||
## Logging
|
||||
@@ -216,9 +223,10 @@ These parameters are irrelevant for languages that don't support different versi
|
||||
|
||||
Example:
|
||||
|
||||
``` shell
|
||||
./run.sh pmd -d src/main/java -f text -R rulesets/java/quickstart.xml --use-version java-1.8
|
||||
```
|
||||
{% include cli_example.html
|
||||
id="lang-ver"
|
||||
linux="pmd check -d src/main/java -f text -R rulesets/java/quickstart.xml --use-version java-1.8"
|
||||
windows="pmd.bat check -d src\main\java -f text -R rulesets/java/quickstart.xml --use-version java-1.8" %}
|
||||
|
||||
* [apex](pmd_rules_apex.html) (Salesforce Apex)
|
||||
* [ecmascript](pmd_rules_ecmascript.html) (JavaScript)
|
||||
@@ -227,11 +235,13 @@ Example:
|
||||
* [Supported Versions](pmd_languages_java.html)
|
||||
* [ecmascript](pmd_rules_ecmascript.html) (JavaScript)
|
||||
* [jsp](pmd_rules_jsp.html)
|
||||
* [kotlin](pmd_rules_kotlin.html)
|
||||
* [modelica](pmd_rules_modelica.html)
|
||||
* [plsql](pmd_rules_plsql.html)
|
||||
* [pom](pmd_rules_pom.html) (Maven POM)
|
||||
* [scala](pmd_rules_scala.html)
|
||||
* Supported Versions: 2.10, 2.11, 2.12, 2.13 (default)
|
||||
* [swift](pmd_rules_swift.html)
|
||||
* [vf](pmd_rules_vf.html) (Salesforce VisualForce)
|
||||
* [vm](pmd_rules_vm.html) (Apache Velocity)
|
||||
* [xml](pmd_rules_xml.html)
|
||||
@@ -248,20 +258,25 @@ All formats are described at [PMD Report formats](pmd_userdocs_report_formats.ht
|
||||
|
||||
If your xml language doesn't use `xml` as file extension, you can still use PMD with `--force-language`:
|
||||
|
||||
```
|
||||
$ ./run.sh pmd -d /home/me/src/xml-file.ext -f text -R ruleset.xml --force-language xml
|
||||
```
|
||||
{% include cli_example.html
|
||||
id="force"
|
||||
linux="pmd check -d src/xml-file.ext -f text -R ruleset.xml --force-language xml"
|
||||
windows="pmd.bat check -d src\xml-file.ext -f text -R ruleset.xml --force-language xml" %}
|
||||
|
||||
You can also specify a directory instead of a single file. Then all files are analyzed. In that case,
|
||||
parse errors are suppressed in order to reduce irrelevant noise:
|
||||
|
||||
```
|
||||
$ ./run.sh pmd -d /home/me/src/ -f text -R ruleset.xml --force-language xml
|
||||
```
|
||||
{% include cli_example.html
|
||||
id="force-dir"
|
||||
linux="pmd check -d src/ -f text -R ruleset.xml --force-language xml"
|
||||
windows="pmd.bat check -d src\ -f text -R ruleset.xml --force-language xml" %}
|
||||
|
||||
Alternatively, you can create a filelist to only analyze files with a given extension:
|
||||
|
||||
```
|
||||
$ find /home/me/src -name "*.ext" > /home/me/src/filelist.txt
|
||||
$ ./run.sh pmd --file-list /home/me/src/filelist.txt -f text -R ruleset.xml --force-language xml
|
||||
```
|
||||
{% include cli_example.html
|
||||
id="file-list"
|
||||
linux="find src/ -name \"*.ext\" > filelist.txt
|
||||
pmd check --file-list filelist.txt -f text -R ruleset.xml --force-language xml"
|
||||
windows="for /r src/ %i in (*.ext) do echo %i >> filelist.txt
|
||||
pmd.bat check --file-list filelist.txt -f text -R ruleset.xml --force-language xml" %}
|
||||
|
||||
@@ -59,32 +59,51 @@ Novice as much as advanced readers may want to [read on on Refactoring Guru](htt
|
||||
<th>Applies to</th>
|
||||
</tr>
|
||||
{% include custom/cli_option_row.html options="--minimum-tokens"
|
||||
option_arg="count"
|
||||
description="The minimum token length which should be reported as a duplicate."
|
||||
required="yes"
|
||||
%}
|
||||
{% include custom/cli_option_row.html options="--files,--dir,-d"
|
||||
description="List of files and directories to process"
|
||||
required="yes"
|
||||
{% include custom/cli_option_row.html options="--dir,-d"
|
||||
option_arg="path"
|
||||
description="Path to a source file, or directory containing
|
||||
source files to analyze. Zip and Jar files are
|
||||
also supported, if they are specified directly
|
||||
(archive files found while exploring a directory
|
||||
are not recursively expanded). This option can
|
||||
be repeated, and multiple arguments can be
|
||||
provided to a single occurrence of the option.
|
||||
One of `--dir`, `--file-list` or `--uri` must be
|
||||
provided."
|
||||
%}
|
||||
{% include custom/cli_option_row.html options="--file-list"
|
||||
description="Path to file containing a comma delimited list of files to analyze. If this is given, then you don't need to provide `--files`."
|
||||
option_arg="filepath"
|
||||
description="Path to a file containing a list of files to
|
||||
analyze, one path per line. One of `--dir`,
|
||||
`--file-list` or `--uri` must be provided."
|
||||
%}
|
||||
{% include custom/cli_option_row.html options="--language"
|
||||
description="Sources code language."
|
||||
{% include custom/cli_option_row.html options="--language,-l"
|
||||
option_arg="lang"
|
||||
description="The source code language.
|
||||
<p>See also [Supported Languages](#supported-languages).
|
||||
Using `--help` will display a full list of supported languages.</p>"
|
||||
default="java"
|
||||
%}
|
||||
{% include custom/cli_option_row.html options="--debug,--verbose,-v,-D"
|
||||
description="Debug mode. Prints more log output."
|
||||
{% include custom/cli_option_row.html options="--debug,--verbose,-D,-v"
|
||||
description="Debug mode. Prints more log output. See also [Logging](#logging)."
|
||||
%}
|
||||
{% include custom/cli_option_row.html options="--encoding,-e"
|
||||
description="Character encoding to use when processing files. If not specified, CPD uses the system default encoding."
|
||||
option_arg="charset"
|
||||
description="Specifies the character set encoding of the source code files PMD is reading.
|
||||
The valid values are the standard character sets of `java.nio.charset.Charset`."
|
||||
default="UTF-8"
|
||||
%}
|
||||
{% include custom/cli_option_row.html options="--skip-duplicate-files"
|
||||
description="Ignore multiple copies of files of the same name and length in comparison."
|
||||
default="false"
|
||||
%}
|
||||
{% include custom/cli_option_row.html options="--exclude"
|
||||
description="Files to be excluded from CPD check"
|
||||
option_arg="path"
|
||||
description="Files to be excluded from the analysis"
|
||||
%}
|
||||
{% include custom/cli_option_row.html options="--non-recursive"
|
||||
description="Don't scan subdirectories"
|
||||
@@ -94,15 +113,16 @@ Novice as much as advanced readers may want to [read on on Refactoring Guru](htt
|
||||
description="Skip files which can't be tokenized due to invalid characters instead of aborting CPD"
|
||||
default="false"
|
||||
%}
|
||||
{% include custom/cli_option_row.html options="--format"
|
||||
description="Report format."
|
||||
{% include custom/cli_option_row.html options="--format,-f"
|
||||
option_arg="format"
|
||||
description="Output format of the analysis report. The available formats
|
||||
are described [here](#available-report-formats)."
|
||||
default="text"
|
||||
%}
|
||||
{% include custom/cli_option_row.html options="--fail-on-violation"
|
||||
option_arg="bool"
|
||||
description="By default CPD exits with status 4 if code duplications are found.
|
||||
Disable this option with `--fail-on-violation false` to exit with 0 instead and just write the report."
|
||||
default="true"
|
||||
{% include custom/cli_option_row.html options="--[no-]fail-on-violation"
|
||||
description="Specifies whether CPD exits with non-zero status if violations are found.
|
||||
By default CPD exits with status 4 if violations are found.
|
||||
Disable this feature with `--no-fail-on-violation` to exit with 0 instead and just output the report."
|
||||
%}
|
||||
{% include custom/cli_option_row.html options="--ignore-literals"
|
||||
description="Ignore number values and string contents when comparing text"
|
||||
@@ -140,66 +160,80 @@ Novice as much as advanced readers may want to [read on on Refactoring Guru](htt
|
||||
default="#if 0|#endif"
|
||||
languages="C++"
|
||||
%}
|
||||
{% include custom/cli_option_row.html options="--uri"
|
||||
description="URI to process"
|
||||
{% include custom/cli_option_row.html options="--uri,-u"
|
||||
option_arg="uri"
|
||||
description="Database URI for sources. One of `--dir`,
|
||||
`--file-list` or `--uri` must be provided."
|
||||
languages="PLSQL"
|
||||
%}
|
||||
{% include custom/cli_option_row.html options="--help,-h"
|
||||
default="false"
|
||||
description="Print help text"
|
||||
%}
|
||||
</table>
|
||||
|
||||
### Examples
|
||||
|
||||
_Note:_ The following example use the Linux start script. For Windows, just replace "./run.sh cpd" by "cpd.bat".
|
||||
|
||||
|
||||
Minimum required options: Just give it the minimum duplicate size and the source directory:
|
||||
|
||||
$ ./run.sh cpd --minimum-tokens 100 --files /usr/local/java/src/java
|
||||
{% include cli_example.html
|
||||
id="basic"
|
||||
linux="pmd cpd --minimum-tokens 100 --dir src/main/java"
|
||||
windows="pmd.bat cpd --minimum-tokens 100 --dir src\main\java" %}
|
||||
|
||||
You can also specify the language:
|
||||
|
||||
$ ./run.sh cpd --minimum-tokens 100 --files /path/to/c/source --language cpp
|
||||
{% include cli_example.html
|
||||
id="lang"
|
||||
linux="pmd cpd --minimum-tokens 100 --dir src/main/cpp --language cpp"
|
||||
windows="pmd.bat cpd --minimum-tokens 100 --dir src\main\cpp --language cpp" %}
|
||||
|
||||
You may wish to check sources that are stored in different directories:
|
||||
|
||||
$ ./run.sh cpd --minimum-tokens 100 --files /path/to/other/source --files /path/to/other/source --files /path/to/other/source --language fortran
|
||||
{% include cli_example.html
|
||||
id="multiple"
|
||||
linux="pmd cpd --minimum-tokens 100 --dir src/main/java --dir src/test/java"
|
||||
windows="pmd.bat cpd --minimum-tokens 100 --dir src\main\java --dir src\test\java" %}
|
||||
|
||||
<em>There should be no limit to the number of '--files', you may add... But if you stumble one, please tell us !</em>
|
||||
<em>There is no limit to the number of `--dir`, you may add.</em>
|
||||
|
||||
And if you're checking a C source tree with duplicate files in different architecture directories
|
||||
you can skip those using --skip-duplicate-files:
|
||||
you can skip those using `--skip-duplicate-files`:
|
||||
|
||||
$ ./run.sh cpd --minimum-tokens 100 --files /path/to/c/source --language cpp --skip-duplicate-files
|
||||
{% include cli_example.html
|
||||
id="duplicates"
|
||||
linux="pmd cpd --minimum-tokens 100 --dir src/main/cpp --language cpp --skip-duplicate-files"
|
||||
windows="pmd.bat cpd --minimum-tokens 100 --dir src\main\cpp --language cpp --skip-duplicate-files" %}
|
||||
|
||||
You can also specify the encoding to use when parsing files:
|
||||
|
||||
$ ./run.sh cpd --minimum-tokens 100 --files /usr/local/java/src/java --encoding utf-16le
|
||||
{% include cli_example.html
|
||||
id="encoding"
|
||||
linux="pmd cpd --minimum-tokens 100 --dir src/main/java --encoding utf-16le"
|
||||
windows="pmd.bat cpd --minimum-tokens 100 --dir src\main\java --encoding utf-16le" %}
|
||||
|
||||
You can also specify a report format - here we're using the XML report:
|
||||
|
||||
$ ./run.sh cpd --minimum-tokens 100 --files /usr/local/java/src/java --format xml
|
||||
{% include cli_example.html
|
||||
id="report"
|
||||
linux="pmd cpd --minimum-tokens 100 --dir src/main/java --format xml"
|
||||
windows="pmd.bat cpd --minimum-tokens 100 --dir src\main\java --format xml" %}
|
||||
|
||||
The default format is a text report, and there's also a `csv` report.
|
||||
|
||||
Note that CPD is pretty memory-hungry; you may need to give Java more memory to run it, like this:
|
||||
|
||||
$ export PMD_JAVA_OPTS=-Xmx512m
|
||||
$ ./run.sh cpd --minimum-tokens 100 --files /usr/local/java/src/java
|
||||
|
||||
In order to change the heap size under Windows, you'll need to edit the batch file `cpd.bat` or
|
||||
set the environment variable `PMD_JAVA_OPTS` prior to starting CPD:
|
||||
|
||||
C:\ > cd C:\pmd-bin-{{site.pmd.version}}\bin
|
||||
C:\...\bin > set PMD_JAVA_OPTS=-Xmx512m
|
||||
C:\...\bin > .\cpd.bat --minimum-tokens 100 --files c:\temp\src
|
||||
The default format is a text report, but there are [other supported formats](#available-report-formats)
|
||||
|
||||
Note that CPD's memory usage increases linearly with the size of the analyzed source code; you may need to give Java more memory to run it, like this:
|
||||
{% include cli_example.html
|
||||
id="memchange"
|
||||
linux="export PMD_JAVA_OPTS=-Xmx512m
|
||||
pmd cpd --minimum-tokens 100 --dir src/main/java"
|
||||
windows="set PMD_JAVA_OPTS=-Xmx512m
|
||||
pmd.bat cpd --minimum-tokens 100 --dir src\main\java" %}
|
||||
|
||||
If you specify a source directory but don't want to scan the sub-directories, you can use the non-recursive option:
|
||||
|
||||
$ ./run.sh cpd --minimum-tokens 100 --non-recursive --files /usr/local/java/src/java
|
||||
{% include cli_example.html
|
||||
id="nonrecursive"
|
||||
linux="pmd cpd --minimum-tokens 100 --dir src/main/java --non-recursive"
|
||||
windows="pmd.bat cpd --minimum-tokens 100 --dir src\main\java --non-recursive" %}
|
||||
|
||||
### Exit status
|
||||
|
||||
@@ -207,11 +241,21 @@ Please note that if CPD detects duplicated source code, it will exit with status
|
||||
This behavior has been introduced to ease CPD integration into scripts or hooks, such as SVN hooks.
|
||||
|
||||
<table>
|
||||
<tr><td>0</td><td>Everything is fine, no code duplications found</td></tr>
|
||||
<tr><td>1</td><td>Couldn't understand command line parameters or CPD exited with an exception</td></tr>
|
||||
<tr><td>4</td><td>At least one code duplication has been detected unless '--fail-on-violation false' is used.</td></tr>
|
||||
<tr><td>0</td><td>Everything is fine, no code duplications found.</td></tr>
|
||||
<tr><td>1</td><td>CPD exited with an exception.</td></tr>
|
||||
<tr><td>2</td><td>Usage error. Command-line parameters are invalid or missing.</td></tr>
|
||||
<tr><td>4</td><td>At least one code duplication has been detected unless <code>--no-fail-on-violation</code> is set.</td></tr>
|
||||
</table>
|
||||
|
||||
## Logging
|
||||
|
||||
PMD internally uses [slf4j](https://www.slf4j.org/) and ships with slf4j-simple as the logging implementation.
|
||||
Logging messages are printed to System.err.
|
||||
|
||||
The configuration for slf4j-simple is in the file `conf/simplelogger.properties`. There you can enable
|
||||
logging of specific classes if needed. The `--debug` command line option configures the default log level
|
||||
to be "debug".
|
||||
|
||||
|
||||
## Supported Languages
|
||||
|
||||
@@ -362,15 +406,12 @@ the CPD task as usual and right after it invoke the Ant XSLT script like this:
|
||||
|
||||
## GUI
|
||||
|
||||
CPD also comes with a simple GUI. You can start it via some scripts in the `bin` folder:
|
||||
CPD also comes with a simple GUI. You can start it through the unified CLI interface provided in the `bin` folder:
|
||||
|
||||
For Windows:
|
||||
|
||||
cpdgui.bat
|
||||
|
||||
For Linux:
|
||||
|
||||
./run.sh cpd-gui
|
||||
{% include cli_example.html
|
||||
id="gui"
|
||||
linux="pmd cpd-gui"
|
||||
windows="pmd.bat cpd-gui" %}
|
||||
|
||||
Here's a screenshot of CPD after running on the JDK 8 java.lang package:
|
||||
|
||||
@@ -407,7 +448,7 @@ Additionally, **Java** allows to toggle suppression by adding the annotations
|
||||
all code within will be ignored by CPD.
|
||||
|
||||
This approach however, is limited to the locations were `@SuppressWarnings` is accepted.
|
||||
It's legacy and the new comment's based approach should be favored.
|
||||
It is legacy and the new comment based approach should be favored.
|
||||
|
||||
```java
|
||||
//enable suppression
|
||||
|
||||
@@ -16,8 +16,10 @@ The app needs JRE 1.8 or above to run. Be aware that on JRE 11+, the JavaFX dist
|
||||
|
||||
If the bin directory of your PMD distribution is on your shell's path, then you can **launch the app** with
|
||||
|
||||
run.sh designer on Linux/ OSX
|
||||
designer.bat on Windows
|
||||
{% include cli_example.html
|
||||
id="pmd"
|
||||
linux="pmd designer"
|
||||
windows="pmd.bat designer" %}
|
||||
|
||||
|
||||
{% include note.html content="pmd-ui.jar is not a runnable jar, because it doesn't include any PMD language module, or PMD Core. " %}
|
||||
|
||||
@@ -22,10 +22,15 @@ expressions.
|
||||
|
||||
The rule designer is a tool that packs a lot of features to help you develop XPath
|
||||
rules quickly and painlessly. Basically, it allows you to examine the AST of a code
|
||||
snippet and evaluate an XPath expression against it.
|
||||
snippet and evaluate an XPath expression against it. You can launch it from Command Line as follows:
|
||||
|
||||
Like for PMD and CPD, you can launch it using `run.sh designer` on Linux/Unix
|
||||
and `designer.bat` on Windows. The interface looks like the following:
|
||||
{% include cli_example.html
|
||||
id="designer"
|
||||
linux="pmd designer"
|
||||
windows="pmd.bat designer" %}
|
||||
|
||||
|
||||
The interface looks like the following:
|
||||
|
||||
{% include image.html file="userdocs/designer-overview-with-nums.png" alt="Designer overview" %}
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ sidebar: pmd_sidebar
|
||||
* For Windows: [Winzip](http://winzip.com) or the free [7-zip](http://www.7-zip.org/)
|
||||
* For Linux / Unix: [InfoZip](http://infozip.sourceforge.net/)
|
||||
|
||||
{% include note.html content="For executing the Designer (./run.sh designer) using [OpenJDK](http://jdk.java.net) or Java 11, you need additionally [JavaFX](https://gluonhq.com/products/javafx/). Download it, extract it and set the environment variable JAVAFX_HOME pointing at that directory." %}
|
||||
{% include note.html content="For executing the Designer (`pmd designer`) using [OpenJDK](http://jdk.java.net) or Java 11+, you need additionally [JavaFX](https://gluonhq.com/products/javafx/). Download it, extract it and set the environment variable JAVAFX_HOME pointing at that directory." %}
|
||||
|
||||
|
||||
### Installation
|
||||
@@ -31,28 +31,44 @@ sidebar: pmd_sidebar
|
||||
PMD is distributed as a zip archive, which includes both [PMD](#running-pmd-via-command-line) and [CPD](pmd_userdocs_cpd.html).
|
||||
You can download the latest binary distribution from [the github releases page](https://github.com/pmd/pmd/releases).
|
||||
|
||||
Unzip it into any directory, optionally add the `bin` subdirectory in your `PATH`, and you're good to go!
|
||||
It's highly recommended (but not required) to include it to your `PATH`.
|
||||
|
||||
|
||||
On Linux you can do this by adding `PATH=$PATH:*path_to_pmd*/bin/` to your `~/.bashrc` / `~/.zshrc` file.
|
||||
|
||||
On Windows this is achieved by:
|
||||
1. On the **Start menu**, right-click **Computer**.
|
||||
2. On the context menu, click **Properties**.
|
||||
3. In the **System** dialog box, click **Advanced system settings**.
|
||||
4. On the **Advanced** tab of the **System Properties** dialog box, click **Environment Variables**
|
||||
5. In the **System Variables** box of the **Environment Variables** dialog box, scroll to **Path** and select it.
|
||||
6. Click the lower of the two **Edit** buttons in the dialog box.
|
||||
7. In the **Edit System Variable** dialog box, scroll to the end of the string in the **Variable value** box and add a semicolon (;).
|
||||
8. Add the proper value for `*path_to_pmd*/bin/` after the semicolon.
|
||||
9. Click **OK** in three successive dialog boxes, and then close the **System** dialog box.
|
||||
|
||||
#### Shell completion
|
||||
|
||||
PMD ships with built-in completion support for Bash / Zsh.
|
||||
|
||||
To enable it, simply add `source *path_to_pmd*/shell/pmd-completion.sh` to your `~/.bashrc` / `~/.zshrc` file.
|
||||
|
||||
## Running PMD via command line
|
||||
|
||||
{% include callout.html type="primary"
|
||||
content="PMD comes with several command line utilities, like CPD, the rule designer or PMD itself.
|
||||
On Unix, you can run any of them using the script `run.sh`, located inside the `bin/`
|
||||
You can run any of them using the script `pmd` (`pmd.bat` under Windows), located inside the `bin/`
|
||||
directory of the PMD distribution. The first argument is the name of the utility you want
|
||||
to execute ('pmd', 'designer', ...), e.g. PMD is launched via `run.sh pmd`. The rest of
|
||||
the arguments are specific to the utility used.<br/><br/>
|
||||
On Windows, each utility has its own startup script, e.g. `pmd.bat`, `cpd.bat`." %}
|
||||
to execute ('check', 'designer', ...), e.g. PMD is launched via `pmd check`. The rest of
|
||||
the arguments are specific to the utility used.<br/><br/>" %}
|
||||
|
||||
The PMD command (`pmd.bat` or `run.sh pmd`) requires two options:
|
||||
Running a PMD analysis (`pmd check` or `pmd.bat check`) requires at least one option and a list of sources:
|
||||
|
||||
* `-d <path>`: path to the sources to analyse. This can be a file name, a directory, or a jar or zip file containing the
|
||||
sources.
|
||||
* `-R <path>`: the ruleset file you want to use. PMD uses xml configuration files, called *rulesets*, which specify
|
||||
which rules to execute on your sources. You can also run a single rule by referencing it using its *category* and
|
||||
name (more details [here](pmd_userdocs_making_rulesets.html#referencing-a-single-rule)). For example, you can check for unnecessary
|
||||
modifiers on Java sources with `-R category/java/codestyle.xml/UnnecessaryModifier`.
|
||||
* `<source> …`: path to the sources to analyse. This can be a file name, a directory, or a jar or zip file containing the
|
||||
sources. Alternatively You can use the `-d` or `--dir` flag, which is equivalent.
|
||||
|
||||
{% include note.html
|
||||
content="At the moment the formerly provided rulesets (eg `rulesets/java/basic.xml`) are deprecated,
|
||||
@@ -75,41 +91,22 @@ Additionally, the following options, are specified most of the time even though
|
||||
|
||||
The following shows a sample run of PMD with the `text` format:
|
||||
|
||||
{% include cli_example.html
|
||||
id="pmd"
|
||||
linux="pmd check -f text -R rulesets/java/quickstart.xml src/main/java
|
||||
|
||||
<div class="text-left">
|
||||
<ul class="nav nav-tabs" role="tablist" id="pmd-sample-usage-tabs">
|
||||
<li class="nav-item" role="presentation">
|
||||
<a class="nav-link active" id="linux-tab" data-toggle="tab" href="#linux" role="tab" aria-controls="linux" aria-selected="true">Linux / Unix</a>
|
||||
</li>
|
||||
<li class="nav-item" role="presentation">
|
||||
<a class="nav-link" id="windows-tab" data-toggle="tab" href="#windows" role="tab" aria-controls="windows" aria-selected="false">Windows</a>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<div class="tab-content border">
|
||||
<div class="tab-pane fade show active" id="linux" role="tabpanel" aria-labelledby="linux-tab">
|
||||
<figure class="highlight"><pre><code class="language-bash" data-lang="bash"><span class="gp">~ $ </span><span class="s2">cd</span> ~/bin/pmd-bin-{{site.pmd.version}}/bin
|
||||
<span class="gp">~/.../bin $ </span><span class="s2">./run.sh</span> pmd -d ../../../src/main/java/ -f text -R rulesets/java/quickstart.xml
|
||||
|
||||
.../src/main/java/com/me/RuleSet.java:123 These nested if statements could be combined
|
||||
.../src/main/java/com/me/RuleSet.java:231 Useless parentheses.
|
||||
.../src/main/java/com/me/RuleSet.java:232 Useless parentheses.
|
||||
.../src/main/java/com/me/RuleSet.java:357 These nested if statements could be combined
|
||||
.../src/main/java/com/me/RuleSetWriter.java:66 Avoid empty catch blocks</code></pre></figure>
|
||||
</div>
|
||||
<div class="tab-pane fade" id="windows" role="tabpanel" aria-labelledby="windows-tab">
|
||||
<figure class="highlight"><pre><code class="language-bash" data-lang="bash"><span class="gp">C:\ > </span><span class="s2">cd</span> C:\pmd-bin-{{site.pmd.version}}\bin
|
||||
<span class="gp">C:\...\bin > </span><span class="s2">.\pmd.bat</span> -d ..\..\src\main\java\ -f text -R rulesets/java/quickstart.xml
|
||||
|
||||
.../src/main/java/com/me/RuleSetWriter.java:66 Avoid empty catch blocks"
|
||||
windows="pmd.bat check -f text -R rulesets/java/quickstart.xml ..\..\src\main\java
|
||||
|
||||
.../src/main/java/com/me/RuleSet.java:123 These nested if statements could be combined
|
||||
.../src/main/java/com/me/RuleSet.java:231 Useless parentheses.
|
||||
.../src/main/java/com/me/RuleSet.java:232 Useless parentheses.
|
||||
.../src/main/java/com/me/RuleSet.java:357 These nested if statements could be combined
|
||||
.../src/main/java/com/me/RuleSetWriter.java:66 Avoid empty catch blocks</code></pre></figure>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
.../src/main/java/com/me/RuleSetWriter.java:66 Avoid empty catch blocks" %}
|
||||
|
||||
## Running CPD via command line
|
||||
|
||||
@@ -117,12 +114,11 @@ Additionally, the following options, are specified most of the time even though
|
||||
content="CPD supports Java, JSP, C, C++, C#, Fortran and PHP source code, among other languages.
|
||||
For the full list, see [Supported Languages](pmd_userdocs_cpd.html#supported-languages)." %}
|
||||
|
||||
Like for PMD, CPD is started on Unix by `run.sh cpd` and on Windows by `cpd.bat`.
|
||||
Like for PMD, CPD is started on Unix by `pmd cpd` and on Windows by `pmd.bat cpd`, and it requires one option and a list of sources:
|
||||
|
||||
There are two required parameters:
|
||||
* `--files <path>`: path to the sources to analyse. This can be a file name, a
|
||||
directory or a jar or zip file containing the sources.
|
||||
* `--minimum-tokens <number>`: the minimum token length which should be reported as a duplicate.
|
||||
* `<source> …`: path to the sources to analyse. This can be a file name, a directory, or a jar or zip file containing the
|
||||
sources. Alternatively You can use the `-d` or `--dir` flag, which is equivalent.
|
||||
|
||||
{% include tip.html
|
||||
content="CPD's command-line reference, Ant task usage, and many examples are documented in the
|
||||
@@ -132,21 +128,9 @@ There are two required parameters:
|
||||
|
||||
The following shows a sample run of CPD with the `text` format:
|
||||
|
||||
|
||||
<div class="text-left">
|
||||
<ul class="nav nav-tabs" role="tablist" id="cpd-sample-usage-tabs">
|
||||
<li class="nav-item" role="presentation">
|
||||
<a class="nav-link active" id="cpd-linux-tab" data-toggle="tab" href="#cpd-linux" role="tab" aria-controls="cpd-linux" aria-selected="true">Linux / Unix</a>
|
||||
</li>
|
||||
<li class="nav-item" role="presentation">
|
||||
<a class="nav-link" id="cpd-windows-tab" data-toggle="tab" href="#cpd-windows" role="tab" aria-controls="windows" aria-selected="false">Windows</a>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<div class="tab-content border">
|
||||
<div class="tab-pane fade show active" id="cpd-linux" role="tabpanel" aria-labelledby="cpd-linux-tab">
|
||||
<figure class="highlight"><pre><code class="language-bash" data-lang="bash"><span class="gp">~ $ </span><span class="s2">cd</span> ~/bin/pmd-bin-{{site.pmd.version}}/bin
|
||||
<span class="gp">~/.../bin $ </span><span class="s2">./run.sh</span> cpd --minimum-tokens 100 --files /home/me/src
|
||||
{% include cli_example.html
|
||||
id="cpd"
|
||||
linux="pmd cpd --minimum-tokens 100 /home/me/src
|
||||
|
||||
Found a 7 line (110 tokens) duplication in the following files:
|
||||
Starting at line 579 of /home/me/src/test/java/foo/FooTypeTest.java
|
||||
@@ -158,11 +142,8 @@ There are two required parameters:
|
||||
assertEquals(Boolean.TYPE, expressions.get(index++).getType());
|
||||
assertEquals(Boolean.TYPE, expressions.get(index++).getType());
|
||||
assertEquals(Boolean.TYPE, expressions.get(index++).getType());
|
||||
assertEquals(Boolean.TYPE, expressions.get(index++).getType());</code></pre></figure>
|
||||
</div>
|
||||
<div class="tab-pane fade" id="cpd-windows" role="tabpanel" aria-labelledby="cpd-windows-tab">
|
||||
<figure class="highlight"><pre><code class="language-bash" data-lang="bash"><span class="gp">C:\ > </span><span class="s2">cd</span> C:\pmd-bin-{{site.pmd.version}}\bin
|
||||
<span class="gp">C:\...\bin > </span><span class="s2">.\cpd.bat</span> --minimum-tokens 100 --files c:\temp\src
|
||||
assertEquals(Boolean.TYPE, expressions.get(index++).getType());"
|
||||
windows="pmd.bat cpd --minimum-tokens 100 /home/me/src
|
||||
|
||||
Found a 7 line (110 tokens) duplication in the following files:
|
||||
Starting at line 579 of c:\temp\src\test\java\foo\FooTypeTest.java
|
||||
@@ -174,7 +155,5 @@ There are two required parameters:
|
||||
assertEquals(Boolean.TYPE, expressions.get(index++).getType());
|
||||
assertEquals(Boolean.TYPE, expressions.get(index++).getType());
|
||||
assertEquals(Boolean.TYPE, expressions.get(index++).getType());
|
||||
assertEquals(Boolean.TYPE, expressions.get(index++).getType());</code></pre></figure>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
assertEquals(Boolean.TYPE, expressions.get(index++).getType());" %}
|
||||
|
||||
@@ -14,10 +14,10 @@ be customized further via properties. Violations might also be suppressed and th
|
||||
be processing errors or configuration errors. Not all report formats display all information.
|
||||
|
||||
The header of the sections below are used to select the format on the command line, as
|
||||
arguments to the `-format` option. When a format accepts *properties*,
|
||||
those can be specified with the `-property` / `-P` option on the command-line.
|
||||
arguments to the `--format` option. When a format accepts *properties*,
|
||||
those can be specified with the `--property` / `-P` option on the command-line.
|
||||
|
||||
{% include note.html content="Suppressed violations are only reported, if the CLI parameter `-showsuppressed` is set." %}
|
||||
{% include note.html content="Suppressed violations are only reported, if the CLI parameter `--show-suppressed` is set." %}
|
||||
|
||||
## sarif
|
||||
|
||||
@@ -122,11 +122,11 @@ It has two ways of calling:
|
||||
|
||||
1. For a single file: then all three properties need to be provided
|
||||
|
||||
`run.sh pmd -d src/Foo.java -R rulesets/java/quickstart.xml -f ideaj -P fileName=src/Foo.java -P sourcePath=/home/pmd/src -P classAndMethodName=Foo`
|
||||
`pmd check -d src/Foo.java -R rulesets/java/quickstart.xml -f ideaj -P fileName=src/Foo.java -P sourcePath=/home/pmd/src -P classAndMethodName=Foo`
|
||||
|
||||
2. For a directory: then the fileName property can be omitted
|
||||
|
||||
`run.sh pmd -d src -R rulesets/java/quickstart.xml -f ideaj -P sourcePath=/home/pmd/src -P classAndMethodName=.method`
|
||||
`pmd check -d src -R rulesets/java/quickstart.xml -f ideaj -P sourcePath=/home/pmd/src -P classAndMethodName=.method`
|
||||
|
||||
Example:
|
||||
|
||||
|
||||
@@ -116,7 +116,7 @@ public class Foo {
|
||||
}
|
||||
}
|
||||
|
||||
$ ./run.sh pmd -d Foo.java -f text -R java-unusedcode -suppressmarker TURN_OFF_WARNINGS
|
||||
$ pmd check -d Foo.java -f text -R java-unusedcode --suppress-marker TURN_OFF_WARNINGS
|
||||
No problems found!
|
||||
UnusedLocalVariable rule violation suppressed by //NOPMD in /home/tom/pmd/pmd/bin/Foo.java
|
||||
```
|
||||
|
||||
@@ -147,7 +147,7 @@ public class Formatter {
|
||||
}
|
||||
|
||||
private static String[] validRendererCodes() {
|
||||
return RendererFactory.REPORT_FORMAT_TO_RENDERER.keySet().toArray(new String[0]);
|
||||
return RendererFactory.supportedRenderers().toArray(new String[0]);
|
||||
}
|
||||
|
||||
private static String unknownRendererMessage(String userSpecifiedType) {
|
||||
|
||||
+1
-6
@@ -72,11 +72,6 @@
|
||||
<artifactId>hamcrest</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter</artifactId>
|
||||
@@ -84,7 +79,7 @@
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.stefanbirkner</groupId>
|
||||
<artifactId>system-rules</artifactId>
|
||||
<artifactId>system-lambda</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
||||
@@ -4,30 +4,30 @@
|
||||
|
||||
package net.sourceforge.pmd.cpd;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import net.sourceforge.pmd.lang.apex.ApexLanguageModule;
|
||||
import net.sourceforge.pmd.util.IOUtil;
|
||||
|
||||
public class ApexCpdTest {
|
||||
class ApexCpdTest {
|
||||
private File testdir;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
String path = IOUtil.normalizePath("src/test/resources/net/sourceforge/pmd/cpd/issue427");
|
||||
testdir = new File(path);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIssue427() throws IOException {
|
||||
void testIssue427() throws IOException {
|
||||
CPDConfiguration configuration = new CPDConfiguration();
|
||||
configuration.setMinimumTileSize(10);
|
||||
configuration.setLanguage(LanguageFactory.createLanguage(ApexLanguageModule.TERSE_NAME));
|
||||
|
||||
@@ -6,13 +6,13 @@ package net.sourceforge.pmd.cpd;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import net.sourceforge.pmd.cpd.test.CpdTextComparisonTest;
|
||||
|
||||
public class ApexTokenizerTest extends CpdTextComparisonTest {
|
||||
class ApexTokenizerTest extends CpdTextComparisonTest {
|
||||
|
||||
public ApexTokenizerTest() {
|
||||
ApexTokenizerTest() {
|
||||
super(".cls");
|
||||
}
|
||||
|
||||
@@ -30,12 +30,12 @@ public class ApexTokenizerTest extends CpdTextComparisonTest {
|
||||
|
||||
|
||||
@Test
|
||||
public void testTokenize() {
|
||||
void testTokenize() {
|
||||
doTest("Simple");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTokenizeCaseSensitive() {
|
||||
void testTokenizeCaseSensitive() {
|
||||
doTest("Simple", "_caseSensitive", caseSensitive());
|
||||
}
|
||||
|
||||
@@ -43,12 +43,12 @@ public class ApexTokenizerTest extends CpdTextComparisonTest {
|
||||
* Comments are ignored since using ApexLexer.
|
||||
*/
|
||||
@Test
|
||||
public void testTokenizeWithComments() {
|
||||
void testTokenizeWithComments() {
|
||||
doTest("comments");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTabWidth() {
|
||||
void testTabWidth() {
|
||||
doTest("tabWidth");
|
||||
}
|
||||
|
||||
|
||||
@@ -4,29 +4,31 @@
|
||||
|
||||
package net.sourceforge.pmd.lang.apex;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.contrib.java.lang.system.SystemErrRule;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import net.sourceforge.pmd.RuleSet;
|
||||
import net.sourceforge.pmd.RuleSetLoader;
|
||||
|
||||
public class DefaultRulesetTest {
|
||||
@Rule
|
||||
public final SystemErrRule systemErrRule = new SystemErrRule().enableLog().muteForSuccessfulTests();
|
||||
import com.github.stefanbirkner.systemlambda.SystemLambda;
|
||||
|
||||
class DefaultRulesetTest {
|
||||
|
||||
@Test
|
||||
public void loadDefaultRuleset() {
|
||||
void loadDefaultRuleset() {
|
||||
RuleSet ruleset = rulesetLoader().loadFromResource("rulesets/apex/ruleset.xml");
|
||||
Assert.assertNotNull(ruleset);
|
||||
assertNotNull(ruleset);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void loadQuickstartRuleset() {
|
||||
RuleSet ruleset = rulesetLoader().loadFromResource("rulesets/apex/quickstart.xml");
|
||||
Assert.assertNotNull(ruleset);
|
||||
Assert.assertTrue("No Logging expected", systemErrRule.getLog().isEmpty());
|
||||
void loadQuickstartRuleset() throws Exception {
|
||||
String log = SystemLambda.tapSystemErr(() -> {
|
||||
RuleSet ruleset = rulesetLoader().loadFromResource("rulesets/apex/quickstart.xml");
|
||||
assertNotNull(ruleset);
|
||||
});
|
||||
assertTrue(log.isEmpty(), "No Logging expected");
|
||||
}
|
||||
|
||||
private RuleSetLoader rulesetLoader() {
|
||||
|
||||
@@ -6,11 +6,11 @@ package net.sourceforge.pmd.lang.apex;
|
||||
|
||||
import static net.sourceforge.pmd.lang.ast.test.TestUtilsKt.assertSize;
|
||||
import static net.sourceforge.pmd.lang.ast.test.TestUtilsKt.assertSuppressed;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import net.sourceforge.pmd.PMD;
|
||||
import net.sourceforge.pmd.Report;
|
||||
@@ -19,7 +19,7 @@ import net.sourceforge.pmd.lang.apex.ast.ASTUserClass;
|
||||
import net.sourceforge.pmd.lang.apex.ast.ApexParserTestBase;
|
||||
import net.sourceforge.pmd.lang.apex.rule.AbstractApexRule;
|
||||
|
||||
public class SuppressWarningsTest extends ApexParserTestBase {
|
||||
class SuppressWarningsTest extends ApexParserTestBase {
|
||||
|
||||
// This could be a regular xml test
|
||||
|
||||
@@ -45,7 +45,7 @@ public class SuppressWarningsTest extends ApexParserTestBase {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testClassLevelSuppression() {
|
||||
void testClassLevelSuppression() {
|
||||
Report rpt = apex.executeRule(new FooRule(), TEST1);
|
||||
assertSize(rpt, 0);
|
||||
rpt = apex.executeRule(new FooRule(), TEST2);
|
||||
@@ -53,86 +53,86 @@ public class SuppressWarningsTest extends ApexParserTestBase {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInheritedSuppression() {
|
||||
void testInheritedSuppression() {
|
||||
Report rpt = apex.executeRule(new FooRule(), TEST3);
|
||||
assertSize(rpt, 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMethodLevelSuppression() {
|
||||
void testMethodLevelSuppression() {
|
||||
Report rpt = apex.executeRule(new FooRule(), TEST4);
|
||||
assertSize(rpt, 1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstructorLevelSuppression() {
|
||||
void testConstructorLevelSuppression() {
|
||||
Report rpt = apex.executeRule(new FooRule(), TEST5);
|
||||
assertSize(rpt, 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFieldLevelSuppression() {
|
||||
void testFieldLevelSuppression() {
|
||||
Report rpt = apex.executeRule(new FooRule(), TEST6);
|
||||
assertSize(rpt, 1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParameterLevelSuppression() {
|
||||
void testParameterLevelSuppression() {
|
||||
Report rpt = apex.executeRule(new FooRule(), TEST7);
|
||||
assertSize(rpt, 1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLocalVariableLevelSuppression() {
|
||||
void testLocalVariableLevelSuppression() {
|
||||
Report rpt = apex.executeRule(new FooRule(), TEST8);
|
||||
assertSize(rpt, 1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSpecificSuppression() {
|
||||
void testSpecificSuppression() {
|
||||
Report rpt = apex.executeRule(new FooRule(), TEST9);
|
||||
assertSize(rpt, 1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSpecificSuppressionMulitpleValues() {
|
||||
void testSpecificSuppressionMulitpleValues() {
|
||||
Report rpt = apex.executeRule(new FooRule(), TEST9_MULTIPLE_VALUES);
|
||||
assertSize(rpt, 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoSuppressionBlank() {
|
||||
void testNoSuppressionBlank() {
|
||||
Report rpt = apex.executeRule(new FooRule(), TEST10);
|
||||
assertSize(rpt, 2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoSuppressionSomethingElseS() {
|
||||
void testNoSuppressionSomethingElseS() {
|
||||
Report rpt = apex.executeRule(new FooRule(), TEST11);
|
||||
assertSize(rpt, 2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSuppressAll() {
|
||||
void testSuppressAll() {
|
||||
Report rpt = apex.executeRule(new FooRule(), TEST12);
|
||||
assertSize(rpt, 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSpecificSuppressionAtTopLevel() {
|
||||
void testSpecificSuppressionAtTopLevel() {
|
||||
Report rpt = apex.executeRule(new BarRule(), TEST13);
|
||||
assertSize(rpt, 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCommentSuppression() {
|
||||
void testCommentSuppression() {
|
||||
Report rpt = apex.executeRule(new FooRule(), TEST14);
|
||||
assertSize(rpt, 0);
|
||||
assertSuppressed(rpt, 1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMessageWithCommentSuppression() {
|
||||
void testMessageWithCommentSuppression() {
|
||||
Report rpt = apex.executeRule(new FooRule(), TEST15);
|
||||
assertSize(rpt, 0);
|
||||
|
||||
|
||||
@@ -4,34 +4,36 @@
|
||||
|
||||
package net.sourceforge.pmd.lang.apex.ast;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
|
||||
public class ASTFieldTest extends ApexParserTestBase {
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class ASTFieldTest extends ApexParserTestBase {
|
||||
|
||||
@Test
|
||||
public void testGetType() {
|
||||
void testGetType() {
|
||||
ASTField field = parse("public class Foo { private String myField = 'a'; }")
|
||||
.descendants(ASTField.class).firstOrThrow();
|
||||
|
||||
Assert.assertEquals("myField", field.getImage());
|
||||
Assert.assertEquals("String", field.getType());
|
||||
Assert.assertEquals("a", field.getValue());
|
||||
assertEquals("myField", field.getImage());
|
||||
assertEquals("String", field.getType());
|
||||
assertEquals("a", field.getValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetValue() {
|
||||
void testGetValue() {
|
||||
ASTField field = parse("public class Foo { private String myField = 'a'; }")
|
||||
.descendants(ASTField.class).firstOrThrow();
|
||||
|
||||
Assert.assertEquals("a", field.getValue());
|
||||
assertEquals("a", field.getValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetNoValue() {
|
||||
void testGetNoValue() {
|
||||
ASTField field = parse("public class Foo { private String myField; }")
|
||||
.descendants(ASTField.class).firstOrThrow();
|
||||
|
||||
Assert.assertNull(field.getValue());
|
||||
assertNull(field.getValue());
|
||||
}
|
||||
}
|
||||
@@ -4,19 +4,20 @@
|
||||
|
||||
package net.sourceforge.pmd.lang.apex.ast;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class ASTMethodTest extends ApexParserTestBase {
|
||||
class ASTMethodTest extends ApexParserTestBase {
|
||||
|
||||
@Test
|
||||
public void testConstructorName() {
|
||||
void testConstructorName() {
|
||||
ASTUserClass node = (ASTUserClass) parse("public class Foo { public Foo() {} public void bar() {} }");
|
||||
List<ASTMethod> methods = node.children(ASTMethod.class).toList();
|
||||
Assert.assertEquals("Foo", methods.get(0).getImage()); // constructor
|
||||
Assert.assertEquals("<init>", methods.get(0).getCanonicalName());
|
||||
Assert.assertEquals("bar", methods.get(1).getImage()); // normal method
|
||||
assertEquals("Foo", methods.get(0).getImage()); // constructor
|
||||
assertEquals("<init>", methods.get(0).getCanonicalName());
|
||||
assertEquals("bar", methods.get(1).getImage()); // normal method
|
||||
}
|
||||
}
|
||||
+10
-9
@@ -4,15 +4,16 @@
|
||||
|
||||
package net.sourceforge.pmd.lang.apex.ast;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class ASTNewKeyValueObjectExpressionTest extends ApexParserTestBase {
|
||||
class ASTNewKeyValueObjectExpressionTest extends ApexParserTestBase {
|
||||
|
||||
@Test
|
||||
public void testParameterName() {
|
||||
void testParameterName() {
|
||||
ASTUserClassOrInterface<?> node = parse("public class Foo { \n"
|
||||
+ " public void foo(String newName, String tempID) { \n"
|
||||
+ " if (Contact.sObjectType.getDescribe().isCreateable() && Contact.sObjectType.getDescribe().isUpdateable()) {\n"
|
||||
@@ -20,13 +21,13 @@ public class ASTNewKeyValueObjectExpressionTest extends ApexParserTestBase {
|
||||
+ " }\n" + " } \n" + "}");
|
||||
|
||||
ASTNewKeyValueObjectExpression keyValueExpr = node.getFirstDescendantOfType(ASTNewKeyValueObjectExpression.class);
|
||||
Assert.assertEquals(3, keyValueExpr.getParameterCount());
|
||||
assertEquals(3, keyValueExpr.getParameterCount());
|
||||
|
||||
List<ASTLiteralExpression> literals = keyValueExpr.findDescendantsOfType(ASTLiteralExpression.class);
|
||||
Assert.assertEquals(3, literals.size());
|
||||
Assert.assertEquals("FirstName", literals.get(0).getName());
|
||||
Assert.assertEquals("LastName", literals.get(1).getName());
|
||||
Assert.assertEquals("Phone", literals.get(2).getName());
|
||||
assertEquals(3, literals.size());
|
||||
assertEquals("FirstName", literals.get(0).getName());
|
||||
assertEquals("LastName", literals.get(1).getName());
|
||||
assertEquals("Phone", literals.get(2).getName());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -4,15 +4,16 @@
|
||||
|
||||
package net.sourceforge.pmd.lang.apex.ast;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
public class ASTSoqlExpressionTest extends ApexParserTestBase {
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class ASTSoqlExpressionTest extends ApexParserTestBase {
|
||||
|
||||
@Test
|
||||
public void testQuery() {
|
||||
void testQuery() {
|
||||
ApexNode<?> root = parse("class Foo { void test1() { Account acc = [SELECT col FROM Account]; } }");
|
||||
ASTSoqlExpression soqlExpression = root.descendants(ASTSoqlExpression.class).firstOrThrow();
|
||||
Assert.assertEquals("SELECT col FROM Account", soqlExpression.getQuery());
|
||||
assertEquals("SELECT col FROM Account", soqlExpression.getQuery());
|
||||
}
|
||||
}
|
||||
+26
-24
@@ -4,41 +4,43 @@
|
||||
|
||||
package net.sourceforge.pmd.lang.apex.ast;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class ASTSwitchStatementTest extends ApexParserTestBase {
|
||||
class ASTSwitchStatementTest extends ApexParserTestBase {
|
||||
|
||||
@Test
|
||||
public void testExamples() {
|
||||
void testExamples() {
|
||||
ApexNode<?> node = parseResource("SwitchStatements.cls");
|
||||
List<ASTSwitchStatement> switchStatements = node.findDescendantsOfType(ASTSwitchStatement.class);
|
||||
Assert.assertEquals(4, switchStatements.size());
|
||||
assertEquals(4, switchStatements.size());
|
||||
|
||||
Assert.assertTrue(switchStatements.get(0).getChild(0) instanceof ASTVariableExpression);
|
||||
Assert.assertEquals(5, switchStatements.get(0).findChildrenOfType(ASTValueWhenBlock.class).size());
|
||||
Assert.assertEquals(3, switchStatements.get(0).findChildrenOfType(ASTValueWhenBlock.class)
|
||||
.get(1).findChildrenOfType(ASTLiteralCase.class).size());
|
||||
Assert.assertEquals(1, switchStatements.get(0).findChildrenOfType(ASTElseWhenBlock.class).size());
|
||||
assertTrue(switchStatements.get(0).getChild(0) instanceof ASTVariableExpression);
|
||||
assertEquals(5, switchStatements.get(0).findChildrenOfType(ASTValueWhenBlock.class).size());
|
||||
assertEquals(3, switchStatements.get(0).findChildrenOfType(ASTValueWhenBlock.class)
|
||||
.get(1).findChildrenOfType(ASTLiteralCase.class).size());
|
||||
assertEquals(1, switchStatements.get(0).findChildrenOfType(ASTElseWhenBlock.class).size());
|
||||
|
||||
Assert.assertTrue(switchStatements.get(1).getChild(0) instanceof ASTMethodCallExpression);
|
||||
Assert.assertEquals(2, switchStatements.get(1).findChildrenOfType(ASTValueWhenBlock.class).size());
|
||||
Assert.assertEquals(1, switchStatements.get(1).findChildrenOfType(ASTElseWhenBlock.class).size());
|
||||
assertTrue(switchStatements.get(1).getChild(0) instanceof ASTMethodCallExpression);
|
||||
assertEquals(2, switchStatements.get(1).findChildrenOfType(ASTValueWhenBlock.class).size());
|
||||
assertEquals(1, switchStatements.get(1).findChildrenOfType(ASTElseWhenBlock.class).size());
|
||||
|
||||
Assert.assertTrue(switchStatements.get(2).getChild(0) instanceof ASTVariableExpression);
|
||||
Assert.assertEquals(2, switchStatements.get(2).findChildrenOfType(ASTTypeWhenBlock.class).size());
|
||||
Assert.assertEquals("Account", switchStatements.get(2).findChildrenOfType(ASTTypeWhenBlock.class)
|
||||
.get(0).getType());
|
||||
Assert.assertEquals("a", switchStatements.get(2).findChildrenOfType(ASTTypeWhenBlock.class)
|
||||
.get(0).getName());
|
||||
Assert.assertEquals(1, switchStatements.get(2).findChildrenOfType(ASTValueWhenBlock.class).size());
|
||||
Assert.assertEquals(1, switchStatements.get(2).findChildrenOfType(ASTElseWhenBlock.class).size());
|
||||
assertTrue(switchStatements.get(2).getChild(0) instanceof ASTVariableExpression);
|
||||
assertEquals(2, switchStatements.get(2).findChildrenOfType(ASTTypeWhenBlock.class).size());
|
||||
assertEquals("Account", switchStatements.get(2).findChildrenOfType(ASTTypeWhenBlock.class)
|
||||
.get(0).getType());
|
||||
assertEquals("a", switchStatements.get(2).findChildrenOfType(ASTTypeWhenBlock.class)
|
||||
.get(0).getName());
|
||||
assertEquals(1, switchStatements.get(2).findChildrenOfType(ASTValueWhenBlock.class).size());
|
||||
assertEquals(1, switchStatements.get(2).findChildrenOfType(ASTElseWhenBlock.class).size());
|
||||
|
||||
Assert.assertTrue(switchStatements.get(3).getChild(0) instanceof ASTVariableExpression);
|
||||
Assert.assertEquals(2, switchStatements.get(3).findChildrenOfType(ASTValueWhenBlock.class).size());
|
||||
Assert.assertEquals(1, switchStatements.get(3).findChildrenOfType(ASTElseWhenBlock.class).size());
|
||||
assertTrue(switchStatements.get(3).getChild(0) instanceof ASTVariableExpression);
|
||||
assertEquals(2, switchStatements.get(3).findChildrenOfType(ASTValueWhenBlock.class).size());
|
||||
assertEquals(1, switchStatements.get(3).findChildrenOfType(ASTElseWhenBlock.class).size());
|
||||
}
|
||||
|
||||
}
|
||||
+27
-24
@@ -4,44 +4,47 @@
|
||||
|
||||
package net.sourceforge.pmd.lang.apex.ast;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
|
||||
public class ASTTryCatchFinallyBlockStatementTest extends ApexParserTestBase {
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class ASTTryCatchFinallyBlockStatementTest extends ApexParserTestBase {
|
||||
|
||||
@Test
|
||||
public void testTryFinally() {
|
||||
void testTryFinally() {
|
||||
ApexNode<?> node = parse("class Foo { void bar() { try { methodCall(); } finally { methodCall(); } } }");
|
||||
ASTTryCatchFinallyBlockStatement statement = node.getFirstDescendantOfType(ASTTryCatchFinallyBlockStatement.class);
|
||||
Assert.assertNotNull(statement.getTryBlock());
|
||||
Assert.assertEquals(0, statement.getTryBlock().getIndexInParent());
|
||||
Assert.assertNotNull(statement.getFinallyBlock());
|
||||
Assert.assertEquals(1, statement.getFinallyBlock().getIndexInParent());
|
||||
Assert.assertEquals(0, statement.getCatchClauses().size());
|
||||
assertNotNull(statement.getTryBlock());
|
||||
assertEquals(0, statement.getTryBlock().getIndexInParent());
|
||||
assertNotNull(statement.getFinallyBlock());
|
||||
assertEquals(1, statement.getFinallyBlock().getIndexInParent());
|
||||
assertEquals(0, statement.getCatchClauses().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTryCatch() {
|
||||
void testTryCatch() {
|
||||
ApexNode<?> node = parse("class Foo { void bar() { try { methodCall(); } catch (Exception e) { methodCall(); } } }");
|
||||
ASTTryCatchFinallyBlockStatement statement = node.getFirstDescendantOfType(ASTTryCatchFinallyBlockStatement.class);
|
||||
Assert.assertNotNull(statement.getTryBlock());
|
||||
Assert.assertEquals(0, statement.getTryBlock().getIndexInParent());
|
||||
Assert.assertNull(statement.getFinallyBlock());
|
||||
Assert.assertEquals(1, statement.getCatchClauses().size());
|
||||
Assert.assertNotNull(statement.getCatchClauses().get(0).getBody());
|
||||
Assert.assertEquals(1, statement.getCatchClauses().get(0).getIndexInParent());
|
||||
assertNotNull(statement.getTryBlock());
|
||||
assertEquals(0, statement.getTryBlock().getIndexInParent());
|
||||
assertNull(statement.getFinallyBlock());
|
||||
assertEquals(1, statement.getCatchClauses().size());
|
||||
assertNotNull(statement.getCatchClauses().get(0).getBody());
|
||||
assertEquals(1, statement.getCatchClauses().get(0).getIndexInParent());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTryCatchFinally() {
|
||||
void testTryCatchFinally() {
|
||||
ApexNode<?> node = parse("class Foo { void bar() { try { methodCall(); } catch (Exception e) { methodCall(); } finally { } } }");
|
||||
ASTTryCatchFinallyBlockStatement statement = node.getFirstDescendantOfType(ASTTryCatchFinallyBlockStatement.class);
|
||||
Assert.assertNotNull(statement.getTryBlock());
|
||||
Assert.assertEquals(0, statement.getTryBlock().getIndexInParent());
|
||||
Assert.assertNotNull(statement.getFinallyBlock());
|
||||
Assert.assertEquals(2, statement.getFinallyBlock().getIndexInParent());
|
||||
Assert.assertEquals(1, statement.getCatchClauses().size());
|
||||
Assert.assertNotNull(statement.getCatchClauses().get(0).getBody());
|
||||
Assert.assertEquals(1, statement.getCatchClauses().get(0).getIndexInParent());
|
||||
assertNotNull(statement.getTryBlock());
|
||||
assertEquals(0, statement.getTryBlock().getIndexInParent());
|
||||
assertNotNull(statement.getFinallyBlock());
|
||||
assertEquals(2, statement.getFinallyBlock().getIndexInParent());
|
||||
assertEquals(1, statement.getCatchClauses().size());
|
||||
assertNotNull(statement.getCatchClauses().get(0).getBody());
|
||||
assertEquals(1, statement.getCatchClauses().get(0).getIndexInParent());
|
||||
}
|
||||
}
|
||||
Loaded 30 of 745 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user