Skip to content

Commit

Permalink
feat: deprecation for patches
Browse files Browse the repository at this point in the history
  • Loading branch information
Sculas committed Sep 7, 2022
1 parent c3db23d commit 80c2e80
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 7 deletions.
5 changes: 5 additions & 0 deletions src/main/kotlin/app/revanced/patcher/Patcher.kt
Expand Up @@ -4,6 +4,7 @@ import app.revanced.patcher.data.Data
import app.revanced.patcher.data.PackageMetadata
import app.revanced.patcher.data.impl.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.utils.MethodFingerprintUtils.resolve
Expand Down Expand Up @@ -289,6 +290,10 @@ class Patcher(private val options: PatcherOptions) {
return PatchResultError("'$patchName' is a resource patch, but resource patching is disabled")
}

patch.deprecated?.let { (reason, replacement) ->
logger.warn("'$patchName' is deprecated: '$reason'" + if (replacement != null) ". Use '$replacement' instead." else "")
}

// TODO: find a solution for this
val data = if (isResourcePatch) {
data.resourceData
Expand Down
20 changes: 20 additions & 0 deletions src/main/kotlin/app/revanced/patcher/annotation/Deprecated.kt
@@ -0,0 +1,20 @@
package app.revanced.patcher.annotation

import app.revanced.patcher.data.Data
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
@Repeatable

This comment has been minimized.

Copy link
@oSumAtrIX

oSumAtrIX Sep 7, 2022

Member

What is the reason for this annotation to be repeatable?

This comment has been minimized.

Copy link
@Sculas

Sculas Sep 7, 2022

Author Contributor

Oh, that's leftover code. Oops.

annotation class PatchDeprecated(

This comment has been minimized.

Copy link
@oSumAtrIX

oSumAtrIX Sep 7, 2022

Member

Currently this is the only annotation for patches which contains Patch in the name next to the Patch annotation. Instead this annotation should be called Deprecated to be consistent with the other annotations.

This comment has been minimized.

Copy link
@Sculas

Sculas Sep 7, 2022

Author Contributor

I understand, but it would conflict with the built-in @Deprecated annotation. Do you have another idea?

This comment has been minimized.

Copy link
@oSumAtrIX

oSumAtrIX Sep 7, 2022

Member

The full qualifier can be used for this annotation to get around the other @Deprecated annotation. Other than that I wouldn't bother too much about it.

val reason: String,
val replacement: KClass<out Patch<Data>> = Patch::class
// Values cannot be nullable in annotations, so this will have to do.
)
@@ -1,9 +1,6 @@
package app.revanced.patcher.extensions

import app.revanced.patcher.annotation.Compatibility
import app.revanced.patcher.annotation.Description
import app.revanced.patcher.annotation.Name
import app.revanced.patcher.annotation.Version
import app.revanced.patcher.annotation.*
import app.revanced.patcher.data.Data
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
import app.revanced.patcher.patch.OptionsContainer
Expand Down Expand Up @@ -45,9 +42,16 @@ object PatchExtensions {
val Class<out Patch<Data>>.description get() = recursiveAnnotation(Description::class)?.description
val Class<out Patch<Data>>.dependencies get() = recursiveAnnotation(app.revanced.patcher.patch.annotations.DependsOn::class)?.dependencies
val Class<out Patch<Data>>.compatiblePackages get() = recursiveAnnotation(Compatibility::class)?.compatiblePackages
val Class<out Patch<Data>>.options get() = kotlin.companionObjectInstance?.let {
(it as? OptionsContainer)?.options
}
val Class<out Patch<Data>>.options
get() = kotlin.companionObjectInstance?.let {
(it as? OptionsContainer)?.options
}
val Class<out Patch<Data>>.deprecated: Pair<String, KClass<out Patch<Data>>?>?
get() = recursiveAnnotation(PatchDeprecated::class)?.let {
it.reason to it.replacement.let { cl ->
if (cl == Patch::class) null else cl
}
}

@JvmStatic
fun Class<out Patch<Data>>.dependsOn(patch: Class<out Patch<Data>>): Boolean {
Expand Down

0 comments on commit 80c2e80

Please sign in to comment.