Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: print report to console when reporting is not specified (#172) #363

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ class CacheabilityFunctionalTest extends Specification {
|repositories {
| mavenCentral()
|}
|spotbugsMain {
| reports {
| text.enabled = true
| }
|}
|'''.stripMargin()

if (runScan) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"() {
Expand Down Expand Up @@ -468,4 +476,4 @@ spotbugsMain {
File report = rootDir.toPath().resolve("build").resolve("reports").resolve("spotbugs").resolve("main.sarif").toFile()
assertTrue(report.isFile())
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,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 {
Expand Down
6 changes: 1 addition & 5 deletions src/main/groovy/com/github/spotbugs/snom/SpotBugsTask.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -409,11 +409,7 @@ class SpotBugsTask extends DefaultTask implements VerificationTask {
@Nested
SpotBugsReport getFirstEnabledReport() {
java.util.Optional<SpotBugsReport> 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) {
Expand Down