mirror of
https://github.com/revanced/revanced-cli.git
synced 2025-01-22 00:47:32 +01:00
feat: improve logging
This commit is contained in:
parent
04805e45fe
commit
df85fa37ef
@ -1,7 +1,8 @@
|
|||||||
package app.revanced.cli.command
|
package app.revanced.cli.command
|
||||||
|
|
||||||
|
import app.revanced.cli.logging.impl.DefaultCliLogger
|
||||||
import app.revanced.cli.patcher.Patcher
|
import app.revanced.cli.patcher.Patcher
|
||||||
import app.revanced.cli.patcher.PatcherLogger
|
import app.revanced.cli.patcher.logging.impl.PatcherLogger
|
||||||
import app.revanced.cli.signing.Signing
|
import app.revanced.cli.signing.Signing
|
||||||
import app.revanced.cli.signing.SigningOptions
|
import app.revanced.cli.signing.SigningOptions
|
||||||
import app.revanced.patcher.PatcherOptions
|
import app.revanced.patcher.PatcherOptions
|
||||||
@ -25,6 +26,8 @@ private class CLIVersionProvider : IVersionProvider {
|
|||||||
versionProvider = CLIVersionProvider::class
|
versionProvider = CLIVersionProvider::class
|
||||||
)
|
)
|
||||||
internal object MainCommand : Runnable {
|
internal object MainCommand : Runnable {
|
||||||
|
val logger = DefaultCliLogger()
|
||||||
|
|
||||||
@ArgGroup(exclusive = false, multiplicity = "1")
|
@ArgGroup(exclusive = false, multiplicity = "1")
|
||||||
lateinit var args: Args
|
lateinit var args: Args
|
||||||
|
|
||||||
@ -91,7 +94,7 @@ internal object MainCommand : Runnable {
|
|||||||
override fun run() {
|
override fun run() {
|
||||||
if (args.lArgs?.listOnly == true) {
|
if (args.lArgs?.listOnly == true) {
|
||||||
for (patchBundlePath in args.patchBundles) for (patch in JarPatchBundle(patchBundlePath).loadPatches()) {
|
for (patchBundlePath in args.patchBundles) for (patch in JarPatchBundle(patchBundlePath).loadPatches()) {
|
||||||
println("[available] ${patch.patchName}: ${patch.description}")
|
logger.info("${patch.patchName}: ${patch.description}")
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -134,13 +137,10 @@ internal object MainCommand : Runnable {
|
|||||||
|
|
||||||
if (args.clean) File(args.cacheDirectory).deleteRecursively()
|
if (args.clean) File(args.cacheDirectory).deleteRecursively()
|
||||||
|
|
||||||
adb?.let {
|
adb?.deploy()
|
||||||
println("[deploying]")
|
|
||||||
it.deploy()
|
|
||||||
}
|
|
||||||
|
|
||||||
if (args.clean && args.deploy != null) Files.delete(outputFile.toPath())
|
if (args.clean && args.deploy != null) Files.delete(outputFile.toPath())
|
||||||
|
|
||||||
println("[done]")
|
logger.info("Finished")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
8
src/main/kotlin/app/revanced/cli/logging/CliLogger.kt
Normal file
8
src/main/kotlin/app/revanced/cli/logging/CliLogger.kt
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
package app.revanced.cli.logging
|
||||||
|
|
||||||
|
internal interface CliLogger {
|
||||||
|
fun error(msg: String)
|
||||||
|
fun info(msg: String)
|
||||||
|
fun trace(msg: String)
|
||||||
|
fun warn(msg: String)
|
||||||
|
}
|
@ -0,0 +1,20 @@
|
|||||||
|
package app.revanced.cli.logging.impl
|
||||||
|
|
||||||
|
import app.revanced.cli.command.MainCommand
|
||||||
|
import app.revanced.cli.logging.CliLogger
|
||||||
|
import java.util.logging.Logger
|
||||||
|
|
||||||
|
internal class DefaultCliLogger(
|
||||||
|
private val logger: Logger = Logger.getLogger(MainCommand::javaClass.name)
|
||||||
|
) : CliLogger {
|
||||||
|
companion object {
|
||||||
|
init {
|
||||||
|
System.setProperty("java.util.logging.SimpleFormatter.format", "%4\$s: %5\$s %n")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun error(msg: String) = logger.severe(msg)
|
||||||
|
override fun info(msg: String) = logger.info(msg)
|
||||||
|
override fun trace(msg: String) = logger.finest(msg)
|
||||||
|
override fun warn(msg: String) = logger.warning(msg)
|
||||||
|
}
|
@ -1,6 +1,7 @@
|
|||||||
package app.revanced.cli.patcher
|
package app.revanced.cli.patcher
|
||||||
|
|
||||||
import app.revanced.cli.command.MainCommand.args
|
import app.revanced.cli.command.MainCommand.args
|
||||||
|
import app.revanced.cli.command.MainCommand.logger
|
||||||
import app.revanced.utils.filesystem.ZipFileSystemUtils
|
import app.revanced.utils.filesystem.ZipFileSystemUtils
|
||||||
import app.revanced.utils.patcher.addPatchesFiltered
|
import app.revanced.utils.patcher.addPatchesFiltered
|
||||||
import app.revanced.utils.patcher.applyPatchesVerbose
|
import app.revanced.utils.patcher.applyPatchesVerbose
|
||||||
@ -30,12 +31,14 @@ internal object Patcher {
|
|||||||
ZipFileSystemUtils(inputFile, output).use { fileSystem ->
|
ZipFileSystemUtils(inputFile, output).use { fileSystem ->
|
||||||
// replace all dex files
|
// replace all dex files
|
||||||
result.dexFiles.forEach {
|
result.dexFiles.forEach {
|
||||||
|
logger.info("Writing dex file ${it.name}")
|
||||||
fileSystem.write(it.name, it.dexFileInputStream.readAllBytes())
|
fileSystem.write(it.name, it.dexFileInputStream.readAllBytes())
|
||||||
}
|
}
|
||||||
|
|
||||||
// inputFile being null implies resource patching being disabled
|
// inputFile being null implies resource patching being disabled
|
||||||
if (inputFile != null) {
|
if (inputFile != null) {
|
||||||
// write resources
|
// write resources
|
||||||
|
logger.info("Writing resources")
|
||||||
fileSystem.writeInput()
|
fileSystem.writeInput()
|
||||||
fileSystem.uncompress(*result.doNotCompress!!.toTypedArray())
|
fileSystem.uncompress(*result.doNotCompress!!.toTypedArray())
|
||||||
}
|
}
|
||||||
|
@ -1,23 +0,0 @@
|
|||||||
package app.revanced.cli.patcher
|
|
||||||
|
|
||||||
import app.revanced.patcher.PatchLogger
|
|
||||||
|
|
||||||
object PatcherLogger : PatchLogger {
|
|
||||||
private const val prefix = "[patcher]"
|
|
||||||
|
|
||||||
override fun error(msg: String) {
|
|
||||||
println("error: $prefix: $msg")
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun info(msg: String) {
|
|
||||||
println("info: $prefix: $msg")
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun trace(msg: String) {
|
|
||||||
println("trace: $prefix: $msg")
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun warn(msg: String) {
|
|
||||||
println("warn: $prefix: $msg")
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,13 @@
|
|||||||
|
package app.revanced.cli.patcher.logging.impl
|
||||||
|
|
||||||
|
import app.revanced.cli.logging.impl.DefaultCliLogger
|
||||||
|
import java.util.logging.Logger
|
||||||
|
|
||||||
|
internal object PatcherLogger : app.revanced.patcher.logging.Logger{
|
||||||
|
private val logger = DefaultCliLogger(Logger.getLogger(app.revanced.patcher.Patcher::javaClass.name))
|
||||||
|
|
||||||
|
override fun error(msg: String) = logger.error(msg)
|
||||||
|
override fun info(msg: String) = logger.info(msg)
|
||||||
|
override fun warn(msg: String)= logger.warn(msg)
|
||||||
|
override fun trace(msg: String)= logger.trace(msg)
|
||||||
|
}
|
@ -1,6 +1,7 @@
|
|||||||
package app.revanced.cli.signing
|
package app.revanced.cli.signing
|
||||||
|
|
||||||
import app.revanced.cli.command.MainCommand.args
|
import app.revanced.cli.command.MainCommand.args
|
||||||
|
import app.revanced.cli.command.MainCommand.logger
|
||||||
import app.revanced.utils.signing.Signer
|
import app.revanced.utils.signing.Signer
|
||||||
import app.revanced.utils.signing.align.ZipAligner
|
import app.revanced.utils.signing.align.ZipAligner
|
||||||
import java.io.File
|
import java.io.File
|
||||||
@ -12,15 +13,16 @@ object Signing {
|
|||||||
val signedOutput = cacheDirectory.resolve("${outputFile.nameWithoutExtension}_signed.apk")
|
val signedOutput = cacheDirectory.resolve("${outputFile.nameWithoutExtension}_signed.apk")
|
||||||
|
|
||||||
// align the inputFile and write to alignedOutput
|
// align the inputFile and write to alignedOutput
|
||||||
println("[aligning]")
|
logger.info("Aligning ${inputFile.name}")
|
||||||
ZipAligner.align(inputFile, alignedOutput)
|
ZipAligner.align(inputFile, alignedOutput)
|
||||||
// sign the alignedOutput and write to signedOutput
|
// sign the alignedOutput and write to signedOutput
|
||||||
// the reason is, in case the signer fails
|
// the reason is, in case the signer fails
|
||||||
// it does not damage the output file
|
// it does not damage the output file
|
||||||
println("[signing]")
|
logger.info("Signing ${alignedOutput.name}")
|
||||||
Signer(signingOptions).signApk(alignedOutput, signedOutput)
|
Signer(signingOptions).signApk(alignedOutput, signedOutput)
|
||||||
|
|
||||||
// afterwards copy over the file to the output
|
// afterwards copy over the file to the output
|
||||||
|
logger.info("Copying ${signedOutput.name} to ${outputFile.name}")
|
||||||
signedOutput.copyTo(outputFile, true)
|
signedOutput.copyTo(outputFile, true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package app.revanced.utils.adb
|
package app.revanced.utils.adb
|
||||||
|
|
||||||
|
import app.revanced.cli.command.MainCommand.logger
|
||||||
import se.vidstige.jadb.JadbConnection
|
import se.vidstige.jadb.JadbConnection
|
||||||
import se.vidstige.jadb.JadbDevice
|
import se.vidstige.jadb.JadbDevice
|
||||||
import se.vidstige.jadb.managers.PackageManager
|
import se.vidstige.jadb.managers.PackageManager
|
||||||
@ -29,8 +30,12 @@ internal class Adb(
|
|||||||
|
|
||||||
internal fun deploy() {
|
internal fun deploy() {
|
||||||
if (modeInstall) {
|
if (modeInstall) {
|
||||||
|
logger.info("Installing without mounting")
|
||||||
|
|
||||||
PackageManager(device).install(file)
|
PackageManager(device).install(file)
|
||||||
} else {
|
} else {
|
||||||
|
logger.info("Installing by mounting")
|
||||||
|
|
||||||
// push patched file
|
// push patched file
|
||||||
device.copy(Constants.PATH_INIT_PUSH, file)
|
device.copy(Constants.PATH_INIT_PUSH, file)
|
||||||
|
|
||||||
@ -91,10 +96,10 @@ internal class Adb(
|
|||||||
}
|
}
|
||||||
break
|
break
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
throw RuntimeException("An error occurred while monitoring state of app", e)
|
throw RuntimeException("An error occurred while monitoring the state of app", e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
println("App closed, continuing.")
|
logger.info("Stopped logging because the app was closed")
|
||||||
process.destroy()
|
process.destroy()
|
||||||
executor.shutdown()
|
executor.shutdown()
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ package app.revanced.utils.patcher
|
|||||||
|
|
||||||
import app.revanced.cli.command.MainCommand
|
import app.revanced.cli.command.MainCommand
|
||||||
import app.revanced.cli.command.MainCommand.args
|
import app.revanced.cli.command.MainCommand.args
|
||||||
|
import app.revanced.cli.command.MainCommand.logger
|
||||||
import app.revanced.patcher.Patcher
|
import app.revanced.patcher.Patcher
|
||||||
import app.revanced.patcher.data.base.Data
|
import app.revanced.patcher.data.base.Data
|
||||||
import app.revanced.patcher.extensions.PatchExtensions.compatiblePackages
|
import app.revanced.patcher.extensions.PatchExtensions.compatiblePackages
|
||||||
@ -22,33 +23,40 @@ fun Patcher.addPatchesFiltered(
|
|||||||
val compatiblePackages = patch.compatiblePackages
|
val compatiblePackages = patch.compatiblePackages
|
||||||
val patchName = patch.patchName
|
val patchName = patch.patchName
|
||||||
|
|
||||||
val prefix = "[skipped] $patchName"
|
val prefix = "Skipping $patchName"
|
||||||
|
|
||||||
val args = MainCommand.args.pArgs!!
|
val args = MainCommand.args.pArgs!!
|
||||||
|
|
||||||
if (excludePatches && args.excludedPatches.contains(patchName)) {
|
if (excludePatches && args.excludedPatches.contains(patchName)) {
|
||||||
println("$prefix: Explicitly excluded.")
|
logger.info("$prefix: Explicitly excluded")
|
||||||
return@patch
|
return@patch
|
||||||
} else if (!patch.include) {
|
} else if (!patch.include) {
|
||||||
println("$prefix: Implicitly excluded.")
|
logger.info("$prefix: Explicitly excluded")
|
||||||
return@patch
|
return@patch
|
||||||
}
|
}
|
||||||
|
|
||||||
if (compatiblePackages == null) println("$prefix: Missing compatibility annotation. Continuing.")
|
if (compatiblePackages == null) logger.warn("$prefix: Missing compatibility annotation. Continuing.")
|
||||||
else {
|
else {
|
||||||
if (!compatiblePackages.any { it.name == packageName }) {
|
if (!compatiblePackages.any { it.name == packageName }) {
|
||||||
println("$prefix: Incompatible package.")
|
logger.warn("$prefix: Incompatible with $packageName. This patch is only compatible with ${
|
||||||
|
compatiblePackages.joinToString(
|
||||||
|
", "
|
||||||
|
) { it.name }
|
||||||
|
}")
|
||||||
return@patch
|
return@patch
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(args.experimental || compatiblePackages.any { it.versions.isEmpty() || it.versions.any { version -> version == packageVersion } })) {
|
if (!(args.experimental || compatiblePackages.any { it.versions.isEmpty() || it.versions.any { version -> version == packageVersion } })) {
|
||||||
println("$prefix: The package version is $packageVersion and is incompatible.")
|
val compatibleWith = compatiblePackages.map { _package ->
|
||||||
|
"${_package.name}: ${_package.versions.joinToString(", ")}"
|
||||||
|
}.joinToString(";")
|
||||||
|
logger.warn("$prefix: Incompatible with version $packageVersion. This patch is only compatible with version $compatibleWith")
|
||||||
return@patch
|
return@patch
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logger.trace("Adding $patchName")
|
||||||
includedPatches.add(patch)
|
includedPatches.add(patch)
|
||||||
println("[added] $patchName")
|
|
||||||
}
|
}
|
||||||
this.addPatches(includedPatches)
|
this.addPatches(includedPatches)
|
||||||
}
|
}
|
||||||
@ -57,16 +65,16 @@ fun Patcher.addPatchesFiltered(
|
|||||||
fun Patcher.applyPatchesVerbose() {
|
fun Patcher.applyPatchesVerbose() {
|
||||||
this.applyPatches().forEach { (patch, result) ->
|
this.applyPatches().forEach { (patch, result) ->
|
||||||
if (result.isSuccess) {
|
if (result.isSuccess) {
|
||||||
println("[success] $patch")
|
logger.info("$patch succeeded")
|
||||||
return@forEach
|
return@forEach
|
||||||
}
|
}
|
||||||
println("[error] $patch:")
|
logger.error("$patch failed:")
|
||||||
result.exceptionOrNull()!!.printStackTrace()
|
result.exceptionOrNull()!!.printStackTrace()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Patcher.mergeFiles() {
|
fun Patcher.mergeFiles() {
|
||||||
this.addFiles(args.pArgs!!.mergeFiles) {
|
this.addFiles(args.pArgs!!.mergeFiles) { file ->
|
||||||
println("[merged] ${it.name}")
|
logger.info("Merging $file")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package app.revanced.utils.signing
|
package app.revanced.utils.signing
|
||||||
|
|
||||||
|
import app.revanced.cli.command.MainCommand.logger
|
||||||
import app.revanced.cli.signing.SigningOptions
|
import app.revanced.cli.signing.SigningOptions
|
||||||
import com.android.apksig.ApkSigner
|
import com.android.apksig.ApkSigner
|
||||||
import org.bouncycastle.asn1.x500.X500Name
|
import org.bouncycastle.asn1.x500.X500Name
|
||||||
@ -55,7 +56,7 @@ internal class Signer(
|
|||||||
// TODO: keystore should be saved securely
|
// TODO: keystore should be saved securely
|
||||||
val ks = File(signingOptions.keyStoreFilePath)
|
val ks = File(signingOptions.keyStoreFilePath)
|
||||||
if (!ks.exists()) newKeystore(ks) else {
|
if (!ks.exists()) newKeystore(ks) else {
|
||||||
println("[found] existing keystore: ${ks.nameWithoutExtension}")
|
logger.info("Found existing keystore: ${ks.nameWithoutExtension}")
|
||||||
}
|
}
|
||||||
|
|
||||||
val keyStore = KeyStore.getInstance("BKS", "BC")
|
val keyStore = KeyStore.getInstance("BKS", "BC")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user