/*
 * This file was generated by the Gradle 'init' task.
 *
 * This generated file contains a sample Java Library project to get you started.
 * For more details take a look at the Java Libraries chapter in the Gradle
 * User Manual available at https://docs.gradle.org/5.4.1/userguide/java_library_plugin.html
 */

allprojects {
    apply plugin: 'idea'
    apply plugin: 'java'

    version = '1.0'

    repositories {
        jcenter()
    }

    idea {
        module {
            outputDir = file('build/classes/java/main')
            testOutputDir = file('build/classes/java/test')
        }
    }

    task buildSagemaker("type": Jar) {

        doFirst{ task ->
            println "building $task.project.name"
        }

        with project.jar

        doLast {
            copy {
                def fromDir = project.jar
                def intoDir = "${rootProject.projectDir}/build/plugins"
                from fromDir
                into intoDir
                println "Copying files from" + fromDir + " into " + intoDir
            }
        }
    }

    buildSagemaker.onlyIf {project.hasProperty("sagemaker")}
}

def javaProjects() {
    return subprojects.findAll()
}

configure(javaProjects()) {
    sourceCompatibility = 1.8
    targetCompatibility = 1.8

    defaultTasks 'jar'

    apply from: file("${rootProject.projectDir}/tools/gradle/formatter.gradle")
    apply from: file("${rootProject.projectDir}/tools/gradle/check.gradle")

    test {
        useTestNG() {
            // suiteXmlFiles << new File(rootDir, "testng.xml") //This is how to add custom testng.xml
        }

        testLogging {
            showStandardStreams = true
            events "passed", "skipped", "failed", "standardOut", "standardError"
        }
    }

    test.finalizedBy(project.tasks.jacocoTestReport)

    compileJava {
        options.compilerArgs << "-Xlint:all,-options,-static" << "-Werror"
    }

    jacocoTestCoverageVerification {
        violationRules {
            rule {
                limit {
                    minimum = 0.75
                }
            }
        }
    }
}

