From ba9d99868103406fe36b9aa0cfaa0ed5023edfab Mon Sep 17 00:00:00 2001 From: oSumAtrIX Date: Wed, 23 Nov 2022 00:01:40 +0100 Subject: [PATCH] feat: apply changes from ReVanced Patcher BREAKING-CHANGE: Some annotations have been removed regarding fingerprints and patches. --- .../kotlin/app/revanced/patcher/Patcher.kt | 6 ------ .../annotation/CompatibilityAnnotation.kt | 7 +++---- .../revanced/patcher/annotation/Deprecated.kt | 19 ------------------- .../patcher/annotation/MetadataAnnotation.kt | 13 ++++++------- .../extensions/AnnotationExtensions.kt | 15 +-------------- .../usage/bytecode/ExampleFingerprint.kt | 6 ------ 6 files changed, 10 insertions(+), 56 deletions(-) delete mode 100644 src/main/kotlin/app/revanced/patcher/annotation/Deprecated.kt diff --git a/src/main/kotlin/app/revanced/patcher/Patcher.kt b/src/main/kotlin/app/revanced/patcher/Patcher.kt index ab85e08..bd3505a 100644 --- a/src/main/kotlin/app/revanced/patcher/Patcher.kt +++ b/src/main/kotlin/app/revanced/patcher/Patcher.kt @@ -3,7 +3,6 @@ package app.revanced.patcher import app.revanced.patcher.data.Context import app.revanced.patcher.data.findIndexed import app.revanced.patcher.extensions.PatchExtensions.dependencies -import app.revanced.patcher.extensions.PatchExtensions.deprecated import app.revanced.patcher.extensions.PatchExtensions.patchName import app.revanced.patcher.extensions.nullOutputStream import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint.Companion.resolve @@ -316,11 +315,6 @@ class Patcher(private val options: PatcherOptions) { return PatchResultError("'$patchName' depends on '${dependency.patchName}' but the following error was raised: $errorMessage") } - patchClass.deprecated?.let { (reason, replacement) -> - logger.warn("'$patchName' is deprecated, reason: $reason") - if (replacement != null) logger.warn("Use '${replacement.java.patchName}' instead") - } - val isResourcePatch = ResourcePatch::class.java.isAssignableFrom(patchClass) val patchInstance = patchClass.getDeclaredConstructor().newInstance() diff --git a/src/main/kotlin/app/revanced/patcher/annotation/CompatibilityAnnotation.kt b/src/main/kotlin/app/revanced/patcher/annotation/CompatibilityAnnotation.kt index 1924b62..9e7e0a5 100644 --- a/src/main/kotlin/app/revanced/patcher/annotation/CompatibilityAnnotation.kt +++ b/src/main/kotlin/app/revanced/patcher/annotation/CompatibilityAnnotation.kt @@ -1,11 +1,10 @@ package app.revanced.patcher.annotation -import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint import app.revanced.patcher.patch.Patch /** - * Annotation to constrain a [Patch] or [MethodFingerprint] to compatible packages. - * @param compatiblePackages A list of packages a [Patch] or [MethodFingerprint] is compatible with. + * Annotation to constrain a [Patch] to compatible packages. + * @param compatiblePackages A list of packages a [Patch] is compatible with. */ @Target(AnnotationTarget.CLASS) @Retention(AnnotationRetention.RUNTIME) @@ -17,7 +16,7 @@ annotation class Compatibility( /** * Annotation to represent packages a patch can be compatible with. * @param name The package identifier name. - * @param versions The versions of the package the [Patch] or [MethodFingerprint]is compatible with. + * @param versions The versions of the package the [Patch] is compatible with. */ @Target() @Retention(AnnotationRetention.RUNTIME) diff --git a/src/main/kotlin/app/revanced/patcher/annotation/Deprecated.kt b/src/main/kotlin/app/revanced/patcher/annotation/Deprecated.kt deleted file mode 100644 index c5fbbc5..0000000 --- a/src/main/kotlin/app/revanced/patcher/annotation/Deprecated.kt +++ /dev/null @@ -1,19 +0,0 @@ -package app.revanced.patcher.annotation - -import app.revanced.patcher.data.Context -import app.revanced.patcher.patch.Patch -import kotlin.reflect.KClass - -/** - * Declares a [Patch] deprecated for removal. - * @param reason The reason why the patch is deprecated. - * @param replacement The replacement for the deprecated patch, if any. - */ -@Target(AnnotationTarget.CLASS) -@Retention(AnnotationRetention.RUNTIME) -@MustBeDocumented -annotation class PatchDeprecated( - val reason: String, - val replacement: KClass> = Patch::class - // Values cannot be nullable in annotations, so this will have to do. -) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patcher/annotation/MetadataAnnotation.kt b/src/main/kotlin/app/revanced/patcher/annotation/MetadataAnnotation.kt index b8526dd..cdd4c92 100644 --- a/src/main/kotlin/app/revanced/patcher/annotation/MetadataAnnotation.kt +++ b/src/main/kotlin/app/revanced/patcher/annotation/MetadataAnnotation.kt @@ -1,11 +1,10 @@ package app.revanced.patcher.annotation -import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint import app.revanced.patcher.patch.Patch /** - * Annotation to name a [Patch] or [MethodFingerprint]. - * @param name A suggestive name for the [Patch] or [MethodFingerprint]. + * Annotation to name a [Patch]. + * @param name A suggestive name for the [Patch]. */ @Target(AnnotationTarget.CLASS) @Retention(AnnotationRetention.RUNTIME) @@ -15,8 +14,8 @@ annotation class Name( ) /** - * Annotation to describe a [Patch] or [MethodFingerprint]. - * @param description A description for the [Patch] or [MethodFingerprint]. + * Annotation to describe a [Patch]. + * @param description A description for the [Patch]. */ @Target(AnnotationTarget.CLASS) @Retention(AnnotationRetention.RUNTIME) @@ -27,8 +26,8 @@ annotation class Description( /** - * Annotation to version a [Patch] or [MethodFingerprint]. - * @param version The version of a [Patch] or [MethodFingerprint]. + * Annotation to version a [Patch]. + * @param version The version of a [Patch]. */ @Target(AnnotationTarget.CLASS) @Retention(AnnotationRetention.RUNTIME) diff --git a/src/main/kotlin/app/revanced/patcher/extensions/AnnotationExtensions.kt b/src/main/kotlin/app/revanced/patcher/extensions/AnnotationExtensions.kt index 9c06372..cdc7358 100644 --- a/src/main/kotlin/app/revanced/patcher/extensions/AnnotationExtensions.kt +++ b/src/main/kotlin/app/revanced/patcher/extensions/AnnotationExtensions.kt @@ -65,24 +65,11 @@ object PatchExtensions { (it as? OptionsContainer)?.options } } - - val Class>.deprecated: Pair>?>? - get() = findAnnotationRecursively(PatchDeprecated::class)?.let { - it.reason to it.replacement.let { cl -> - if (cl == Patch::class) null else cl - } - } } object MethodFingerprintExtensions { val MethodFingerprint.name: String - get() = javaClass.findAnnotationRecursively(Name::class)?.name ?: this.javaClass.simpleName - - val MethodFingerprint.version - get() = javaClass.findAnnotationRecursively(Version::class)?.version ?: "0.0.1" - - val MethodFingerprint.description - get() = javaClass.findAnnotationRecursively(Description::class)?.description + get() = this.javaClass.simpleName val MethodFingerprint.fuzzyPatternScanMethod get() = javaClass.findAnnotationRecursively(FuzzyPatternScanMethod::class) diff --git a/src/test/kotlin/app/revanced/patcher/usage/bytecode/ExampleFingerprint.kt b/src/test/kotlin/app/revanced/patcher/usage/bytecode/ExampleFingerprint.kt index 1d18bb0..e87b651 100644 --- a/src/test/kotlin/app/revanced/patcher/usage/bytecode/ExampleFingerprint.kt +++ b/src/test/kotlin/app/revanced/patcher/usage/bytecode/ExampleFingerprint.kt @@ -1,17 +1,11 @@ package app.revanced.patcher.usage.bytecode - -import app.revanced.patcher.annotation.Name -import app.revanced.patcher.annotation.Version import app.revanced.patcher.extensions.or import app.revanced.patcher.fingerprint.method.annotation.FuzzyPatternScanMethod import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint import org.jf.dexlib2.AccessFlags import org.jf.dexlib2.Opcode -@Name("example-fingerprint") @FuzzyPatternScanMethod(2) -@ExampleBytecodeCompatibility -@Version("0.0.1") object ExampleFingerprint : MethodFingerprint( "V", AccessFlags.PUBLIC or AccessFlags.STATIC,