Skip to content

Commit

Permalink
refactor: remove deprecated elements, fix TODOs
Browse files Browse the repository at this point in the history
  • Loading branch information
zlataovce committed Dec 1, 2024
1 parent 70191c2 commit 9b939d1
Show file tree
Hide file tree
Showing 31 changed files with 178 additions and 643 deletions.
2 changes: 1 addition & 1 deletion core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ plugins {

dependencies {
api(libs.bundles.asm)
api(libs.bundles.jackson)
api(libs.mapping.io)
implementation(libs.bundles.jackson)
implementation(libs.bundles.kotlin)
implementation(libs.kotlin.logging.jvm)
implementation(libs.kotlinx.coroutines.core.jvm)
Expand Down
49 changes: 0 additions & 49 deletions core/src/main/kotlin/me/kcra/takenaka/core/VersionManifest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ package me.kcra.takenaka.core
import com.fasterxml.jackson.annotation.JsonIgnoreProperties
import com.fasterxml.jackson.annotation.JsonProperty
import com.fasterxml.jackson.core.JacksonException
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.module.kotlin.readValue
import me.kcra.takenaka.core.util.*
import java.io.IOException
Expand All @@ -37,17 +36,6 @@ import kotlin.io.path.isRegularFile
*/
const val VERSION_MANIFEST_V2 = "https://piston-meta.mojang.com/mc/game/version_manifest_v2.json"

/**
* Fetches and deserializes the version manifest from Mojang's API.
*
* @return the version manifest
*/
@Deprecated(
"Jackson will be an implementation detail in the future.",
ReplaceWith("versionManifestOf()", "me.kcra.takenaka.core.versionManifestOf")
)
fun ObjectMapper.versionManifest(): VersionManifest = readValue(URL(VERSION_MANIFEST_V2))

/**
* Fetches and deserializes the version manifest from Mojang's API.
*
Expand Down Expand Up @@ -86,43 +74,6 @@ fun versionManifestFrom(cacheFile: Path, url: String = VERSION_MANIFEST_V2): Ver
}
}

/**
* Retrieves the version manifest from Mojang's API or a cache file,
* fetching it if it could not be deserialized or the content length changed.
*
* @param cacheFile the cache file, does not need to exist
* @return the version manifest
*/
@Deprecated(
"Jackson will be an implementation detail in the future.",
ReplaceWith("versionManifestFrom(cacheFile)", "me.kcra.takenaka.core.versionManifestFrom")
)
fun ObjectMapper.cachedVersionManifest(cacheFile: Path): VersionManifest {
val url = URL(VERSION_MANIFEST_V2)

if (cacheFile.isRegularFile()) {
val length = url.contentLength
if (cacheFile.fileSize() == length) {
try {
return readValue(cacheFile)
} catch (_: JacksonException) {
// failed to read cached file, corrupted? fetch it again
}
}
}

url.httpRequest {
if (it.ok) {
cacheFile.parent.createDirectories()
it.copyTo(cacheFile)

return readValue(cacheFile)
}

throw IOException("Failed to fetch v2 Mojang manifest, received ${it.responseCode}")
}
}

/**
* Mojang's v2 version manifest.
*
Expand Down
6 changes: 0 additions & 6 deletions core/src/main/kotlin/me/kcra/takenaka/core/Workspace.kt
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,6 @@ open class WorkspaceBuilder {
*/
open var rootDirectory by Delegates.notNull<Path>()

/**
* The resolver options.
*/
@Deprecated("Unused.")
var options = 0

/**
* Sets the root directory.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,12 @@
package me.kcra.takenaka.core.mapping.resolve.impl

import com.fasterxml.jackson.core.JacksonException
import com.fasterxml.jackson.databind.ObjectMapper
import io.github.oshai.kotlinlogging.KotlinLogging
import me.kcra.takenaka.core.VersionAttributes
import me.kcra.takenaka.core.VersionedWorkspace
import me.kcra.takenaka.core.util.MAPPER
import me.kcra.takenaka.core.util.copyTo
import me.kcra.takenaka.core.util.readValue
import io.github.oshai.kotlinlogging.KotlinLogging
import java.net.URL

private val logger = KotlinLogging.logger {}
Expand All @@ -35,28 +34,15 @@ private val logger = KotlinLogging.logger {}
* This class is thread-safe and presumes multiple instances operate on a single workspace.
*
* @property workspace the workspace
* @property objectMapper an [ObjectMapper] that can deserialize JSON data
* @property relaxedCache whether output cache verification constraints should be relaxed
* @author Matouš Kučera
*/
class MojangManifestAttributeProvider @Deprecated(
"Jackson will be an implementation detail in the future.",
ReplaceWith("MojangManifestAttributeProvider(workspace, relaxedCache)")
) constructor(val workspace: VersionedWorkspace, private val objectMapper: ObjectMapper, val relaxedCache: Boolean = true) {
class MojangManifestAttributeProvider(val workspace: VersionedWorkspace, val relaxedCache: Boolean = true) {
/**
* The version attributes.
*/
val attributes: VersionAttributes by lazy(::readAttributes)

/**
* Creates a new attribute provider.
*
* @param workspace the workspace
* @param relaxedCache whether output cache verification constraints should be relaxed
*/
@Suppress("DEPRECATION")
constructor(workspace: VersionedWorkspace, relaxedCache: Boolean = true) : this(workspace, MAPPER, relaxedCache)

/**
* Reads the attributes of the targeted version from cache, fetching it if the cache missed.
*
Expand All @@ -68,7 +54,7 @@ class MojangManifestAttributeProvider @Deprecated(

if (relaxedCache && ATTRIBUTES in workspace) {
try {
return@withLock objectMapper.readValue<VersionAttributes>(file).apply {
return@withLock MAPPER.readValue<VersionAttributes>(file).apply {
logger.info { "read cached ${workspace.version.id} attributes" }
}
} catch (e: JacksonException) {
Expand All @@ -79,7 +65,7 @@ class MojangManifestAttributeProvider @Deprecated(
URL(workspace.version.url).copyTo(file)

logger.info { "fetched ${workspace.version.id} attributes" }
return@withLock objectMapper.readValue(file)
return@withLock MAPPER.readValue(file)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,17 @@

package me.kcra.takenaka.core.mapping.resolve.impl

import com.fasterxml.jackson.databind.ObjectMapper
import io.github.oshai.kotlinlogging.KotlinLogging
import kotlinx.coroutines.CoroutineName
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import me.kcra.takenaka.core.VersionedWorkspace
import me.kcra.takenaka.core.mapping.MappingContributor
import me.kcra.takenaka.core.mapping.resolve.*
import me.kcra.takenaka.core.mapping.resolve.AbstractMappingResolver
import me.kcra.takenaka.core.mapping.resolve.LicenseResolver
import me.kcra.takenaka.core.mapping.resolve.Output
import me.kcra.takenaka.core.mapping.resolve.lazyOutput
import me.kcra.takenaka.core.util.*
import io.github.oshai.kotlinlogging.KotlinLogging
import net.fabricmc.mappingio.MappingUtil
import net.fabricmc.mappingio.MappingVisitor
import net.fabricmc.mappingio.adapter.MappingSourceNsSwitch
Expand Down Expand Up @@ -176,21 +178,6 @@ class MojangClientMappingResolver(
workspace: VersionedWorkspace,
val mojangProvider: MojangManifestAttributeProvider
) : AbstractMojangMappingResolver(workspace) {
/**
* Creates a new resolver with a default metadata provider.
*
* @param workspace the workspace
* @param objectMapper an [ObjectMapper] that can deserialize JSON data
* @param relaxedCache whether output cache verification constraints should be relaxed
*/
@Deprecated(
"Jackson will be an implementation detail in the future.",
ReplaceWith("MojangClientMappingResolver(workspace, relaxedCache)")
)
@Suppress("DEPRECATION")
constructor(workspace: VersionedWorkspace, objectMapper: ObjectMapper, relaxedCache: Boolean = true) :
this(workspace, MojangManifestAttributeProvider(workspace, objectMapper, relaxedCache))

/**
* Creates a new resolver with a default metadata provider.
*
Expand Down Expand Up @@ -225,21 +212,6 @@ class MojangServerMappingResolver(
workspace: VersionedWorkspace,
val mojangProvider: MojangManifestAttributeProvider
) : AbstractMojangMappingResolver(workspace) {
/**
* Creates a new resolver with a default metadata provider.
*
* @param workspace the workspace
* @param objectMapper an [ObjectMapper] that can deserialize JSON data
* @param relaxedCache whether output cache verification constraints should be relaxed
*/
@Deprecated(
"Jackson will be an implementation detail in the future.",
ReplaceWith("MojangServerMappingResolver(workspace, relaxedCache)")
)
@Suppress("DEPRECATION")
constructor(workspace: VersionedWorkspace, objectMapper: ObjectMapper, relaxedCache: Boolean = true) :
this(workspace, MojangManifestAttributeProvider(workspace, objectMapper, relaxedCache))

/**
* Creates a new resolver with a default metadata provider.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
package me.kcra.takenaka.core.mapping.resolve.impl

import com.fasterxml.jackson.core.JacksonException
import com.fasterxml.jackson.databind.ObjectMapper
import me.kcra.takenaka.core.*
import me.kcra.takenaka.core.util.*
import me.kcra.takenaka.core.util.MAPPER
import io.github.oshai.kotlinlogging.KotlinLogging
import me.kcra.takenaka.core.SpigotVersionAttributes
import me.kcra.takenaka.core.SpigotVersionManifest
import me.kcra.takenaka.core.VersionedWorkspace
import me.kcra.takenaka.core.util.*
import java.net.URL

private val logger = KotlinLogging.logger {}
Expand All @@ -33,14 +33,10 @@ private val logger = KotlinLogging.logger {}
* This class is thread-safe and presumes multiple instances operate on a single workspace.
*
* @property workspace the workspace
* @property objectMapper an [ObjectMapper] that can deserialize JSON data
* @property relaxedCache whether output cache verification constraints should be relaxed
* @author Matouš Kučera
*/
class SpigotManifestProvider @Deprecated(
"Jackson will be an implementation detail in the future.",
ReplaceWith("SpigotManifestProvider(workspace, relaxedCache)")
) constructor(val workspace: VersionedWorkspace, private val objectMapper: ObjectMapper, val relaxedCache: Boolean = true) {
class SpigotManifestProvider(val workspace: VersionedWorkspace, val relaxedCache: Boolean = true) {
/**
* The version manifest.
*/
Expand All @@ -57,15 +53,6 @@ class SpigotManifestProvider @Deprecated(
val isAliased: Boolean
get() = attributes?.let { workspace.version.id != it.minecraftVersion } ?: false

/**
* Creates a new manifest provider.
*
* @param workspace the workspace
* @param relaxedCache whether output cache verification constraints should be relaxed
*/
@Suppress("DEPRECATION")
constructor(workspace: VersionedWorkspace, relaxedCache: Boolean = true) : this(workspace, MAPPER, relaxedCache)

/**
* Reads the manifest of the targeted version from cache, fetching it if the cache missed.
*
Expand All @@ -77,7 +64,7 @@ class SpigotManifestProvider @Deprecated(

if (relaxedCache && MANIFEST in workspace) {
try {
return@withLock objectMapper.readValue<SpigotVersionManifest>(file).apply {
return@withLock MAPPER.readValue<SpigotVersionManifest>(file).apply {
logger.info { "read cached ${workspace.version.id} Spigot manifest" }
}
} catch (e: JacksonException) {
Expand All @@ -90,7 +77,7 @@ class SpigotManifestProvider @Deprecated(
it.copyTo(file)

logger.info { "fetched ${workspace.version.id} Spigot manifest" }
return@withLock objectMapper.readValue(file)
return@withLock MAPPER.readValue(file)
}

logger.warn { "failed to fetch ${workspace.version.id} Spigot manifest, received ${it.responseCode}" }
Expand All @@ -113,7 +100,7 @@ class SpigotManifestProvider @Deprecated(

if (relaxedCache && BUILDDATA_INFO in workspace) {
try {
return@withLock objectMapper.readValue<SpigotVersionAttributes>(file).apply {
return@withLock MAPPER.readValue<SpigotVersionAttributes>(file).apply {
logger.info { "read cached ${workspace.version.id} Spigot attributes" }
}
} catch (e: JacksonException) {
Expand All @@ -124,7 +111,7 @@ class SpigotManifestProvider @Deprecated(
URL("https://hub.spigotmc.org/stash/projects/SPIGOT/repos/builddata/raw/info.json?at=${manifest!!.refs["BuildData"]}").copyTo(file)

logger.info { "fetched ${workspace.version.id} Spigot attributes" }
return@withLock objectMapper.readValue(file)
return@withLock MAPPER.readValue(file)
}
}

Expand Down
Loading

0 comments on commit 9b939d1

Please sign in to comment.