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"
version = "0.0.1-alpha.17"
version = "0.0.1-alpha.18"
repositories {
maven {

View file

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

View file

@ -19,6 +19,7 @@ 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")