//file:noinspection GroovyAssignabilityCheck

plugins {
    id("java")
    id("checkstyle")
    id("com.github.spotbugs").version("6.1.7")
    id("org.cadixdev.licenser").version("0.6.1")
    id("com.gradleup.shadow").version("8.3.6")
}

setGroup("net.elytrium")
setVersion("1.0.8")

java {
    setSourceCompatibility(JavaVersion.VERSION_17)
    setTargetCompatibility(JavaVersion.VERSION_17)
}

compileJava {
    getOptions().setEncoding("UTF-8")
}

repositories {
    mavenCentral()

    maven {
        setName("elytrium-repo")
        setUrl("https://maven.elytrium.net/repo/")
    }
    maven {
        setName("papermc-repo")
        setUrl("https://repo.papermc.io/repository/maven-public/")
    }
}

dependencies {
    implementation("net.elytrium.commons:kyori:1.3.0")
    implementation("net.elytrium.commons:velocity:1.3.0")
    implementation("net.elytrium.commons:utils:1.3.0")
    implementation("net.elytrium:fastprepare:1.0.11")
    implementation("net.elytrium:serializer:1.1.1")
    implementation('it.unimi.dsi:fastutil-core:8.5.11')
    compileOnly("com.velocitypowered:velocity-api:3.4.0-SNAPSHOT")
    annotationProcessor("com.velocitypowered:velocity-api:3.4.0-SNAPSHOT")
    compileOnly("com.velocitypowered:velocity-proxy:3.4.0-SNAPSHOT")
    compileOnly('com.github.spotbugs:spotbugs-annotations:4.9.3')
    // Needs for some velocity methods.
    compileOnly('io.netty:netty-codec:4.1.86.Final')
    compileOnly('io.netty:netty-handler:4.1.86.Final')

    implementation("org.bstats:bstats-velocity:3.0.0")
}

shadowJar {
    getArchiveClassifier().set("")

    exclude("it/unimi/dsi/fastutil/booleans/**")
    exclude("it/unimi/dsi/fastutil/bytes/**")
    exclude("it/unimi/dsi/fastutil/chars/**")
    exclude("it/unimi/dsi/fastutil/doubles/**")
    exclude("it/unimi/dsi/fastutil/floats/**")
    exclude("it/unimi/dsi/fastutil/longs/**")
    exclude("it/unimi/dsi/fastutil/shorts/**")
    exclude("it/unimi/dsi/fastutil/io/**")

    exclude("it/unimi/dsi/fastutil/objects/*ObjectArray*")
    exclude("it/unimi/dsi/fastutil/objects/*ObjectAVL*")
    exclude("it/unimi/dsi/fastutil/objects/*Object*Big*")
    exclude("it/unimi/dsi/fastutil/objects/*Object2Boolean*")
    exclude("it/unimi/dsi/fastutil/objects/*Object2Byte*")
    exclude("it/unimi/dsi/fastutil/objects/*Object2Char*")
    exclude("it/unimi/dsi/fastutil/objects/*Object2Double*")
    exclude("it/unimi/dsi/fastutil/objects/*Object2Float*")
    exclude("it/unimi/dsi/fastutil/objects/*Object2IntArray*")
    exclude("it/unimi/dsi/fastutil/objects/*Object2IntAVL*")
    exclude("it/unimi/dsi/fastutil/objects/*Object2IntRB*")
    exclude("it/unimi/dsi/fastutil/objects/*Object2Long*")
    exclude("it/unimi/dsi/fastutil/objects/*Object2Object*")
    exclude("it/unimi/dsi/fastutil/objects/*Object2Reference*")
    exclude("it/unimi/dsi/fastutil/objects/*Object2Short*")
    exclude("it/unimi/dsi/fastutil/objects/*ObjectRB*")
    exclude("it/unimi/dsi/fastutil/objects/*Reference*")

    exclude("it/unimi/dsi/fastutil/ints/*Int2Boolean*")
    exclude("it/unimi/dsi/fastutil/ints/*Int2Byte*")
    exclude("it/unimi/dsi/fastutil/ints/*Int2Char*")
    exclude("it/unimi/dsi/fastutil/ints/*Int2Double*")
    exclude("it/unimi/dsi/fastutil/ints/*Int2Float*")
    exclude("it/unimi/dsi/fastutil/ints/*Int2Long*")
    exclude("it/unimi/dsi/fastutil/ints/*Int2Short*")
    exclude("it/unimi/dsi/fastutil/ints/*Int2Reference*")
    exclude("it/unimi/dsi/fastutil/ints/IntAVL*")
    exclude("it/unimi/dsi/fastutil/ints/IntArray*")
    exclude("it/unimi/dsi/fastutil/ints/*IntBi*")
    exclude("it/unimi/dsi/fastutil/ints/Int*Pair")
    exclude("it/unimi/dsi/fastutil/ints/IntLinked*")
    exclude("it/unimi/dsi/fastutil/ints/IntList*")
    exclude("it/unimi/dsi/fastutil/ints/IntHeap*")
    exclude("it/unimi/dsi/fastutil/ints/IntRB*")
    exclude("it/unimi/dsi/fastutil/ints/IntSorted*")
    exclude("it/unimi/dsi/fastutil/ints/*Priority*")
    exclude("it/unimi/dsi/fastutil/ints/*BigList*")

    relocate("org.bstats", "net.elytrium.fastmotd.thirdparty.org.bstats")
    relocate("net.elytrium.fastprepare", "net.elytrium.fastmotd.thirdparty.fastprepare")
    relocate("net.elytrium.commons", "net.elytrium.fastmotd.thirdparty.commons")
    relocate("net.elytrium.serializer", "net.elytrium.fastmotd.thirdparty.serializer")
}

license {
    setHeader(file("HEADER.txt"))
}

checkstyle {
    setToolVersion("10.1")
    setConfigFile(file("${this.getRootDir()}/config/checkstyle/checkstyle.xml"))
    setConfigProperties("configDirectory": "${this.getRootDir()}/config/checkstyle")

    // The build should immediately fail if we have errors.
    setMaxErrors(0)
    setMaxWarnings(0)
}

spotbugsMain {
    setExcludeFilter(file("${this.getRootDir()}/config/spotbugs/suppressions.xml"))

    reports {
        html {
            getRequired().set(true)
            getOutputLocation().set(file("${this.getBuildDir()}/reports/spotbugs/main/spotbugs.html"))
            setStylesheet("fancy-hist.xsl")
        }
    }
}

artifacts {
    archives(shadowJar)
}

sourceSets.main.getJava().srcDir(getTasks().register("generateTemplates", Copy) { task ->
    task.getInputs().properties("version": getVersion())

    task.from(file("src/main/templates"))
            .into(getLayout().getBuildDirectory().dir("generated/sources/templates"))
            .expand("version": getVersion())
}.map {
    it.getOutputs()
})

assemble.dependsOn(shadowJar)