A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://docs.pmd-code.org/latest/pmd_userdocs_installation.html below:

Installation and basic CLI usage

Sums up the first steps to set up a CLI installation and get started using PMD

Table of Contents How to install PMD and CPD Requirements

Note: For executing the Designer (pmd designer) using OpenJDK or Java 11+, you need additionally JavaFX. Download it, extract it and set the environment variable JAVAFX_HOME pointing at that directory.

Installation

PMD is distributed as a zip archive, which includes both PMD and CPD. You can download the latest binary distribution from the github releases page.

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 <(pmd generate-completion) to your ~/.bashrc / ~/.zshrc file.

Running PMD via command line

PMD comes with several command line utilities, like CPD, the rule designer or PMD itself. 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 (‘check’, ‘designer’, …), e.g. PMD is launched via

pmd check

. The rest of the arguments are specific to the utility used.

Running a PMD analysis (pmd check or pmd.bat check) requires at least one option and a list of sources:

Note: At the moment the formerly provided rulesets (eg rulesets/java/basic.xml) are deprecated, though you can still use them. PMD includes a quickstart ruleset for some languages (currently, Java) as base configurations, which you can reference as e.g. rulesets/java/quickstart.xml. You’re strongly encouraged to create your own ruleset from the start though.

Additionally, the following options, are specified most of the time even though they’re not required:

Tip:

A full CLI reference, including report formats, is available under

PMD CLI Reference Sample usage

The following shows a sample run of PMD with the text format:

~ $ pmd 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
C:\> 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
Running CPD via command line

Note: CPD supports Java, JSP, C, C++, C#, Fortran and PHP source code, among other languages. For the full list, see Supported Languages.

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:

Tip:

CPD’s command-line reference, Ant task usage, and many examples are documented in the

CPD documentation page Sample usage

The following shows a sample run of CPD with the text format:

~ $ 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
Starting at line 586 of /home/me/src/test/java/foo/FooTypeTest.java

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());
assertEquals(Boolean.TYPE, expressions.get(index++).getType());
assertEquals(Boolean.TYPE, expressions.get(index++).getType());
assertEquals(Boolean.TYPE, expressions.get(index++).getType());
C:\> pmd.bat cpd --minimum-tokens 100 c:\temp\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
Starting at line 586 of c:\temp\src\test\java\foo\FooTypeTest.java

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());
assertEquals(Boolean.TYPE, expressions.get(index++).getType());
assertEquals(Boolean.TYPE, expressions.get(index++).getType());
assertEquals(Boolean.TYPE, expressions.get(index++).getType());

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4