buildscript {
    repositories {
        maven { url "https://dl.bintray.com/47deg/hood" }
    }
    
    dependencies {
        classpath "com.47deg:hood:$HOOD_VERSION"
    }
    ext {
        JMH_RESULT_FOR_MASTER_BRANCH = "$rootDir/master-branch.json"
        JMH_RESULT_FOR_PULL_REQUEST = "$rootDir/pull-request.json"
    }
}

plugins {
    id "org.jetbrains.kotlin.jvm"
    id "org.jlleitschuh.gradle.ktlint"
    id "me.champeau.gradle.jmh" version "$JMH_PLUGIN_VERSION"
    id "io.morethan.jmhreport" version "$JMH_REPORT_PLUGIN_VERSION"
}

apply plugin: "com.47deg.hood"

apply from: "$SUB_PROJECT"

dependencies {
    compile project(":arrow-fx")
    compile project(":arrow-fx-rx2")
    compile project(":arrow-fx-reactor")
    compile project(":arrow-benchmarks-fx:arrow-scala-benchmarks")
    compile project(":arrow-benchmarks-fx:arrow-kio-benchmarks")
    compile "org.jetbrains.kotlinx:kotlinx-coroutines-core:$KOTLINX_COROUTINES_VERSION"
    compileOnly "org.openjdk.jmh:jmh-core:$JMH_CORE_VERSION"
}

jmh {
    include = [
//            'arrow.benchmarks.Async',
//            'arrow.benchmarks.AttemptNonRaised',
//            'arrow.benchmarks.AttemptRaisedError',
//            'arrow.benchmarks.Bracket',
//            'arrow.benchmarks.Cancellable',
//            'arrow.benchmarks.DeepBind',
//            'arrow.benchmarks.Defer',
//            'arrow.benchmarks.Delay',
//            'arrow.benchmarks.ForkFiber',
//            'arrow.benchmarks.HandleNonRaised',
//            'arrow.benchmarks.HandleRaisedError',
//            'arrow.benchmarks.LeftBind',
//            'arrow.benchmarks.Map',
//            'arrow.benchmarks.MapStream',
//            'arrow.benchmarks.ParMap',
//            'arrow.benchmarks.Pure',
//            'arrow.benchmarks.RacePair',
//            'arrow.benchmarks.Uncancellable',
            'arrow.benchmarks.Queue'
    ]
    resultFormat = 'json'
    resultsFile = file('build/reports/benchmarks.json')
    timeOnIteration = '1s'
    failOnError = true
    if (project.hasProperty("jmhInclude"))
        include = [jmhInclude]
    if (project.hasProperty("jmhResultsFile"))
        resultsFile = file(jmhResultsFile)

}

jmhReport {
    jmhResultPath = project.file('build/reports/benchmarks.json')
    jmhReportOutput = project.file('build/reports')
}

task jmhForMasterBranch {
    doLast {
        jmh.resultsFile = file(JMH_RESULT_FOR_MASTER_BRANCH)
    }
    finalizedBy "jmh"
}

task jmhForPullRequest {
    doLast {
        jmh.resultsFile = file(JMH_RESULT_FOR_PULL_REQUEST)
    }
    finalizedBy "jmh"
}

compareBenchmarksCI {
    previousBenchmarkPath = file(JMH_RESULT_FOR_MASTER_BRANCH)
    currentBenchmarkPath = [file(JMH_RESULT_FOR_PULL_REQUEST)]
    outputToFile = true
    outputFormat = "json"
    token = System.getenv("CI_TOKEN")
    repositoryOwner = "arrow-kt"
    repositoryName = "arrow-fx"
    pullRequestSha = System.getenv("GITHUB_SHA")
    pullRequestNumber = System.getenv("PULL_REQUEST_NUMBER")?.toInteger()
}

repositories {
    maven { url "https://jitpack.io" }
}
