72 lines
2.7 KiB
Plaintext
72 lines
2.7 KiB
Plaintext
|
import com.squareup.javapoet.ClassName
|
||
|
import com.squareup.javapoet.ParameterizedTypeName
|
||
|
import com.squareup.javapoet.TypeName
|
||
|
import java.nio.file.Files
|
||
|
import io.gitlab.jfronny.scripts.*
|
||
|
import java.util.LinkedList
|
||
|
import javax.lang.model.element.Modifier.*
|
||
|
|
||
|
plugins {
|
||
|
id("jfmod") version "1.2-SNAPSHOT"
|
||
|
id("jf.codegen") version "1.2-SNAPSHOT"
|
||
|
id("io.gitlab.jfronny.libjf.libjf-config-compiler-plugin")
|
||
|
}
|
||
|
|
||
|
val flavor by extra(prop("flavor", "modrinth"))
|
||
|
|
||
|
dependencies {
|
||
|
modImplementation("io.gitlab.jfronny.libjf:libjf-config-core-v1:${prop("libjf_version")}")
|
||
|
|
||
|
// Dev env
|
||
|
modLocalRuntime("io.gitlab.jfronny.libjf:libjf-devutil:${prop("libjf_version")}")
|
||
|
modLocalRuntime("io.gitlab.jfronny.libjf:libjf-config-ui-tiny-v1:${prop("libjf_version")}")
|
||
|
modLocalRuntime("net.fabricmc.fabric-api:fabric-api:${prop("fabric_version")}")
|
||
|
modLocalRuntime("com.terraformersmc:modmenu:4.1.1")
|
||
|
}
|
||
|
|
||
|
fun list(`package`: String) = Files.list(projectDir.resolve("src/main/java").resolve(`package`.replace('.', '/')).toPath()).use { stream ->
|
||
|
stream
|
||
|
.map { it.fileName.toString() }
|
||
|
.map { it.substring(0, it.lastIndexOf('.')) }
|
||
|
.filter { it.endsWith("Provider") }
|
||
|
.map { ClassName.get(`package`, it) }
|
||
|
.toList()
|
||
|
}
|
||
|
|
||
|
val classes = LinkedList(list("io.gitlab.jfronny.breakme.crash.safe"))
|
||
|
|
||
|
if (flavor == "curseforge") {
|
||
|
sourceSets.main.get().java.filter.exclude("**/unsafe/*")
|
||
|
sourceSets.main.get().resources.exclude("**/native/*")
|
||
|
} else {
|
||
|
classes.addAll(list("io.gitlab.jfronny.breakme.crash.unsafe"))
|
||
|
}
|
||
|
|
||
|
sourceSets {
|
||
|
main {
|
||
|
generate(project) {
|
||
|
`class`("io.gitlab.jfronny.breakme.crash", "KnownProviders") {
|
||
|
modifiers(PUBLIC)
|
||
|
val type = ParameterizedTypeName.get(ClassName.get(Map::class.java), TypeName.get(String::class.java), ClassName.get("io.gitlab.jfronny.breakme.crash", "CrashProvider"))
|
||
|
field(type, "PROVIDERS", PUBLIC, STATIC, FINAL) {
|
||
|
initializer {
|
||
|
add("Map.of(\$>")
|
||
|
if (!classes.isEmpty()) {
|
||
|
indent()
|
||
|
var first = false
|
||
|
for (klazz in classes) {
|
||
|
if (!first) first = true
|
||
|
else add(",")
|
||
|
val name = klazz.simpleName()
|
||
|
add("\n\$S, new \$T()", name.substring(0, name.length - "Provider".length), klazz)
|
||
|
}
|
||
|
add("\n")
|
||
|
}
|
||
|
add("\$<)")
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|