/*
 * Copyright 2021 Aiven Oy
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

// JMH execution borrowed from https://github.com/apache/kafka/blob/trunk/jmh-benchmarks

plugins {
    id 'com.github.johnrengelman.shadow' version '8.1.1'
}

shadowJar {
    archiveBaseName = 'kafka-ts-benchmarks'
}

ext {
    jmhVersion = "1.37"
}

dependencies {
    implementation project(':core')
    implementation group: "org.apache.kafka", name: "kafka-storage-api", version: kafkaVersion
    implementation group: "org.apache.kafka", name: "kafka-clients", version: kafkaVersion

    implementation "org.openjdk.jmh:jmh-core:$jmhVersion"
    implementation "org.openjdk.jmh:jmh-core-benchmarks:$jmhVersion"
    annotationProcessor "org.openjdk.jmh:jmh-generator-annprocess:$jmhVersion"

    implementation "org.slf4j:slf4j-log4j12:1.7.36"
}

jar {
    manifest {
        attributes "Main-Class": "org.openjdk.jmh.Main"
    }
}

tasks.register('jmh', JavaExec) {
    dependsOn ':benchmarks:clean'
    dependsOn ':benchmarks:shadowJar'

    mainClass = "-jar"

    doFirst {
        if (System.getProperty("jmhArgs")) {
            args System.getProperty("jmhArgs").split(' ')
        }
        args = [shadowJar.getArchiveFile(), *args]
    }
}

javadoc {
    enabled = false
}
