Skip to content

Commit 5161974

Browse files
authored
Merge branch 'zlataovce:master' into master
2 parents 18057ed + 20c86e2 commit 5161974

File tree

11 files changed

+71
-165
lines changed

11 files changed

+71
-165
lines changed

build.gradle.kts

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ plugins {
55

66
allprojects {
77
group = "me.kcra.takenaka"
8-
version = "1.1.2"
8+
version = "1.1.3"
99
description = "A Kotlin library for reconciling multiple obfuscation mapping files from multiple versions of Minecraft: JE."
1010
}

core/build.gradle.kts

-33
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,10 @@
1-
import kotlinx.benchmark.gradle.JvmBenchmarkTarget
2-
31
plugins {
42
id("takenaka.base-conventions")
53
id("takenaka.publish-conventions")
6-
alias(libs.plugins.kotlinx.benchmark)
7-
alias(libs.plugins.kotlin.plugin.allopen)
84
}
95

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

12-
sourceSets {
13-
create("benchmark") {
14-
compileClasspath += sourceSets.main.get().output
15-
runtimeClasspath += sourceSets.main.get().output
16-
}
17-
}
18-
19-
val benchmarkImplementation by configurations.getting {
20-
extendsFrom(configurations.implementation.get())
21-
}
22-
val benchmarkRuntimeOnly by configurations.getting {
23-
extendsFrom(configurations.runtimeOnly.get())
24-
}
25-
268
dependencies {
279
api(libs.bundles.asm)
2810
api(libs.bundles.jackson)
@@ -32,23 +14,8 @@ dependencies {
3214
implementation(libs.kotlinx.coroutines.core.jvm)
3315
testImplementation(kotlin("test"))
3416
testRuntimeOnly(libs.slf4j.simple)
35-
benchmarkImplementation(libs.kotlinx.benchmark.runtime)
36-
benchmarkRuntimeOnly(libs.slf4j.simple)
37-
}
38-
39-
allOpen {
40-
annotation("org.openjdk.jmh.annotations.State")
4117
}
4218

4319
tasks.withType<Test> {
4420
maxHeapSize = "2048m"
4521
}
46-
47-
benchmark {
48-
targets {
49-
register("benchmark") {
50-
this as JvmBenchmarkTarget
51-
jmhVersion = libs.versions.jmh.get()
52-
}
53-
}
54-
}

core/src/benchmark/kotlin/me/kcra/takenaka/core/benchmark/mapping/analysis/impl/MappingAnalyzerImplBenchmark.kt

-97
This file was deleted.

core/src/benchmark/resources/simplelogger.properties

-1
This file was deleted.

core/src/main/kotlin/me/kcra/takenaka/core/mapping/resolve/impl/IntermediaryMappingResolver.kt

+3-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ class IntermediaryMappingResolver(
9292

9393
override val licenseOutput = lazyOutput {
9494
resolver {
95-
licenseWorkspace.withLock("intermediary-license") {
95+
licenseWorkspace.withLock(WORKSPACE_LOCK) {
9696
val file = licenseWorkspace[LICENSE]
9797

9898
if (LICENSE in licenseWorkspace) {
@@ -134,6 +134,8 @@ class IntermediaryMappingResolver(
134134
}
135135

136136
companion object {
137+
private val WORKSPACE_LOCK = object {}
138+
137139
/**
138140
* The file name of the cached mappings.
139141
*/

core/src/main/kotlin/me/kcra/takenaka/core/mapping/resolve/impl/MojangManifestAttributeProvider.kt

+3-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class MojangManifestAttributeProvider(val workspace: VersionedWorkspace, private
5050
* @return the attributes
5151
*/
5252
private fun readAttributes(): VersionAttributes {
53-
return workspace.withLock("mojang-manifest") {
53+
return workspace.withLock(WORKSPACE_LOCK) {
5454
val file = workspace[ATTRIBUTES]
5555

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

7373
companion object {
74+
private val WORKSPACE_LOCK = object {}
75+
7476
/**
7577
* The file name of the cached attributes.
7678
*/

core/src/main/kotlin/me/kcra/takenaka/core/mapping/resolve/impl/SeargeMappingResolver.kt

+3-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ class SeargeMappingResolver(
103103

104104
override val licenseOutput = lazyOutput {
105105
resolver {
106-
licenseWorkspace.withLock("searge-license") {
106+
licenseWorkspace.withLock(WORKSPACE_LOCK) {
107107
val file = licenseWorkspace[LICENSE]
108108

109109
if (LICENSE in licenseWorkspace) {
@@ -172,6 +172,8 @@ class SeargeMappingResolver(
172172
}
173173

174174
companion object {
175+
private val WORKSPACE_LOCK = object {}
176+
175177
/**
176178
* The file name of the cached zip file.
177179
*/

core/src/main/kotlin/me/kcra/takenaka/core/mapping/resolve/impl/SpigotManifestProvider.kt

+10-2
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,19 @@ class SpigotManifestProvider(val workspace: VersionedWorkspace, private val obje
5050
*/
5151
val attributes by lazy(::readAttributes)
5252

53+
/**
54+
* Whether the resolved manifest is of a different version than requested.
55+
*/
56+
val isAliased: Boolean
57+
get() = attributes?.let { workspace.version.id != it.minecraftVersion } ?: false
58+
5359
/**
5460
* Reads the manifest of the targeted version from cache, fetching it if the cache missed.
5561
*
5662
* @return the manifest
5763
*/
5864
private fun readManifest(): SpigotVersionManifest? {
59-
return workspace.withLock("spigot-manifest") {
65+
return workspace.withLock(WORKSPACE_LOCK) {
6066
val file = workspace[MANIFEST]
6167

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

95-
return workspace.withLock("spigot-manifest") {
101+
return workspace.withLock(WORKSPACE_LOCK) {
96102
val file = workspace[BUILDDATA_INFO]
97103

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

115121
companion object {
122+
private val WORKSPACE_LOCK = object {}
123+
116124
/**
117125
* The file name of the cached version manifest.
118126
*/

core/src/main/kotlin/me/kcra/takenaka/core/mapping/resolve/impl/SpigotMappingResolver.kt

+4
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,10 @@ class SpigotClassMappingResolver(
281281
* @return the mapping attribute
282282
*/
283283
override fun resolveMappingAttribute(): MappingAttribute {
284+
if (spigotProvider.isAliased) {
285+
logger.warn { "expected ${workspace.version.id}, got ${spigotProvider.attributes?.minecraftVersion}; aliased manifest?" }
286+
}
287+
284288
return MappingAttribute("classMappings", spigotProvider.attributes?.classMappings)
285289
}
286290

generator/accessor-runtime/src/main/java/me/kcra/takenaka/accessor/platform/MapperPlatforms.java

+45-21
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
package me.kcra.takenaka.accessor.platform;
1919

20+
import org.jetbrains.annotations.ApiStatus;
2021
import org.jetbrains.annotations.NotNull;
2122

2223
import java.lang.reflect.InvocationTargetException;
@@ -33,6 +34,43 @@
3334
* @author Matouš Kučera
3435
*/
3536
public enum MapperPlatforms implements MapperPlatform {
37+
/**
38+
* A generic abstraction for Mojang software derivatives (Mojang mappings).
39+
*/
40+
MOJANG {
41+
private String minecraftVersion = null;
42+
43+
{
44+
try {
45+
final Class<?> constClass = Class.forName("net.minecraft.SharedConstants", true, getClassLoader());
46+
final Object gameVersion = constClass.getMethod("getCurrentVersion").invoke(null);
47+
48+
minecraftVersion = (String) gameVersion.getClass().getMethod("getName").invoke(gameVersion);
49+
} catch (IllegalAccessException | InvocationTargetException e) {
50+
throw new RuntimeException("Failed to get Minecraft version", e);
51+
} catch (ClassNotFoundException | NoSuchMethodException ignored) {
52+
}
53+
}
54+
55+
@Override
56+
public boolean isSupported() {
57+
return minecraftVersion != null;
58+
}
59+
60+
@Override
61+
public @NotNull String getVersion() {
62+
if (!isSupported()) {
63+
throw new UnsupportedOperationException("Mojang is not supported by this environment");
64+
}
65+
return minecraftVersion;
66+
}
67+
68+
@Override
69+
public @NotNull String[] getMappingNamespaces() {
70+
return new String[] { "mojang" };
71+
}
72+
},
73+
3674
/**
3775
* An abstraction for platforms that implement the Bukkit API (Spigot mappings).
3876
*/
@@ -84,39 +122,25 @@ public boolean isSupported() {
84122

85123
/**
86124
* An abstraction for NeoForge-based platforms (Mojang mappings).
125+
*
126+
* @deprecated use {@link #MOJANG}
87127
*/
128+
@Deprecated
129+
@ApiStatus.ScheduledForRemoval(inVersion = "2.0.0")
88130
NEOFORGE {
89-
private String minecraftVersion = null;
90-
91-
{
92-
try {
93-
final Class<?> neoFormVersionClass = Class.forName(
94-
"net.neoforged.neoforge.internal.versions.neoform.NeoFormVersion",
95-
true, getClassLoader()
96-
);
97-
minecraftVersion = (String) neoFormVersionClass.getMethod("getMCVersion").invoke(null);
98-
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
99-
throw new RuntimeException("Failed to get Minecraft version", e);
100-
} catch (ClassNotFoundException ignored) {
101-
}
102-
}
103-
104131
@Override
105132
public boolean isSupported() {
106-
return minecraftVersion != null;
133+
return MOJANG.isSupported();
107134
}
108135

109136
@Override
110137
public @NotNull String getVersion() {
111-
if (!isSupported()) {
112-
throw new UnsupportedOperationException("NeoForge is not supported by this environment");
113-
}
114-
return minecraftVersion;
138+
return MOJANG.getVersion();
115139
}
116140

117141
@Override
118142
public @NotNull String[] getMappingNamespaces() {
119-
return new String[] { "mojang" };
143+
return MOJANG.getMappingNamespaces();
120144
}
121145
},
122146

gradle/libs.versions.toml

+2-7
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
[versions]
22
kotlin = "1.9.22"
33
asm = "9.7"
4-
jackson = "2.17.0"
5-
jmh = "1.37"
6-
kotlinx-benchmark = "0.4.10"
4+
jackson = "2.17.1"
75
kotlinpoet = "1.16.0"
86

97
[libraries]
@@ -16,11 +14,10 @@ jackson-datatype-jsr310 = { group = "com.fasterxml.jackson.datatype", name = "ja
1614
jackson-dataformat-xml = { group = "com.fasterxml.jackson.dataformat", name = "jackson-dataformat-xml", version.ref = "jackson" }
1715
mapping-io = { group = "net.fabricmc", name = "mapping-io", version = "0.4.2" }
1816
kotlin-logging-jvm = { group = "io.github.microutils", name = "kotlin-logging-jvm", version = "3.0.5" }
19-
slf4j-simple = { group = "org.slf4j", name = "slf4j-simple", version = "2.0.12" }
17+
slf4j-simple = { group = "org.slf4j", name = "slf4j-simple", version = "2.0.13" }
2018
kotlinx-coroutines-core-jvm = { group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-core-jvm", version = "1.8.0" }
2119
kotlinx-html-jvm = { group = "org.jetbrains.kotlinx", name = "kotlinx-html-jvm", version = "0.11.0" }
2220
kotlinx-cli-jvm = { group = "org.jetbrains.kotlinx", name = "kotlinx-cli-jvm", version = "0.3.6" }
23-
kotlinx-benchmark-runtime = { group = "org.jetbrains.kotlinx", name = "kotlinx-benchmark-runtime", version.ref = "kotlinx-benchmark" }
2421
jb-annotations = { group = "org.jetbrains", name = "annotations", version = "24.1.0" }
2522
javapoet = { group = "com.squareup", name = "javapoet", version = "1.13.0" }
2623
kotlinpoet = { group = "com.squareup", name = "kotlinpoet", version.ref = "kotlinpoet" }
@@ -36,7 +33,5 @@ jackson = ["jackson-module-kotlin", "jackson-datatype-jsr310", "jackson-dataform
3633
[plugins]
3734
kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
3835
shadow = { id = "io.github.goooler.shadow", version = "8.1.7" }
39-
kotlinx-benchmark = { id = "org.jetbrains.kotlinx.benchmark", version.ref = "kotlinx-benchmark" }
40-
kotlin-plugin-allopen = { id = "org.jetbrains.kotlin.plugin.allopen", version.ref = "kotlin" }
4136
gradle-plugin-publish = { id = "com.gradle.plugin-publish", version = "1.2.1" }
4237
build-config = { id = "com.github.gmazzo.buildconfig", version = "5.3.5" }

0 commit comments

Comments
 (0)