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

//noinspection GroovyAssignabilityCheck
configurations {
    integrationTestImplementation.extendsFrom testImplementation
    integrationTestRuntime.extendsFrom testRuntimeOnly
}

sourceSets {
    integrationTest {
        kotlin {
            compileClasspath += main.output + test.output
            runtimeClasspath += main.output + test.output
            srcDir file('src/integration-test/kotlin')
        }
        resources {
            srcDir file('src/integration-test/resources')
        }
    }
}

dependencies {
    implementation project(':core')
    implementation project(':node')
    implementation project(':node-api')
    implementation project(':serialization')
    implementation project(':client:rpc')
    implementation project(':client:mock')
    implementation project(':common-configuration-parsing')
    implementation project(':common-validation')
    implementation project(':core-test-utils')
    implementation project(':test-common')
    implementation project(':test-utils')
    implementation project(':tools:cliutils')

    implementation group: 'org.apache.sshd', name: 'sshd-common', version: '2.12.1'
    implementation "javax.persistence:javax.persistence-api:2.2"

    // Integration test helpers
    testImplementation "org.assertj:assertj-core:$assertj_version"

    integrationTestImplementation project(":client:jackson")
    integrationTestImplementation "junit:junit:$junit_version"
    integrationTestImplementation "org.junit.jupiter:junit-jupiter-api:${junit_jupiter_version}"
    integrationTestImplementation "info.picocli:picocli:$picocli_version"
    integrationTestImplementation "com.google.guava:guava:$guava_version"
    integrationTestImplementation 'com.googlecode.json-simple:json-simple:1.1.1'
    integrationTestImplementation "com.fasterxml.jackson.core:jackson-databind:$jackson_version"
    integrationTestImplementation 'org.hamcrest:hamcrest-library:2.1'

    integrationTestRuntimeOnly "org.junit.vintage:junit-vintage-engine:${junit_vintage_version}"
    integrationTestRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:${junit_jupiter_version}"
    integrationTestRuntimeOnly "org.junit.platform:junit-platform-launcher:${junit_platform_version}"

    // Jetty dependencies for NetworkMapClient test.
    // Web stuff: for HTTP[S] servlets
    implementation "org.eclipse.jetty.ee10:jetty-ee10-servlet:${jetty_version}"
    implementation "org.eclipse.jetty.ee10:jetty-ee10-webapp:${jetty_version}"
    implementation "javax.servlet:javax.servlet-api:${servlet_version}"

    implementation "org.gradle:gradle-tooling-api:7.1"

    // Jersey for JAX-RS implementation for use in Jetty
    implementation "org.glassfish.jersey.core:jersey-server:${jersey_version}"
    implementation "org.glassfish.jersey.containers:jersey-container-servlet-core:${jersey_version}"
    implementation "org.glassfish.jersey.containers:jersey-container-jetty-http:${jersey_version}"
    implementation "org.glassfish.jersey.inject:jersey-hk2:$jersey_version"

    implementation "io.reactivex:rxjava:$rxjava_version"
    implementation("org.apache.activemq:artemis-core-client:${artemis_version}") {
        exclude group: 'org.jgroups', module: 'jgroups'
    }

    // Bouncy castle support needed for X509 certificate manipulation
    implementation "org.bouncycastle:bcprov-lts8on:${bouncycastle_version}"
    implementation "org.bouncycastle:bcpkix-lts8on:${bouncycastle_version}"
    implementation "org.bouncycastle:bcutil-lts8on:${bouncycastle_version}"

    implementation "com.google.code.findbugs:jsr305:$jsr305_version"
    implementation "com.google.jimfs:jimfs:1.1"
    implementation group: "com.typesafe", name: "config", version: typesafe_config_version
    implementation "io.github.classgraph:classgraph:$class_graph_version"
    implementation "com.squareup.okhttp3:okhttp:$okhttp_version"
    implementation "org.mockito.kotlin:mockito-kotlin:$mockito_kotlin_version"
    implementation "com.esotericsoftware:kryo:$kryo_version"
    implementation "io.dropwizard.metrics:metrics-jmx:$metrics_version"
    implementation "org.apache.commons:commons-lang3:$commons_lang3_version"
    implementation "org.assertj:assertj-core:${assertj_version}"
    implementation "org.apache.logging.log4j:log4j-core:$log4j_version"
    implementation "junit:junit:$junit_version"

    implementation("org.apache.activemq:artemis-server:${artemis_version}") {
        exclude group: 'org.apache.commons', module: 'commons-dbcp2'
        exclude group: 'org.jgroups', module: 'jgroups'
    }

    implementation "co.paralleluniverse:quasar-core:$quasar_version"
}

compileJava {
    doFirst {
        options.compilerArgs = [
                '--add-modules', 'jdk.incubator.foreign'
        ]
    }
}

processResources {
    from(project(":node:capsule").files("src/main/resources/node-jvm-args.txt")) {
        into("net/corda/testing/node/internal")
    }
}

task integrationTest(type: Test) {
    testClassesDirs = sourceSets.integrationTest.output.classesDirs
    classpath = sourceSets.integrationTest.runtimeClasspath
}

jar {
    baseName 'corda-node-driver'
    manifest {
        // This JAR is part of Corda's testing framework.
        // Driver will not include it as part of an out-of-process node.
        attributes('Corda-Testing': true)
    }
}

tasks.named('javadoc', Javadoc) {
    enabled = false
}

scanApi {
    //Constructors that are synthesized by Kotlin unexpectedly
    excludeMethods = [
        "net.corda.testing.node.MockServices": [
            "<init>(Lnet/corda/node/cordapp/CordappLoader;Lnet/corda/core/node/services/IdentityService;Lnet/corda/core/node/NetworkParameters;Lnet/corda/testing/core/TestIdentity;[Ljava/security/KeyPair;Lkotlin/jvm/internal/DefaultConstructorMarker;)V"
        ],
        "net.corda.testing.node.InMemoryMessagingNetwork\$MessageTransfer": [
            "<init>(Lnet/corda/testing/node/InMemoryMessagingNetwork\$PeerHandle;Lnet/corda/node/services/messaging/Message;Lnet/corda/core/messaging/MessageRecipients;Lkotlin/jvm/internal/DefaultConstructorMarker;)V"
        ]
    ]
}

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