# HG changeset patch # User Da Risk # Date 1426442244 -3600 # Node ID 6ca974ea549b9724ba718b80ad199908910cb146 # Parent e5a970600066581bd6e8117a89ad10204f55b3d7 Add checkstyle configuration to gradle diff -r e5a970600066 -r 6ca974ea549b app/build.gradle --- a/app/build.gradle Sun Mar 15 18:13:26 2015 +0100 +++ b/app/build.gradle Sun Mar 15 18:57:24 2015 +0100 @@ -28,3 +28,5 @@ dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) } + +apply from: "$project.rootDir/tools/android-checkstyle.gradle" diff -r e5a970600066 -r 6ca974ea549b tools/android-checkstyle.gradle --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tools/android-checkstyle.gradle Sun Mar 15 18:57:24 2015 +0100 @@ -0,0 +1,86 @@ +configurations { + codequality +} + +dependencies { + codequality 'com.puppycrawl.tools:checkstyle:6.1' +} + +task checkstyle(type: AndroidCheckstyleTask) { + ignoreFailures true + showViolations false + configFile file("$project.rootDir/tools/checkstyle.xml") + xslFile file("$project.rootDir/tools/checkstyle-noframes-sorted.xsl") +} + +task checkstyleCmdLine(type: AndroidCheckstyleTask) { + ignoreFailures false + showViolations true + configFile file("$project.rootDir/tools/checkstyle.xml") + xslFile file("$project.rootDir/tools/checkstyle-noframes-sorted.xsl") +} + +check.dependsOn(checkstyle) + +/////////////////////////////////////////////// +////////////// Groovy Task Class ////////////// +/////////////////////////////////////////////// +import org.gradle.api.internal.project.IsolatedAntBuilder + +/** + * See parameters at http://checkstyle.sourceforge.net/anttask.html + */ +class AndroidCheckstyleTask extends DefaultTask { + @InputFile + @Optional + File configFile = new File("$project.rootDir/config/checkstyle/checkstyle.xml") + @InputFile + @Optional + File xslFile = new File("$project.rootDir/config/checkstyle/checkstyle-noframes-sorted.xsl") + @OutputFile + @Optional + File outputFile = new File("$project.buildDir/reports/checkstyle/checkstyle-${project.name}.xml") + def outputHtmlFile = outputFile.absolutePath.replaceFirst(~/\.[^\.]+$/, ".html") + FileCollection checkstyleClasspath = project.configurations.codequality + Boolean ignoreFailures = false + Boolean showViolations = true + Project gradleProject = project + + def AndroidCheckstyleTask() { + description = 'Runs checkstyle against Android sourcesets.' + group = 'Code Quality' + } + + @TaskAction + def runCheckstyle() { + outputFile.parentFile.mkdirs() + def antBuilder = services.get(IsolatedAntBuilder) + antBuilder.withClasspath(checkstyleClasspath).execute { + ant.taskdef(name: 'checkstyle', classname: 'com.puppycrawl.tools.checkstyle.CheckStyleTask') + // see also, maxWarnings and failureProperty arguments + ant.checkstyle(config: configFile, failOnViolation: !ignoreFailures) { + gradleProject.allprojects.each { submodule -> + submodule.android.sourceSets.each { sourceSet -> + sourceSet.java.each { file -> + file.getSrcDirs().each { + if (it.exists()) { + fileset(dir: it) + } + } + } + } + } + if (showViolations) { + formatter(type: 'plain', useFile: false) + } + formatter(type: 'xml', toFile: outputFile) + } + if (outputFile.exists()) { + ant.xslt(in: outputFile, + style: xslFile, + out: outputHtmlFile + ) + } + } + } +} diff -r e5a970600066 -r 6ca974ea549b tools/checkstyle-noframes-sorted.xsl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tools/checkstyle-noframes-sorted.xsl Sun Mar 15 18:57:24 2015 +0100 @@ -0,0 +1,196 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + +

CheckStyle Audit

+
Designed for use with + CheckStyle + andAnt. +
+
+ + + +
+ + + +
+ + + + +
+ + + + +
+ + + +

Files

+ + + + + + + + + + + + + + +
NameErrors
+ + + + + +
+
+ + + + +

File + +

+ + + + + + + + + + + + + + +
Error DescriptionLine
+ + + +
+ Back to top +
+ + + +

Summary

+ + + + + + + + + + + + +
FilesErrors
+ + + +
+
+ + + + a + b + + +
diff -r e5a970600066 -r 6ca974ea549b tools/checkstyle.xml --- a/tools/checkstyle.xml Sun Mar 15 18:13:26 2015 +0100 +++ b/tools/checkstyle.xml Sun Mar 15 18:57:24 2015 +0100 @@ -255,7 +255,6 @@ -