plugins {
    id 'java'
    id 'application'
    id 'com.google.osdetector' version '1.6.2'
}

if (project.ext.properties.get('isDevBuild') == null) {
    project.ext.isDevBuild = !project.ext.properties.containsKey("buildConfig") || !"release".equals(project.ext.buildConfig)
}

repositories {
    mavenCentral()
}

sourceSets {
    systemTest {
        java {
            compileClasspath += main.output
            runtimeClasspath += main.output
            srcDir file('src/systemTest/java')
        }
        resources.srcDir file('src/systemTest/resources')
    }
}

configurations {
    systemTestCompile.extendsFrom testCompile
}

sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8

project.ext.jenkinsBuildNumber = "$System.env.VERSION_NUMBER"
project.ext.jenkinsJobName = "hub-v2"

group = 'com.flightstats'

version = project.ext.jenkinsBuildNumber

project.ext.isDevBuild = !project.ext.properties.containsKey("buildConfig") || !"release".equals(project.ext.buildConfig)

println "Building version: ${version}"

buildDir = 'build'

mainClassName = "com.flightstats.hub.app.SingleHubMain"

task nasTest(type: Test) {
    exclude 'com/flightstats/hub/dao/aws/**'
    exclude 'com/flightstats/hub/spoke/**'
}

test {
    useJUnitPlatform()
    testLogging {
        events "failed"
    }
}

task systemTest(type: Test, description: 'Runs the system tests.', group: 'Verification') {
    // Retrieve properties passed in via -D that coincide with system tests. After "systemTest.", names should match those
    // found in system-test-hub.properties
    systemProperties System.properties.findAll { property ->
        property.key.startsWith("systemTest.")
    }
    systemProperty 'kubernetes.websocket.ping.interval', 30000

    useJUnitPlatform()
    testLogging {
        events "failed"
    }
    testClassesDirs = sourceSets.systemTest.output.classesDirs
    classpath = sourceSets.systemTest.runtimeClasspath
}

wrapper {
    gradleVersion = '5.2'
}

configurations {
    all*.exclude(group: 'org.slf4j', module: 'slf4j-log4j12')
    all*.exclude(group: 'org.slf4j', module: 'slf4j-simple')
    all*.exclude(group: 'javax.ws.rs', module: 'jsr311-api')
    all*.exclude(module: 'log4j')
    integrationTests
}

