apply plugin: 'checkstyle'
apply plugin: 'findbugs'
apply plugin: 'pmd'

// Add checkstyle, findbugs, pmd and lint to the check task.
check.dependsOn 'checkstyle', 'findbugs', 'pmd', 'lint'

checkstyle {
    toolVersion = "5.9"
}

def qualityConfigDir = "$project.rootDir/config/quality"
def reportsDir = "$project.buildDir/reports"

task checkstyle(type: Checkstyle) {
    group = "verification"
    description = "Checks style of source code for all variants."
    configFile rootProject.file('config/quality/checkstyle/checkstyle.xml')
    configProperties.checkstyleSuppressionsPath = file("${qualityConfigDir}/checkstyle/suppressions.xml").absolutePath
    source 'src'
    include '**/*.java'
    exclude '**/gen/**'
    classpath = files()
}

task findbugs(type: FindBugs) {
    group = "verification"
    description = "Finds bugs in bytecode for all variants."
    ignoreFailures = false
    effort = "max"
    reportLevel = "high"
    excludeFilter = new File("${qualityConfigDir}/findbugs/findbugs-filter.xml")
    classes = files("${project.rootDir}/app/build/intermediates/classes")

    source 'src'
    include '**/*.java'
    exclude '**/gen/**'

    reports {
        xml.enabled = false
        html.enabled = true 
        html {
            destination file("${reportsDir}/findbugs/findbugs.html")
        }
    }

    classpath = files()
}

task pmd(type: Pmd) {
    group = "verification"
    description = "Performs quality checks in source code for all variants."
    ignoreFailures = false
    ruleSetFiles = files("${qualityConfigDir}/pmd/pmd-ruleset.xml")

    source 'src'
    include '**/*.java'
    exclude '**/gen/**'

    reports {
        xml.enabled = false
        html.enabled = true
        html {
            destination file("${reportsDir}/pmd/pmd.html")
        }
    }
}

android {
    lintOptions {
        abortOnError true 
        xmlReport false
        htmlReport true
        lintConfig file("${qualityConfigDir}/lint/lint.xml")
        htmlOutput file("${reportsDir}/lint/lint-result.html")
    }
}

