fix configuration
All checks were successful
Publish to snapshot maven / build (push) Successful in 25s

This commit is contained in:
moehreag 2024-08-27 18:17:17 +02:00
parent 247e5f06a1
commit 089535b8b1
4 changed files with 55 additions and 28 deletions

View file

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

View file

@ -1,9 +1,13 @@
package dev.frogmc.phytotelma package dev.frogmc.phytotelma
import com.google.gson.* import com.google.gson.FieldNamingPolicy
import com.google.gson.GsonBuilder
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.MappingBundle import dev.frogmc.thyroxine.api.data.MappingBundle
import org.gradle.api.Project import org.gradle.api.Project
import java.lang.reflect.Type
import java.nio.file.Path import java.nio.file.Path
import java.util.* import java.util.*
import kotlin.io.path.absolutePathString import kotlin.io.path.absolutePathString
@ -13,7 +17,7 @@ import kotlin.io.path.writeText
object ProjectStorage { object ProjectStorage {
private val data = WeakHashMap<String, ProjectData>() private val data = HashMap<String, ProjectData>()
private val gson = GsonBuilder() private val gson = GsonBuilder()
.setPrettyPrinting() .setPrettyPrinting()
.setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES) .setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES)
@ -23,12 +27,10 @@ object ProjectStorage {
fun get(project: Project): ProjectData { fun get(project: Project): ProjectData {
val id = project.getId() val id = project.getId()
if (!data.containsKey(id)) { if (!data.containsKey(id)) {
val cacheFile = getCacheFile(project) val projectData = read(getCacheFile(project))
val projectData = cacheFile.takeIf { it.exists() }?.let { read(it) }
if (projectData != null) { if (projectData != null) {
data[id] = projectData data[id] = projectData
} else { } else {
println("Creating project data store for $id, size: ${data.size}, ${this.hashCode()}")
data[id] = ProjectData() data[id] = ProjectData()
} }
} }
@ -40,7 +42,7 @@ object ProjectStorage {
} }
fun write(project: Project) { fun write(project: Project) {
write(getCacheFile(project), data[project.getId()]!!) write(getCacheFile(project), data.remove(project.getId())!!)
} }
private fun write(path: Path, projectData: ProjectData) { private fun write(path: Path, projectData: ProjectData) {
@ -70,28 +72,51 @@ class ProjectData(
internal constructor() : this(null, null, null, null, null, null, null, null) internal constructor() : this(null, null, null, null, null, null, null, null)
} }
class ProjectDataTypeAdapter : JsonSerializer<ProjectData>, JsonDeserializer<ProjectData> { class ProjectDataTypeAdapter : TypeAdapter<ProjectData>() {
override fun serialize(value: ProjectData?, typeOfSrc: Type?, context: JsonSerializationContext?): JsonElement { override fun write(out: JsonWriter, value: ProjectData) {
val out = JsonObject() out.beginObject()
if (value != null) { out.serializeNulls = true
out.addProperty("local_cache_dir", value.localCacheDir?.absolutePathString()) out.name("local_cache_dir").value(value.localCacheDir?.absolutePathString())
out.addProperty("minecraft_version", value.minecraftVersion) out.name("minecraft_version").value(value.minecraftVersion)
out.addProperty("remapped_game_jar_path", value.remappedGameJarPath?.absolutePathString()) out.name("remapped_game_jar_path").value(value.remappedGameJarPath?.absolutePathString())
out.addProperty("mappings_name", value.mappingsName) out.name("mappings_name").value(value.mappingsName)
out.addProperty("target_namespace", value.targetNamespace) out.name("target_namespace").value(value.targetNamespace)
} out.endObject()
return out
} }
override fun deserialize(json: JsonElement?, typeOfT: Type?, context: JsonDeserializationContext?): ProjectData { override fun read(r: JsonReader): ProjectData {
val out = ProjectData() r.beginObject()
if (json != null && json.isJsonObject) { val data = ProjectData()
out.localCacheDir = Path.of(json.asJsonObject.get("local_cache_dir").asString) while (r.peek() != JsonToken.END_OBJECT) {
out.minecraftVersion = json.asJsonObject.get("minecraft_version").asString val name = r.nextName()
out.remappedGameJarPath = Path.of(json.asJsonObject.get("remapped_game_jar_path").asString) if (r.peek() == JsonToken.STRING) {
out.mappingsName = json.asJsonObject.get("mappings_name").asString val value = r.nextString()
out.targetNamespace = json.asJsonObject.get("target_namespace").asString when (name) {
"local_cache_dir" -> {
data.localCacheDir = Path.of(value)
} }
return out
"minecraft_version" -> {
data.minecraftVersion = value
}
"remapped_game_jar_path" -> {
data.remappedGameJarPath = Path.of(value)
}
"mappings_name" -> {
data.mappingsName = value
}
"target_namespace" -> {
data.targetNamespace = value
}
}
} else {
r.skipValue()
}
}
r.endObject()
return data
} }
} }

View file

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

View file

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