import org.codehaus.groovy.runtime.InvokerHelper

description = 'Conscrypt: OpenJDK Integration Tests'

evaluationDependsOn(':conscrypt-openjdk')

def preferredSourceSet = project(':conscrypt-openjdk').preferredSourceSet
def preferredNativeFileDir = project(':conscrypt-openjdk').preferredNativeFileDir

sourceSets {
    main {
        resources {
            // This shouldn't be needed but seems to help IntelliJ locate the native artifact.
            srcDirs += preferredNativeFileDir
        }
    }
}

dependencies {
    implementation project(':conscrypt-openjdk')

    // Add the preferred native openjdk configuration for this platform.
    implementation project(':conscrypt-openjdk').sourceSets["$preferredSourceSet"].output

    testImplementation project(':conscrypt-constants'),
                       project(':conscrypt-testing')
}

// Check which version
def javaError = new ByteArrayOutputStream()
exec {
    executable test.executable
    args = ['-version']
    ignoreExitValue true
    errorOutput = javaError
}

def suiteClass = (javaError.toString() =~ /"1[.]7[.].*"/) ?
    "org/conscrypt/ConscryptJava7Suite.class" : "org/conscrypt/ConscryptSuite.class";

test {
    include suiteClass
}

task testEngineSocket(type: Test, dependsOn: test) {
    jvmArgs "-Dorg.conscrypt.useEngineSocketByDefault=true"
    include suiteClass
    InvokerHelper.setProperties(testLogging, test.testLogging.properties)
    systemProperties = test.systemProperties
}
check.dependsOn testEngineSocket

// Don't include this artifact in the distribution.
tasks.install.enabled = false
tasks.uploadArchives.enabled = false;