Skip to content
This repository has been archived by the owner on Feb 11, 2022. It is now read-only.

Docs/Update custom evaluator sample #194

Merged
merged 5 commits into from
May 30, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions docs/incubating/custom-evaluator.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ can be provided as a closure as well:

```gradle
staticAnalysis {
evaluator { Set<Violations> allViolations ->
evaluator { Set allViolations ->
// add your evaluation logic here
}
//...
Expand All @@ -61,10 +61,29 @@ Anything that respect such contract is valid. For example, a custom evaluator mi
* Only break the build if there are errors or warnings in one specific report
* Or anything else that you can think of

For example, this custom evaluator fails the build if PMD errors are greater than five:

```gradle
evaluator { Set allViolations ->
allViolations.each { violation ->
if (violation.name == "PMD" && violation.errors > 5) {
throw new GradleException("PMD Violations exceeded")
}
}
}
```
The properties you can read from a [`Violation`][violationscode] result are:

* `name`: Possible values are: `"PMD"`, `"Checkstyle"`, `"Findbugs"`, `"KTlint"`, `"Detekt"` and `"Lint"`.
* `errors`: Represents the number of errors found during the analysis.
* `warnings`: Represents the number of warnings found during the analysis.
* `reports`: Contains a list of the generated report files.

---
Please note that the presence of an `evaluator` property will make the plugin ignore the `penalty` closure and its thresholds. If you
want to provide behaviour on top of the default [`DefaultViolationsEvaluator`][defaultviolationsevaluatorcode], you can have your own
evaluator run its logic and then delegate the thresholds counting to an instance of `DefaultViolationsEvaluator` you create.

[violationsevaluatorcode]: https://github.com/novoda/gradle-static-analysis-plugin/blob/master/plugin/src/main/groovy/com/novoda/staticanalysis/ViolationsEvaluator.groovy
[defaultviolationsevaluatorcode]: https://github.com/novoda/gradle-static-analysis-plugin/blob/master/plugin/src/main/groovy/com/novoda/staticanalysis/DefaultViolationsEvaluator.groovy
[violationscode]: https://github.com/novoda/gradle-static-analysis-plugin/blob/master/plugin/src/main/groovy/com/novoda/staticanalysis/internal/Violations.groovy
[violationscode]: https://github.com/novoda/gradle-static-analysis-plugin/blob/master/plugin/src/main/groovy/com/novoda/staticanalysis/Violations.groovy