@@ -68,11 +68,11 @@ internal object PatchCommand : Runnable {
68
68
private var exclusive = false
69
69
70
70
@CommandLine.Option (
71
- names = [" --experimental " ],
72
- description = [" Ignore patches incompatibility to versions " ],
71
+ names = [" -f " , " --force " ],
72
+ description = [" Force inclusion of patches that are incompatible with the supplied APK file's version " ],
73
73
showDefaultValue = ALWAYS
74
74
)
75
- private var experimental : Boolean = false
75
+ private var force : Boolean = false
76
76
77
77
@CommandLine.Option (
78
78
names = [" -o" , " --out" ], description = [" Path to save the patched APK file to" ], required = true
@@ -225,8 +225,8 @@ internal object PatchCommand : Runnable {
225
225
* - [includedPatches] (explicitly included)
226
226
* - [excludedPatches] (explicitly excluded)
227
227
* - [exclusive] (only include patches that are explicitly included)
228
- * - [experimental ] (ignore patches incompatibility to versions)
229
- * - package name and version of the input APK file (if [experimental ] is false)
228
+ * - [force ] (ignore patches incompatibility to versions)
229
+ * - Package name and version of the input APK file (if [force ] is false)
230
230
*
231
231
* @param patches The patches to filter.
232
232
* @return The filtered patches.
@@ -238,46 +238,22 @@ internal object PatchCommand : Runnable {
238
238
patches.forEach patch@{ patch ->
239
239
val formattedPatchName = patch.patchName.lowercase().replace(" " , " -" )
240
240
241
- /* *
242
- * Check if the patch is explicitly excluded.
243
- *
244
- * Cases:
245
- * 1. -e patch.name
246
- * 2. -i patch.name -e patch.name
247
- */
248
-
249
- /* *
250
- * Check if the patch is explicitly excluded.
251
- *
252
- * Cases:
253
- * 1. -e patch.name
254
- * 2. -i patch.name -e patch.name
255
- */
256
-
257
- val excluded = excludedPatches.contains(formattedPatchName)
258
- if (excluded) return @patch logger.info(" Excluding ${patch.patchName} " )
259
-
260
- /* *
261
- * Check if the patch is constrained to packages.
262
- */
263
-
264
- /* *
265
- * Check if the patch is constrained to packages.
266
- */
241
+ val explicitlyExcluded = excludedPatches.contains(formattedPatchName)
242
+ if (explicitlyExcluded) return @patch logger.info(" Excluding ${patch.patchName} " )
267
243
268
- patch.compatiblePackages?.let { packages ->
269
- packages.singleOrNull { it.name == packageName }?.let { `package` ->
270
- /* *
271
- * Check if the package version matches.
272
- * If experimental is true, version matching will be skipped.
273
- */
244
+ // If the patch is explicitly included, it will be included if [exclusive] is false.
245
+ val explicitlyIncluded = exclusive && includedPatches.contains(formattedPatchName)
274
246
275
- /* *
276
- * Check if the package version matches.
277
- * If experimental is true, version matching will be skipped.
278
- */
247
+ // If the patch is implicitly included, it will be only included if [exclusive] is false.
248
+ val implicitlyIncluded = ! exclusive && patch.include
249
+
250
+ val included = implicitlyIncluded || explicitlyIncluded
251
+ if (! included) return @patch logger.info(" ${patch.patchName} excluded by default" ) // Case 1.
279
252
280
- val matchesVersion = experimental || `package`.versions.let {
253
+ // At last make sure the patch is compatible with the supplied APK files package name and version.
254
+ patch.compatiblePackages?.let { packages ->
255
+ packages.singleOrNull { it.name == packageName }?.let { `package` ->
256
+ val matchesVersion = force || `package`.versions.let {
281
257
it.isEmpty() || it.any { version -> version == packageVersion }
282
258
}
283
259
@@ -287,38 +263,13 @@ internal object PatchCommand : Runnable {
287
263
" ${pkg.name} : ${pkg.versions.joinToString(" , " )} "
288
264
})
289
265
290
- }
291
- ? : return @patch logger.fine(" ${patch.patchName} is incompatible with $packageName . " + " This patch is only compatible with " + packages.joinToString(
292
- " , "
293
- ) { `package` -> `package`.name })
266
+ } ? : return @patch logger.fine(" ${patch.patchName} is incompatible with $packageName . "
267
+ + " This patch is only compatible with "
268
+ + packages.joinToString(" , " ) { `package` -> `package`.name })
294
269
295
270
return @let
296
271
} ? : logger.fine(" $formattedPatchName : No constraint on packages." )
297
272
298
- /* *
299
- * Check if the patch is explicitly included.
300
- *
301
- * Cases:
302
- * 1. --exclusive
303
- * 2. --exclusive -i patch.name
304
- */
305
-
306
- /* *
307
- * Check if the patch is explicitly included.
308
- *
309
- * Cases:
310
- * 1. --exclusive
311
- * 2. --exclusive -i patch.name
312
- */
313
-
314
- val explicitlyIncluded = includedPatches.contains(formattedPatchName)
315
-
316
- val implicitlyIncluded = ! exclusive && patch.include // Case 3.
317
- val exclusivelyIncluded = exclusive && explicitlyIncluded // Case 2.
318
-
319
- val included = implicitlyIncluded || exclusivelyIncluded
320
- if (! included) return @patch logger.info(" ${patch.patchName} excluded by default" ) // Case 1.
321
-
322
273
logger.fine(" Adding $formattedPatchName " )
323
274
324
275
add(patch)
0 commit comments