apply plugin: 'groovy'
apply plugin: 'java'
apply plugin: 'codenarc'

def utilsPath = System.getenv('UTILS_PATH') ?: 'utils'
def pluginsPath = System.getenv('PLUGIN_OUTPUT_DIR') ?: 'plugins'
// jenkins war GAVs are only available in the following version format: x.x
def jenkinsVersion = System.getenv('JENKINS_VERSION').split('_|\\.')[1,2].join('.')

repositories {
    maven { url 'http://repo.jenkins-ci.org/releases/' }
    mavenCentral()
    jcenter()
}

configurations {
    libs
}

dependencies {
    libs 'org.apache.ivy:ivy:2.4.0@jar'
}

codenarc {
    toolVersion = '1.0'
    configFile = file('codenarc/rules.groovy')
    ignoreFailures = false
    maxPriority1Violations = 0
    maxPriority2Violations = 0
    maxPriority3Violations = 0

    // Display codenarc violations in the console for GitHub CI builds
    // otherwise, default to creating an html report
    if (System.getenv('CI_SYSTEM') == 'GitHub_CI') {
        reportFormat = 'console'
    }
}

task libs(type: Copy) {
    into "${utilsPath}"
    from configurations.libs
}

clean {
    delete "${utilsPath}"
    delete "${pluginsPath}"
}

tasks.withType(GroovyCompile) {
    groovyClasspath += configurations.libs
}
