<commit_before>@file:Suppress("KDocMissingDocumentation", "PublicApiImplicitType")

import com.adarshr.gradle.testlogger.theme.ThemeType
import com.github.breadmoirai.ChangeLogSupplier
import com.jfrog.bintray.gradle.tasks.BintrayUploadTask
import org.jetbrains.dokka.gradle.DokkaTask
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import java.nio.file.Files
import java.nio.file.Paths
import java.text.SimpleDateFormat
import java.util.*
import kotlin.properties.ReadOnlyProperty
import kotlin.reflect.KProperty

val githubOrganizationName = "NephyProject"
val githubRepositoryName = "Penicillin"
val packageGroupId = "jp.nephy"
val packageName = "Penicillin"
val packageVersion = Version(4, 1, 2)
val packageDescription = "Full-featured Twitter API wrapper for Kotlin."

val ktorVersion = "1.1.2"
val spekVersion = "2.0.0-rc.1"

plugins { 
    kotlin("jvm") version "1.3.20"
    id("kotlinx-serialization") version "1.3.20"

    // For testing
    id("com.adarshr.test-logger") version "1.6.0"
    id("build-time-tracker") version "0.11.0"

    // For publishing
    id("maven-publish")
    id("com.jfrog.bintray") version "1.8.4"
    id("com.github.breadmoirai.github-release") version "2.2.4"
    
    // For documentation
    id("org.jetbrains.dokka") version "0.9.17"
}

/*
 * Extensions
 */

inline fun <reified T: Task> Project.task(name: String, crossinline block: T.() -> Unit): T {
    return (tasks.findByName(name) as? T ?: task<T>(name)).apply(block)
}

fun Project.property(key: String? = null) = object: ReadOnlyProperty<Project, String?> {
    override fun getValue(thisRef: Project, property: KProperty<*>): String? {
        val name = key ?: property.name
        return (properties[name] ?: System.getProperty(name) ?: System.getenv(name))?.toString()
    }
}

/*
 * Dependencies
 */

repositories {
    mavenCentral()
    jcenter()
    maven(url = "https://kotlin.bintray.com/ktor")
    maven(url = "https://kotlin.bintray.com/kotlinx")
    maven(url = "https://kotlin.bintray.com/kotlin-eap")
    maven(url = "https://dl.bintray.com/spekframework/spek-dev")
}

dependencies {
    implementation(kotlin("stdlib-jdk8"))

    implementation("io.ktor:ktor-client-core-jvm:$ktorVersion")
    testImplementation("io.ktor:ktor-client-apache:$ktorVersion")
    testImplementation("io.ktor:ktor-client-cio:$ktorVersion")
    testImplementation("io.ktor:ktor-client-jetty:$ktorVersion")
    testImplementation("io.ktor:ktor-client-okhttp:$ktorVersion")
    testImplementation("io.ktor:ktor-client-mock-jvm:$ktorVersion")

    implementation("jp.nephy:jsonkt:4.7")

    testImplementation("com.twitter.twittertext:twitter-text:3.0.1")
    
    // For testing
    testImplementation("org.spekframework.spek2:spek-dsl-jvm:$spekVersion") {
        exclude(group = "org.jetbrains.kotlin")
    }
    testRuntimeOnly("org.spekframework.spek2:spek-runner-junit5:$spekVersion") {
        exclude(group = "org.junit.platform")
        exclude(group = "org.jetbrains.kotlin")
    }
    testRuntimeOnly(kotlin("reflect"))
    
    // For logging
    implementation("io.github.microutils:kotlin-logging:1.6.22")
    testImplementation("ch.qos.logback:logback-core:1.2.3")
    testImplementation("ch.qos.logback:logback-classic:1.2.3")
    testImplementation("org.fusesource.jansi:jansi:1.17.1")
}

/*
 * Compilations
 */

