fix: wrong use of dependency to revanced-patches

Signed-off-by: oSumAtrIX <johan.melkonyan1@web.de>
This commit is contained in:
oSumAtrIX 2022-05-07 23:15:31 +02:00
parent 52dacc16a0
commit 351de6cb90
No known key found for this signature in database
GPG Key ID: A9B3094ACDB604B4
3 changed files with 10 additions and 26 deletions

View File

@ -22,12 +22,9 @@ repositories {
}
}
val patchesDependency = "app.revanced:revanced-patches:1.+"
dependencies {
implementation(kotlin("stdlib"))
implementation("app.revanced:revanced-patcher:+")
implementation(patchesDependency)
implementation("info.picocli:picocli:+")
implementation("me.tongfei:progressbar:+")
@ -45,9 +42,6 @@ tasks {
dependsOn(shadowJar)
}
shadowJar {
dependencies {
exclude(dependency(patchesDependency))
}
manifest {
attributes("Main-Class" to "app.revanced.cli.MainKt")
attributes("Implementation-Title" to project.name)

View File

@ -1,10 +0,0 @@
package app.revanced.patch
import java.io.File
import java.net.URLClassLoader
internal class PatchLoader {
internal companion object {
}
}

View File

@ -2,25 +2,25 @@ package app.revanced.patch
import app.revanced.patcher.data.base.Data
import app.revanced.patcher.patch.base.Patch
import app.revanced.patches.Index
import java.io.File
import java.net.URLClassLoader
internal object Patches {
/**
* This method loads patches from a given patch file
* @return the loaded patches represented as a list of functions returning instances of [Patch]
*/
internal fun load(patchFile: File): List<() -> Patch<Data>> {
val url = patchFile.toURI().toURL()
internal fun load(patchesJar: File): List<() -> Patch<Data>> {
val url = patchesJar.toURI().toURL()
val classLoader = URLClassLoader(arrayOf(url))
return loadIndex(classLoader).patches
val indexClass = classLoader.loadClass("app.revanced.patches.Index")
val index = indexClass.declaredFields.last()
index.isAccessible = true
@Suppress("UNCHECKED_CAST")
return index.get(null) as List<() -> Patch<Data>>
}
private fun loadIndex(classLoader: ClassLoader) = classLoader
.loadClass(Index::class.java.canonicalName)
.fields
.first()
.get(null) as Index
}