// Capsule plugin
plugins {
    id "us.kirchmeier.capsule" version "1.0.2"
}

apply plugin: 'java'

sourceCompatibility = 1.8
targetCompatibility = 1.8

version = '0.3'

ext.jacksonVer  = '2.9.9'
ext.quasarVer   = '0.7.5'
ext.comsatVer   = '0.7.0'
ext.capsuleVer  = '1.0.2'

ext.jettyVer    = '9.3.9.v20160517'
ext.undertowVer = '1.3.22.Final'
ext.nettyVer    = '4.0.37.Final'

ext.slf4jVer    = '1.7.21'

[compileJava, compileTestJava]*.options*.encoding = "UTF-8"

repositories {
    mavenCentral()
    maven { url 'https://oss.sonatype.org/content/repositories/snapshots' }
    // mavenLocal()
}

configurations {
    quasar
}

configurations.all {
    resolutionStrategy {
        failOnVersionConflict()
        force "org.eclipse.jetty:jetty-util:$jettyVer"
        force "org.eclipse.jetty:jetty-io:$jettyVer"
        force "org.eclipse.jetty:jetty-http:$jettyVer"
        force "org.eclipse.jetty:jetty-server:$jettyVer"
        force "org.eclipse.jetty:jetty-servlet:$jettyVer"
        force "org.eclipse.jetty:jetty-webapp:$jettyVer"
        force "org.eclipse.jetty:jetty-xml:$jettyVer"
        force "org.eclipse.jetty.websocket:websocket-server:$jettyVer"
        force "org.eclipse.jetty.websocket:websocket-servlet:$jettyVer"
        force "org.eclipse.jetty.websocket:websocket-client:$jettyVer"
        force "io.undertow:undertow-core:$undertowVer"
        force "io.undertow:undertow-servlet:$undertowVer"
        force "io.netty:netty-all:$nettyVer"
        force "org.slf4j:slf4j-api:$slf4jVer"
        force "co.paralleluniverse:quasar-actors:$quasarVer"
    }
}

configurations.capsule.dependencies.clear()

dependencies {
    compile "co.paralleluniverse:quasar-core:$quasarVer:jdk8"
    compile "com.fasterxml.jackson.core:jackson-databind:$jacksonVer"
    compile "co.paralleluniverse:comsat-servlet:$comsatVer"
    compile "co.paralleluniverse:comsat-test-utils:$comsatVer"
    compile "co.paralleluniverse:comsat-actors-api:$comsatVer"
    compile "co.paralleluniverse:comsat-actors-netty:$comsatVer"
    compile "co.paralleluniverse:comsat-actors-undertow:$comsatVer"
    compile "co.paralleluniverse:comsat-test-utils:$comsatVer"

    capsule "co.paralleluniverse:capsule:$capsuleVer"

    quasar "co.paralleluniverse:quasar-core:$quasarVer:jdk8"
}

task capsule(type: FatCapsule) {
    applicationClass "hello.World"

    capsuleManifest {
        javaAgents = [configurations.quasar.iterator().next().getName()]

        mode('servlet-undertow') {
            systemProperties['serverClass'] = 'hello.servlet.UndertowServer'
        }

        mode('servlet-jetty') {
            systemProperties['serverClass'] = 'hello.servlet.JettyServer'
        }
        
        mode('webactors-netty') {
            systemProperties['serverClass'] = 'hello.webactors.NettyServer'
        }

        mode('webactors-undertow') {
            systemProperties['serverClass'] = 'hello.webactors.UndertowServer'
        }
    }
}

task wrapper(type: Wrapper) {
    gradleVersion = '2.14'
}
