novoda / gradle-static-analysis-plugin

Easy setup of static analysis tools for Android and Java projects.
Apache License 2.0
410 stars 28 forks source link

Is it possible to allow warnings from one analysis tool, but not others #226

Closed stealthrabbi closed 4 years ago

stealthrabbi commented 4 years ago

e.g. allow warnings in Android Linter, but not SpotBugs

tasomaniac commented 4 years ago

Hi, you can do this by 2 possible ways

stealthrabbi commented 4 years ago

OK thanks. And sorry if "issues" are not the right way to ask this, but I saw no other way.

So I (temporarily) want to cause builds to fail if there are any warnings or errors in PMD, spotbugs, or checkstyles. And I want it to fail if there are any Errors in Android Lint (warnings are OK).

So perhas a custom validator like so? I assume that if I fail to configure the evaluator correctly, the gradle task itself will fail to run.

evaluator { Set allViolations ->
    allViolations.each { violation ->
        // an error from any analyzer should fail the build
        if (violation.errors > 0) {
            throw new GradleException("Static Analysis errors reported")
        } else if (violation.name != "Lint" && violations.warnings > 0) {
            // do not allow warnings, unless it's android lint
            throw new GradleException("non-Lint Static Analysis warnings have reported")
        }
    }
}
tasomaniac commented 4 years ago

No problem at all. Let us know if this works. It looks correct to me. The name for Android Lint is just Lint.

The violation class has paths to XML and HTML report files. The original evaluator outputs those for the failed tasks. You might want to keep that.