import org.apache.tools.ant.filters.ReplaceTokens

plugins {
    id "com.github.johnrengelman.shadow" version "1.2.4"
    id "org.sonarqube" version "2.2"
    id "net.saliman.properties" version "1.4.4"
}

apply plugin: "java"
apply plugin:'application'

group "com.epam"

apply plugin: "checkstyle"
apply plugin: "pmd"
apply plugin: "jacoco"

repositories  {
    mavenCentral()
}

dependencies {

    //Logging
    compile group: "org.slf4j", name: "slf4j-api", version: "1.7.21"
    compile group: 'org.apache.logging.log4j', name: 'log4j-slf4j-impl', version: '2.17.1'
    compile group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.17.1'
    compile group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.17.1'

    //CLI parsing
    compile group: 'args4j', name: 'args4j', version: '2.33'

    //HTTP handling
    compile group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.5.2'
    compile group: 'org.apache.httpcomponents', name: 'httpmime', version: '4.5.2'
    compile group: 'com.google.http-client', name: 'google-http-client-jackson2', version: '1.22.0'

    // Jackson
    compile group: "com.fasterxml.jackson.core", name: "jackson-core", version: "2.7.5"
    compile group: "com.fasterxml.jackson.core", name: "jackson-databind", version: "2.7.5"
    compile group: "com.fasterxml.jackson.core", name: "jackson-annotations", version: "2.7.5"

    compile group: 'commons-io', name: 'commons-io', version: '2.5'
    compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.5'
    compile group: 'commons-configuration', name: 'commons-configuration', version: '1.10'
    compile group: 'commons-collections', name: 'commons-collections', version: '3.2.2'
    
    // lombok
    compileOnly "org.projectlombok:lombok:1.16.16"
    
    //to find classes by annotation
    compile group: 'io.github.lukehutch', name: 'fast-classpath-scanner', version: '2.0.9'

    testCompile 'junit:junit:4.12'

    //http server mock
    testCompile group: 'net.jadler', name: 'jadler-all', version: '1.3.0'
}

mainClassName = "com.epam.ngb.cli.app.Application"

task copyConfiguration {
    doLast {
        filterTokens.putAt("version", escape("$version"))
        copy {
            from('profiles/server.properties')
            into("$buildDir/resources/main/external")
            filter(ReplaceTokens, tokens: project.filterTokens)
        }
    }
}

processResources.dependsOn copyConfiguration

startScripts {
    applicationName = 'ngb'
}



distZip {
    doFirst{
        setVersion('')
    }
    doLast {
        file("$destinationDir/$archiveName").renameTo("$destinationDir/"+baseName+'.zip')
    }
}

distTar {
    compression = Compression.GZIP
    doFirst{
        setVersion('')
    }
    doLast {
        file("$destinationDir/$archiveName").renameTo("$destinationDir/" + baseName+'.tar.gz')
    }
}

installDist {
    doLast {
        from ("$destinationDir/ngb-cli-$version") {
            into "$destinationDir/ngb-cli"
        }
    }
}

distributions {
    main {
        baseName = 'ngb-cli'
        contents {
            def properties = file("$buildDir/resources/main/external")
            from(properties) {
                into "config"
            }
        }
    }
}

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

checkstyle {
    toolVersion = "7.2"
}

task regression(type: Exec) {
    executable 'bash'
    args 'script\\regression_test.sh'
}

def escape(String s) {
    return s.replace("\\", "\\\\")
}

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