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
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.
8
+
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.
9
9
It is especially designed for openHAB to respect the defined coding guidelines.
10
10
11
11
This project contains:
12
12
13
-
- properties files for the PMD, Checkstyle and FindBugs Maven plugins configuration in the `src/main/resources/configuration` folder;
14
-
- rule sets for the plugins in the `src/main/resources/rulesets` folder;
15
-
- custom rules for PMD, CheckStyle and FindBugs and unit tests for the rules;
13
+
- properties files for the PMD, Checkstyle and SpotBugs Maven plugins configuration in the `sat-plugin/src/main/resources/configuration` folder;
14
+
- rule sets for the plugins in the `sat-plugin/src/main/resources/rulesets` folder;
15
+
- custom rules for PMD, CheckStyle and SpotBugs and unit tests for the rules;
16
16
- tool that merges the reports from the individual plugins in a summary report.
17
17
18
18
## Essentials
@@ -23,5 +23,5 @@ This project contains:
23
23
24
24
## 3rd Party
25
25
26
-
- The example checks provided in the `static-code-analysis-config` (`MethodLimitCheck`, `CustomClassNameLengthDetector`, `WhileLoopsMustUseBracesRule`) are based on tutorials how to use the API of Checkstyle, FindBugs and PMD. For more info, see javadoc;
26
+
- The example checks provided in the `static-code-analysis-config` (`MethodLimitCheck`, `CustomClassNameLengthDetector`, `WhileLoopsMustUseBracesRule`) are based on tutorials how to use the API of Checkstyle, SpotBugs and PMD. For more info, see javadoc;
27
27
- The tool that merges the individual reports is based completely on source files from the https://github.com/MarkusSprunck/static-code-analysis-report that are distributed under a custom license. More information can be found in the [LICENSE](LICENSE) file.
Copy file name to clipboardExpand all lines: docs/implement-check.md
+19-11Lines changed: 19 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,20 +1,22 @@
1
1
# Integrating Custom Check Into The Tool
2
2
3
-
The Static Analysis Tool provides the necessary infrastructure for custom check implementations using the API of FindBugs, Checkstyle and PMD.
3
+
The Static Analysis Tool provides the necessary infrastructure for custom check implementations using the API of SpotBugs, Checkstyle and PMD.
4
4
5
5
Helpful links when writing a custom check for the first time may be:
6
6
7
-
- for [Writing custom checks in Checkstyle](http://checkstyle.sourceforge.net/writingchecks.html#Writing_Checks);
8
-
- for [Writing a custom PDM rule](http://pmd.sourceforge.net/pmd-4.3.0/howtowritearule.html);
9
-
- for [Writing custom bug detectors for Findbugs](https://www.ibm.com/developerworks/library/j-findbug2/).
7
+
- for [Writing custom checks in Checkstyle](https://checkstyle.sourceforge.io/writingchecks.html#Writing_Checks);
8
+
- for [Writing a custom PMD rule](https://pmd.github.io/latest/pmd_userdocs_extending_writing_rules_intro.html);
9
+
- for [Writing custom bug detectors for SpotBugs](https://spotbugs.readthedocs.io/en/stable/implement-plugin.html).
10
10
11
11
In this guide we will use the Checkstyle API, because it is easy to use, supports different file extensions and languages.
12
12
13
-
If you haven't set up the IDE for openHAB, please visit the [openHAB IDE Setup page](https://www.openhab.org/docs/developer/development/ide.html).
13
+
If you haven't set up the IDE for openHAB, please visit the [openHAB IDE Setup page](https://www.openhab.org/docs/developer/#setup-the-development-environment).
14
14
15
15
## Create an Eclipse project
16
16
17
-
After checking out the repository on your local machine execute `mvn eclipse:eclipse` in project root directory. This will generate an Eclipse project, containing the `.classpath` and `.project` files. You are ready to import the project in Eclipse.
17
+
After checking out the repository on your local machine execute `mvn eclipse:eclipse` in project root directory.
18
+
This will generate an Eclipse project, containing the `.classpath` and `.project` files.
19
+
You are ready to import the project in Eclipse.
18
20
19
21
>Hint! Depending on your Java installation the static-code-analysis project might not find tools.jar. Please make sure that the folder containing the tools.jar is included in the PATH variable (for Windows) and rerun mvn eclipse:eclipse.
20
22
@@ -26,11 +28,13 @@ The first answer that you would have to answer before staring is what kind of fi
26
28
- for **none .java** files extend the `org.openhab.tools.analysis.checkstyle.api.AbstractStaticCheck`. We have included there some helpful methods for processing different types of files and others, take a look at the javadoc for detailed information;
27
29
- for **.java** files you will most probably have to extend `com.puppycrawl.tools.checkstyle.api.AbstractCheck`.
28
30
29
-
And once again, please refer to the [Checkstyle documentation for writing a check](http://checkstyle.sourceforge.net/writingchecks.html), if you haven't.
31
+
And once again, please refer to the [Checkstyle documentation for writing a check](https://checkstyle.sourceforge.io/writingchecks.html), if you haven't.
30
32
31
33
## Include Checks In The Ruleset
32
34
33
-
The next step is to integrate your check into the tool. You will have to add it to the ruleset. The ruleset location for Checkstyle is in the `src/main/resources/rulesets/checkstyle` folder.
35
+
The next step is to integrate your check into the tool.
36
+
You will have to add it to the ruleset.
37
+
The ruleset location for Checkstyle is in the `sat-plugin/src/main/resources/rulesets/checkstyle` folder.
34
38
35
39
You will have to consider several things before adding your check there.
36
40
@@ -56,13 +60,17 @@ In order to test your check the testing framework expects that you provide an ex
56
60
57
61
## [Optional] Execute The Check On openHAB Addons Repository
58
62
59
-
We would highly recommend this step. The static code analysis tool is used in the `openhab2-addons` build.
63
+
We would highly recommend this step.
64
+
The static code analysis tool is used in the `openhab-addons` build.
60
65
61
-
This is a two step process. Firstly execute `mvn clean install` from the root of the `static-code-analysis` repository. This will install the artifact into your local Maven repository. Please note that this is a snapshot version (e.g. x.y.z-SNAPSHOT, where x.y.z is the current Major.Minor.Patch version or at the moment of writing 0.1.0).
66
+
This is a two step process.
67
+
Firstly execute `mvn clean install` from the root of the `static-code-analysis` repository.
68
+
This will install the artifact into your local Maven repository.
69
+
Please note that this is a snapshot version (e.g. x.y.z-SNAPSHOT, where x.y.z is the current Major.Minor.Patch version or at the moment of writing 0.12.0).
62
70
63
71
The second step is to execute `mvn clean install -Dsat.version=x.y.z-SNAPSHOT` from the root of the `openhab2-addons` repository.
64
72
65
-
Take a look at the log as it is described in the [openHAB documentation](https://www.openhab.org/docs/developer/development/bindings.html#static-code-analysis).
73
+
Take a look at the log as it is described in the [openHAB documentation](https://www.openhab.org/docs/developer/guidelines.html#static-code-analysis).
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:
61
+
The build will fail if a problem with high priority is found by some of the Maven plugins for PMD, Checkstyle and SpotBugs.
62
+
Each of the plugins has its own way to prioritize the detected problems:
62
63
63
64
- for PMD - the build will fail when a rule with Priority "1" is found;
64
65
- for Checkstyle - a rule with severity="Error";
@@ -139,9 +140,11 @@ Parameters:
139
140
140
141
Different sets of checks can be executed on different types of projects.
141
142
142
-
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`.
143
+
The tool executes different checks on OSGi bundles and openHAB add-ons.
144
+
It uses default configuration files for SpotBugs, Checkstyle and PMD that are stored in `sat-plugin/src/main/resources/configuration`.
143
145
144
-
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;
146
+
If you want to use a custom set of rules you will have to set the configuration parameters for the individual MOJOs.
147
+
An example configuration may look like this;
145
148
146
149
```
147
150
<plugin>
@@ -173,12 +176,12 @@ The `visitors.xml` contains a list with SpotBugs visitors (bug detectors) and ha
173
176
174
177
### Individual plugin customization
175
178
176
-
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.
179
+
Each of the Maven plugins that are used (for SpotBugs, Checkstyle and PMD) are configured by setting user properties that are located in the `sat-plugin/src/main/resources/configuration` directory.
177
180
178
181
You can refer to the following links for more configuration options for the specific Maven plugins:
0 commit comments