fix: Do not set CompatiblePackage.versions if @CompatiblePackage.versions is empty

This commit is contained in:
oSumAtrIX
2023-09-13 02:13:30 +02:00
parent 72c9eb2129
commit 6b1e0a1656
3 changed files with 28 additions and 4 deletions

View File

@ -81,14 +81,14 @@ class PatchProcessor(
dependencies?.map { dependency -> dependency.toClassName() },
compatiblePackages?.map {
val packageName = it.property("name")
val packageVersions = (it.property("versions") as List<String>)
.joinToString(", ") { version -> "\"$version\"" }
val packageVersions = (it.property("versions") as List<String>).ifEmpty { null }
?.joinToString(", ") { version -> "\"$version\"" }
CodeBlock.of(
"%T(%S, setOf(%L))",
"%T(%S, %L)",
app.revanced.patcher.patch.Patch.CompatiblePackage::class,
packageName,
packageVersions
packageVersions?.let { "setOf($packageVersions)" },
)
},
use,

View File

@ -21,6 +21,16 @@ class TestPatchAnnotationProcessor {
).loadPatch("$SAMPLE_PACKAGE.processing.ProcessablePatchGenerated").name
)
@Test
fun generateNullProperties() = compile(
getSourceFile(
"null", "NullPropertiesPatch"
)
).loadPatch("$SAMPLE_PACKAGE.null.NullPropertiesPatchGenerated").let {
assertNull(it.description) // Because no description was provided.
assertNull(it.compatiblePackages!!.first().versions) // Because no versions were provided.
}
// endregion
// region Dependencies

View File

@ -0,0 +1,14 @@
package app.revanced.patcher.patch.annotation.processor.samples.`null`
import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.patch.BytecodePatch
import app.revanced.patcher.patch.annotation.CompatiblePackage
import app.revanced.patcher.patch.annotation.Patch
@Patch(
"Patch with null properties",
compatiblePackages = [CompatiblePackage("com.google.android.youtube")],
)
object NullPropertiesPatch : BytecodePatch() {
override fun execute(context: BytecodeContext) {}
}