feat: Do not format patch names

This gets rid of the ability to input a patch name in lower camel case. The reason for this is because there may be two distinct patches such as "Some Patch" and "some-patch" with no way to exclude or include either.
This commit is contained in:
oSumAtrIX 2023-09-22 02:52:20 +02:00
parent 50c0f98ce5
commit 80a8d88406
No known key found for this signature in database
GPG Key ID: A9B3094ACDB604B4
1 changed files with 5 additions and 18 deletions

View File

@ -256,31 +256,18 @@ internal object PatchCommand : Runnable {
/**
* Filter the patches to be added to the patcher. The filter is based on the following:
* - [includedPatches] (explicitly included)
* - [excludedPatches] (explicitly excluded)
* - [exclusive] (only include patches that are explicitly included)
* - [force] (ignore patches incompatibility to versions)
* - Package name and version of the input APK file (if [force] is false)
*
* @param patches The patches to filter.
* @return The filtered patches.
*/
private fun Patcher.filterPatchSelection(patches: PatchSet) = buildList {
// TODO: Remove this eventually because
// patches named "patch-name" and "patch name" will conflict.
fun String.format() = lowercase().replace(" ", "-")
val formattedExcludedPatches = excludedPatches.map { it.format() }
val formattedIncludedPatches = includedPatches.map { it.format() }
val packageName = context.packageMetadata.packageName
val packageVersion = context.packageMetadata.packageVersion
patches.forEach patch@{ patch ->
val patchName = patch.name!!
val formattedPatchName = patchName.format()
val explicitlyExcluded = formattedExcludedPatches.contains(formattedPatchName)
val explicitlyExcluded = excludedPatches.contains(patchName)
if (explicitlyExcluded) return@patch logger.info("Excluding $patchName")
// Make sure the patch is compatible with the supplied APK files package name and version.
@ -303,17 +290,17 @@ internal object PatchCommand : Runnable {
+ packages.joinToString(", ") { `package` -> `package`.name })
return@let
} ?: logger.fine("$formattedPatchName: No constraint on packages.")
} ?: logger.fine("$patchName has no constraint on packages.")
// If the patch is implicitly used, it will be only included if [exclusive] is false.
val implicitlyIncluded = !exclusive && patch.use
// If the patch is explicitly used, it will be included even if [exclusive] is false.
val explicitlyIncluded = formattedIncludedPatches.contains(formattedPatchName)
val explicitlyIncluded = includedPatches.contains(patchName)
val included = implicitlyIncluded || explicitlyIncluded
if (!included) return@patch logger.info("$patchName excluded by default") // Case 1.
if (!included) return@patch logger.info("$patchName excluded") // Case 1.
logger.fine("Adding $formattedPatchName")
logger.fine("Adding $patchName")
add(patch)
}