mirror of
https://github.com/revanced/revanced-patcher.git
synced 2025-05-02 05:54:26 +02:00
feat: SincePatcher annotation
This commit is contained in:
parent
6e73631d4d
commit
25f74dc5e9
@ -37,6 +37,9 @@ tasks {
|
|||||||
events("PASSED", "SKIPPED", "FAILED")
|
events("PASSED", "SKIPPED", "FAILED")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
processResources {
|
||||||
|
expand("projectVersion" to project.version)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
java {
|
java {
|
||||||
|
@ -6,6 +6,7 @@ import app.revanced.patcher.data.impl.findIndexed
|
|||||||
import app.revanced.patcher.extensions.PatchExtensions.dependencies
|
import app.revanced.patcher.extensions.PatchExtensions.dependencies
|
||||||
import app.revanced.patcher.extensions.PatchExtensions.deprecated
|
import app.revanced.patcher.extensions.PatchExtensions.deprecated
|
||||||
import app.revanced.patcher.extensions.PatchExtensions.patchName
|
import app.revanced.patcher.extensions.PatchExtensions.patchName
|
||||||
|
import app.revanced.patcher.extensions.PatchExtensions.sincePatcherVersion
|
||||||
import app.revanced.patcher.extensions.nullOutputStream
|
import app.revanced.patcher.extensions.nullOutputStream
|
||||||
import app.revanced.patcher.fingerprint.method.utils.MethodFingerprintUtils.resolve
|
import app.revanced.patcher.fingerprint.method.utils.MethodFingerprintUtils.resolve
|
||||||
import app.revanced.patcher.patch.Patch
|
import app.revanced.patcher.patch.Patch
|
||||||
@ -15,6 +16,7 @@ import app.revanced.patcher.patch.PatchResultSuccess
|
|||||||
import app.revanced.patcher.patch.impl.BytecodePatch
|
import app.revanced.patcher.patch.impl.BytecodePatch
|
||||||
import app.revanced.patcher.patch.impl.ResourcePatch
|
import app.revanced.patcher.patch.impl.ResourcePatch
|
||||||
import app.revanced.patcher.util.ListBackedSet
|
import app.revanced.patcher.util.ListBackedSet
|
||||||
|
import app.revanced.patcher.util.VersionReader
|
||||||
import brut.androlib.Androlib
|
import brut.androlib.Androlib
|
||||||
import brut.androlib.meta.UsesFramework
|
import brut.androlib.meta.UsesFramework
|
||||||
import brut.androlib.options.BuildOptions
|
import brut.androlib.options.BuildOptions
|
||||||
@ -36,7 +38,8 @@ import java.io.Closeable
|
|||||||
import java.io.File
|
import java.io.File
|
||||||
import java.nio.file.Files
|
import java.nio.file.Files
|
||||||
|
|
||||||
val NAMER = BasicDexFileNamer()
|
private val NAMER = BasicDexFileNamer()
|
||||||
|
private val VERSION = VersionReader.read()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The ReVanced Patcher.
|
* The ReVanced Patcher.
|
||||||
@ -244,6 +247,15 @@ class Patcher(private val options: PatcherOptions) {
|
|||||||
* @param patches [Patch]es The patches to add.
|
* @param patches [Patch]es The patches to add.
|
||||||
*/
|
*/
|
||||||
fun addPatches(patches: Iterable<Class<out Patch<Data>>>) {
|
fun addPatches(patches: Iterable<Class<out Patch<Data>>>) {
|
||||||
|
for (patch in patches) {
|
||||||
|
val needsVersion = patch.sincePatcherVersion
|
||||||
|
if (needsVersion != null && needsVersion > VERSION) {
|
||||||
|
logger.error("Patch '${patch.patchName}' requires Patcher version $needsVersion or higher")
|
||||||
|
logger.error("Current Patcher version is $VERSION")
|
||||||
|
logger.warn("Skipping '${patch.patchName}'!")
|
||||||
|
continue // TODO: continue or halt/throw?
|
||||||
|
}
|
||||||
|
}
|
||||||
data.patches.addAll(patches)
|
data.patches.addAll(patches)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -0,0 +1,13 @@
|
|||||||
|
package app.revanced.patcher.annotation
|
||||||
|
|
||||||
|
import app.revanced.patcher.patch.Patch
|
||||||
|
import app.revanced.patcher.Patcher
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Declares a [Patch] deprecated for removal.
|
||||||
|
* @param version The minimum version of the [Patcher] this [Patch] supports.
|
||||||
|
*/
|
||||||
|
@Target(AnnotationTarget.CLASS)
|
||||||
|
@Retention(AnnotationRetention.RUNTIME)
|
||||||
|
@MustBeDocumented
|
||||||
|
annotation class SincePatcher(val version: String)
|
@ -58,6 +58,7 @@ object PatchExtensions {
|
|||||||
if (cl == Patch::class) null else cl
|
if (cl == Patch::class) null else cl
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
val Class<out Patch<Data>>.sincePatcherVersion get() = recursiveAnnotation(SincePatcher::class)?.version
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun Class<out Patch<Data>>.dependsOn(patch: Class<out Patch<Data>>): Boolean {
|
fun Class<out Patch<Data>>.dependsOn(patch: Class<out Patch<Data>>): Boolean {
|
||||||
|
18
src/main/kotlin/app/revanced/patcher/util/VersionReader.kt
Normal file
18
src/main/kotlin/app/revanced/patcher/util/VersionReader.kt
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
package app.revanced.patcher.util
|
||||||
|
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
|
internal object VersionReader {
|
||||||
|
@JvmStatic
|
||||||
|
private val props = Properties().apply {
|
||||||
|
load(
|
||||||
|
VersionReader::class.java.getResourceAsStream("/revanced-patcher/version.properties")
|
||||||
|
?: throw IllegalStateException("Could not load version.properties")
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@JvmStatic
|
||||||
|
fun read(): String {
|
||||||
|
return props.getProperty("version") ?: throw IllegalStateException("Version not found")
|
||||||
|
}
|
||||||
|
}
|
1
src/main/resources/revanced-patcher/version.properties
Normal file
1
src/main/resources/revanced-patcher/version.properties
Normal file
@ -0,0 +1 @@
|
|||||||
|
version=${projectVersion}
|
@ -0,0 +1,20 @@
|
|||||||
|
package app.revanced.patcher.util
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Assertions.*
|
||||||
|
|
||||||
|
internal class VersionReaderTest {
|
||||||
|
@Test
|
||||||
|
fun read() {
|
||||||
|
val version = VersionReader.read()
|
||||||
|
assertNotNull(version)
|
||||||
|
assertTrue(version.isNotEmpty())
|
||||||
|
val parts = version.split(".")
|
||||||
|
assertEquals(3, parts.size)
|
||||||
|
parts.forEach {
|
||||||
|
assertTrue(it.toInt() >= 0)
|
||||||
|
}
|
||||||
|
println(version)
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user