-
-
Save kyonmm/5e09087584cf5394f0ce to your computer and use it in GitHub Desktop.
Findbugs for Gradle
This file contains 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
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