apply plugin: 'java'

configurations {
    integTestCompile {
        extendsFrom testCompile
    }
    integTestRuntime {
        extendsFrom integTestCompile, testRuntime
    }
}

sourceSets {
    integTest {
        compileClasspath = sourceSets.main.classes + sourceSets.test.classes + configurations.integTestCompile
        runtimeClasspath = classes + compileClasspath + configurations.integTestRuntime
    }
}

ideaModule {
    testSourceDirs += sourceSets.integTest.groovy.srcDirs
    testSourceDirs += sourceSets.integTest.resources.srcDirs
    scopes.TEST.plus.add(configurations.integTestCompile)
    scopes.TEST.plus.add(configurations.integTestRuntime)
}

eclipseClasspath {
    plusConfigurations.add(configurations.integTestCompile)
    plusConfigurations.add(configurations.integTestRuntime)
}

integTestUserDir = rootProject.file('intTestHomeDir')

integTestTasks = tasks.withType(Test).matching { it.name.toLowerCase().endsWith('integtest') }

integTestTasks.all {
    dependsOn ':intTestImage'
    testClassesDir = sourceSets.integTest.classesDir
    classpath = sourceSets.integTest.runtimeClasspath
    testSrcDirs = []

    doFirst {
        testResultsDir = file("${project.testResultsDir}/$name")
        testReportDir = file("${project.testReportDir}/$name")
    }
}
