buildscript {
    repositories {
        mavenCentral()
        jcenter()
    }
}

plugins {
    id "com.github.kt3k.coveralls" version "2.3.1"
    id "info.solidsoft.pitest" version "1.1.4"
//    id "com.github.ben-manes.versions" version "0.8"
}

apply plugin: 'sonar-runner'

ext.jadxVersion = file('version').readLines().get(0)
version = jadxVersion

subprojects {
    apply plugin: 'java'
    apply plugin: 'groovy'
    apply plugin: 'jacoco'
    apply plugin: 'com.github.kt3k.coveralls'

    version = jadxVersion

    tasks.withType(JavaCompile) {
        sourceCompatibility = JavaVersion.VERSION_1_6
        targetCompatibility = JavaVersion.VERSION_1_6

        if (!"$it".contains(':jadx-samples:')) {
            options.compilerArgs << '-Xlint' << '-Xlint:unchecked' << '-Xlint:deprecation'
        }
    }

    jar {
        version = jadxVersion
        manifest {
            mainAttributes('jadx-version': jadxVersion)
        }
    }

    dependencies {
        compile 'org.slf4j:slf4j-api:1.7.10'

        testCompile 'ch.qos.logback:logback-classic:1.1.2'
        testCompile 'junit:junit:4.12'
        testCompile 'org.hamcrest:hamcrest-library:1.3'
        testCompile 'org.mockito:mockito-core:1.10.19'
        testCompile 'org.spockframework:spock-core:1.0-groovy-2.4'
        testCompile 'cglib:cglib-nodep:3.1'
    }

    repositories {
        mavenCentral()
        mavenLocal()
        jcenter()
    }

    jacocoTestReport {
        reports {
            xml.enabled = true // coveralls plugin depends on xml format report
            html.enabled = true
        }
    }
}

/* Sonar runner configuration */
repositories {
    mavenCentral()
}
sonarRunner {
    toolVersion = '2.4'
}

task copyArtifacts(type: Sync, dependsOn: ['jadx-cli:installDist', 'jadx-gui:installDist']) {
    destinationDir file("$buildDir/jadx")
    ['jadx-cli', 'jadx-gui'].each {
        from tasks.getByPath(":${it}:installDist").destinationDir
    }
}

task pack(type: Zip, dependsOn: copyArtifacts) {
    destinationDir buildDir
    archiveName "jadx-${jadxVersion}.zip"
    from copyArtifacts.destinationDir
}

task dist(dependsOn: pack) {
    description = 'Build jadx distribution zip'
}

task samples(dependsOn: 'jadx-samples:samples') {
}

task pitest(overwrite: true, dependsOn: 'jadx-core:pitest') {
}

task cleanBuildDir(type: Delete) {
    delete buildDir
}

build.dependsOn(dist, samples)

clean.dependsOn(cleanBuildDir)

task wrapper(type: Wrapper) {
    gradleVersion = '2.3'
}
