apply plugin: 'org.jetbrains.kotlin.jvm'
apply plugin: 'net.corda.plugins.quasar-utils'
apply plugin: 'net.corda.plugins.api-scanner'
apply plugin: 'corda.common-publishing'
apply plugin: 'us.kirchmeier.capsule'

description 'Corda client RPC modules'

//noinspection GroovyAssignabilityCheck
configurations {
    integrationTestImplementation.extendsFrom testImplementation
    integrationTestRuntimeOnly.extendsFrom testRuntimeOnly

    smokeTestImplementation.extendsFrom compile
    smokeTestRuntimeOnly.extendsFrom runtimeOnly
}

sourceSets {
    integrationTest {
        kotlin {
            compileClasspath += main.output + test.output
            runtimeClasspath += main.output + test.output
            srcDir file('src/integration-test/kotlin')
        }
        java {
            compileClasspath += main.output + test.output
            runtimeClasspath += main.output + test.output
            srcDir file('src/integration-test/java')
        }
        resources {
            srcDirs "src/integration-test/resources"
        }
    }
    smokeTest {
        kotlin {
            // We must NOT have any Node code on the classpath, so do NOT
            // include the test or integrationTest dependencies here.
            compileClasspath += main.output
            runtimeClasspath += main.output
            srcDir file('src/smoke-test/kotlin')
        }
        java {
            compileClasspath += main.output
            runtimeClasspath += main.output
            srcDir file('src/smoke-test/java')
        }
    }
}

dependencies {
    implementation project(':core')
    implementation project(':node-api')
    implementation project(':serialization')
    // For caches rather than guava
    implementation "com.github.ben-manes.caffeine:caffeine:$caffeine_version"
    implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
    implementation "io.reactivex:rxjava:$rxjava_version"
    implementation("org.apache.activemq:artemis-core-client:${artemis_version}") {
        exclude group: 'org.jgroups', module: 'jgroups'
    }
    implementation "com.google.guava:guava-testlib:$guava_version"

    testImplementation project(':node')
    testImplementation project(':node-driver')
    testImplementation project(':client:mock')
    testImplementation project(':core-test-utils')
    testImplementation "junit:junit:$junit_version"
    // Unit testing helpers.
    testImplementation "org.jetbrains.kotlin:kotlin-test:$kotlin_version"
    testImplementation "org.assertj:assertj-core:${assertj_version}"
    testImplementation "io.dropwizard.metrics:metrics-core:$metrics_version"

    testRuntimeOnly "org.junit.vintage:junit-vintage-engine:${junit_vintage_version}"
    testRuntimeOnly "org.junit.platform:junit-platform-launcher:${junit_platform_version}"

    integrationTestImplementation project(path: ':node-api', configuration: 'testArtifacts')
    integrationTestImplementation project(':common-configuration-parsing')
    integrationTestImplementation project(':finance:contracts')
    integrationTestImplementation project(':finance:workflows')
    integrationTestImplementation project(':test-utils')
    integrationTestImplementation "co.paralleluniverse:quasar-core:$quasar_version"
    integrationTestImplementation "org.mockito.kotlin:mockito-kotlin:$mockito_kotlin_version"

    smokeTestImplementation project(':core')
    smokeTestImplementation project(':node-api')
    smokeTestImplementation project(':finance:contracts')
    smokeTestImplementation project(':finance:workflows')
    smokeTestImplementation project(':smoke-test-utils')
    smokeTestImplementation project(':testing:cordapps:sleeping')
    smokeTestImplementation "junit:junit:$junit_version"
    smokeTestImplementation "org.jetbrains.kotlin:kotlin-test:$kotlin_version"
    smokeTestImplementation "com.google.guava:guava:$guava_version"
    smokeTestImplementation "org.hamcrest:hamcrest-library:2.1"

    smokeTestRuntimeOnly "org.junit.vintage:junit-vintage-engine:${junit_vintage_version}"
    smokeTestRuntimeOnly "org.junit.platform:junit-platform-launcher:${junit_platform_version}"
}

processSmokeTestResources {
    // Bring in the fully built corda.jar for use by NodeFactory in the smoke tests
    from(project(":node:capsule").tasks['buildCordaJAR']) {
        rename 'corda-(.*)', 'corda.jar'
    }
    from(project(':finance:workflows').tasks['jar']) {
        rename '.*finance-workflows-.*', 'cordapp-finance-workflows.jar'
    }
    from(project(':finance:contracts').tasks['jar']) {
        rename '.*finance-contracts-.*', 'cordapp-finance-contracts.jar'
    }
    from(project(':testing:cordapps:sleeping').tasks['jar']) {
        rename 'testing-sleeping-cordapp-*', 'cordapp-sleeping.jar'
    }
}

tasks.register('integrationTest', Test) {
    testClassesDirs = sourceSets.integrationTest.output.classesDirs
    classpath = sourceSets.integrationTest.runtimeClasspath
}

tasks.register('smokeTest', Test) {
    testClassesDirs = sourceSets.smokeTest.output.classesDirs
    classpath = sourceSets.smokeTest.runtimeClasspath
}

jar {
    baseName 'corda-rpc'
    manifest {
        attributes 'Automatic-Module-Name': 'net.corda.client.rpc'
    }
}

publishing {
    publications {
        maven(MavenPublication) {
            artifactId jar.baseName
            from components.java
        }
    }
}