task<KotlinCompile>("compileKotlin") {
    kotlinOptions { <commit_msg>Update Kotlin to 1.3.21 and upgrade other deps<commit_after>@file:Suppress("KDocMissingDocumentation", "PublicApiImplicitType")

import com.adarshr.gradle.testlogger.theme.ThemeType
import com.github.breadmoirai.ChangeLogSupplier
import com.jfrog.bintray.gradle.tasks.BintrayUploadTask
import org.jetbrains.dokka.gradle.DokkaTask
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import java.nio.file.Files
import java.nio.file.Paths
import java.text.SimpleDateFormat
import java.util.*
import kotlin.properties.ReadOnlyProperty
import kotlin.reflect.KProperty

val githubOrganizationName = "NephyProject"
val githubRepositoryName = "Penicillin"
val packageGroupId = "jp.nephy"
val packageName = "Penicillin"
val packageVersion = Version(4, 1, 2)
val packageDescription = "Full-featured Twitter API wrapper for Kotlin."

val ktorVersion = "1.1.2"
val spekVersion = "2.0.0"

plugins { 
    kotlin("jvm") version "1.3.21"
    id("kotlinx-serialization") version "1.3.21"

    // For testing
    id("com.adarshr.test-logger") version "1.6.0"
    id("build-time-tracker") version "0.11.1"

    // For publishing
    id("maven-publish")
    id("com.jfrog.bintray") version "1.8.4"
    id("com.github.breadmoirai.github-release") version "2.2.4"
    
    // For documentation
    id("org.jetbrains.dokka") version "0.9.17"
}

/*
 * Extensions
 */

inline fun <reified T: Task> Project.task(name: String, crossinline block: T.() -> Unit): T {
    return (tasks.findByName(name) as? T ?: task<T>(name)).apply(block)
}

fun Project.property(key: String? = null) = object: ReadOnlyProperty<Project, String?> {
    override fun getValue(thisRef: Project, property: KProperty<*>): String? {
        val name = key ?: property.name
        return (properties[name] ?: System.getProperty(name) ?: System.getenv(name))?.toString()
    }
}

/*
 * Dependencies
 */

repositories {
    mavenCentral()
    jcenter()
    maven(url = "https://kotlin.bintray.com/ktor")
    maven(url = "https://kotlin.bintray.com/kotlinx")
    maven(url = "https://kotlin.bintray.com/kotlin-eap")
    maven(url = "https://dl.bintray.com/spekframework/spek-dev")
}

dependencies {
    implementation(kotlin("stdlib-jdk8"))

    implementation("io.ktor:ktor-client-core-jvm:$ktorVersion")
    testImplementation("io.ktor:ktor-client-apache:$ktorVersion")
    testImplementation("io.ktor:ktor-client-cio:$ktorVersion")
    testImplementation("io.ktor:ktor-client-jetty:$ktorVersion")
    testImplementation("io.ktor:ktor-client-okhttp:$ktorVersion")
    testImplementation("io.ktor:ktor-client-mock-jvm:$ktorVersion")

    implementation("jp.nephy:jsonkt:4.7")

    testImplementation("com.twitter.twittertext:twitter-text:3.0.1")
    
    // For testing
    testImplementation("org.spekframework.spek2:spek-dsl-jvm:$spekVersion") {
        exclude(group = "org.jetbrains.kotlin")
    }
    testRuntimeOnly("org.spekframework.spek2:spek-runner-junit5:$spekVersion") {
        exclude(group = "org.junit.platform")
        exclude(group = "org.jetbrains.kotlin")
    }
    testRuntimeOnly(kotlin("reflect"))
    
    // For logging
    implementation("io.github.microutils:kotlin-logging:1.6.23")
    testImplementation("ch.qos.logback:logback-core:1.2.3")
    testImplementation("ch.qos.logback:logback-classic:1.2.3")
    testImplementation("org.fusesource.jansi:jansi:1.17.1")
}

/*
 * Compilations
 */

task<KotlinCompile>("compileKotlin") {
    kotlinOptions { 
{'fraction_non_alphanumeric': 0.15021961932650074, 'fraction_numerical': 0.017423133235724742, 'mean_word_length': 4.238496932515337, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 15, 'https://': 8, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '59937', 'n_tokens_mistral': 2487, 'n_tokens_neox': 2398, 'n_words': 339}