aboutsummaryrefslogtreecommitdiff
path: root/buildSrc/src/FixMixins.kt
diff options
context:
space:
mode:
authorLinnea Gräf <nea@nea.moe>2024-03-31 22:08:44 +0200
committerLinnea Gräf <nea@nea.moe>2024-03-31 22:08:44 +0200
commit8d32601d891cefe11e3e261343e84aab1a40c341 (patch)
tree4ec227b83fe4538cab72abe1648691e2cc48d149 /buildSrc/src/FixMixins.kt
parent0414b87e02e51b51cf9ef0c165e5ed61e5193160 (diff)
downloadveloxcaelo-8d32601d891cefe11e3e261343e84aab1a40c341.tar.gz
veloxcaelo-8d32601d891cefe11e3e261343e84aab1a40c341.tar.bz2
veloxcaelo-8d32601d891cefe11e3e261343e84aab1a40c341.zip
Add config ui
Diffstat (limited to 'buildSrc/src/FixMixins.kt')
-rw-r--r--buildSrc/src/FixMixins.kt23
1 files changed, 15 insertions, 8 deletions
diff --git a/buildSrc/src/FixMixins.kt b/buildSrc/src/FixMixins.kt
index ea5f031..f662290 100644
--- a/buildSrc/src/FixMixins.kt
+++ b/buildSrc/src/FixMixins.kt
@@ -1,22 +1,23 @@
-import com.google.gson.Gson
+import com.google.gson.GsonBuilder
import com.google.gson.JsonArray
import com.google.gson.JsonObject
import com.google.gson.JsonPrimitive
import org.apache.tools.ant.filters.BaseParamFilterReader
+import org.gradle.api.file.FileCopyDetails
+import org.gradle.api.tasks.SourceSet
import java.io.File
import java.io.Reader
import java.io.StringReader
class MixinFilterReader(reader: Reader) : BaseParamFilterReader() {
- lateinit var sourceRoots: String
+ lateinit var sourceRoots: Collection<File>
+ val gson = GsonBuilder().setPrettyPrinting().create()
val betterReader: StringReader by lazy {
StringReader(run {
- val json = Gson().fromJson(reader.readText(), JsonObject::class.java)
+ val json = gson.fromJson(reader.readText(), JsonObject::class.java)
val mixinPackage = (json["package"] as JsonPrimitive).asString
- val allMixins = JsonArray()
+ val allMixins = (json["mixins"] as JsonArray?)?.map { it.asString }?.toMutableSet() ?: mutableSetOf()
sourceRoots
- .split(":")
- .map { File(it) }
.forEach { base ->
base.walk()
.filter { it.isFile }
@@ -31,8 +32,10 @@ class MixinFilterReader(reader: Reader) : BaseParamFilterReader() {
)
}
}
- json.add("mixins", allMixins)
- Gson().toJson(json)
+ json.add("mixins", JsonArray().also { jsonAllMixins ->
+ allMixins.forEach { jsonAllMixins.add(it) }
+ })
+ gson.toJson(json)
})
}
@@ -41,3 +44,7 @@ class MixinFilterReader(reader: Reader) : BaseParamFilterReader() {
return betterReader.read()
}
}
+
+fun FileCopyDetails.autoDiscoverMixins(sourceSet: SourceSet) {
+ filter(mapOf("sourceRoots" to sourceSet.allSource.srcDirs), MixinFilterReader::class.java)
+}