summaryrefslogtreecommitdiff
path: root/plugin
diff options
context:
space:
mode:
Diffstat (limited to 'plugin')
-rw-r--r--plugin/build.gradle.kts1
-rw-r--r--plugin/src/main/kotlin/moe/nea/archenemy/mojang/MappedRepositoryProvider.kt27
-rw-r--r--plugin/src/main/kotlin/moe/nea/archenemy/mojang/MappingDependency.kt4
-rw-r--r--plugin/src/main/kotlin/moe/nea/archenemy/mojang/OfficialMappingDependency.kt37
4 files changed, 45 insertions, 24 deletions
diff --git a/plugin/build.gradle.kts b/plugin/build.gradle.kts
index 4ea04aa..f3d7c28 100644
--- a/plugin/build.gradle.kts
+++ b/plugin/build.gradle.kts
@@ -16,6 +16,7 @@ dependencies {
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.6.2")
implementation("net.fabricmc:mapping-io:0.1.8")
+ implementation("net.fabricmc:tiny-remapper:0.8.6")
testImplementation("org.jetbrains.kotlin:kotlin-test")
testImplementation("org.jetbrains.kotlin:kotlin-test-junit")
diff --git a/plugin/src/main/kotlin/moe/nea/archenemy/mojang/MappedRepositoryProvider.kt b/plugin/src/main/kotlin/moe/nea/archenemy/mojang/MappedRepositoryProvider.kt
index ddfff0d..ed158b5 100644
--- a/plugin/src/main/kotlin/moe/nea/archenemy/mojang/MappedRepositoryProvider.kt
+++ b/plugin/src/main/kotlin/moe/nea/archenemy/mojang/MappedRepositoryProvider.kt
@@ -68,26 +68,19 @@ class MappedRepositoryProvider(
private fun getArtifact(coordinates: MappedCoordinates, identifier: ArtifactIdentifier): Artifact? {
if ((identifier.classifier ?: "") != "") return null
- val files = sharedExtension.project.configurations.detachedConfiguration(
- coordinates.dependency,
- coordinates.mappings.get()
- ).also { it.isTransitive = false }.resolve()
- // TODO: move away from classifiers. those are *evil*.
- // for now i will just manually append -client
- // or figure out how loom does it, i suppose
- val sourceName = listOfNotNull(
- coordinates.dependency.name,
- coordinates.dependency.version,
- coordinates.dependency.artifacts.single().classifier
- ).joinToString(separator = "-", postfix = ".jar")
- val sourceFile = files.singleOrNull { it.name == sourceName } ?: return null
- val mappingsFile = coordinates.mappings.findMapping(files) ?: error("Could not find mappings file")
- val targetFile = cacheDir.resolve(coordinates.transformerHash + ".jar")
- targetFile.parentFile.mkdirs()
return StreamableArtifact.ofStreamable(identifier, ArtifactType.BINARY) {
+ val files = sharedExtension.project.configurations.detachedConfiguration(
+ coordinates.dependency,
+ ).also { it.isTransitive = false }.resolve()
+ // TODO: move away from classifiers. those are *evil*.
+ // for now i will just manually append -client
+ // or figure out how loom does it, i suppose
+ val sourceFile = files.singleOrNull { true } ?: error("Only support single file dependencies rn")
+ coordinates.mappings.resolveMappingsOnce(sharedExtension)
+ val targetFile = cacheDir.resolve(coordinates.transformerHash + ".jar")
+ targetFile.parentFile.mkdirs()
if (!targetFile.exists()) {
coordinates.mappings.applyMapping(
- mappingsFile = mappingsFile,
sourceFile = sourceFile,
targetFile = targetFile,
sourceNameSpace = coordinates.from,
diff --git a/plugin/src/main/kotlin/moe/nea/archenemy/mojang/MappingDependency.kt b/plugin/src/main/kotlin/moe/nea/archenemy/mojang/MappingDependency.kt
index a0e1b14..76f109c 100644
--- a/plugin/src/main/kotlin/moe/nea/archenemy/mojang/MappingDependency.kt
+++ b/plugin/src/main/kotlin/moe/nea/archenemy/mojang/MappingDependency.kt
@@ -1,5 +1,6 @@
package moe.nea.archenemy.mojang
+import org.gradle.api.Project
import org.gradle.api.artifacts.Dependency
import org.gradle.api.provider.Provider
import java.io.File
@@ -8,9 +9,8 @@ import java.security.MessageDigest
interface MappingDependency : Provider<Dependency> {
fun updateHash(digest: MessageDigest)
fun title(): String
- fun findMapping(files: Set<File>): File?
+ fun resolveMappingsOnce(extension: ArchenemyMojangExtension)
fun applyMapping(
- mappingsFile: File,
sourceFile: File,
targetFile: File,
sourceNameSpace: String,
diff --git a/plugin/src/main/kotlin/moe/nea/archenemy/mojang/OfficialMappingDependency.kt b/plugin/src/main/kotlin/moe/nea/archenemy/mojang/OfficialMappingDependency.kt
index 4e44146..d9fccd6 100644
--- a/plugin/src/main/kotlin/moe/nea/archenemy/mojang/OfficialMappingDependency.kt
+++ b/plugin/src/main/kotlin/moe/nea/archenemy/mojang/OfficialMappingDependency.kt
@@ -3,9 +3,17 @@ package moe.nea.archenemy.mojang
import moe.nea.archenemy.MCSide
import moe.nea.archenemy.util.update
import moe.nea.archenemy.util.updateField
+import net.fabricmc.mappingio.format.ProGuardReader
+import net.fabricmc.mappingio.format.Tiny2Writer
+import net.fabricmc.tinyremapper.OutputConsumerPath
+import net.fabricmc.tinyremapper.TinyRemapper
+import net.fabricmc.tinyremapper.TinyUtils
import org.gradle.api.artifacts.Dependency
import org.gradle.api.provider.Provider
+import java.io.BufferedReader
import java.io.File
+import java.io.StringReader
+import java.io.StringWriter
import java.security.MessageDigest
class OfficialMappingDependency(
@@ -14,6 +22,7 @@ class OfficialMappingDependency(
val dependency: Provider<Dependency>
) : MappingDependency,
Provider<Dependency> by dependency {
+ var tinyv2Source: String? = null
override fun updateHash(digest: MessageDigest) {
digest.update("official")
@@ -25,20 +34,38 @@ class OfficialMappingDependency(
return "official-$side-${version.replace(".","_")}"
}
- override fun findMapping(files: Set<File>): File? {
- return files.singleOrNull {
- it.name == "minecraft-${version}-${side}-mappings.txt"
+ override fun resolveMappingsOnce(extension: ArchenemyMojangExtension) {
+ if (tinyv2Source != null) return
+ val buffer = StringWriter()
+ val source = extension.project.configurations.detachedConfiguration(get()).resolve().single()
+ source.reader().use {
+ ProGuardReader.read(it, "named", "official", Tiny2Writer(buffer, false))
}
+ buffer.close()
+ tinyv2Source = buffer.toString()
}
override fun applyMapping(
- mappingsFile: File,
sourceFile: File,
targetFile: File,
sourceNameSpace: String,
targetNameSpace: String
) {
- sourceFile.copyTo(targetFile)
+ val remapper = TinyRemapper.newRemapper()
+ .withMappings(
+ TinyUtils.createTinyMappingProvider(
+ BufferedReader(StringReader(tinyv2Source ?: error("Mappings have never been resolved"))),
+ sourceNameSpace,
+ targetNameSpace,
+ )
+ )
+ .build()
+ OutputConsumerPath.Builder(targetFile.toPath()).build().use { output ->
+ remapper.readInputs(sourceFile.toPath())
+ remapper.apply(output)
+ }
+ remapper.finish()
+
}
} \ No newline at end of file