diff --git a/src/functionalTest/groovy/com/github/spotbugs/snom/CacheabilityFunctionalTest.groovy b/src/functionalTest/groovy/com/github/spotbugs/snom/CacheabilityFunctionalTest.groovy index 8002e11a..c7fbb205 100644 --- a/src/functionalTest/groovy/com/github/spotbugs/snom/CacheabilityFunctionalTest.groovy +++ b/src/functionalTest/groovy/com/github/spotbugs/snom/CacheabilityFunctionalTest.groovy @@ -95,6 +95,11 @@ class CacheabilityFunctionalTest extends Specification { |repositories { | mavenCentral() |} + |spotbugsMain { + | reports { + | text.enabled = true + | } + |} |'''.stripMargin() if (runScan) { diff --git a/src/functionalTest/groovy/com/github/spotbugs/snom/ReportFunctionalTest.groovy b/src/functionalTest/groovy/com/github/spotbugs/snom/ReportFunctionalTest.groovy index c281f462..7d1fd46b 100644 --- a/src/functionalTest/groovy/com/github/spotbugs/snom/ReportFunctionalTest.groovy +++ b/src/functionalTest/groovy/com/github/spotbugs/snom/ReportFunctionalTest.groovy @@ -19,6 +19,7 @@ import spock.lang.Specification import org.gradle.testkit.runner.GradleRunner +import static org.gradle.testkit.runner.TaskOutcome.FAILED import static org.gradle.testkit.runner.TaskOutcome.SUCCESS import static org.junit.jupiter.api.Assertions.assertEquals import static org.junit.jupiter.api.Assertions.assertFalse @@ -58,19 +59,26 @@ public class Foo { """ } - def "generate XML report by default"() { + def "generate console report by default"() { + 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() .withGradleVersion(version) - .build() + .buildAndFail() then: - assertEquals(SUCCESS, result.task(":spotbugsMain").outcome) - File report = rootDir.toPath().resolve("build").resolve("reports").resolve("spotbugs").resolve("main.xml").toFile() - report.isFile() + assertEquals(FAILED, result.task(":spotbugsMain").outcome) + assertTrue(result.output.contains("M D UrF: Unread public/protected field: Bar.unreadField At Bar.java:[line 3]")) + assertFalse(rootDir.toPath().resolve("build").toFile().list().contains("reports")) } def "can generate spotbugs.txt"() { @@ -468,4 +476,4 @@ spotbugsMain { File report = rootDir.toPath().resolve("build").resolve("reports").resolve("spotbugs").resolve("main.sarif").toFile() assertTrue(report.isFile()) } -} \ No newline at end of file +} diff --git a/src/functionalTest/groovy/com/github/spotbugs/snom/StandardFunctionalTest.groovy b/src/functionalTest/groovy/com/github/spotbugs/snom/StandardFunctionalTest.groovy index 45404583..6b1c6525 100644 --- a/src/functionalTest/groovy/com/github/spotbugs/snom/StandardFunctionalTest.groovy +++ b/src/functionalTest/groovy/com/github/spotbugs/snom/StandardFunctionalTest.groovy @@ -632,6 +632,13 @@ public class SimpleTest { @Unroll def 'shows report path when failures are found (Worker API? #isWorkerApi)'() { given: + buildFile << """ +spotbugsMain { + reports { + xml.enabled = true + } +}""" + def badCode = new File(rootDir, 'src/main/java/Bar.java') badCode << ''' |public class Bar { diff --git a/src/main/groovy/com/github/spotbugs/snom/SpotBugsTask.groovy b/src/main/groovy/com/github/spotbugs/snom/SpotBugsTask.groovy index 1a69e119..b38aac16 100644 --- a/src/main/groovy/com/github/spotbugs/snom/SpotBugsTask.groovy +++ b/src/main/groovy/com/github/spotbugs/snom/SpotBugsTask.groovy @@ -412,11 +412,7 @@ class SpotBugsTask extends DefaultTask implements VerificationTask { @Nested SpotBugsReport getFirstEnabledReport() { java.util.Optional report = reports.stream().filter({ report -> report.enabled}).findFirst() - if (isSpotBugsPluginApplied) { - return report.orElse(reports.create("xml")) - } else { - return report.orElse(null) - } + return report.orElse(null) } void setReportLevel(@Nullable String name) {