Skip to content

Commit

Permalink
feat: Use ReVanced Library in ReVanced CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
oSumAtrIX committed Sep 19, 2023
1 parent 2b77608 commit 7794327
Show file tree
Hide file tree
Showing 26 changed files with 585 additions and 365 deletions.
4 changes: 3 additions & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ kotlin-reflect = "1.9.0"
kotlin-test = "1.8.20-RC"
kotlinx-coroutines-core = "1.7.3"
picocli = "4.7.3"
revanced-patcher = "15.0.0-dev.2"
revanced-patcher = "15.0.0-dev.4"
binary-compatibility-validator = "0.13.2"

[libraries]
apksig = { module = "com.android.tools.build:apksig", version.ref = "apksig" }
Expand All @@ -23,3 +24,4 @@ revanced-patcher = { module = "app.revanced:revanced-patcher", version.ref = "re

[plugins]
shadow = { id = "com.github.johnrengelman.shadow", version.ref = "shadow" }
binary-compatibility-validator = { id = "org.jetbrains.kotlinx.binary-compatibility-validator", version.ref = "binary-compatibility-validator" }
7 changes: 1 addition & 6 deletions revanced-cli/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,10 @@ plugins {

dependencies {
implementation(project(":revanced-lib"))

implementation(libs.revanced.patcher)
implementation(libs.kotlin.reflect)
implementation(libs.kotlinx.coroutines.core)
implementation(libs.picocli)
implementation(libs.jadb) // Updated fork
implementation(libs.apksig)
implementation(libs.bcpkix.jdk15on)
implementation(libs.jackson.module.kotlin)

testImplementation(libs.kotlin.test)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,52 +1,27 @@
package app.revanced.cli.command

import app.revanced.cli.command.utility.UtilityCommand
import app.revanced.lib.logging.Logger
import picocli.CommandLine
import picocli.CommandLine.Command
import picocli.CommandLine.IVersionProvider
import java.util.*
import java.util.logging.*


fun main(args: Array<String>) {
System.setProperty("java.util.logging.SimpleFormatter.format", "%4\$s: %5\$s %n")
Logger.getLogger("").apply {
handlers.forEach {
it.close()
removeHandler(it)
}

object : Handler() {
override fun publish(record: LogRecord) = formatter.format(record).toByteArray().let {
if (record.level.intValue() > Level.INFO.intValue())
System.err.write(it)
else
System.out.write(it)
}

override fun flush() {
System.out.flush()
System.err.flush()
}

override fun close() = flush()
}.also {
it.level = Level.ALL
it.formatter = SimpleFormatter()
}.let(::addHandler)
}

Logger.setDefault()
CommandLine(MainCommand).execute(*args)
}

private object CLIVersionProvider : IVersionProvider {
override fun getVersion(): Array<String> {
Properties().apply {
load(MainCommand::class.java.getResourceAsStream("/app/revanced/cli/version.properties"))
}.let {
return arrayOf("ReVanced CLI v${it.getProperty("version")}")
}
}
override fun getVersion() = arrayOf(
MainCommand::class.java.getResourceAsStream(
"/app/revanced/cli/version.properties"
)?.use { stream ->
Properties().apply { load(stream) }.let {
"ReVanced CLI v${it.getProperty("version")}"
}
} ?: "ReVanced CLI")
}

@Command(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package app.revanced.cli.command

import app.revanced.lib.Options
import app.revanced.lib.Options.setOptions
import app.revanced.patcher.PatchBundleLoader
import app.revanced.utils.Options
import app.revanced.utils.Options.setOptions
import picocli.CommandLine
import picocli.CommandLine.Help.Visibility.ALWAYS
import java.io.File
Expand Down Expand Up @@ -37,10 +37,17 @@ internal object OptionsCommand : Runnable {
)
private var update: Boolean = false

override fun run() = if (!filePath.exists() || overwrite) with(PatchBundleLoader.Jar(*patchBundles)) {
if (update && filePath.exists()) setOptions(filePath)
override fun run() = try {
PatchBundleLoader.Jar(*patchBundles).let { patches ->
if (!filePath.exists() || overwrite) {
if (update && filePath.exists()) patches.setOptions(filePath)

Options.serialize(this, prettyPrint = true).let(filePath::writeText)
Options.serialize(patches, prettyPrint = true).let(filePath::writeText)
} else throw OptionsFileAlreadyExistsException()
}
} catch (ex: OptionsFileAlreadyExistsException) {
logger.severe("Options file already exists, use --overwrite to override it")
}
else logger.severe("Options file already exists, use --overwrite to override it")

class OptionsFileAlreadyExistsException : Exception()
}
Loading

0 comments on commit 7794327

Please sign in to comment.