From af1a61960b7899461ad8b76655a05af4b247d22a Mon Sep 17 00:00:00 2001 From: Jubril Edu Date: Sun, 9 Oct 2016 00:33:12 +0100 Subject: [PATCH] Incorporated Checkstyle, findbugs, pmd and lint --- build.gradle | 64 ++++++++++++++++++++++++++++++++++++++++++--- checkstyle.xml | 6 +++++ findbugs-filter.xml | 8 ++++++ pmd-ruleset.xml | 24 +++++++++++++++++ suppressions.xml | 4 +++ 5 files changed, 102 insertions(+), 4 deletions(-) create mode 100644 checkstyle.xml create mode 100644 findbugs-filter.xml create mode 100644 pmd-ruleset.xml create mode 100644 suppressions.xml diff --git a/build.gradle b/build.gradle index 1e88c91662..cccf0d51a1 100644 --- a/build.gradle +++ b/build.gradle @@ -15,6 +15,9 @@ buildscript { } apply plugin: 'com.android.application' +apply plugin: 'checkstyle' +apply plugin: 'pmd' +apply plugin: 'findbugs' ext { supportLibraryVersion = '23.4.0' @@ -41,12 +44,10 @@ dependencies { compile "com.android.support:cardview-v7:${supportLibraryVersion}" compile 'com.getbase:floatingactionbutton:1.10.1' - /// dependencies for local unit tests testCompile 'junit:junit:4.12' testCompile 'org.mockito:mockito-core:1.10.19' - /// dependencies for instrumented tests // JUnit4 Rules androidTestCompile 'com.android.support.test:rules:0.5' @@ -73,6 +74,12 @@ tasks.withType(Test) { } android { + lintOptions { + abortOnError true + lintConfig file("${project.rootDir}/lint.xml") + htmlReport true + htmlOutput file("$project.buildDir/reports/lint/lint.html") + } compileSdkVersion 23 buildToolsVersion "23.0.3" @@ -100,14 +107,12 @@ android { assets.srcDirs = ['assets'] } - // move whole local unit tests structure as a whole from src/test/* to test/* test.setRoot('test') // move whole instrumented tests structure as a whole from src/androidTest/* to androidTest/* androidTest.setRoot('androidTest') - // Move the build types to build-types/ // For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ... // This moves them out of them default location under src//... which would @@ -131,4 +136,55 @@ android { exclude 'META-INF/LICENSE.txt' } + task checkstyle(type: Checkstyle) { + configFile = file("${rootProject.projectDir}/checkstyle.xml") + configProperties.checkstyleSuppressionsPath = file("${project.rootDir}/config/quality/checkstyle/suppressions.xml").absolutePath + source 'src' + include '**/*.java' + exclude '**/gen/**' + classpath = files() + } + + task pmd(type: Pmd) { + ruleSetFiles = files("${project.rootDir}/pmd-ruleset.xml") + ignoreFailures = false + ruleSets = [] + + source 'src' + include '**/*.java' + exclude '**/gen/**' + + reports { + xml.enabled = false + html.enabled = true + xml { + destination "$project.buildDir/reports/pmd/pmd.xml" + } + html { + destination "$project.buildDir/reports/pmd/pmd.html" + } + } + } + + task findbugs(type: FindBugs) { + ignoreFailures = false + effort = "max" + reportLevel = "high" + classes = files("$project.buildDir/intermediates/classes") + excludeFilter = new File("${project.rootDir}/findbugs-filter.xml") + source 'src' + include '**/*.java' + exclude '**/gen/**' + + reports { + xml.enabled = false + html.enabled = true + html { + destination "$project.buildDir/reports/findbugs/findbugs.html" + } + } + classpath = files() + } + check.dependsOn 'checkstyle', 'findbugs', 'pmd', 'lint' + } diff --git a/checkstyle.xml b/checkstyle.xml new file mode 100644 index 0000000000..e32ed1b7a1 --- /dev/null +++ b/checkstyle.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/findbugs-filter.xml b/findbugs-filter.xml new file mode 100644 index 0000000000..01ca48c7ee --- /dev/null +++ b/findbugs-filter.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/pmd-ruleset.xml b/pmd-ruleset.xml new file mode 100644 index 0000000000..ce61196628 --- /dev/null +++ b/pmd-ruleset.xml @@ -0,0 +1,24 @@ + + + + The ruleset file checks code using rules defined below, new rules can always be added.The + pmd.html file contains the report which includes perceived coding issues + + .*/R.java + .*/gen/.* + + + + + + + + + + + + + \ No newline at end of file diff --git a/suppressions.xml b/suppressions.xml new file mode 100644 index 0000000000..a1dfee9e11 --- /dev/null +++ b/suppressions.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file