Skip to content

Commit 5619db1

Browse files
Merge pull request #82 from BorderTech/feature/generated
Default QA plugins to ignore generated source
2 parents 9c56958 + 2709f1f commit 5619db1

File tree

4 files changed

+59
-0
lines changed

4 files changed

+59
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Change log
22

33
## Release in-progress
4+
* Default QA plugins to ignore generated code #61
45
* Update OWASP plugin skip property default to use bt.qa.skip #79
56
* Move enforcer convergence check into verify phase. Can be skipped using bt.convergence.check.skip=true property. #78
67
* Move versions-maven-plugin into a profile display-versions to allow projects to opt in or out #74

README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,32 @@ By default qa checks (i.e. Checkstyle, PMD, Spotbugs, OWASP, Convergence Check)
151151
</property>
152152
```
153153

154+
#### Generated Sources
155+
156+
By default, qa-parent configures the code analysis plugins to ignore generated source code and only analyse the project's main source directory.
157+
158+
The following properties are set in qa-parent for Checkstyle and PMD:
159+
160+
``` xml
161+
<property>
162+
<bt.checkstyle.src>${project.build.sourceDirectory}</bt.checkstyle.src>
163+
<bt.pmd.src>${project.build.sourceDirectory}</bt.pmd.src>
164+
</property>
165+
```
166+
167+
Spotbugs is different from Checkstyle and PMD as it requires an exclude filter to be configured to ignore generated files.
168+
169+
The following properties are set in qa-parent for Spotbugs:
170+
171+
``` xml
172+
<property>
173+
<!-- Exclude files in the generated-sources directory -->
174+
<spotbugs.excludeFilterFile>bordertech/bt-spotbugs-exclude-generated-files.xml</spotbugs.excludeFilterFile>
175+
<!-- Need to add sources for source tag in exclude and include filters to work -->
176+
<spotbugs.addSourceDirs>true</spotbugs.addSourceDirs>
177+
</property>
178+
```
179+
154180
#### Checkstyle
155181

156182
Refer to [Checkstyle plugin](https://maven.apache.org/plugins/maven-checkstyle-plugin) for all override details.
@@ -289,6 +315,16 @@ Example filter file:-
289315
</FindBugsFilter>
290316
```
291317

318+
When adding a custom exclude filter and the module still needs to ignore generated source, then merge the excludes used in the default filter [bt-spotbugs-exclude-generated-files](https://github.com/BorderTech/java-common/blob/master/build-tools/src/main/resources/bordertech/bt-spotbugs-exclude-generated-files.xml):
319+
320+
```
321+
<FindBugsFilter>
322+
<!-- Exclude files in the generated-sources directory. For the source tag to work with the full path of the source files the addSourceDirs property on the plugin must be set to true. -->
323+
<Match>
324+
<Source name="~.*generated-sources.*" />
325+
</Match>
326+
</FindBugsFilter>```
327+
292328
#### OWASP
293329
294330
Refer to [OWASP plugin](https://jeremylong.github.io/DependencyCheck/dependency-check-maven) for all override details.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<FindBugsFilter>
3+
<!-- Exclude files in the generated-sources directory. For the source tag to work with the full path of the source files the addSourceDirs property on the plugin must be set to true. -->
4+
<Match>
5+
<Source name="~.*generated-sources.*" />
6+
</Match>
7+
</FindBugsFilter>

qa-parent/pom.xml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
<!-- Checkstyle -->
3232
<!-- Config file -->
3333
<checkstyle.config.location>bordertech/bt-checkstyle.xml</checkstyle.config.location>
34+
<!-- Override default to only use main src (ignore generated) -->
35+
<bt.checkstyle.src>${project.build.sourceDirectory}</bt.checkstyle.src>
3436
<!-- PMD -->
3537
<pmd.printFailingErrors>true</pmd.printFailingErrors>
3638
<!-- Priority: 1 (High) - 5 (Low) -->
@@ -39,6 +41,8 @@
3941
<pmd.verbose>true</pmd.verbose>
4042
<!-- Rules file -->
4143
<bt.pmd.rules.file>bordertech/bt-pmd-rules.xml</bt.pmd.rules.file>
44+
<!-- Override default to only use main src (ignore generated) -->
45+
<bt.pmd.src>${project.build.sourceDirectory}</bt.pmd.src>
4246
<!-- CPD (Default to report only) -->
4347
<cpd.failOnViolation>false</cpd.failOnViolation>
4448

@@ -49,6 +53,11 @@
4953
<spotbugs.threshold>Medium</spotbugs.threshold>
5054
<!-- Rank: Scariest (1-4), Scary (5-9), Troubling (10-14), Of concern (15-20) -->
5155
<spotbugs.maxRank>14</spotbugs.maxRank>
56+
<!-- To ignore generated files Spotbugs is different from checkstyle and PMD as it requires an exclude filter to be configured. -->
57+
<!-- Exclude files in the generated-sources directory -->
58+
<spotbugs.excludeFilterFile>bordertech/bt-spotbugs-exclude-generated-files.xml</spotbugs.excludeFilterFile>
59+
<!-- Need to add sources for source tag in exclude and include filters to work -->
60+
<spotbugs.addSourceDirs>true</spotbugs.addSourceDirs>
5261

5362
<!-- OWASP (Default to Critical) -->
5463
<!-- Check every 12 hours (default is 4) -->
@@ -199,6 +208,11 @@
199208
<groupId>org.apache.maven.plugins</groupId>
200209
<artifactId>maven-checkstyle-plugin</artifactId>
201210
<version>${bt.checkstyle.plugin.version}</version>
211+
<configuration>
212+
<sourceDirectories>
213+
<sourceDirectory>${bt.checkstyle.src}</sourceDirectory>
214+
</sourceDirectories>
215+
</configuration>
202216
<dependencies>
203217
<!-- Latest checkstyle version -->
204218
<dependency>
@@ -233,6 +247,7 @@
233247
<rulesets>
234248
<ruleset>${bt.pmd.rules.file}</ruleset>
235249
</rulesets>
250+
<compileSourceRoots>${bt.pmd.src}</compileSourceRoots>
236251
</configuration>
237252
<dependencies>
238253
<!-- Latest pmd version -->

0 commit comments

Comments
 (0)