Skip to content

Commit

Permalink
Update to spotbugs-maven-plugin 3.1.1
Browse files Browse the repository at this point in the history
Includes also:
- change the spotbugs-maven-plugin to the official fork;
- update the namespace of the properties;
- rename all files that were using FindBugs to SpotBugs;
- update the documentation.

Signed-off-by: Svilen Valkanov <svilen.valkanov@musala.com>
  • Loading branch information
Svilen Valkanov committed Feb 7, 2018
1 parent 64df093 commit b453e9b
Show file tree
Hide file tree
Showing 8 changed files with 92 additions and 93 deletions.
48 changes: 23 additions & 25 deletions docs/maven-plugin.md
@@ -1,6 +1,6 @@
# Usage

The Static Code Analysis Tools is a Maven plugin that executes the Maven plugins for FindBugs, Checkstyle and PMD and generates a merged .html report.
The Static Code Analysis Tools is a Maven plugin that executes the Maven plugins for SpotBugs, Checkstyle and PMD and generates a merged .html report.

Add the following profiles to your pom.xml:

Expand All @@ -20,7 +20,7 @@ Add the following profiles to your pom.xml:
<goals>
<goal>checkstyle</goal>
<goal>pmd</goal>
<goal>findbugs</goal>
<goal>spotbugs</goal>
<goal>report</goal>
</goals>
</execution>
Expand Down Expand Up @@ -58,19 +58,19 @@ The summary report can be found in the root target directory:

![Summary report](images/summary-report.PNG "Summary-report")

The build will fail if a problem with high priority is found by some of the Maven plugins for PMD, Checkstyle and FindBugs. Each of the plugins has its own way to prioritize the detected problems:
The build will fail if a problem with high priority is found by some of the Maven plugins for PMD, Checkstyle and SpotBugs. Each of the plugins has its own way to prioritize the detected problems:

- for PMD - the build will fail when a rule with Priority "1" is found;
- for Checkstyle - a rule with severity="Error";
- for Findbugs - any Matcher with Rank between 1 and 4.
- for SpotBugs - any Matcher with Rank between 1 and 4.

## Maven plugin goals and parameters

The Static Analysis tool includes several goals:

