Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
findbugs.gradle
configurations{
findbugsConf
}
def convention = new FindBugsPluginConvention(project)
project.convention.plugins.findbugs = convention
class FindBugsPluginConvention{
def reportPath;
def version;
def reportFileName;
def reportType;
def emma(Closure close){
close.delegate = this;
close.run()
}
FindBugsPluginConvention(Project project){
reportPath = "${project.buildDir}/reports/findbugs"
version = "1.3.9"
reportType = "html"
reportFileName = "findbugs_result.html"
}
}
task findbugs(dependsOn : jar) << {
println 'Running findbugs static code analysis'
ant {
taskdef(name: 'findbugs', classname: 'edu.umd.cs.findbugs.anttask.FindBugsTask', classpath: configurations.findbugsConf.asPath)
findbugsJarFiles = configurations.findbugsConf.resolve()
findbugsHome = 'NOT_FOUND'
findbugsJarFiles.each() {
jarPath ->
if (jarPath.getName().equalsIgnoreCase("findbugs-${convention.version}.jar")) {
findbugsHome = jarPath.getParentFile()
}
}
if (new File("$findbugsHome/findbugs.jar").exists() == false) {
findbugsJarFiles.each() {
jarPath ->
switch(jarPath.getName()){
case "findbugs-${convention.version}.jar":
new File("${jarPath.getParentFile()}/findbugs.jar") << new File(jarPath.toString()).readBytes()
break
case "bcel-${convention.version}.jar" :
new File("${findbugsHome}/bcel.jar") << new File(jarPath.toString()).readBytes()
break
case"findbugs-ant-${convention.version}.jar" :
new File("${findbugsHome}/findbugs-ant.jar") << new File(jarPath.toString()).readBytes()
break
case"jFormatString-${convention.version}.jar" :
new File("${findbugsHome}/jFormatString.jar") << new File(jarPath.toString()).readBytes()
break
case"coreplugin-${convention.version}.jar" :
new File("${findbugsHome}/coreplugin.jar") << new File(jarPath.toString()).readBytes()
break
case"jsr305-${convention.version}.jar" :
new File("${findbugsHome}/jsr305.jar") << new File(jarPath.toString()).readBytes()
break
default:
new File("${findbugsHome}/${jarPath.getName()}") << new File(jarPath.toString()).readBytes()
}
}
}
mkdir dir: convention.reportPath
findbugs(home: findbugsHome, output: convention.reportType, outputFile: "${convention.reportPath}/${convention.reportFileName}", failOnError: true) {
sourcePath(path: sourceSets.main.java)
"class"(location: "$buildDir/libs/")
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.