plugins {
  id "com.47deg.hood" version "$hoodVersion"
}

repositories {
    maven { url "https://kotlin.bintray.com/kotlinx" }
}

apply plugin: "me.champeau.gradle.jmh"
apply plugin: "kotlin-kapt"
apply plugin: "kotlinx-serialization"

dependencies {
    compile project(":helios-core")
    compile project(":helios-meta")
    compile project(":helios-parser")
    compile "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlinVersion"
    compile "org.jetbrains.kotlin:kotlin-reflect:$kotlinVersion"
    compile "org.jetbrains.kotlinx:kotlinx-serialization-runtime:$kotlinxVersion"
    compile "com.beust:klaxon:$klaxonVersion"
    compile "com.tomatobean:jsonparser:$jsonparserVersion"
    compile "com.squareup.moshi:moshi-kotlin:$moshiVersion"
    compile "com.github.salomonbrys.kotson:kotson:$kotsonVersion"
    compile "com.fasterxml.jackson.module:jackson-module-kotlin:$jacksonVersion"
    compile "com.jsoniter:jsoniter:$jsoniterVersion"

    kapt "io.arrow-kt:arrow-meta:$arrowVersion"
    kapt project(":helios-meta")
}

jmh {
    resultFormat = "JSON"
    resultsFile = file("$rootDir/build/reports/benchmark.json")
    timeOnIteration = "1s"
    if (project.hasProperty("jmhInclude"))
        include = [jmhInclude]
    if (project.hasProperty("jmhResultsFile"))
        resultsFile = file(jmhResultsFile)
}

task executeMasterBenchmark {
    doLast {
        jmh.resultsFile = file("$rootDir/build/reports/master_benchmark.json")
        jmh.include = ["helios.benchmarks.HeliosBenchmark"]
    }
    finalizedBy "jmh"
}

task executeHeliosBenchmark {
    doLast {
        jmh.resultsFile = file("$rootDir/build/reports/helios_benchmark.json")
        jmh.include = ["helios.benchmarks.HeliosBenchmark"]
    }
    finalizedBy "jmh"
}

task executeLibrariesBenchmarks {
    doLast {
        jmh.resultsFile = file("$rootDir/build/reports/libraries_benchmark.json")
        jmh.include = ["helios.benchmarks.Decoding", "helios.benchmarks.DecodingFromRaw", "helios.benchmarks.Parsing"]
    }
    finalizedBy "jmh"
}

task executeBenchmarks {
    doLast {
        jmh.resultsFile = file("$rootDir/build/reports/benchmarks.json")
        jmh.include = ["helios.benchmarks.HeliosBenchmark", "helios.benchmarks.Decoding", "helios.benchmarks.DecodingFromRaw", "helios.benchmarks.Parsing"]
    }
    finalizedBy "jmh"
}

compareBenchmarks {
    previousBenchmarkPath = file("$rootDir/benchmarks/master_benchmark.json")
    currentBenchmarkPath = [file("$rootDir/build/reports/helios_benchmark.json")]
    outputFormat = "json"
    benchmarkThreshold = ["Parsing": 500.00]
}

compareBenchmarksCI {
    previousBenchmarkPath = file("$rootDir/helios_master/build/reports/master_benchmark.json")
    currentBenchmarkPath = [file("$rootDir/build/reports/helios_benchmark.json")]
    outputToFile = true
    outputFormat = "json"
    benchmarkThreshold = ["Parsing": 250.00, "Decodingfromraw": 250]
    token = System.getenv("GITHUB_ACCESS_TOKEN")
    repositoryOwner = POM_GITHUB_ORG
    repositoryName = "helios"
    pullRequestSha = System.getenv("TRAVIS_PULL_REQUEST_SHA")
    pullRequestNumber = (System.getenv("TRAVIS_PULL_REQUEST") != "false") ? System.getenv("TRAVIS_PULL_REQUEST")?.toInteger() : -1
    statusTargetUrl = System.getenv("TRAVIS_JOB_WEB_URL") ? URI.create(System.getenv("TRAVIS_JOB_WEB_URL")) : null
}

uploadBenchmarks {
    benchmarkFiles = [file("$rootDir/build/reports/master_benchmark.json"), file("$rootDir/build/reports/libraries_benchmark.json")]
    token = System.getenv("GITHUB_ACCESS_TOKEN")
    repositoryOwner = POM_GITHUB_ORG
    repositoryName = "helios"
    commitMessage = "[ci skip] - Upload benchmark"
}
