From 0414b87e02e51b51cf9ef0c165e5ed61e5193160 Mon Sep 17 00:00:00 2001 From: Linnea Gräf Date: Sat, 30 Mar 2024 19:44:32 +0100 Subject: Initial commit --- buildSrc/src/FixMixins.kt | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 buildSrc/src/FixMixins.kt (limited to 'buildSrc/src') diff --git a/buildSrc/src/FixMixins.kt b/buildSrc/src/FixMixins.kt new file mode 100644 index 0000000..ea5f031 --- /dev/null +++ b/buildSrc/src/FixMixins.kt @@ -0,0 +1,43 @@ +import com.google.gson.Gson +import com.google.gson.JsonArray +import com.google.gson.JsonObject +import com.google.gson.JsonPrimitive +import org.apache.tools.ant.filters.BaseParamFilterReader +import java.io.File +import java.io.Reader +import java.io.StringReader + +class MixinFilterReader(reader: Reader) : BaseParamFilterReader() { + lateinit var sourceRoots: String + val betterReader: StringReader by lazy { + StringReader(run { + val json = Gson().fromJson(reader.readText(), JsonObject::class.java) + val mixinPackage = (json["package"] as JsonPrimitive).asString + val allMixins = JsonArray() + sourceRoots + .split(":") + .map { File(it) } + .forEach { base -> + base.walk() + .filter { it.isFile } + .forEach { + val relativeString = it.toRelativeString(base).replace("\\", "/") + if (relativeString.startsWith(mixinPackage.replace(".", "/") + "/") + && relativeString.endsWith(".java") + && it.readText().contains("@Mixin") + ) + allMixins.add( + relativeString.replace("/", ".").dropLast(5).drop(mixinPackage.length + 1) + ) + } + } + json.add("mixins", allMixins) + Gson().toJson(json) + }) + + } + + override fun read(): Int { + return betterReader.read() + } +} -- cgit