- [pmd](#sat-pluginpmd);
- [checkstyle](#sat-plugincheckstyle);
- [findbugs](#sat-pluginfindbugs);
- [spotbugs](#sat-pluginspotbugs);
- [report](#sat-pluginreport).

Below you can find detailed information what each goal does and how it can be configured.
Expand Down Expand Up @@ -103,27 +103,27 @@ Parameters:
| **checkstylePlugins** | List<Dependency> | A list with artifacts that contain additional checks for Checkstyle |
| **checkstyleProperties** | String | Relative path of the properties file to use in the ruleset to configure specific checks |

### sat-plugin:findbugs
### sat-plugin:spotbugs

Description:
Executes the `spotbugs-maven-plugin` goal `findbugs` with a ruleset file and configuration properties
Executes the `spotbugs-maven-plugin` goal `spotbugs` with a ruleset file and configuration properties

Parameters:

| Name | Type| Description |
| ------ | ------| -------- |
| **findbugsRuleset** | String | Relative path to the XML that specifies the bug detectors which should be run. If not set the default file will be used|
| **findbugsInclude** | String | Relative path to the XML that specifies the bug instances that will be included in the report. If not set the default file will be used|
| **findbugsExclude** | String | Relative path to the XML that specifies the bug instances that will be excluded from the report. If not set the default file will be used|
| **maven.spotbugs.version** | String | The version of the spotbugs-maven-plugin that will be used (default value is **3.0.6**)|
| **spotbugs.version** | String | The version of SpotBugs that will be used (default value is **3.1.0-RC3**)|
| **findbugsPlugins** | List<Dependency> | A list with artifacts that contain additional detectors/patterns for FindBugs |
| **spotbugsRuleset** | String | Relative path to the XML that specifies the bug detectors which should be run. If not set the default file will be used|
| **spotbugsInclude** | String | Relative path to the XML that specifies the bug instances that will be included in the report. If not set the default file will be used|
| **spotbugsExclude** | String | Relative path to the XML that specifies the bug instances that will be excluded from the report. If not set the default file will be used|
| **maven.spotbugs.version** | String | The version of the spotbugs-maven-plugin that will be used (default value is **3.1.1**)|
| **spotbugs.version** | String | The version of SpotBugs that will be used (default value is **3.1.1**)|
| **spotbugsPlugins** | List<Dependency> | A list with artifacts that contain additional detectors/patterns for SpotBugs |
| **findbugs.slf4j.version** | String | The version of the findbugs-slf4j plugin that will be used (default value is **1.2.4**)|

### sat-plugin:report

Description:
Transforms the results from FindBugs, Checkstyle and PMD into a single HTML Report with XSLT
Transforms the results from SpotBugs, Checkstyle and PMD into a single HTML Report with XSLT

Parameters:

Expand All @@ -138,7 +138,7 @@ Parameters:

Different sets of checks can be executed on different types of projects.

The tool executes different checks on OSGi bundles and ESH Bindings. It uses default configuration files for FindBugs, Checkstyle and PMD that are stored in the `src/main/resources/configuration`.
The tool executes different checks on OSGi bundles and ESH Bindings. It uses default configuration files for SpotBugs, Checkstyle and PMD that are stored in the `src/main/resources/configuration`.

If you want to use a custom set of rules you will have to set the configuration parameters for the individual MOJOs. An example configuration may look like this;

Expand All @@ -150,16 +150,16 @@ If you want to use a custom set of rules you will have to set the configuration
<checkstyleRuleset>build-tools/checkstyle/binding.xml</checkstyleRuleset>
<checkstyleFilter>build-tools/checkstyle/suppressions.xml</checkstyleFilter>
<pmdRuleset>build-tools/pmd/binding.xml</pmdRuleset>
<findbugsInclude>build-tools/findbugs/binding.xml</findbugsInclude>
<findbugsExclude>build-tools/findbugs/exclude.xml</findbugsExclude>
<findbugsRuleset>build-tools/findbugs/visitors.xml</findbugsRuleset>
<spotbugsInclude>build-tools/spotbugs/binding.xml</spotbugsInclude>
<spotbugsExclude>build-tools/spotbugs/exclude.xml</spotbugsExclude>
<spotbugsRuleset>build-tools/spotbugs/visitors.xml</spotbugsRuleset>
</configuration>
</plugin>
```

Information about the syntax of the configuration files (except the `visitors.xml`) can be found on the web pages of the individual plugins.

The `visitors.xml` contains a list with FindBugs visitors (bug detectors) and has the following syntax:
The `visitors.xml` contains a list with SpotBugs visitors (bug detectors) and has the following syntax:

```
<?xml version="1.0" encoding="UTF-8"?>
Expand All @@ -171,22 +171,20 @@ The `visitors.xml` contains a list with FindBugs visitors (bug detectors) and ha

### Individual plugin customization

Each of the Maven plugins that are used (for FindBugs, Checkstyle and PMD) are configured by setting user properties that are located in the `src/main/resources/configuration` directory.
Each of the Maven plugins that are used (for SpotBugs, Checkstyle and PMD) are configured by setting user properties that are located in the `src/main/resources/configuration` directory.

You can refer to the following links for more configuration options for the specific Maven plugins:

- https://maven.apache.org/plugins/maven-pmd-plugin/check-mojo.html;
- https://maven.apache.org/plugins-archives/maven-checkstyle-plugin-2.16/checkstyle-mojo.html;
- http://gleclaire.github.io/findbugs-maven-plugin/check-mojo.html.
- https://spotbugs.github.io/spotbugs-maven-plugin/spotbugs-mojo.html.

## Reuse Checks

PMD, Checkstyle and FindBugs come with a set of custom rules that can be used directly in a rule set.
PMD, Checkstyle and SpotBugs come with a set of custom rules that can be used directly in a rule set.

Helpful resources with lists of the available checks and information how to use them:

- for PMD - https://pmd.github.io/pmd-5.4.0/pmd-java/rules/index.html;
- for Checkstyle - http://checkstyle.sourceforge.net/checks.html;
- for FindBugs - Keep in mind that the process for adding a check in FindBugs contains two steps:
- First you should open the link with [BugDescriptors](http://findbugs.sourceforge.net/bugDescriptions.html), choose the bug that you want to detect and create a Match in `src/main/resources/rulesets/findbugs/YOUR_RULESET`;
- Next you should find the Detector that finds the Bug that you have selected above (you can use [this list](https://github.com/findbugsproject/findbugs/blob/d1e60f8dbeda0a454f2d497ef8dcb878fa8e3852/findbugs/etc/findbugs.xml)) and add the Detector in the `src/main/resources/configuration/findbugs.properties` under the property `visitors`.
- for SpotBugs - http://spotbugs.readthedocs.io/en/latest/implement-plugin.html.

0 comments on commit b453e9b

Please sign in to comment.