You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/pages/pmd/userdocs/installation.md
+24-18Lines changed: 24 additions & 18 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -35,24 +35,36 @@ Unzip it into any directory, optionally add the `bin` subdirectory in your `PATH
35
35
the arguments are specific to the utility used.<br/><br/>
36
36
On Windows, each utility has its own startup script, e.g. `pmd.bat`, `cpd.bat`." %}
37
37
38
-
The PMD command (`pmd.bat` or `run.sh pmd`) requires three options:
38
+
The PMD command (`pmd.bat` or `run.sh pmd`) requires two options:
39
39
40
-
*`-d <path>`: path to the sources to analyse. This can be a file name, a directory or a jar or zip file containing the
40
+
*`-d <path>`: path to the sources to analyse. This can be a file name, a directory, or a jar or zip file containing the
41
41
sources.
42
-
*`-f <format>`: report format. PMD supports many report formats out of the box, you may want to start with the basic
43
-
`text`
44
-
format or `xml` format.
45
42
*`-R <path>`: the ruleset file you want to use. PMD uses xml configuration files, called *rulesets*, which specify
46
-
which rules to check for in your sources. PMD provides standard rulesets for each language it supports, grouping the
47
-
rules by theme. Instead of a path, you can reference those standard rulesets with the lightweight syntax
48
-
`rulesets/<lang>/<name.xml>`, e .g. `rulesets/java/codesize.xml`.
43
+
which rules to execute on your sources. You can also run a single rule by referencing it using its *category* and
44
+
name (more details [here](pmd_userdocs_making_rulesets.html#referencing-rules)). For example, you can check for unnecessary
45
+
modifiers on Java sources with `-R category/java/codestyle.xml/UnnecessaryModifier`.
49
46
50
47
{% include note.html
51
-
content="At the moment most of the formerly provided rulesets are deprecated, though you can still use them. PMD
52
-
will soon propose updated rulesets to use as default configurations." %}
48
+
content="At the moment the formerly provided rulesets (eg `rulesets/java/basic.xml`) are deprecated,
49
+
though you can still use them. PMD will soon include standard rulesets as default configurations,
50
+
but you're strongly encouraged to [create your own ruleset](pmd_userdocs_making_rulesets.html) from
51
+
the start." %}
53
52
53
+
Additionnally, the following options, are specified most of the time even though they're not required:
54
+
*`-f <format>`: report format. PMD supports many report formats out of the box, you may want to start with the basic
55
+
`text` format or `xml` format.
56
+
*`-auxclasspath <classpath>`: class path containing the compiled class files of the analysed Java sources, if any.
57
+
Setting this up correctly allows PMD to do much deeper analysis using reflection. Some rules, such as [MissingOverride](http://localhost:4005/pmd_rules_java_bestpractices.html#missingoverride),
58
+
require it to function properly.
59
+
60
+
{%include tip.html content="A full CLI reference, including report formats, is available under [PMD CLI Reference](pmd_userdocs_cli_reference.html)" %}
61
+
62
+
63
+
64
+
### Sample usage
65
+
66
+
The following shows a sample run of with the `text` format:
54
67
55
-
Sample usage with the `text` format:
56
68
57
69
<divclass="text-left">
58
70
<ulclass="nav nav-tabs"role="tablist">
@@ -82,13 +94,7 @@ Sample usage with the `text` format:
Say you want to pick specific rules from various rule sets and customize them. You can do this by making your own rule set.
19
+
The first step is to create a new empty ruleset. You can use the following template:
13
20
14
-
## Create a new ruleset.xml file
21
+
```xml
22
+
<?xml version="1.0"?>
15
23
16
-
Use one of the current rulesets as an example. Copy and paste it into your new file, delete all the old rules from it, and change the name and description. Like this:
After you add these references it’ll look something like this:
41
+
<!-- TODO this could be better explained, eg first explain how a ruleset reference works, then rule reference, then go on showing single rule & bulk addition, then include/exclude patterns -->
<description>All codestyle rules, but with just the braces rules I like</description>
85
81
<ruleref="category/java/codestyle.xml">
86
82
<excludename="WhileLoopsMustUseBraces"/>
87
83
<excludename="IfElseStmtsMustUseBraces"/>
88
84
</rule>
89
-
</ruleset>
90
85
```
91
86
92
-
## Excluding files from a ruleset
87
+
Here, the `ref` attribute references a whole category. You can also use a file system path or classpath relative path. In any case, the path must address an accessible ruleset XML file.
88
+
89
+
{% include note.html content="Path separators in the source file path are normalized to be the `/` character within PMD, so the same ruleset can be used on multiple platforms transparently." %}
93
90
94
-
You can also exclude certain files from being processed by a ruleset using exclude patterns, with an optional overriding include pattern. A file will be excluded from processing when there is a matching exclude pattern, but no matching include pattern. Path separators in the source file path are normalized to be the ‘/’ character, so the same ruleset can be used on multiple platforms transparently. Additionally, this exclude/include technique works regardless of how PMD is used (e.g. command line, IDE, Ant), making it easier to keep application of your PMD rules consistent throughout your environment. Here is an example:
91
+
### Filtering the processed files
92
+
93
+
You can exclude some files from being processed by a ruleset using **exclude patterns**, with an optional overridding **include pattern**. A file will be excluded from processing *when there is a matching exclude pattern, but no matching include pattern*. This exclude/include technique works regardless of how PMD is used (e.g. command line, IDE, Ant), making it easier to keep application of your PMD rules consistent throughout your environment. Here is an example:
95
94
96
95
```xml
97
96
<?xml version="1.0"?>
@@ -100,32 +99,12 @@ You can also exclude certain files from being processed by a ruleset using exclu
0 commit comments