refactor!: support resource obfuscation

There are still many bugs but it is stable enough for daily usage
This commit is contained in:
rhunk
2024-09-27 22:23:05 +02:00
parent 0fb2551540
commit 4dc78bcbe4
43 changed files with 898 additions and 737 deletions

View File

@@ -83,7 +83,8 @@ abstract class AbstractClassMapper(
}
}
fun writeFromJson(json: JsonObject) {
fun writeFromJson(json: JsonObject): List<String> {
val warns = mutableListOf<String>()
values.forEach { (key, value) ->
runCatching {
when (value) {
@@ -95,7 +96,11 @@ abstract class AbstractClassMapper(
}.onFailure {
Log.e("Mapper","Failed to serialize property $key")
}
if (json.get(key).let { it.isJsonNull || (it.isJsonPrimitive && it.asString == "null") }) {
warns.add("Failed to serialize property $key in $mapperName")
}
}
return warns
}
fun mapper(task: MapperContext.() -> Unit) {

View File

@@ -17,6 +17,7 @@ class ClassMapper(
private vararg val mappers: AbstractClassMapper = DEFAULT_MAPPERS,
) {
private val classes = mutableListOf<ClassDef>()
private val warnings = mutableListOf<String>()
companion object {
val DEFAULT_MAPPERS get() = arrayOf(
@@ -73,6 +74,8 @@ class ClassMapper(
}
}
fun getWarns() = warnings
suspend fun run(): JsonObject {
val context = MapperContext(classes.associateBy { it.type })
@@ -87,7 +90,7 @@ class ClassMapper(
val outputJson = JsonObject()
mappers.forEach { mapper ->
outputJson.add(mapper.mapperName, JsonObject().apply {
mapper.writeFromJson(this)
warnings.addAll(mapper.writeFromJson(this))
})
}
return outputJson