How can I print reported bugs to console in gradle findbugs plugin?
Asked Answered
S

4

8

I am using Gradle FindBugs Plugin. How can I print reported bugs to console? PMD plugin has a consoleOutput property. Is there a similar property for FindBugs?

Shelve answered 11/3, 2015 at 8:56 Comment(5)
is your question answered?Nagging
So, you suggest that parse the report and print it, am I right?Shelve
It seems that this is the only workaround for now. See my updated answer.Nagging
My only purpose to print is to make easy to go line, which is reported by findbugs. I may use the ide plugin, which works perfect for this purpose but it is needed to be done this way unfortunately. I think I may sync the includefilter files of both ide and project config file.Shelve
It seems that an IDE plugin will suit your needs perfectly.Nagging
N
2

As you can see here there's no such property or configuration possibility for FindBugs plugin. However it seems that the plugin can be customized in some way. E.g. by parsing and displaying the results.

See here and here.

Nagging answered 11/3, 2015 at 9:0 Comment(0)
C
1

This is rudimentary ... but it's a start

task checkFindBugsReport << {
    def xmlReport = findbugsMain.reports.xml
    if (!xmlReport.destination.exists()) return;
    def slurped = new XmlSlurper().parse(xmlReport.destination)
    def report = ""
    slurped['BugInstance'].eachWithIndex { bug, index ->
        report += "${index + 1}. Found bug risk ${bug.@'type'} of category ${bug.@'category'} "
        report += "in the following places"
        bug['SourceLine'].each { place ->
            report += "\n       ${place.@'classname'} at lines ${place.@'start'}:${place.@'end'}"
        }
    }
    if (report.length() > 1) {
        logger.error "[FINDBUGS]\n ${report}"
    }
}

findbugsMain.finalizedBy checkFindBugsReport
Continuator answered 12/12, 2016 at 12:39 Comment(1)
can you share plugin dependencies alsoShortcake
F
1

You can do that with Violations Gradle Plugin. It is configured with patterns to identify report files and to run after check. It will

  • Accumulate all static code analysis tools into a unified report.
  • Print it to the build log.
  • Optionally fail the build if there are too many violations.
Fiddler answered 26/12, 2017 at 19:24 Comment(0)
F
0

Findbugs/Spotbugs come with a class that can run after analysis, read an xml report and print to text/html. It is included in the findbugs/spotbugs.jar file.

    <java classname="edu.umd.cs.findbugs.PrintingBugReporter" fork="true">
        <arg value="${build.dir}/findbugs/findbugs-test-report.xml"/>
        <classpath path="${spotbugs.home}/lib/spotbugs.jar"/>
    </java>

Which is same as running

java  -cp path/to/spotbugs.jar edu.umd.cs.findbugs.PrintingBugReporter  path/to/findbugs-report.xml

It has an -html option that will render html.

It should be feasible to achieve the same in gradle/maven.

Farouche answered 14/8, 2018 at 4:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.