executePatches -> applyPatches, made logback a test dep

This commit is contained in:
Lucaskyy 2022-03-19 21:58:31 +01:00
parent 6bd4d80c47
commit f9327a2043
No known key found for this signature in database
GPG Key ID: 1530BFF96D1EEB89
3 changed files with 6 additions and 7 deletions

View File

@ -16,8 +16,8 @@ dependencies {
implementation("org.ow2.asm:asm-util:9.2") implementation("org.ow2.asm:asm-util:9.2")
implementation("org.ow2.asm:asm-tree:9.2") implementation("org.ow2.asm:asm-tree:9.2")
implementation("org.ow2.asm:asm-commons:9.2") implementation("org.ow2.asm:asm-commons:9.2")
implementation("ch.qos.logback:logback-classic:1.2.11")
implementation("io.github.microutils:kotlin-logging:2.1.21") implementation("io.github.microutils:kotlin-logging:2.1.21")
testImplementation("ch.qos.logback:logback-classic:1.2.11") // use your own logger!
testImplementation(kotlin("test")) testImplementation(kotlin("test"))
} }

View File

@ -2,13 +2,11 @@ package net.revanced.patcher
import net.revanced.patcher.cache.Cache import net.revanced.patcher.cache.Cache
import net.revanced.patcher.patch.Patch import net.revanced.patcher.patch.Patch
import net.revanced.patcher.patch.PatchResult
import net.revanced.patcher.resolver.MethodResolver import net.revanced.patcher.resolver.MethodResolver
import net.revanced.patcher.signature.Signature import net.revanced.patcher.signature.Signature
import net.revanced.patcher.util.Jar2ASM import net.revanced.patcher.util.Jar2ASM
import java.io.InputStream import java.io.InputStream
import java.io.OutputStream import java.io.OutputStream
import java.util.jar.JarFile
/** /**
* The patcher. (docs WIP) * The patcher. (docs WIP)
@ -32,7 +30,7 @@ class Patcher (
this.patches.addAll(patches) this.patches.addAll(patches)
} }
fun executePatches(): Map<String, Result<Nothing?>> { fun applyPatches(stopOnError: Boolean = false): Map<String, Result<Nothing?>> {
return buildMap { return buildMap {
for (patch in patches) { for (patch in patches) {
val result: Result<Nothing?> = try { val result: Result<Nothing?> = try {
@ -43,11 +41,12 @@ class Patcher (
Result.failure(e) Result.failure(e)
} }
this[patch.patchName] = result this[patch.patchName] = result
if (stopOnError && result.isFailure) break
} }
} }
} }
fun save(output: OutputStream) { fun saveTo(output: OutputStream) {
} }
} }

View File

@ -37,7 +37,7 @@ internal class PatcherTest {
} }
) )
val result = patcher.executePatches() val result = patcher.applyPatches()
for ((s, r) in result) { for ((s, r) in result) {
if (r.isFailure) { if (r.isFailure) {
throw Exception("Patch $s failed", r.exceptionOrNull()!!) throw Exception("Patch $s failed", r.exceptionOrNull()!!)