/*
 * Copyright 2013-2019 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

apply plugin : 'codenarc'
apply plugin : 'com.github.hierynomus.license'

license {
    header = rootProject.file('config/HEADER')
    strictCheck = true
    ignoreFailures = false
    mapping {
        java   = 'SLASHSTAR_STYLE'
        groovy = 'SLASHSTAR_STYLE'
    }
    ext.year = project.copyrightYear
    excludes(['**/*.ad', '**/*.asciidoc', '**/*.adoc', '**/fake.txt'])
}

dependencies {
    codenarc "org.codenarc:CodeNarc:${codenarcVersion}"
}

codenarc {
    configFile = file("${rootProject.projectDir}/config/codenarc/codenarc.groovy")
    // run codenarc on production sources only
    sourceSets = [project.sourceSets.main]
}

tasks.withType(CodeNarc) { codenarcSourceSetTask ->
    def reportName = (codenarcSourceSetTask.name - 'codenarc').uncapitalize()
    def ideReport = reports.add(org.gradle.api.reporting.internal.TaskGeneratedSingleFileReport, 'ide', reports.task)
    ideReport.enabled = true
    ideReport.destination = file( "${project.codenarc.reportsDir}/${reportName}.ide.txt")
}

pluginManager.withPlugin('jacoco') {
    jacocoTestReport {
        reports {
            xml.enabled = true // coveralls plugin depends on xml format report
            html.enabled = true
        }
        mustRunAfter test
    }
}

task codenarcAll {
    group 'verification'
    description 'Lifecycle task for all codenarc tasks'
}

tasks.withType(CodeNarc) { t ->
    tasks.codenarcAll.dependsOn t

    if(t.name =~ /.+GradleTest.*/) {
        t.enabled = false
    }
}
