aboutsummaryrefslogtreecommitdiff
path: root/src/test/kotlin/com/replaymod/gradle/remap/util
diff options
context:
space:
mode:
authorJonas Herzig <jonas@spark-squared.com>2021-11-10 09:34:39 +0100
committerJonas Herzig <jonas@spark-squared.com>2021-11-10 18:11:16 +0100
commit7d62cd890cb44945e772e18cdb457b1173f4f853 (patch)
treee6f0e969442f464556289a090769e966bc0e2efe /src/test/kotlin/com/replaymod/gradle/remap/util
parent89e079621c7867036d4ac77b018ad904d21364b5 (diff)
downloadRemap-7d62cd890cb44945e772e18cdb457b1173f4f853.tar.gz
Remap-7d62cd890cb44945e772e18cdb457b1173f4f853.tar.bz2
Remap-7d62cd890cb44945e772e18cdb457b1173f4f853.zip
Start adding tests
Diffstat (limited to 'src/test/kotlin/com/replaymod/gradle/remap/util')
-rw-r--r--src/test/kotlin/com/replaymod/gradle/remap/util/TestData.kt48
-rw-r--r--src/test/kotlin/com/replaymod/gradle/remap/util/mappingExtensions.kt13
2 files changed, 61 insertions, 0 deletions
diff --git a/src/test/kotlin/com/replaymod/gradle/remap/util/TestData.kt b/src/test/kotlin/com/replaymod/gradle/remap/util/TestData.kt
new file mode 100644
index 0000000..cb0ad44
--- /dev/null
+++ b/src/test/kotlin/com/replaymod/gradle/remap/util/TestData.kt
@@ -0,0 +1,48 @@
+package com.replaymod.gradle.remap.util
+
+import com.replaymod.gradle.remap.Transformer
+import com.replaymod.gradle.remap.legacy.LegacyMappingSetModelFactory
+import org.cadixdev.lorenz.MappingSet
+import java.net.URL
+import java.nio.file.Paths
+import kotlin.io.path.absolutePathString
+
+object TestData {
+ private val mappingsPath = Paths.get(javaClass.getResource("/mappings.srg")!!.toURI())
+ private val mappings = mappingsPath.readMappings().let { mappings ->
+ val legacyCopy = MappingSet.create(LegacyMappingSetModelFactory())
+ mappings.topLevelClassMappings.forEach { it.copy(legacyCopy) }
+ legacyCopy
+ }
+
+ val transformer = Transformer(mappings).apply {
+ fun findClasspathEntry(cls: String): String {
+ val classFilePath = "/${cls.replace('.', '/')}.class"
+ val url = javaClass.getResource(classFilePath)
+ ?: throw RuntimeException("Failed to find $cls on classpath.")
+
+ return when {
+ url.protocol == "jar" && url.file.endsWith("!$classFilePath") -> {
+ Paths.get(URL(url.file.removeSuffix("!$classFilePath")).toURI()).absolutePathString()
+ }
+ url.protocol == "file" && url.file.endsWith(classFilePath) -> {
+ var path = Paths.get(url.toURI())
+ repeat(cls.count { it == '.' } + 1) {
+ path = path.parent
+ }
+ path.absolutePathString()
+ }
+ else -> {
+ throw RuntimeException("Do not know how to turn $url into classpath entry.")
+ }
+ }
+ }
+ classpath = arrayOf(
+ findClasspathEntry("org.spongepowered.asm.mixin.Mixin"),
+ findClasspathEntry("a.pkg.A"),
+ )
+ }
+
+ fun remap(content: String): String = transformer.remap(mapOf("test.java" to content))["test.java"]!!.first
+ fun remapWithErrors(content: String) = transformer.remap(mapOf("test.java" to content))["test.java"]!!
+} \ No newline at end of file
diff --git a/src/test/kotlin/com/replaymod/gradle/remap/util/mappingExtensions.kt b/src/test/kotlin/com/replaymod/gradle/remap/util/mappingExtensions.kt
new file mode 100644
index 0000000..9a869d4
--- /dev/null
+++ b/src/test/kotlin/com/replaymod/gradle/remap/util/mappingExtensions.kt
@@ -0,0 +1,13 @@
+package com.replaymod.gradle.remap.util
+
+import org.cadixdev.lorenz.MappingSet
+import org.cadixdev.lorenz.io.MappingFormats
+import java.nio.file.Path
+
+fun Path.readMappings(): MappingSet {
+ val name = fileName.toString()
+ val ext = name.substring(name.lastIndexOf(".") + 1)
+ val format = MappingFormats.REGISTRY.values().find { it.standardFileExtension.orElse(null) == ext }
+ ?: throw UnsupportedOperationException("Cannot find mapping format for $this")
+ return format.read(this)
+}