From fb16d11b03b0f4401125d1ad223a71acb91f75cc Mon Sep 17 00:00:00 2001 From: John Scancella Date: Thu, 18 Jun 2020 20:37:10 -0400 Subject: [PATCH] fix: always print message about failure and report location (#285) * feat: this fixes #284 - when suppressing stack trace still print message about where report is * feat: refs #284 - add unit test to prove report location is still printed even when suppressing stack trace * feat: refs #284 - removing line that should have been moved to different test * feat: refs #284 - fixing whitespace --- .../spotbugs/snom/ReportFunctionalTest.groovy | 31 +++++++++++++++++++ .../internal/SpotBugsRunnerForWorker.java | 2 +- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/functionalTest/groovy/com/github/spotbugs/snom/ReportFunctionalTest.groovy b/src/functionalTest/groovy/com/github/spotbugs/snom/ReportFunctionalTest.groovy index f941ce38..31d38e9a 100644 --- a/src/functionalTest/groovy/com/github/spotbugs/snom/ReportFunctionalTest.groovy +++ b/src/functionalTest/groovy/com/github/spotbugs/snom/ReportFunctionalTest.groovy @@ -116,9 +116,40 @@ buildDir = 'new-build-dir' assertTrue(report.isFile()) } + def "prints reports location when stacktrace is suppressed"() { + buildFile << """ +spotbugsMain { + showStackTraces = false + reports { + text.enabled = true + } +} +buildDir = 'new-build-dir' +""" + given: + def badCode = new File(rootDir, 'src/main/java/Bar.java') + badCode << ''' + |public class Bar { + | public int unreadField = 42; // warning: URF_UNREAD_FIELD + |} + |'''.stripMargin() + + when: + def result = GradleRunner.create() + .withProjectDir(rootDir) + .withArguments('spotbugsMain') + .withPluginClasspath() + .buildAndFail() + + then: + //issue 284 - information on where the report should still be printed even if suppressing stack traces. + result.output.contains('SpotBugs report can be found in') + } + def "can generate spotbugs.html in configured buildDir"() { buildFile << """ spotbugsMain { + showStackTraces = false reports { html.enabled = true } diff --git a/src/main/groovy/com/github/spotbugs/snom/internal/SpotBugsRunnerForWorker.java b/src/main/groovy/com/github/spotbugs/snom/internal/SpotBugsRunnerForWorker.java index 6aed1cbe..ebd5aba3 100644 --- a/src/main/groovy/com/github/spotbugs/snom/internal/SpotBugsRunnerForWorker.java +++ b/src/main/groovy/com/github/spotbugs/snom/internal/SpotBugsRunnerForWorker.java @@ -112,7 +112,7 @@ public void execute() { if (params.getIgnoreFailures().getOrElse(Boolean.FALSE).booleanValue()) { final boolean showStackTraces = params.getShowStackTraces().getOrElse(Boolean.TRUE).booleanValue(); - log.warn("SpotBugs reported failures", showStackTraces ? e : null); + log.warn("SpotBugs reported failures", showStackTraces ? e : e.getMessage()); } else { throw e; }