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

pmd {
  ruleSetFiles = files("${project.rootDir}/config/pmd/pmd-ruleset.xml")
}

findbugs {
  includeFilter = file("${project.rootDir}/config/findbugs/findbugs-config.xml")
  excludeFilter = file("${project.rootDir}/config/findbugs/findbugs-excludes.xml")
}

checkstyle {
  toolVersion = "6.16"
}

android.lintOptions {
  abortOnError true
  lintConfig file("${project.rootDir}/config/lint/lint.xml")
  textReport "true".equals(System.getenv("TRAVIS"))
  textOutput 'stdout'
}

task pmd(type: Pmd) {
  description 'Run pmd'
  group 'verification'

  source = fileTree('src/main/java')
  consoleOutput = true
  ignoreFailures = false

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

task findbugs(type: FindBugs, dependsOn: assemble) {
  description 'Run findbugs'
  group 'verification'

  classes = fileTree('build/intermediates/classes/')
  source = fileTree('src/main/java/')
  classpath = files()
  includeFilter = file("$rootProject.projectDir/config/findbugs/findbugs-config.xml")
  excludeFilter = file("$rootProject.projectDir/config/findbugs/findbugs-excludes.xml")
  ignoreFailures = false

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

task checkstyle(type: Checkstyle) {
  description 'Run checkstyle'
  group 'verification'

  configFile file("${project.rootDir}/config/checkstyle/checkstyle.xml")
  configProperties = [rootDir: "${project.rootDir}"]
  source 'src'
  include '**/*.java'
  exclude '**/gen/**'
  classpath = files()
}

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