From 66cd88f4d8a9161a4c51b70f2384dcee92fe2aea Mon Sep 17 00:00:00 2001 From: oSumAtrIX Date: Sun, 22 Jan 2023 15:38:12 +0100 Subject: [PATCH] fix: parse any kind of patch version Signed-off-by: oSumAtrIX --- build.gradle.kts | 2 +- .../kotlin/app/revanced/meta/JsonGenerator.kt | 70 +++++++++++++++++++ src/main/kotlin/app/revanced/meta/Meta.kt | 27 ------- .../app/revanced/meta/PatchesFileGenerator.kt | 25 +++++++ .../app/revanced/meta/ReadmeGenerator.kt | 69 ++++++++++++++++++ .../app/revanced/meta/json/Generator.kt | 48 ------------- .../app/revanced/meta/json/JsonPatch.kt | 26 ------- .../app/revanced/meta/readme/Extensions.kt | 10 --- .../app/revanced/meta/readme/Generator.kt | 42 ----------- .../revanced/meta/readme/SemanticVersion.kt | 22 ------ .../app/revanced/meta/readme/Template.kt | 12 ---- 11 files changed, 165 insertions(+), 188 deletions(-) create mode 100644 src/main/kotlin/app/revanced/meta/JsonGenerator.kt delete mode 100644 src/main/kotlin/app/revanced/meta/Meta.kt create mode 100644 src/main/kotlin/app/revanced/meta/PatchesFileGenerator.kt create mode 100644 src/main/kotlin/app/revanced/meta/ReadmeGenerator.kt delete mode 100644 src/main/kotlin/app/revanced/meta/json/Generator.kt delete mode 100644 src/main/kotlin/app/revanced/meta/json/JsonPatch.kt delete mode 100644 src/main/kotlin/app/revanced/meta/readme/Extensions.kt delete mode 100644 src/main/kotlin/app/revanced/meta/readme/Generator.kt delete mode 100644 src/main/kotlin/app/revanced/meta/readme/SemanticVersion.kt delete mode 100644 src/main/kotlin/app/revanced/meta/readme/Template.kt diff --git a/build.gradle.kts b/build.gradle.kts index 8978489aa..ae1de6cb2 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -53,7 +53,7 @@ tasks { dependsOn(build) classpath = sourceSets["main"].runtimeClasspath - mainClass.set("app.revanced.meta.Meta") + mainClass.set("app.revanced.meta.PatchesFileGenerator") } // Dummy task to fix the Gradle semantic-release plugin. // Remove this if you forked it to support building only. diff --git a/src/main/kotlin/app/revanced/meta/JsonGenerator.kt b/src/main/kotlin/app/revanced/meta/JsonGenerator.kt new file mode 100644 index 000000000..49c7a2c92 --- /dev/null +++ b/src/main/kotlin/app/revanced/meta/JsonGenerator.kt @@ -0,0 +1,70 @@ +package app.revanced.meta + +import app.revanced.patcher.extensions.PatchExtensions.compatiblePackages +import app.revanced.patcher.extensions.PatchExtensions.dependencies +import app.revanced.patcher.extensions.PatchExtensions.description +import app.revanced.patcher.extensions.PatchExtensions.include +import app.revanced.patcher.extensions.PatchExtensions.options +import app.revanced.patcher.extensions.PatchExtensions.patchName +import app.revanced.patcher.extensions.PatchExtensions.version +import app.revanced.patcher.patch.PatchOption +import com.google.gson.GsonBuilder +import java.io.File + +internal class JsonGenerator : PatchesFileGenerator { + override fun generate(bundle: PatchBundlePatches) { + val patches = bundle.map { + JsonPatch( + it.patchName, + it.description ?: "This patch has no description.", + it.version ?: "0.0.0", + !it.include, + it.options?.map { option -> + Option( + option.key, + option.title, + option.description, + option.required, + option.let { lo -> + if (lo is PatchOption.ListOption<*>) { + lo.options.toMutableList().toTypedArray() + } else null + } + ) + }?.toTypedArray() ?: emptyArray(), + it.dependencies?.map { dep -> + dep.java.patchName + }?.toTypedArray() ?: emptyArray(), + it.compatiblePackages?.map { pkg -> + CompatiblePackage(pkg.name, pkg.versions) + }?.toTypedArray() ?: emptyArray() + ) + } + + val json = File("patches.json") + json.writeText(GsonBuilder().serializeNulls().create().toJson(patches)) + } + + data class JsonPatch( + val name: String, + val description: String, + val version: String, + val excluded: Boolean, + val options: Array