re-add mapping configuration caching

This commit is contained in:
moehreag 2024-08-27 19:07:23 +02:00
parent 089535b8b1
commit f3d17a60ca
4 changed files with 270 additions and 4 deletions

View file

@ -7,7 +7,7 @@ plugins {
}
group = "dev.frogmc"
version = "0.0.1-alpha.18"
version = "0.0.1-alpha.19+local"
repositories {
maven {

View file

@ -6,7 +6,10 @@ import com.google.gson.TypeAdapter
import com.google.gson.stream.JsonReader
import com.google.gson.stream.JsonToken
import com.google.gson.stream.JsonWriter
import dev.frogmc.thyroxine.api.data.DocumentationData
import dev.frogmc.thyroxine.api.data.MappingBundle
import dev.frogmc.thyroxine.api.data.MappingData
import dev.frogmc.thyroxine.api.data.Member
import org.gradle.api.Project
import java.nio.file.Path
import java.util.*
@ -23,6 +26,7 @@ object ProjectStorage {
.setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES)
.registerTypeAdapter(ProjectData::class.java, ProjectDataTypeAdapter())
.create()
private val timer = Timer()
fun get(project: Project): ProjectData {
val id = project.getId()
@ -33,6 +37,11 @@ object ProjectStorage {
} else {
data[id] = ProjectData()
}
timer.schedule(object : TimerTask() {
override fun run() {
}
}, 1000 * 60 * 5)
}
return data[id]!!
}
@ -42,7 +51,7 @@ object ProjectStorage {
}
fun write(project: Project) {
write(getCacheFile(project), data.remove(project.getId())!!)
write(getCacheFile(project), data[project.getId()]!!)
}
private fun write(path: Path, projectData: ProjectData) {
@ -79,6 +88,8 @@ class ProjectDataTypeAdapter : TypeAdapter<ProjectData>() {
out.name("local_cache_dir").value(value.localCacheDir?.absolutePathString())
out.name("minecraft_version").value(value.minecraftVersion)
out.name("remapped_game_jar_path").value(value.remappedGameJarPath?.absolutePathString())
out.name("mappings")
value.mappings?.let { MappingBundleTypeAdapter.write(out, it) } ?: out.nullValue()
out.name("mappings_name").value(value.mappingsName)
out.name("target_namespace").value(value.targetNamespace)
out.endObject()
@ -112,6 +123,8 @@ class ProjectDataTypeAdapter : TypeAdapter<ProjectData>() {
data.targetNamespace = value
}
}
} else if (name == "mappings") {
data.mappings = MappingBundleTypeAdapter.read(r)
} else {
r.skipValue()
}
@ -120,3 +133,258 @@ class ProjectDataTypeAdapter : TypeAdapter<ProjectData>() {
return data
}
}
object MappingBundleTypeAdapter : TypeAdapter<MappingBundle>() {
override fun write(out: JsonWriter, value: MappingBundle) {
out.beginObject()
out.name("data").beginArray()
value.data.forEach {
out.beginObject()
out.name("srcNs").value(it.srcNamespace)
out.name("dstNs").value(it.dstNamespace)
out.name("classes").beginObject()
it.classes.forEach { (k, v) ->
out.name(k).value(v)
}
out.endObject()
out.name("methods").beginArray()
it.methods.forEach { (k, v) ->
out.beginObject()
out.name("owner").value(k.owner)
out.name("desc").value(k.descriptor)
out.name("name").value(k.name)
out.name("value").value(v)
out.endObject()
}
out.endArray()
out.name("fields").beginArray()
it.fields.forEach { (k, v) ->
out.beginObject()
out.name("owner").value(k.owner)
out.name("desc").value(k.descriptor)
out.name("name").value(k.name)
out.name("value").value(v)
out.endObject()
}
out.endArray()
out.name("parameters").beginArray()
it.parameters.forEach { (k, v) ->
out.beginObject()
out.name("owner").value(k.owner)
out.name("desc").value(k.descriptor)
out.name("name").value(k.name)
out.name("value").beginObject()
v.forEach { (i, s) ->
out.name("$i").value(s)
}
out.endObject()
out.endObject()
}
out.endArray()
out.endObject()
}
out.endArray()
out.name("documentation").beginArray()
value.documentation.forEach {
out.beginObject()
out.name("ns").value(it.namespace)
out.name("classes").beginArray()
it.classes.forEach { c ->
out.beginObject()
out.name("name").value(c.name)
out.name("javadoc").beginArray()
c.javadoc.forEach { d ->
out.value(d)
}
out.endArray()
out.name("methods").beginArray()
c.methods.forEach { m ->
out.beginObject()
out.name("name").value(m.name)
out.name("desc").value(m.descriptor)
out.name("javadoc").beginArray()
m.javadoc.forEach { d ->
out.value(d)
}
out.endArray()
out.endObject()
}
out.endArray()
out.name("fields").beginArray()
c.fields.forEach { f ->
out.beginObject()
out.name("name").value(f.name)
out.name("desc").value(f.descriptor)
out.name("javadoc").beginArray()
f.javadoc.forEach { d ->
out.value(d)
}
out.endArray()
out.endObject()
}
out.endArray()
out.endObject()
}
out.endArray()
out.endObject()
}
out.endArray()
out.endObject()
}
override fun read(r: JsonReader): MappingBundle {
val out = MappingBundle()
r.beginObject()
r.nextName()
r.beginArray()
while (r.peek() != JsonToken.END_ARRAY) {
r.beginObject()
out.data.add(readData(r))
r.endObject()
}
r.endArray()
r.nextName()
r.beginArray()
while (r.peek() != JsonToken.END_ARRAY) {
r.beginObject()
r.nextName()
val namespace = r.nextString()
val data = DocumentationData(namespace)
out.documentation.add(data)
r.nextName()
r.beginArray()
while (r.peek() != JsonToken.END_ARRAY) {
r.beginObject()
r.nextName()
val name = r.nextString()
r.nextName()
val javadoc = mutableListOf<String>()
r.beginArray()
while (r.peek() != JsonToken.END_ARRAY) {
javadoc.add(r.nextString())
}
r.endArray()
r.nextName()
val methods = mutableListOf<DocumentationData.Method>()
r.beginArray()
while (r.peek() != JsonToken.END_ARRAY) {
r.beginObject()
r.nextName()
val methodName = r.nextString()
r.nextName()
val desc = r.nextString()
r.nextName()
val methodJavadoc = mutableListOf<String>()
r.beginArray()
while (r.peek() != JsonToken.END_ARRAY) {
methodJavadoc.add(r.nextString())
}
r.endArray()
methods.add(DocumentationData.Method(methodName, desc, methodJavadoc))
r.endObject()
}
r.endArray()
r.nextName()
val fields = mutableListOf<DocumentationData.Field>()
r.beginArray()
while (r.peek() != JsonToken.END_ARRAY) {
r.beginObject()
r.nextName()
val fieldName = r.nextString()
r.nextName()
val desc = r.nextString()
r.nextName()
val fieldJavadoc = mutableListOf<String>()
r.beginArray()
while (r.peek() != JsonToken.END_ARRAY) {
fieldJavadoc.add(r.nextString())
}
r.endArray()
fields.add(DocumentationData.Field(fieldName, desc, fieldJavadoc))
r.endObject()
}
r.endArray()
data.classes.add(DocumentationData.Class(name, javadoc, fields, methods))
r.endObject()
}
r.endArray()
r.endObject()
}
r.endArray()
r.endObject()
return out
}
private fun readData(r: JsonReader): MappingData {
r.nextName()
val srcNs = r.nextString()
r.nextName()
val dstNs = r.nextString()
r.nextName()
r.beginObject()
val classes = mutableMapOf<String, String>()
while (r.peek() != JsonToken.END_OBJECT) {
classes[r.nextName()] = r.nextString()
}
r.endObject()
r.nextName()
r.beginArray()
val methods = mutableMapOf<Member, String>()
while (r.peek() != JsonToken.END_ARRAY) {
r.beginObject()
r.nextName()
val owner = r.nextString()
r.nextName()
val desc = r.nextString()
r.nextName()
val name = r.nextString()
r.nextName()
val value = r.nextString()
methods[Member(owner, name, desc)] = value
r.endObject()
}
r.endArray()
r.nextName()
r.beginArray()
val fields = mutableMapOf<Member, String>()
while (r.peek() != JsonToken.END_ARRAY) {
r.beginObject()
r.nextName()
val owner = r.nextString()
r.nextName()
val desc = r.nextString()
r.nextName()
val name = r.nextString()
r.nextName()
val value = r.nextString()
fields[Member(owner, name, desc)] = value
r.endObject()
}
r.endArray()
r.nextName()
r.beginArray()
val parameters = mutableMapOf<Member, MutableMap<Int, String>>()
while (r.peek() != JsonToken.END_ARRAY) {
r.beginObject()
r.nextName()
val owner = r.nextString()
r.nextName()
val desc = r.nextString()
r.nextName()
val name = r.nextString()
r.nextName()
r.beginObject()
val values = mutableMapOf<Int, String>()
while (r.peek() != JsonToken.END_OBJECT) {
values[r.nextName().toInt()] = r.nextString()
}
r.endObject()
parameters[Member(owner, name, desc)] = values
r.endObject()
}
r.endArray()
return MappingData(srcNs, dstNs, classes, methods, fields, parameters)
}
}

View file

@ -39,7 +39,6 @@ abstract class PhytotelmaGradleExtensionImpl @Inject constructor(
if (VersionChecker.validateVersion(project, version, offlineMode = project.gradle.startParameter.isOffline)) {
projectData.minecraftVersion = version
println(projectData.hashCode())
val mappings = mcConf.mappings.get()
println("Using mappings: " + mcConf.mappingsName)

View file

@ -19,7 +19,6 @@ object RunConfigGenerator {
val ADAPTERS = arrayOf(EclipseAdapter(), IdeaAdapter())
fun generate(project: Project) {
println(ProjectStorage.get(project))
val assetPath = PhytotelmaPlugin.globalCacheDir.resolve("assets").absolute()
val assetIndexPath = assetPath.resolve("indexes")