Skip to content

Commit

Permalink
Merge branch 'zlataovce:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
xhyrom authored May 9, 2024
2 parents 18057ed + 20c86e2 commit 5161974
Show file tree
Hide file tree
Showing 11 changed files with 71 additions and 165 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ plugins {

allprojects {
group = "me.kcra.takenaka"
version = "1.1.2"
version = "1.1.3"
description = "A Kotlin library for reconciling multiple obfuscation mapping files from multiple versions of Minecraft: JE."
}
33 changes: 0 additions & 33 deletions core/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,28 +1,10 @@
import kotlinx.benchmark.gradle.JvmBenchmarkTarget

plugins {
id("takenaka.base-conventions")
id("takenaka.publish-conventions")
alias(libs.plugins.kotlinx.benchmark)
alias(libs.plugins.kotlin.plugin.allopen)
}

apply(plugin = "org.jetbrains.kotlin.jvm")

sourceSets {
create("benchmark") {
compileClasspath += sourceSets.main.get().output
runtimeClasspath += sourceSets.main.get().output
}
}

val benchmarkImplementation by configurations.getting {
extendsFrom(configurations.implementation.get())
}
val benchmarkRuntimeOnly by configurations.getting {
extendsFrom(configurations.runtimeOnly.get())
}

dependencies {
api(libs.bundles.asm)
api(libs.bundles.jackson)
Expand All @@ -32,23 +14,8 @@ dependencies {
implementation(libs.kotlinx.coroutines.core.jvm)
testImplementation(kotlin("test"))
testRuntimeOnly(libs.slf4j.simple)
benchmarkImplementation(libs.kotlinx.benchmark.runtime)
benchmarkRuntimeOnly(libs.slf4j.simple)
}

allOpen {
annotation("org.openjdk.jmh.annotations.State")
}

tasks.withType<Test> {
maxHeapSize = "2048m"
}

benchmark {
targets {
register("benchmark") {
this as JvmBenchmarkTarget
jmhVersion = libs.versions.jmh.get()
}
}
}

This file was deleted.

1 change: 0 additions & 1 deletion core/src/benchmark/resources/simplelogger.properties

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class IntermediaryMappingResolver(

override val licenseOutput = lazyOutput {
resolver {
licenseWorkspace.withLock("intermediary-license") {
licenseWorkspace.withLock(WORKSPACE_LOCK) {
val file = licenseWorkspace[LICENSE]

if (LICENSE in licenseWorkspace) {
Expand Down Expand Up @@ -134,6 +134,8 @@ class IntermediaryMappingResolver(
}

companion object {
private val WORKSPACE_LOCK = object {}

/**
* The file name of the cached mappings.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class MojangManifestAttributeProvider(val workspace: VersionedWorkspace, private
* @return the attributes
*/
private fun readAttributes(): VersionAttributes {
return workspace.withLock("mojang-manifest") {
return workspace.withLock(WORKSPACE_LOCK) {
val file = workspace[ATTRIBUTES]

if (relaxedCache && ATTRIBUTES in workspace) {
Expand All @@ -71,6 +71,8 @@ class MojangManifestAttributeProvider(val workspace: VersionedWorkspace, private
}

companion object {
private val WORKSPACE_LOCK = object {}

/**
* The file name of the cached attributes.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class SeargeMappingResolver(

override val licenseOutput = lazyOutput {
resolver {
licenseWorkspace.withLock("searge-license") {
licenseWorkspace.withLock(WORKSPACE_LOCK) {
val file = licenseWorkspace[LICENSE]

if (LICENSE in licenseWorkspace) {
Expand Down Expand Up @@ -172,6 +172,8 @@ class SeargeMappingResolver(
}

companion object {
private val WORKSPACE_LOCK = object {}

/**
* The file name of the cached zip file.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,19 @@ class SpigotManifestProvider(val workspace: VersionedWorkspace, private val obje
*/
val attributes by lazy(::readAttributes)

/**
* Whether the resolved manifest is of a different version than requested.
*/
val isAliased: Boolean
get() = attributes?.let { workspace.version.id != it.minecraftVersion } ?: false

/**
* Reads the manifest of the targeted version from cache, fetching it if the cache missed.
*
* @return the manifest
*/
private fun readManifest(): SpigotVersionManifest? {
return workspace.withLock("spigot-manifest") {
return workspace.withLock(WORKSPACE_LOCK) {
val file = workspace[MANIFEST]

if (relaxedCache && MANIFEST in workspace) {
Expand Down Expand Up @@ -92,7 +98,7 @@ class SpigotManifestProvider(val workspace: VersionedWorkspace, private val obje
private fun readAttributes(): SpigotVersionAttributes? {
if (manifest == null) return null

return workspace.withLock("spigot-manifest") {
return workspace.withLock(WORKSPACE_LOCK) {
val file = workspace[BUILDDATA_INFO]

if (relaxedCache && BUILDDATA_INFO in workspace) {
Expand All @@ -113,6 +119,8 @@ class SpigotManifestProvider(val workspace: VersionedWorkspace, private val obje
}

companion object {
private val WORKSPACE_LOCK = object {}

/**
* The file name of the cached version manifest.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,10 @@ class SpigotClassMappingResolver(
* @return the mapping attribute
*/
override fun resolveMappingAttribute(): MappingAttribute {
if (spigotProvider.isAliased) {
logger.warn { "expected ${workspace.version.id}, got ${spigotProvider.attributes?.minecraftVersion}; aliased manifest?" }
}

return MappingAttribute("classMappings", spigotProvider.attributes?.classMappings)
}

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

package me.kcra.takenaka.accessor.platform;

import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;

import java.lang.reflect.InvocationTargetException;
Expand All @@ -33,6 +34,43 @@
* @author Matouš Kučera
*/
public enum MapperPlatforms implements MapperPlatform {
/**
* A generic abstraction for Mojang software derivatives (Mojang mappings).
*/
MOJANG {
private String minecraftVersion = null;

{
try {
final Class<?> constClass = Class.forName("net.minecraft.SharedConstants", true, getClassLoader());
final Object gameVersion = constClass.getMethod("getCurrentVersion").invoke(null);

minecraftVersion = (String) gameVersion.getClass().getMethod("getName").invoke(gameVersion);
} catch (IllegalAccessException | InvocationTargetException e) {
throw new RuntimeException("Failed to get Minecraft version", e);
} catch (ClassNotFoundException | NoSuchMethodException ignored) {
}
}

@Override
public boolean isSupported() {
return minecraftVersion != null;
}

@Override
public @NotNull String getVersion() {
if (!isSupported()) {
throw new UnsupportedOperationException("Mojang is not supported by this environment");
}
return minecraftVersion;
}

@Override
public @NotNull String[] getMappingNamespaces() {
return new String[] { "mojang" };
}
},

/**
* An abstraction for platforms that implement the Bukkit API (Spigot mappings).
*/
Expand Down Expand Up @@ -84,39 +122,25 @@ public boolean isSupported() {

/**
* An abstraction for NeoForge-based platforms (Mojang mappings).
*
* @deprecated use {@link #MOJANG}
*/
@Deprecated
@ApiStatus.ScheduledForRemoval(inVersion = "2.0.0")
NEOFORGE {
private String minecraftVersion = null;

{
try {
final Class<?> neoFormVersionClass = Class.forName(
"net.neoforged.neoforge.internal.versions.neoform.NeoFormVersion",
true, getClassLoader()
);
minecraftVersion = (String) neoFormVersionClass.getMethod("getMCVersion").invoke(null);
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
throw new RuntimeException("Failed to get Minecraft version", e);
} catch (ClassNotFoundException ignored) {
}
}

@Override
public boolean isSupported() {
return minecraftVersion != null;
return MOJANG.isSupported();
}

@Override
public @NotNull String getVersion() {
if (!isSupported()) {
throw new UnsupportedOperationException("NeoForge is not supported by this environment");
}
return minecraftVersion;
return MOJANG.getVersion();
}

@Override
public @NotNull String[] getMappingNamespaces() {
return new String[] { "mojang" };
return MOJANG.getMappingNamespaces();
}
},

Expand Down
9 changes: 2 additions & 7 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
[versions]
kotlin = "1.9.22"
asm = "9.7"
jackson = "2.17.0"
jmh = "1.37"
kotlinx-benchmark = "0.4.10"
jackson = "2.17.1"
kotlinpoet = "1.16.0"

[libraries]
Expand All @@ -16,11 +14,10 @@ jackson-datatype-jsr310 = { group = "com.fasterxml.jackson.datatype", name = "ja
jackson-dataformat-xml = { group = "com.fasterxml.jackson.dataformat", name = "jackson-dataformat-xml", version.ref = "jackson" }
mapping-io = { group = "net.fabricmc", name = "mapping-io", version = "0.4.2" }
kotlin-logging-jvm = { group = "io.github.microutils", name = "kotlin-logging-jvm", version = "3.0.5" }
slf4j-simple = { group = "org.slf4j", name = "slf4j-simple", version = "2.0.12" }
slf4j-simple = { group = "org.slf4j", name = "slf4j-simple", version = "2.0.13" }
kotlinx-coroutines-core-jvm = { group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-core-jvm", version = "1.8.0" }
kotlinx-html-jvm = { group = "org.jetbrains.kotlinx", name = "kotlinx-html-jvm", version = "0.11.0" }
kotlinx-cli-jvm = { group = "org.jetbrains.kotlinx", name = "kotlinx-cli-jvm", version = "0.3.6" }
kotlinx-benchmark-runtime = { group = "org.jetbrains.kotlinx", name = "kotlinx-benchmark-runtime", version.ref = "kotlinx-benchmark" }
jb-annotations = { group = "org.jetbrains", name = "annotations", version = "24.1.0" }
javapoet = { group = "com.squareup", name = "javapoet", version = "1.13.0" }
kotlinpoet = { group = "com.squareup", name = "kotlinpoet", version.ref = "kotlinpoet" }
Expand All @@ -36,7 +33,5 @@ jackson = ["jackson-module-kotlin", "jackson-datatype-jsr310", "jackson-dataform
[plugins]
kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
shadow = { id = "io.github.goooler.shadow", version = "8.1.7" }
kotlinx-benchmark = { id = "org.jetbrains.kotlinx.benchmark", version.ref = "kotlinx-benchmark" }
kotlin-plugin-allopen = { id = "org.jetbrains.kotlin.plugin.allopen", version.ref = "kotlin" }
gradle-plugin-publish = { id = "com.gradle.plugin-publish", version = "1.2.1" }
build-config = { id = "com.github.gmazzo.buildconfig", version = "5.3.5" }

0 comments on commit 5161974

Please sign in to comment.