diff --git a/README.md b/README.md index c0bb0f4..4c0073b 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # Gradle static analysis plugin -[![](https://ci.novoda.com/buildStatus/icon?job=gradle-static-analysis-plugin)](https://ci.novoda.com/job/gradle-static-analysis-plugin/lastSuccessfulBuild) [![](https://img.shields.io/badge/License-Apache%202.0-lightgrey.svg)](LICENSE.txt) [![Bintray](https://api.bintray.com/packages/novoda/maven/gradle-static-analysis-plugin/images/download.svg)](https://bintray.com/novoda-oss/maven/gradle-static-analysis-plugin/_latestVersion) +[![](https://ci.novoda.com/buildStatus/icon?job=gradle-static-analysis-plugin)](https://ci.novoda.com/job/gradle-static-analysis-plugin/lastSuccessfulBuild) [![](https://img.shields.io/badge/License-Apache%202.0-lightgrey.svg)](LICENSE.txt) [![Bintray](https://api.bintray.com/packages/novoda-oss/maven/gradle-static-analysis-plugin/images/download.svg)](https://bintray.com/novoda-oss/maven/gradle-static-analysis-plugin/_latestVersion) A Gradle plugin to easily apply the same setup of static analysis tools across different Android, Java or Kotlin projects. @@ -32,7 +32,7 @@ Please note that the tools availability depends on the project the plugin is app ### Tools in-consideration * `Spotbugs` [#142](https://github.com/novoda/gradle-static-analysis-plugin/issues/142) - * `CPD (Duplicate Code Detection) ` [#150](https://github.com/novoda/gradle-static-analysis-plugin/iss (Duplicate Code Detection) ues/150) + * `CPD (Duplicate Code Detection) ` [#150](https://github.com/novoda/gradle-static-analysis-plugin/issues/150) * `error-prone` [#151](https://github.com/novoda/gradle-static-analysis-plugin/issues/151) * `Jetbrains IDEA Inspections` [#152](https://github.com/novoda/gradle-static-analysis-plugin/issues/152) @@ -85,7 +85,7 @@ staticAnalysis { } ``` -This will enable all the tools with their default settings. For more advanced configurations, please refer to the +This will enable all the tools with their default settings and create `evaluateViolations` task. Running `./gradlew evaluateViolations` task will run all configured tools and print the reports to console. For more advanced configurations, please refer to the [advanced usage](docs/advanced-usage.md) and to the [supported tools](docs/supported-tools.md) pages. ## Sample app @@ -107,6 +107,7 @@ repositories { You can find the latest snapshot version following this [link](https://bintray.com/novoda-oss/snapshots/gradle-static-analysis-plugin/_latestVersion). ## Roadmap + This project is routinely used by many Novoda projects and by other external projects with no known critical issues. Future improvements and new tool integrations can be found on the repository's diff --git a/docs/incubating/custom-evaluator.md b/docs/incubating/custom-evaluator.md index 98c261c..18bc3af 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 allViolations -> + evaluator { Set allViolations -> // add your evaluation logic here } //... @@ -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