dependencies {
    compile 'io.prometheus.jmx:jmx_prometheus_javaagent:1.0.1'
    compile 'org.eclipse.jetty:jetty-server:9.4.8.v20171121'
    compile 'org.eclipse.jetty:jetty-servlet:9.4.8.v20171121'
    compile 'org.eclipse.jetty:jetty-servlets:9.4.8.v20171121'
    compile 'org.eclipse.jetty.websocket:javax-websocket-server-impl:9.4.8.v20171121'
    compile 'org.eclipse.jetty:jetty-jmx:9.4.8.v20171121'
    compile group: 'org.owasp.encoder', name: 'encoder', version: '1.2.3'

    compile 'org.glassfish.jersey.containers:jersey-container-jetty-http:2.26'
    compile 'org.glassfish.jersey.core:jersey-common:2.26'
    compile 'org.glassfish.jersey.media:jersey-media-sse:2.26'
    compile 'org.glassfish.jersey.inject:jersey-hk2:2.26'
    compile 'org.glassfish.hk2:guice-bridge:2.5.0'

    // TODO: migrate to the Jersey 2 client
    compile 'com.sun.jersey:jersey-client:1.19.4'

    compile 'com.fasterxml.jackson.core:jackson-core:2.9.3'
    compile 'com.fasterxml.jackson.core:jackson-annotations:2.9.3'
    compile 'com.fasterxml.jackson.core:jackson-databind:2.9.3'
    compile 'com.fasterxml.jackson.jaxrs:jackson-jaxrs-json-provider:2.9.3'
    compile 'com.fasterxml.jackson.datatype:jackson-datatype-guava:2.9.3'

    compile 'com.google.inject:guice:4.1.0'
    compile 'com.google.inject.extensions:guice-servlet:4.1.0'
    compile 'com.google.guava:guava:23.5-jre'
    compile 'com.diffplug.durian:durian:3.4.0'
    compile 'joda-time:joda-time:2.9.9'

    compile group: 'org.json', name: 'json', version: '20240303'

    compile 'ch.qos.logback:logback-core:1.2.3'
    compile 'ch.qos.logback:logback-classic:1.2.3'
    compile 'net.logstash.logback:logstash-logback-encoder:4.11'
    compile 'org.slf4j:jul-to-slf4j:1.7.25'
    compile 'org.slf4j:log4j-over-slf4j:1.7.25'
    compile 'org.slf4j:jcl-over-slf4j:1.7.25'

    compile 'de.danielbechler:java-object-diff:0.94'

    compile 'com.amazonaws:aws-java-sdk:1.11.248'

    compile('org.apache.curator:curator-recipes:5.3.0')
    compile('org.apache.zookeeper:zookeeper:3.8.0')
    compile('org.apache.curator:curator-test:5.3.0')

    compile 'org.apache.commons:commons-lang3:3.7'
    compile group: 'org.apache.commons', name: 'commons-text', version: '1.10.0'
    compile 'commons-io:commons-io:2.6'
    compile('com.github.rholder:guava-retrying:2.0.0') {
        exclude group: 'com.google.guava'
    }

    compile 'com.google.code.gson:gson:2.8.2'

    compile 'de.jkeylockmanager:jkeylockmanager:2.1.0'

    compile 'com.datadoghq:java-dogstatsd-client:2.4'
    compile 'io.dropwizard.metrics:metrics-core:4.0.0'
    compile 'io.dropwizard.metrics:metrics-jvm:4.0.0'
    compile 'com.github.davidb:metrics-influxdb:0.9.3'

    compile 'com.atlassian.commonmark:commonmark:0.10.0'

    compileOnly 'org.projectlombok:lombok:1.18.6'
    annotationProcessor 'org.projectlombok:lombok:1.18.6'

    testCompileOnly 'org.projectlombok:lombok:1.18.6'
    testAnnotationProcessor 'org.projectlombok:lombok:1.18.6'
    testImplementation 'com.sparkjava:spark-core:2.7.1'

    testImplementation 'org.hamcrest:hamcrest:2.1'
    testImplementation 'org.junit.jupiter:junit-jupiter:5.9.0'

    testImplementation 'org.mockito:mockito-junit-jupiter:4.8.0'

    systemTestImplementation 'org.junit.jupiter:junit-jupiter:5.9.0'
    systemTestCompileOnly 'org.projectlombok:lombok:1.18.6'
    systemTestAnnotationProcessor 'org.projectlombok:lombok:1.18.6'

    systemTestCompile 'com.squareup.retrofit2:retrofit:2.4.0'
    systemTestCompile 'com.squareup.retrofit2:converter-gson:2.5.0'
    systemTestCompile 'com.squareup.retrofit2:converter-scalars:2.5.0'

    systemTestCompile 'org.awaitility:awaitility:3.0.0'
    systemTestCompile 'org.awaitility:awaitility-proxy:3.1.6'

    systemTestCompile 'org.glassfish.jersey.containers:jersey-container-servlet-core:2.28'
    systemTestCompile 'org.glassfish.jersey.media:jersey-media-json-jackson:2.28'

    if (osdetector.classifier == "osx-aarch_64") {
        systemTestCompile('io.netty:netty-tcnative-boringssl-static:2.0.6.Final:osx-x86_64.jar')
    } else {
        systemTestCompile('io.netty:netty-tcnative-boringssl-static:2.0.6.Final:' + osdetector.classifier)
    }
    systemTestCompile('org.microbean:microbean-helm:2.8.2.1.0.5') {
        exclude group: 'io.netty', module: 'netty-tcnative-boringssl-static'
    }

    systemTestCompile 'com.amazonaws:aws-java-sdk:1.11.248'
}


distTar {
    compression = Compression.GZIP
}

applicationDistribution.from('README.md') {
    into "doc"
}

applicationDistribution.from('config/conf') {
    into "conf"
}

applicationDistribution.from('config/bin') {
    into "bin"
}
