diff --git a/CHANGELOG.md b/CHANGELOG.md index 7a4ad97..e7e98ae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,29 @@ +# [3.1.0-dev.1](https://github.com/ReVanced/revanced-cli/compare/v3.0.2-dev.2...v3.1.0-dev.1) (2023-08-28) + + +### Bug Fixes + +* format patches input ([bbb1a63](https://github.com/ReVanced/revanced-cli/commit/bbb1a63abd80dcbecdcf362158c0429cf3e6318f)) + + +### Features + +* Simplify command description ([3b3f7c7](https://github.com/ReVanced/revanced-cli/commit/3b3f7c7a7a7b2795e3d1fad776f6b457f2e68c7b)) + +## [3.0.2-dev.2](https://github.com/ReVanced/revanced-cli/compare/v3.0.2-dev.1...v3.0.2-dev.2) (2023-08-28) + + +### Bug Fixes + +* check for package compatibility at first ([9fe5a0b](https://github.com/ReVanced/revanced-cli/commit/9fe5a0b6d93304f630436ed0e954723d9a27b0f6)) + +## [3.0.2-dev.1](https://github.com/ReVanced/revanced-cli/compare/v3.0.1...v3.0.2-dev.1) (2023-08-28) + + +### Bug Fixes + +* do not filter explicitly included patches ([a3d8f00](https://github.com/ReVanced/revanced-cli/commit/a3d8f004ec405f696d99d96c74ca41b573ecf425)) + ## [3.0.1](https://github.com/ReVanced/revanced-cli/compare/v3.0.0...v3.0.1) (2023-08-28) ## [3.0.1-dev.1](https://github.com/ReVanced/revanced-cli/compare/v3.0.0...v3.0.1-dev.1) (2023-08-28) diff --git a/gradle.properties b/gradle.properties index b0270b5..e6ac794 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ org.gradle.parallel = true org.gradle.caching = true kotlin.code.style = official -version = 3.0.1 +version = 3.1.0-dev.1 diff --git a/src/main/kotlin/app/revanced/cli/command/PatchCommand.kt b/src/main/kotlin/app/revanced/cli/command/PatchCommand.kt index 4bc2641..9d3796c 100644 --- a/src/main/kotlin/app/revanced/cli/command/PatchCommand.kt +++ b/src/main/kotlin/app/revanced/cli/command/PatchCommand.kt @@ -25,7 +25,7 @@ import java.util.logging.Logger @CommandLine.Command( - name = "patch", description = ["Patch the supplied APK file with the supplied patches and integrations"] + name = "patch", description = ["Patch an APK file"] ) internal object PatchCommand : Runnable { private val logger = Logger.getLogger(PatchCommand::class.java.name) @@ -232,37 +232,36 @@ internal object PatchCommand : Runnable { * @return The filtered patches. */ private fun Patcher.filterPatchSelection(patches: PatchList) = 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 formattedPatchName = patch.patchName.lowercase().replace(" ", "-") + val formattedPatchName = patch.patchName.format() - val explicitlyExcluded = excludedPatches.contains(formattedPatchName) + val explicitlyExcluded = formattedExcludedPatches.contains(formattedPatchName) if (explicitlyExcluded) return@patch logger.info("Excluding ${patch.patchName}") - // If the patch is explicitly included, it will be included if [exclusive] is false. - val explicitlyIncluded = exclusive && includedPatches.contains(formattedPatchName) - - // If the patch is implicitly included, it will be only included if [exclusive] is false. - val implicitlyIncluded = !exclusive && patch.include - - val included = implicitlyIncluded || explicitlyIncluded - if (!included) return@patch logger.info("${patch.patchName} excluded by default") // Case 1. - - // At last make sure the patch is compatible with the supplied APK files package name and version. + // Make sure the patch is compatible with the supplied APK files package name and version. patch.compatiblePackages?.let { packages -> packages.singleOrNull { it.name == packageName }?.let { `package` -> val matchesVersion = force || `package`.versions.let { it.isEmpty() || it.any { version -> version == packageVersion } } - if (!matchesVersion) return@patch logger.warning("${patch.patchName} is incompatible with version $packageVersion. " + "This patch is only compatible with version " + packages.joinToString( - ";" - ) { pkg -> - "${pkg.name}: ${pkg.versions.joinToString(", ")}" - }) - + if (!matchesVersion) return@patch logger.warning( + "${patch.patchName} is incompatible with version $packageVersion. " + + "This patch is only compatible with version " + + packages.joinToString(";") { pkg -> + "${pkg.name}: ${pkg.versions.joinToString(", ")}" + } + ) } ?: return@patch logger.fine("${patch.patchName} is incompatible with $packageName. " + "This patch is only compatible with " + packages.joinToString(", ") { `package` -> `package`.name }) @@ -270,6 +269,14 @@ internal object PatchCommand : Runnable { return@let } ?: logger.fine("$formattedPatchName: No constraint on packages.") + // If the patch is implicitly included, it will be only included if [exclusive] is false. + val implicitlyIncluded = !exclusive && patch.include + // If the patch is explicitly included, it will be included even if [exclusive] is false. + val explicitlyIncluded = formattedIncludedPatches.contains(formattedPatchName) + + val included = implicitlyIncluded || explicitlyIncluded + if (!included) return@patch logger.info("${patch.patchName} excluded by default") // Case 1. + logger.fine("Adding $formattedPatchName") add(patch)