Skip to content

Commit

Permalink
add spotbugsShowStackTraces option to change default for spotbug's sh…
Browse files Browse the repository at this point in the history
…owStackTraces option to false. required to avoid stacktrace in logs in non-strict mode
  • Loading branch information
xvik committed Nov 8, 2021
1 parent a591fbd commit c2ee668
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
* Fix gradle 7 deprecation warnings (#30)
* Update spotbugs plugin 4.7.1 -> 4.7.9
(maven group changed: gradle.plugin.com.github.spotbugs.snom -> com.github.spotbugs.snom)
* Add spotbugsShowStackTraces option with default to false.
Option introduced to change the default for spotbug's showStackTraces option
to avoid additional stacktrace in logs in non-strict mode (when plugin not fails on errors)
* Deprecate quality.pmdIncremental property because incremental analysis is enabled by default
since gradle 6.4 (property only useful for enabling it in gradle 5.6 - 6.3)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,13 @@ class QualityExtension {
*/
boolean cpdUnifySources = true

/**
* Shortcut for {@code spotbugs.showStackTraces}. Original spotbugs property is enabled by default, causing
* not pretty exception logs in non strict mode (when not fails on errors). This option was introduced to change
* the default to false not not show that nasty stacktrace, but still provide an easy way to revert default back.
*/
boolean spotbugsShowStackTraces = false

/**
* The analysis effort level. The value specified should be one of min, default, or max.
* Higher levels increase precision and find more bugs at the expense of running time and
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,8 @@ class QualityPlugin implements Plugin<Project> {
spotbugs {
toolVersion = extension.spotbugsVersion
ignoreFailures = !extension.strict
// when enabled show an additional stacktrace in non strict mode (plugin default changed)
showStackTraces = extension.spotbugsShowStackTraces
effort = extension.spotbugsEffort
reportLevel = extension.spotbugsLevel

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
package ru.vyarus.gradle.plugin.quality.tools.spotbugs

import org.gradle.testkit.runner.BuildResult
import org.gradle.testkit.runner.TaskOutcome
import ru.vyarus.gradle.plugin.quality.AbstractKitTest

/**
* @author Vyacheslav Rusakov
* @since 09.11.2021
*/
class ShowStackTraceOptionTest extends AbstractKitTest {

def "Check default behavior"() {
setup:
build("""
plugins {
id 'groovy'
id 'ru.vyarus.quality'
}
quality {
checkstyle false
pmd false
strict false
}
afterEvaluate {
tasks.withType(com.github.spotbugs.snom.SpotBugsTask).configureEach {
classes = classes.filter {
!it.path.endsWith('Sample2.class')
}
}
}
repositories {
mavenCentral() //required for testKit run
}
dependencies {
implementation localGroovy()
}
""")

fileFromClasspath('src/main/java/sample/Sample.java', '/ru/vyarus/gradle/plugin/quality/java/sample/Sample.java')
fileFromClasspath('src/main/java/sample/Sample2.java', '/ru/vyarus/gradle/plugin/quality/java/sample/Sample2.java')

when: "run check task with java and groovy sources"
BuildResult result = run('check')

then: "spotbugs detect violations, but don't print stack trace"
result.task(":check").outcome == TaskOutcome.SUCCESS
def output = result.output
output.contains("1 (0 / 1 / 0) SpotBugs violations were found in 1 files")
!output.contains("org.gradle.api.GradleException: 1 SpotBugs violations were found. See the report at:")
}

def "Check original spotbugs behavior"() {
setup:
build("""
plugins {
id 'groovy'
id 'ru.vyarus.quality'
}
quality {
spotbugsShowStackTraces true
checkstyle false
pmd false
strict false
}
afterEvaluate {
tasks.withType(com.github.spotbugs.snom.SpotBugsTask).configureEach {
classes = classes.filter {
!it.path.endsWith('Sample2.class')
}
}
}
repositories {
mavenCentral() //required for testKit run
}
dependencies {
implementation localGroovy()
}
""")

fileFromClasspath('src/main/java/sample/Sample.java', '/ru/vyarus/gradle/plugin/quality/java/sample/Sample.java')
fileFromClasspath('src/main/java/sample/Sample2.java', '/ru/vyarus/gradle/plugin/quality/java/sample/Sample2.java')

when: "run check task with java and groovy sources"
BuildResult result = run('check')

then: "spotbugs detect violations and print stack trace"
result.task(":check").outcome == TaskOutcome.SUCCESS
def output = result.output
output.contains "org.gradle.api.GradleException: 1 SpotBugs violations were found. See the report at:"
}
}

0 comments on commit c2ee668

Please sign in to comment.