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

倖福魔咒の 提交于 2019-12-22 04:44:05

问题


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?


回答1:


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.




回答2:


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



回答3:


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.



回答4:


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.



来源:https://stackoverflow.com/questions/28982149/how-can-i-print-reported-bugs-to-console-in-gradle-findbugs-plugin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!