aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/com/replaymod/gradle/remap
diff options
context:
space:
mode:
authorJonas Herzig <me@johni0702.de>2019-11-01 00:52:04 +0100
committerJonas Herzig <me@johni0702.de>2019-11-01 00:52:04 +0100
commitfcae86692edc4dbb3764174a341cc622099f4969 (patch)
treee4696ef7a65dde34a92ffa73351038c7f1b95c34 /src/main/kotlin/com/replaymod/gradle/remap
parentfb0e54ad548e63a8e847a074cbf8998683d6b595 (diff)
downloadRemap-fcae86692edc4dbb3764174a341cc622099f4969.tar.gz
Remap-fcae86692edc4dbb3764174a341cc622099f4969.tar.bz2
Remap-fcae86692edc4dbb3764174a341cc622099f4969.zip
Add methods for parsing legacy mappings from string instead of file
Diffstat (limited to 'src/main/kotlin/com/replaymod/gradle/remap')
-rw-r--r--src/main/kotlin/com/replaymod/gradle/remap/legacy/LegacyMapping.kt20
1 files changed, 16 insertions, 4 deletions
diff --git a/src/main/kotlin/com/replaymod/gradle/remap/legacy/LegacyMapping.kt b/src/main/kotlin/com/replaymod/gradle/remap/legacy/LegacyMapping.kt
index 389b1c9..5530794 100644
--- a/src/main/kotlin/com/replaymod/gradle/remap/legacy/LegacyMapping.kt
+++ b/src/main/kotlin/com/replaymod/gradle/remap/legacy/LegacyMapping.kt
@@ -1,8 +1,8 @@
package com.replaymod.gradle.remap.legacy
import org.cadixdev.lorenz.MappingSet
+import java.io.*
-import java.io.IOException
import java.nio.charset.StandardCharsets
import java.nio.file.Files
import java.nio.file.Path
@@ -19,16 +19,28 @@ class LegacyMapping(var oldName: String, var newName: String) {
}
@Throws(IOException::class)
+ fun readMappingSet(fileName: String, reader: Reader, invert: Boolean): MappingSet {
+ return LegacyMappingsReader(readMappings(fileName, reader, invert)).read()
+ }
+
+ @Throws(IOException::class)
fun readMappings(mappingFile: Path, invert: Boolean): Map<String, LegacyMapping> {
+ Files.newBufferedReader(mappingFile, StandardCharsets.UTF_8).use {
+ return readMappings(mappingFile.toString(), it, invert)
+ }
+ }
+
+ @Throws(IOException::class)
+ fun readMappings(fileName: String, reader: Reader, invert: Boolean): Map<String, LegacyMapping> {
val mappings = HashMap<String, LegacyMapping>()
val revMappings = HashMap<String, LegacyMapping>()
var lineNumber = 0
- for (line in Files.readAllLines(mappingFile, StandardCharsets.UTF_8)) {
+ for (line in BufferedReader(reader).lineSequence()) {
lineNumber++
if (line.trim { it <= ' ' }.startsWith("#") || line.trim { it <= ' ' }.isEmpty()) continue
val parts = line.split(" ".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
- require(!(parts.size < 2 || line.contains(";"))) { "Failed to parse line $lineNumber in $mappingFile." }
+ require(!(parts.size < 2 || line.contains(";"))) { "Failed to parse line $lineNumber in $fileName." }
var mapping: LegacyMapping? = mappings[parts[0]]
if (mapping == null) {
@@ -73,7 +85,7 @@ class LegacyMapping(var oldName: String, var newName: String) {
revMapping.fields[fromName] = toName
}
} else {
- throw IllegalArgumentException("Failed to parse line $lineNumber in $mappingFile.")
+ throw IllegalArgumentException("Failed to parse line $lineNumber in $fileName.")
}
}
if (invert) {