buildscript {
    apply from: "$rootProject.projectDir/../gradle/kotlinGradlePlugin.gradle"
}

def rootBuildDirectory = rootProject.projectDir

task konanRun {
    subprojects.each {
        dependsOn it.getTasksByName('konanRun', true)[0]
    }
}
    
task jvmRun {
    subprojects.each {
        dependsOn it.getTasksByName('jvmRun', true)[0]
    }
}

task clean {
    subprojects.each {
        dependsOn it.getTasksByName('clean', true)[0]
    }
    delete(layout.buildDirectory)
}

defaultTasks 'konanRun'

task mergeNativeReports {
    doLast {
        mergeReports(nativeJson)
        uploadBenchmarkResultToArtifactory(nativeJson)
    }
}

task mergeJvmReports {
    doLast {
        mergeReports(jvmJson)
        uploadBenchmarkResultToArtifactory(jvmJson)
    }
}

task jvmJsonReport {
    subprojects.each {
        dependsOn(it.getTasksByName('jvmJsonReport', true)[0])
    }
}

task konanJsonReport {
    subprojects.each {
        dependsOn(it.getTasksByName('konanJsonReport', true)[0])
    }
}

subprojects.each {
    it.getTasksByName('jvmJsonReport', true)[0].finalizedBy mergeJvmReports
    it.getTasksByName('konanJsonReport', true)[0].finalizedBy mergeNativeReports
}

task ring {
    dependsOn 'clean'
    dependsOn 'ring:konanRun'
}
