Skip to content
This repository was archived by the owner on Apr 15, 2024. It is now read-only.

Commit 157278c

Browse files
authored
feat: Add ReVanced Library subproject (ReVanced#265)
2 parents e7c9da7 + 049a385 commit 157278c

35 files changed

+874
-565
lines changed

.releaserc

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
{
3232
"assets": [
3333
{
34-
"path": "build/libs/*all.jar"
34+
"path": "revanced-cli/build/libs/*all.jar"
3535
}
3636
],
3737
successComment: false

build.gradle.kts

+4-54
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,7 @@
11
plugins {
2-
kotlin("jvm") version "1.8.20"
3-
alias(libs.plugins.shadow)
2+
kotlin("jvm") version "1.9.0" apply false
43
}
54

6-
group = "app.revanced"
7-
8-
dependencies {
9-
implementation(libs.revanced.patcher)
10-
implementation(libs.kotlin.reflect)
11-
implementation(libs.kotlinx.coroutines.core)
12-
implementation(libs.picocli)
13-
implementation(libs.jadb) // Updated fork
14-
implementation(libs.apksig)
15-
implementation(libs.bcpkix.jdk15on)
16-
implementation(libs.jackson.module.kotlin)
17-
testImplementation(libs.kotlin.test)
18-
}
19-
20-
kotlin { jvmToolchain(11) }
21-
22-
tasks {
23-
test {
24-
useJUnitPlatform()
25-
testLogging {
26-
events("PASSED", "SKIPPED", "FAILED")
27-
}
28-
}
29-
30-
processResources {
31-
expand("projectVersion" to project.version)
32-
}
33-
34-
shadowJar {
35-
manifest {
36-
attributes("Main-Class" to "app.revanced.cli.command.MainCommandKt")
37-
}
38-
minimize {
39-
exclude(dependency("org.jetbrains.kotlin:.*"))
40-
exclude(dependency("org.bouncycastle:.*"))
41-
exclude(dependency("app.revanced:.*"))
42-
}
43-
}
44-
45-
build {
46-
dependsOn(shadowJar)
47-
}
48-
49-
// Dummy task to fix the Gradle semantic-release plugin.
50-
// Remove this if you forked it to support building only.
51-
// Tracking issue: https://github.com/KengoTODA/gradle-semantic-release-plugin/issues/435
52-
register<DefaultTask>("publish") {
53-
group = "publish"
54-
description = "Dummy task"
55-
dependsOn(build)
56-
}
57-
}
5+
allprojects {
6+
group = "app.revanced"
7+
}

gradle/libs.versions.toml

+4-2
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ jackson-module-kotlin = "2.14.3"
66
jadb = "2531a28109"
77
kotlin-reflect = "1.9.0"
88
kotlin-test = "1.8.20-RC"
9-
kotlinx-coroutines-core = "1.7.1"
9+
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"
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

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
plugins {
2+
kotlin("jvm") version "1.9.0"
3+
alias(libs.plugins.shadow)
4+
}
5+
6+
dependencies {
7+
implementation(project(":revanced-lib"))
8+
implementation(libs.revanced.patcher)
9+
implementation(libs.kotlinx.coroutines.core)
10+
implementation(libs.picocli)
11+
12+
testImplementation(libs.kotlin.test)
13+
}
14+
15+
kotlin { jvmToolchain(11) }
16+
17+
tasks {
18+
test {
19+
useJUnitPlatform()
20+
testLogging {
21+
events("PASSED", "SKIPPED", "FAILED")
22+
}
23+
}
24+
25+
processResources {
26+
expand("projectVersion" to project.version)
27+
}
28+
29+
shadowJar {
30+
manifest {
31+
attributes("Main-Class" to "app.revanced.cli.command.MainCommandKt")
32+
}
33+
minimize {
34+
exclude(dependency("org.jetbrains.kotlin:.*"))
35+
exclude(dependency("org.bouncycastle:.*"))
36+
exclude(dependency("app.revanced:.*"))
37+
}
38+
}
39+
40+
build {
41+
dependsOn(shadowJar)
42+
}
43+
44+
// Dummy task to fix the Gradle semantic-release plugin.
45+
// Remove this if you forked it to support building only.
46+
// Tracking issue: https://github.com/KengoTODA/gradle-semantic-release-plugin/issues/435
47+
register<DefaultTask>("publish") {
48+
group = "publish"
49+
description = "Dummy task"
50+
dependsOn(build)
51+
}
52+
}

revanced-cli/settings.gradle.kts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
rootProject.name = "revanced-cli"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package app.revanced.cli.command
2+
3+
import app.revanced.cli.command.utility.UtilityCommand
4+
import app.revanced.lib.logging.Logger
5+
import picocli.CommandLine
6+
import picocli.CommandLine.Command
7+
import picocli.CommandLine.IVersionProvider
8+
import java.util.*
9+
10+
11+
fun main(args: Array<String>) {
12+
Logger.setDefault()
13+
CommandLine(MainCommand).execute(*args)
14+
}
15+
16+
private object CLIVersionProvider : IVersionProvider {
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")
25+
}
26+
27+
@Command(
28+
name = "revanced-cli",
29+
description = ["Command line application to use ReVanced"],
30+
mixinStandardHelpOptions = true,
31+
versionProvider = CLIVersionProvider::class,
32+
subcommands = [
33+
ListPatchesCommand::class,
34+
PatchCommand::class,
35+
OptionsCommand::class,
36+
UtilityCommand::class,
37+
]
38+
)
39+
private object MainCommand

src/main/kotlin/app/revanced/cli/command/OptionsCommand.kt renamed to 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)