Skip to content

Commit 11195f5

Browse files
committed
fix: XML report was not generated by default
in the previous version, XML report was enabled by default. so even in this v4, it should be enabled by default. Note that the base plugin should introduce no convention, so this feature is enabled only in the spotbugs plugin (not spotbugs-base plugin).
1 parent 55d5de2 commit 11195f5

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

src/functionalTest/groovy/com/github/spotbugs/snom/BasePluginFunctionalTest.groovy

+24
Original file line numberDiff line numberDiff line change
@@ -99,4 +99,28 @@ task spotbugsMain(type: com.github.spotbugs.snom.SpotBugsTask) {
9999
result.task(":classes").outcome == TaskOutcome.SUCCESS
100100
result.task(":spotbugsMain").outcome == TaskOutcome.SUCCESS
101101
}
102+
103+
def "SpotBugsTask does not create report by default"() {
104+
setup:
105+
buildFile << """
106+
task spotbugsMain(type: com.github.spotbugs.snom.SpotBugsTask) {
107+
dependsOn 'classes'
108+
classDirs = sourceSets.main.output
109+
}
110+
"""
111+
when:
112+
BuildResult result =
113+
GradleRunner.create()
114+
.withProjectDir(rootDir)
115+
.withArguments(":spotbugsMain")
116+
.withPluginClasspath()
117+
.forwardOutput()
118+
.withGradleVersion(version)
119+
.build()
120+
121+
then:
122+
result.task(":spotbugsMain").outcome == TaskOutcome.SUCCESS
123+
File report = rootDir.toPath().resolve("build").resolve("reports").resolve("spotbugs").resolve("main.xml").toFile()
124+
!report.isFile()
125+
}
102126
}

src/main/groovy/com/github/spotbugs/snom/SpotBugsTask.groovy

+9-1
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,15 @@ class SpotBugsTask extends DefaultTask implements VerificationTask {
363363
@Optional
364364
@Nested
365365
SpotBugsReport getFirstEnabledReport() {
366-
return reports.stream().filter({report -> report.enabled}).findFirst().orElse(null)
366+
// use XML report by default, only when SpotBugs plugin is applied
367+
boolean isSpotBugsPluingApplied = project.pluginManager.hasPlugin("com.github.spotbugs")
368+
369+
java.util.Optional<SpotBugsReport> report = reports.stream().filter({ report -> report.enabled}).findFirst()
370+
if (isSpotBugsPluingApplied) {
371+
return report.orElse(reports.create("xml"))
372+
} else {
373+
return report.orElse(null)
374+
}
367375
}
368376

369377
void setReportLevel(@Nullable String name) {

0 commit comments

Comments
 (0)