Skip to content

Commit 7794327

Browse files
committed
feat: Use ReVanced Library in ReVanced CLI
1 parent 2b77608 commit 7794327

File tree

26 files changed

+585
-365
lines changed

26 files changed

+585
-365
lines changed

gradle/libs.versions.toml

+3-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ kotlin-reflect = "1.9.0"
88
kotlin-test = "1.8.20-RC"
99
kotlinx-coroutines-core = "1.7.3"
1010
picocli = "4.7.3"
11-
revanced-patcher = "15.0.0-dev.2"
11+
revanced-patcher = "15.0.0-dev.4"
12+
binary-compatibility-validator = "0.13.2"
1213

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

2425
[plugins]
2526
shadow = { id = "com.github.johnrengelman.shadow", version.ref = "shadow" }
27+
binary-compatibility-validator = { id = "org.jetbrains.kotlinx.binary-compatibility-validator", version.ref = "binary-compatibility-validator" }

revanced-cli/build.gradle.kts

+1-6
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,10 @@ plugins {
55

66
dependencies {
77
implementation(project(":revanced-lib"))
8-
98
implementation(libs.revanced.patcher)
10-
implementation(libs.kotlin.reflect)
119
implementation(libs.kotlinx.coroutines.core)
1210
implementation(libs.picocli)
13-
implementation(libs.jadb) // Updated fork
14-
implementation(libs.apksig)
15-
implementation(libs.bcpkix.jdk15on)
16-
implementation(libs.jackson.module.kotlin)
11+
1712
testImplementation(libs.kotlin.test)
1813
}
1914

revanced-cli/src/main/kotlin/app/revanced/cli/command/MainCommand.kt

+10-35
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,27 @@
11
package app.revanced.cli.command
22

33
import app.revanced.cli.command.utility.UtilityCommand
4+
import app.revanced.lib.logging.Logger
45
import picocli.CommandLine
56
import picocli.CommandLine.Command
67
import picocli.CommandLine.IVersionProvider
78
import java.util.*
8-
import java.util.logging.*
99

1010

1111
fun main(args: Array<String>) {
12-
System.setProperty("java.util.logging.SimpleFormatter.format", "%4\$s: %5\$s %n")
13-
Logger.getLogger("").apply {
14-
handlers.forEach {
15-
it.close()
16-
removeHandler(it)
17-
}
18-
19-
object : Handler() {
20-
override fun publish(record: LogRecord) = formatter.format(record).toByteArray().let {
21-
if (record.level.intValue() > Level.INFO.intValue())
22-
System.err.write(it)
23-
else
24-
System.out.write(it)
25-
}
26-
27-
override fun flush() {
28-
System.out.flush()
29-
System.err.flush()
30-
}
31-
32-
override fun close() = flush()
33-
}.also {
34-
it.level = Level.ALL
35-
it.formatter = SimpleFormatter()
36-
}.let(::addHandler)
37-
}
38-
12+
Logger.setDefault()
3913
CommandLine(MainCommand).execute(*args)
4014
}
4115

4216
private object CLIVersionProvider : IVersionProvider {
43-
override fun getVersion(): Array<String> {
44-
Properties().apply {
45-
load(MainCommand::class.java.getResourceAsStream("/app/revanced/cli/version.properties"))
46-
}.let {
47-
return arrayOf("ReVanced CLI v${it.getProperty("version")}")
48-
}
49-
}
17+
override fun getVersion() = arrayOf(
18+
MainCommand::class.java.getResourceAsStream(
19+
"/app/revanced/cli/version.properties"
20+
)?.use { stream ->
21+
Properties().apply { load(stream) }.let {
22+
"ReVanced CLI v${it.getProperty("version")}"
23+
}
24+
} ?: "ReVanced CLI")
5025
}
5126

5227
@Command(

revanced-cli/src/main/kotlin/app/revanced/cli/command/OptionsCommand.kt

+13-6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package app.revanced.cli.command
22

3+
import app.revanced.lib.Options
4+
import app.revanced.lib.Options.setOptions
35
import app.revanced.patcher.PatchBundleLoader
4-
import app.revanced.utils.Options
5-
import app.revanced.utils.Options.setOptions
66
import picocli.CommandLine
77
import picocli.CommandLine.Help.Visibility.ALWAYS
88
import java.io.File
@@ -37,10 +37,17 @@ internal object OptionsCommand : Runnable {
3737
)
3838
private var update: Boolean = false
3939

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

43-
Options.serialize(this, prettyPrint = true).let(filePath::writeText)
45+
Options.serialize(patches, prettyPrint = true).let(filePath::writeText)
46+
} else throw OptionsFileAlreadyExistsException()
47+
}
48+
} catch (ex: OptionsFileAlreadyExistsException) {
49+
logger.severe("Options file already exists, use --overwrite to override it")
4450
}
45-
else logger.severe("Options file already exists, use --overwrite to override it")
51+
52+
class OptionsFileAlreadyExistsException : Exception()
4653
}

0 commit comments

Comments
 (0)