/**
 * Set up Checkstyle, Findbugs and PMD to perform extensive code analysis.
 *
 * Gradle tasks added:
 * - checkstyle
 * - findbugs
 * - pmd
 *
 * The three tasks above are added as dependencies of the check task so running check will
 * run all of them.
 */

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

findbugs {
  toolVersion = '3.0.1'
}

dependencies {
    checkstyle 'com.puppycrawl.tools:checkstyle:8.5'
}

def qualityConfigDir = "$project.rootDir/config/quality";

check.dependsOn 'checkstyle', 'findbugs', 'pmd'

task checkstyle(type: Checkstyle, group: 'Verification', description: 'Runs code style checks') {
    configFile file("$qualityConfigDir/checkstyle/checkstyle-config.xml")
    ignoreFailures false
    source 'src'
    include '**/*.java'
    showViolations true

    reports {
        xml.enabled = true
        html.enabled = true
    }

    classpath = files( )
}

task findbugs(type: FindBugs,
        group: 'Verification',
        description: 'Inspect java bytecode for bugs',
        dependsOn: ['compileDebugSources','compileReleaseSources']) {

    ignoreFailures = false
    effort = "max"
    reportLevel = "high"
    excludeFilter = new File("$qualityConfigDir/findbugs/android-exclude-filter.xml")
    classes = files("$project.rootDir/app/build/intermediates/classes")

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

    reports {
        xml.enabled = true
        html.enabled = false
    }

    classpath = files()
}


task pmd(type: Pmd, group: 'Verification', description: 'Inspect sourcecode for bugs') {
    ruleSetFiles = files("$qualityConfigDir/pmd/pmd-ruleset.xml")
    ignoreFailures = false
    ruleSets = []

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

    reports {
        xml.enabled = true
        html.enabled = true
    }
}
