/**
 * This build.gradle exists to publish our capsule (executable fat jar) to maven. It cannot be placed in the
 * node project because the bintray plugin cannot publish two modules from one project.
 */
apply plugin: 'net.corda.plugins.publish-utils'
apply plugin: 'us.kirchmeier.capsule'
apply plugin: 'com.jfrog.artifactory'

description 'Corda standalone node'

configurations {
    runtimeArtifacts.extendsFrom runtime
    capsuleRuntime
}

dependencies {
    // TypeSafe Config: for simple and human friendly config files.
    capsuleRuntime "com.typesafe:config:$typesafe_config_version"
}

// Force the Caplet to target Java 6. This ensures that running 'java -jar corda.jar' on any Java 6 VM upwards
// will get as far as the Capsule version checks, meaning that if your JVM is too old, you will at least get
// a sensible error message telling you what to do rather than a bytecode version exception that doesn't.
// If we introduce .java files into this module that need Java 8+ then we will have to push the caplet into
// its own module so its target can be controlled individually, but for now this suffices.
sourceCompatibility = 1.6
targetCompatibility = 1.6

task buildCordaJAR(type: FatCapsule, dependsOn: project(':node').compileJava) {
    applicationClass 'net.corda.node.Corda'
    archiveName "corda-${corda_release_version}.jar"
    applicationSource = files(
            project(':node').configurations.runtime,
            project(':node').jar,
            project(':node').sourceSets.main.java.outputDir.toString() + '/CordaCaplet.class',
            project(':node').sourceSets.main.java.outputDir.toString() + '/CordaCaplet$1.class',
            "$rootDir/config/dev/log4j2.xml",
            "$rootDir/node/build/resources/main/reference.conf"
    )
    from 'NOTICE' // Copy CDDL notice
    from configurations.capsuleRuntime.files.collect { zipTree(it) }

    capsuleManifest {
        applicationVersion = corda_release_version

        // See experimental/quasar-hook/README.md for how to generate.
        def quasarExcludeExpression = "x(antlr**;bftsmart**;ch**;co.paralleluniverse**;com.codahale**;com.esotericsoftware**;com.fasterxml**;com.google**;com.ibm**;com.intellij**;com.jcabi**;com.nhaarman**;com.opengamma**;com.typesafe**;com.zaxxer**;de.javakaffee**;groovy**;groovyjarjarantlr**;groovyjarjarasm**;io.atomix**;io.github**;io.netty**;jdk**;joptsimple**;junit**;kotlin**;net.bytebuddy**;net.i2p**;org.apache**;org.assertj**;org.bouncycastle**;org.codehaus**;org.crsh**;org.dom4j**;org.fusesource**;org.h2**;org.hamcrest**;org.hibernate**;org.jboss**;org.jcp**;org.joda**;org.junit**;org.mockito**;org.objectweb**;org.objenesis**;org.slf4j**;org.w3c**;org.xml**;org.yaml**;reflectasm**;rx**;org.jolokia**)"
        javaAgents = ["quasar-core-${quasar_version}-jdk8.jar=${quasarExcludeExpression}"]
        systemProperties['visualvm.display.name'] = 'Corda'
        minJavaVersion = '1.8.0'
        minUpdateVersion['1.8'] = java8_minUpdateVersion
        caplets = ['CordaCaplet']

        // JVM configuration:
        // - Constrain to small heap sizes to ease development on low end devices.
        // - Switch to the G1 GC which is going to be the default in Java 9 and gives low pause times/string dedup.
        // NOTE: these can be overridden in node.conf.
        //
        // If you change these flags, please also update Driver.kt
        jvmArgs = ['-Xmx200m', '-XX:+UseG1GC']
    }

    // Make the resulting JAR file directly executable on UNIX by prepending a shell script to it.
    // This lets you run the file like so: ./corda.jar
    // Other than being slightly less typing, this has one big advantage: Ctrl-C works properly in the terminal.
    reallyExecutable { trampolining() }
}

artifacts {
    runtimeArtifacts buildCordaJAR
    publish buildCordaJAR {
        classifier ""
    }
}

publish {
    disableDefaultJar = true
    name  'corda'
}