From df238b8da5ab0791723a4c027ef64f9ae6684161 Mon Sep 17 00:00:00 2001 From: lgvalle <luis.gvalle@gmail.com> Date: Thu, 30 May 2019 12:44:27 +0200 Subject: [PATCH 1/5] Fix sample code --- docs/incubating/custom-evaluator.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/incubating/custom-evaluator.md b/docs/incubating/custom-evaluator.md index 98c261c..03eb473 100644 --- a/docs/incubating/custom-evaluator.md +++ b/docs/incubating/custom-evaluator.md @@ -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 } //... From 190199d6e49d33e2d4b7c857812dac07e70db82b Mon Sep 17 00:00:00 2001 From: lgvalle <luis.gvalle@gmail.com> Date: Thu, 30 May 2019 12:44:41 +0200 Subject: [PATCH 2/5] Fix link to sourcecode --- docs/incubating/custom-evaluator.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/incubating/custom-evaluator.md b/docs/incubating/custom-evaluator.md index 03eb473..e1e9bf1 100644 --- a/docs/incubating/custom-evaluator.md +++ b/docs/incubating/custom-evaluator.md @@ -67,4 +67,4 @@ evaluator run its logic and then delegate the thresholds counting to an instance [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 From 3b3d1617e43909c48249b34109779cbe945938e8 Mon Sep 17 00:00:00 2001 From: lgvalle <luis.gvalle@gmail.com> Date: Thu, 30 May 2019 12:44:55 +0200 Subject: [PATCH 3/5] Add extended code sample --- docs/incubating/custom-evaluator.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/docs/incubating/custom-evaluator.md b/docs/incubating/custom-evaluator.md index e1e9bf1..2734375 100644 --- a/docs/incubating/custom-evaluator.md +++ b/docs/incubating/custom-evaluator.md @@ -61,6 +61,25 @@ 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 \n") + } + } +} +``` +The properties you can read from a [`Violation`][violationscode] result are: + +* `toolName`: 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. From 1641f345728fa58cd697a3d98320d69c1c5ba166 Mon Sep 17 00:00:00 2001 From: lgvalle <luis.gvalle@gmail.com> Date: Thu, 30 May 2019 15:37:22 +0200 Subject: [PATCH 4/5] Make sample cleaner --- docs/incubating/custom-evaluator.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/incubating/custom-evaluator.md b/docs/incubating/custom-evaluator.md index 2734375..767b9df 100644 --- a/docs/incubating/custom-evaluator.md +++ b/docs/incubating/custom-evaluator.md @@ -66,8 +66,8 @@ For example, this custom evaluator fails the build if PMD errors are greater tha ```gradle evaluator { Set allViolations -> allViolations.each { violation -> - if (violation.name == "PMD" && (violation.errors > 5)) { - throw new GradleException("PMD Violations exceeded \n") + if (violation.name == "PMD" && violation.errors > 5) { + throw new GradleException("PMD Violations exceeded") } } } From d3da57b7a29e7273ba37c120dde085b407778f16 Mon Sep 17 00:00:00 2001 From: lgvalle <luis.gvalle@gmail.com> Date: Thu, 30 May 2019 15:37:35 +0200 Subject: [PATCH 5/5] Replace toolName with just name --- docs/incubating/custom-evaluator.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/incubating/custom-evaluator.md b/docs/incubating/custom-evaluator.md index 767b9df..18bc3af 100644 --- a/docs/incubating/custom-evaluator.md +++ b/docs/incubating/custom-evaluator.md @@ -74,7 +74,7 @@ evaluator { Set allViolations -> ``` The properties you can read from a [`Violation`][violationscode] result are: -* `toolName`: Possible values are: `"PMD"`, `"Checkstyle"`, `"Findbugs"`, `"KTlint"`, `"Detekt"` and `"Lint"`. +* `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.