Created
December 11, 2015 10:23
-
-
Save kui/f0d7b586cf0c6d5f600a to your computer and use it in GitHub Desktop.
print findbugs results to stdout console.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import edu.umd.cs.findbugs.SortedBugCollection | |
buildscript { | |
repositories { | |
mavenCentral() | |
} | |
dependencies { | |
classpath 'com.google.code.findbugs:findbugs:3.0.1' | |
} | |
} | |
apply plugin: 'findbugs' | |
// ... other settings | |
// print findbugs results to console | |
task printFindbugsResults << { | |
[findbugsMain, findbugsTest].forEach { | |
printFBXml it.reports.xml.destination | |
} | |
} | |
printFindbugsResults.mustRunAfter findbugsMain, findbugsTest | |
check.dependsOn printFindbugsResults | |
def printFBXml(File xml) { | |
if (!xml.exists()) return | |
def bugs = new SortedBugCollection() | |
bugs.readXML(xml) | |
if (bugs.size() == 0) return | |
def msg = bugs.collect { bug -> | |
def srcLine = bug.primarySourceLineAnnotation | |
"""\ | |
|# ${bug.type} | |
|${srcLine.className}:${srcLine.startLine}:${srcLine.endLine} | |
|${bug.abridgedMessage} | |
|${bug.bugPattern.detailPlainText.trim()} | |
""".stripMargin().trim() | |
}.join("\n---\n") | |
System.setProperty('org.gradle.color.error', 'RED') | |
logger.error """\ | |
|=== | |
|$msg | |
|=== | |
""".stripMergin().trim() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment