build: Refactor to DSL to bump ReVanced Patcher

BREAKING CHANGE:  The signature of some functions has changed.
This commit is contained in:
oSumAtrIX
2024-06-16 16:02:38 +02:00
parent 8aca650ebc
commit 7f5d6dad7b
8 changed files with 69 additions and 80 deletions

View File

@@ -104,13 +104,10 @@ public final class app/revanced/library/PatchUtils$Json {
public final class app/revanced/library/PatchUtils$Json$FullJsonPatch : app/revanced/library/PatchUtils$Json$JsonPatch { public final class app/revanced/library/PatchUtils$Json$FullJsonPatch : app/revanced/library/PatchUtils$Json$JsonPatch {
public static final field Companion Lapp/revanced/library/PatchUtils$Json$FullJsonPatch$Companion; public static final field Companion Lapp/revanced/library/PatchUtils$Json$FullJsonPatch$Companion;
public final fun getCompatiblePackages ()Ljava/util/Set; public final fun getCompatiblePackages ()Ljava/util/Set;
public final fun getDependencies ()Ljava/util/Set;
public final fun getDescription ()Ljava/lang/String; public final fun getDescription ()Ljava/lang/String;
public final fun getName ()Ljava/lang/String; public final fun getName ()Ljava/lang/String;
public final fun getOptions ()Ljava/util/Map; public final fun getOptions ()Ljava/util/Map;
public final fun getRequiresIntegrations ()Z
public final fun getUse ()Z public final fun getUse ()Z
public final fun setRequiresIntegrations (Z)V
} }
public final class app/revanced/library/PatchUtils$Json$FullJsonPatch$Companion { public final class app/revanced/library/PatchUtils$Json$FullJsonPatch$Companion {
@@ -124,12 +121,12 @@ public final class app/revanced/library/PatchUtils$Json$FullJsonPatch$FullJsonPa
public final fun getKey ()Ljava/lang/String; public final fun getKey ()Ljava/lang/String;
public final fun getRequired ()Z public final fun getRequired ()Z
public final fun getTitle ()Ljava/lang/String; public final fun getTitle ()Ljava/lang/String;
public final fun getValueType ()Ljava/lang/String; public final fun getType ()Lkotlin/reflect/KType;
public final fun getValues ()Ljava/util/Map; public final fun getValues ()Ljava/util/Map;
} }
public final class app/revanced/library/PatchUtils$Json$FullJsonPatch$FullJsonPatchOption$Companion { public final class app/revanced/library/PatchUtils$Json$FullJsonPatch$FullJsonPatchOption$Companion {
public final fun fromPatchOption (Lapp/revanced/patcher/patch/options/PatchOption;)Lapp/revanced/library/PatchUtils$Json$FullJsonPatch$FullJsonPatchOption; public final fun fromPatchOption (Lapp/revanced/patcher/patch/Option;)Lapp/revanced/library/PatchUtils$Json$FullJsonPatch$FullJsonPatchOption;
} }
public abstract interface class app/revanced/library/PatchUtils$Json$JsonPatch { public abstract interface class app/revanced/library/PatchUtils$Json$JsonPatch {
@@ -255,6 +252,10 @@ public final class app/revanced/library/installation/installer/AdbRootInstaller
public synthetic fun <init> (Ljava/lang/String;ILkotlin/jvm/internal/DefaultConstructorMarker;)V public synthetic fun <init> (Ljava/lang/String;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
} }
public final class app/revanced/library/installation/installer/DeviceNotFoundException : java/lang/Exception {
public fun <init> ()V
}
public class app/revanced/library/installation/installer/Installation { public class app/revanced/library/installation/installer/Installation {
public final fun getApkFilePath ()Ljava/lang/String; public final fun getApkFilePath ()Ljava/lang/String;
} }

View File

@@ -104,13 +104,10 @@ public final class app/revanced/library/PatchUtils$Json {
public final class app/revanced/library/PatchUtils$Json$FullJsonPatch : app/revanced/library/PatchUtils$Json$JsonPatch { public final class app/revanced/library/PatchUtils$Json$FullJsonPatch : app/revanced/library/PatchUtils$Json$JsonPatch {
public static final field Companion Lapp/revanced/library/PatchUtils$Json$FullJsonPatch$Companion; public static final field Companion Lapp/revanced/library/PatchUtils$Json$FullJsonPatch$Companion;
public final fun getCompatiblePackages ()Ljava/util/Set; public final fun getCompatiblePackages ()Ljava/util/Set;
public final fun getDependencies ()Ljava/util/Set;
public final fun getDescription ()Ljava/lang/String; public final fun getDescription ()Ljava/lang/String;
public final fun getName ()Ljava/lang/String; public final fun getName ()Ljava/lang/String;
public final fun getOptions ()Ljava/util/Map; public final fun getOptions ()Ljava/util/Map;
public final fun getRequiresIntegrations ()Z
public final fun getUse ()Z public final fun getUse ()Z
public final fun setRequiresIntegrations (Z)V
} }
public final class app/revanced/library/PatchUtils$Json$FullJsonPatch$Companion { public final class app/revanced/library/PatchUtils$Json$FullJsonPatch$Companion {
@@ -124,12 +121,12 @@ public final class app/revanced/library/PatchUtils$Json$FullJsonPatch$FullJsonPa
public final fun getKey ()Ljava/lang/String; public final fun getKey ()Ljava/lang/String;
public final fun getRequired ()Z public final fun getRequired ()Z
public final fun getTitle ()Ljava/lang/String; public final fun getTitle ()Ljava/lang/String;
public final fun getValueType ()Ljava/lang/String; public final fun getType ()Lkotlin/reflect/KType;
public final fun getValues ()Ljava/util/Map; public final fun getValues ()Ljava/util/Map;
} }
public final class app/revanced/library/PatchUtils$Json$FullJsonPatch$FullJsonPatchOption$Companion { public final class app/revanced/library/PatchUtils$Json$FullJsonPatch$FullJsonPatchOption$Companion {
public final fun fromPatchOption (Lapp/revanced/patcher/patch/options/PatchOption;)Lapp/revanced/library/PatchUtils$Json$FullJsonPatch$FullJsonPatchOption; public final fun fromPatchOption (Lapp/revanced/patcher/patch/Option;)Lapp/revanced/library/PatchUtils$Json$FullJsonPatch$FullJsonPatchOption;
} }
public abstract interface class app/revanced/library/PatchUtils$Json$JsonPatch { public abstract interface class app/revanced/library/PatchUtils$Json$JsonPatch {
@@ -231,6 +228,10 @@ public final class app/revanced/library/installation/installer/AdbRootInstaller
public synthetic fun <init> (Ljava/lang/String;ILkotlin/jvm/internal/DefaultConstructorMarker;)V public synthetic fun <init> (Ljava/lang/String;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
} }
public final class app/revanced/library/installation/installer/DeviceNotFoundException : java/lang/Exception {
public fun <init> ()V
}
public class app/revanced/library/installation/installer/Installation { public class app/revanced/library/installation/installer/Installation {
public final fun getApkFilePath ()Ljava/lang/String; public final fun getApkFilePath ()Ljava/lang/String;
} }

View File

@@ -1,14 +1,11 @@
[versions] [versions]
jackson-module-kotlin = "2.15.0" jackson-module-kotlin = "2.16.1"
jadb = "1.2.1" jadb = "1.2.1"
kotlin = "1.9.22" kotlin = "2.0.0"
revanced-patcher = "19.3.1" kotlinx-coroutines = "1.8.1"
binary-compatibility-validator = "0.14.0" kotlinx-serialization = "1.7.1"
android = "8.3.0"
bcpkix-jdk15on = "1.70"
guava = "33.0.0-jre"
libsu = "5.2.2" libsu = "5.2.2"
core-ktx = "1.12.0" revanced-patcher = "20.0.0"
[libraries] [libraries]
jackson-module-kotlin = { module = "com.fasterxml.jackson.module:jackson-module-kotlin", version.ref = "jackson-module-kotlin" } jackson-module-kotlin = { module = "com.fasterxml.jackson.module:jackson-module-kotlin", version.ref = "jackson-module-kotlin" }

View File

@@ -2,9 +2,8 @@
package app.revanced.library package app.revanced.library
import app.revanced.library.Options.Patch.Option import app.revanced.patcher.patch.OptionException
import app.revanced.patcher.PatchSet import app.revanced.patcher.patch.Patch
import app.revanced.patcher.patch.options.PatchOptionException
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import java.io.File import java.io.File
import java.util.logging.Logger import java.util.logging.Logger
@@ -23,7 +22,7 @@ object Options {
* @return The JSON string containing the options. * @return The JSON string containing the options.
*/ */
fun serialize( fun serialize(
patches: PatchSet, patches: Set<app.revanced.patcher.patch.Patch<*>>,
prettyPrint: Boolean = false, prettyPrint: Boolean = false,
): String = ): String =
patches patches
@@ -35,12 +34,12 @@ object Options {
val optionValue = val optionValue =
try { try {
option.value option.value
} catch (e: PatchOptionException) { } catch (e: OptionException) {
logger.warning("Using default option value for the ${patch.name} patch: ${e.message}") logger.warning("Using default option value for the ${patch.name} patch: ${e.message}")
option.default option.default
} }
Option(option.key, optionValue) Patch.Option(option.key, optionValue)
}, },
) )
} }
@@ -68,7 +67,7 @@ object Options {
* *
* @param json The JSON string containing the options. * @param json The JSON string containing the options.
*/ */
fun PatchSet.setOptions(json: String) { fun Set<app.revanced.patcher.patch.Patch<*>>.setOptions(json: String) {
filter { it.options.any() }.let { patches -> filter { it.options.any() }.let { patches ->
if (patches.isEmpty()) return if (patches.isEmpty()) return
@@ -82,7 +81,7 @@ object Options {
jsonPatchOptions.forEach { (option, value) -> jsonPatchOptions.forEach { (option, value) ->
try { try {
patch.options[option] = value patch.options[option] = value
} catch (e: PatchOptionException) { } catch (e: OptionException) {
logger.warning("Could not set option value for the ${patch.name} patch: ${e.message}") logger.warning("Could not set option value for the ${patch.name} patch: ${e.message}")
} }
} }
@@ -97,7 +96,7 @@ object Options {
* @param file The file containing the JSON string containing the options. * @param file The file containing the JSON string containing the options.
* @see setOptions * @see setOptions
*/ */
fun PatchSet.setOptions(file: File) = setOptions(file.readText()) fun Set<app.revanced.patcher.patch.Patch<*>>.setOptions(file: File) = setOptions(file.readText())
/** /**
* Data class for a patch and its [Option]s. * Data class for a patch and its [Option]s.

View File

@@ -1,12 +1,12 @@
package app.revanced.library package app.revanced.library
import app.revanced.patcher.PatchSet import app.revanced.patcher.patch.Option
import app.revanced.patcher.patch.Package
import app.revanced.patcher.patch.Patch import app.revanced.patcher.patch.Patch
import app.revanced.patcher.patch.options.PatchOption
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import java.io.InputStream import java.io.InputStream
import java.io.OutputStream import java.io.OutputStream
import kotlin.reflect.jvm.jvmName import kotlin.reflect.KType
typealias PackageName = String typealias PackageName = String
typealias Version = String typealias Version = String
@@ -29,31 +29,29 @@ object PatchUtils {
* @return A map of package names to a map of versions to their count. * @return A map of package names to a map of versions to their count.
*/ */
fun getMostCommonCompatibleVersions( fun getMostCommonCompatibleVersions(
patches: PatchSet, patches: Set<Patch<*>>,
packageNames: Set<String>? = null, packageNames: Set<String>? = null,
countUnusedPatches: Boolean = false, countUnusedPatches: Boolean = false,
): PackageNameMap = ): PackageNameMap =
buildMap { buildMap {
fun filterWantedPackages(compatiblePackages: Iterable<Patch.CompatiblePackage>): Iterable<Patch.CompatiblePackage> { fun filterWantedPackages(compatiblePackages: Iterable<Package>): Iterable<Package> {
val wantedPackages = packageNames?.toHashSet() ?: return compatiblePackages val wantedPackages = packageNames?.toHashSet() ?: return compatiblePackages
return compatiblePackages.filter { it.name in wantedPackages } return compatiblePackages.filter { (name, _) -> name in wantedPackages }
} }
patches patches
.filter { it.use || countUnusedPatches } .filter { it.use || countUnusedPatches }
.flatMap { it.compatiblePackages ?: emptyList() } .flatMap { it.compatiblePackages ?: emptyList() }
.let(::filterWantedPackages) .let(::filterWantedPackages)
.forEach { compatiblePackage -> .forEach { (name, versions) ->
if (compatiblePackage.versions?.isEmpty() == true) { if (versions?.isEmpty() == true) {
return@forEach return@forEach
} }
val versionMap = getOrPut(compatiblePackage.name) { linkedMapOf() } val versionMap = getOrPut(name) { linkedMapOf() }
compatiblePackage.versions?.let { versions -> versions?.forEach { version ->
versions.forEach { version -> versionMap[version] = versionMap.getOrDefault(version, 0) + 1
versionMap[version] = versionMap.getOrDefault(version, 0) + 1
}
} }
} }
@@ -79,7 +77,7 @@ object PatchUtils {
* @param outputStream The output stream to write the JSON to. * @param outputStream The output stream to write the JSON to.
*/ */
fun serialize( fun serialize(
patches: PatchSet, patches: Set<Patch<*>>,
transform: (Patch<*>) -> JsonPatch = { patch -> FullJsonPatch.fromPatch(patch) }, transform: (Patch<*>) -> JsonPatch = { patch -> FullJsonPatch.fromPatch(patch) },
prettyPrint: Boolean = false, prettyPrint: Boolean = false,
outputStream: OutputStream, outputStream: OutputStream,
@@ -119,10 +117,10 @@ object PatchUtils {
class FullJsonPatch internal constructor( class FullJsonPatch internal constructor(
val name: String?, val name: String?,
val description: String?, val description: String?,
val compatiblePackages: Set<Patch.CompatiblePackage>?, val compatiblePackages: Set<Package>?,
val dependencies: Set<String>?, // Cannot serialize dependencies, because they are references to other patches and patch names are nullable.
// val dependencies: Set<String>,
val use: Boolean, val use: Boolean,
var requiresIntegrations: Boolean,
val options: Map<String, FullJsonPatchOption<*>>, val options: Map<String, FullJsonPatchOption<*>>,
) : JsonPatch { ) : JsonPatch {
companion object { companion object {
@@ -131,16 +129,15 @@ object PatchUtils {
patch.name, patch.name,
patch.description, patch.description,
patch.compatiblePackages, patch.compatiblePackages,
buildSet { patch.dependencies?.forEach { add(it.jvmName) } }, // buildSet { patch.dependencies.forEach { add(it.name) } },
patch.use, patch.use,
patch.requiresIntegrations,
patch.options.mapValues { FullJsonPatchOption.fromPatchOption(it.value) }, patch.options.mapValues { FullJsonPatchOption.fromPatchOption(it.value) },
) )
} }
/** /**
* A JSON representation of a [PatchOption]. * A JSON representation of a [Option].
* @see PatchOption * @see Option
*/ */
class FullJsonPatchOption<T> internal constructor( class FullJsonPatchOption<T> internal constructor(
val key: String, val key: String,
@@ -149,10 +146,10 @@ object PatchUtils {
val title: String?, val title: String?,
val description: String?, val description: String?,
val required: Boolean, val required: Boolean,
val valueType: String, val type: KType,
) { ) {
companion object { companion object {
fun fromPatchOption(option: PatchOption<*>) = fun fromPatchOption(option: Option<*>) =
FullJsonPatchOption( FullJsonPatchOption(
option.key, option.key,
option.default, option.default,
@@ -160,7 +157,7 @@ object PatchUtils {
option.title, option.title,
option.description, option.description,
option.required, option.required,
option.valueType, option.type,
) )
} }
} }

View File

@@ -1,6 +1,6 @@
package app.revanced.library.installation.command package app.revanced.library.installation.command
import app.revanced.library.installation.installer.Utils import app.revanced.library.installation.installer.getDevice
import se.vidstige.jadb.JadbDevice import se.vidstige.jadb.JadbDevice
import se.vidstige.jadb.RemoteFile import se.vidstige.jadb.RemoteFile
import java.io.File import java.io.File
@@ -29,7 +29,7 @@ class AdbShellCommandRunner : ShellCommandRunner {
* @param deviceSerial deviceSerial The device serial. If null, the first connected device will be used. * @param deviceSerial deviceSerial The device serial. If null, the first connected device will be used.
*/ */
internal constructor(deviceSerial: String?) { internal constructor(deviceSerial: String?) {
device = Utils.getDevice(deviceSerial, logger) device = getDevice(deviceSerial, logger)
} }
override fun runCommand(command: String) = device.shellProcessBuilder(command).start().let { process -> override fun runCommand(command: String) = device.shellProcessBuilder(command).start().let { process ->

View File

@@ -17,7 +17,7 @@ import se.vidstige.jadb.managers.PackageManager
class AdbInstaller( class AdbInstaller(
deviceSerial: String? = null, deviceSerial: String? = null,
) : Installer<AdbInstallerResult, Installation>() { ) : Installer<AdbInstallerResult, Installation>() {
private val device = Utils.getDevice(deviceSerial, logger) private val device = getDevice(deviceSerial, logger)
private val adbShellCommandRunner = AdbShellCommandRunner(device) private val adbShellCommandRunner = AdbShellCommandRunner(device)
private val packageManager = PackageManager(device) private val packageManager = PackageManager(device)

View File

@@ -4,37 +4,31 @@ import se.vidstige.jadb.JadbConnection
import java.util.logging.Logger import java.util.logging.Logger
/** /**
* Utility functions for [Installer]. * Gets the device with the given serial.
* *
* @see Installer * @param deviceSerial The device serial. If null, the first connected device will be used.
* @param logger The logger.
* @return The device.
* @throws DeviceNotFoundException If no device with the given serial is found.
*/ */
internal object Utils { internal fun getDevice(
/** deviceSerial: String? = null,
* Gets the device with the given serial. logger: Logger,
* ) = with(JadbConnection().devices) {
* @param deviceSerial The device serial. If null, the first connected device will be used. if (isEmpty()) throw DeviceNotFoundException()
* @param logger The logger.
* @return The device.
* @throws DeviceNotFoundException If no device with the given serial is found.
*/
internal fun getDevice(
deviceSerial: String? = null,
logger: Logger,
) = with(JadbConnection().devices) {
if (isEmpty()) throw DeviceNotFoundException()
deviceSerial?.let { deviceSerial?.let {
firstOrNull { it.serial == deviceSerial } ?: throw DeviceNotFoundException( firstOrNull { it.serial == deviceSerial } ?: throw DeviceNotFoundException(
deviceSerial, deviceSerial,
) )
} ?: first().also { } ?: first().also {
logger.warning("No device serial supplied. Using device with serial ${it.serial}") logger.warning("No device serial supplied. Using device with serial ${it.serial}")
} }
}!! }!!
class DeviceNotFoundException internal constructor(deviceSerial: String? = null) : Exception( class DeviceNotFoundException internal constructor(deviceSerial: String? = null) :
Exception(
deviceSerial?.let { deviceSerial?.let {
"The device with the ADB device serial \"$deviceSerial\" can not be found" "The device with the ADB device serial \"$deviceSerial\" can not be found"
} ?: "No ADB device found", } ?: "No ADB device found",
) )
}