Skip to content

Commit

Permalink
feat: Add ReVanced Library subproject (#265)
Browse files Browse the repository at this point in the history
  • Loading branch information
oSumAtrIX committed Sep 20, 2023
2 parents e7c9da7 + 049a385 commit 157278c
Show file tree
Hide file tree
Showing 35 changed files with 874 additions and 565 deletions.
2 changes: 1 addition & 1 deletion .releaserc
Expand Up @@ -31,7 +31,7 @@
{
"assets": [
{
"path": "build/libs/*all.jar"
"path": "revanced-cli/build/libs/*all.jar"
}
],
successComment: false
Expand Down
58 changes: 4 additions & 54 deletions build.gradle.kts
@@ -1,57 +1,7 @@
plugins {
kotlin("jvm") version "1.8.20"
alias(libs.plugins.shadow)
kotlin("jvm") version "1.9.0" apply false
}

group = "app.revanced"

dependencies {
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)
}

kotlin { jvmToolchain(11) }

tasks {
test {
useJUnitPlatform()
testLogging {
events("PASSED", "SKIPPED", "FAILED")
}
}

processResources {
expand("projectVersion" to project.version)
}

shadowJar {
manifest {
attributes("Main-Class" to "app.revanced.cli.command.MainCommandKt")
}
minimize {
exclude(dependency("org.jetbrains.kotlin:.*"))
exclude(dependency("org.bouncycastle:.*"))
exclude(dependency("app.revanced:.*"))
}
}

build {
dependsOn(shadowJar)
}

// Dummy task to fix the Gradle semantic-release plugin.
// Remove this if you forked it to support building only.
// Tracking issue: https://github.com/KengoTODA/gradle-semantic-release-plugin/issues/435
register<DefaultTask>("publish") {
group = "publish"
description = "Dummy task"
dependsOn(build)
}
}
allprojects {
group = "app.revanced"
}
6 changes: 4 additions & 2 deletions gradle/libs.versions.toml
Expand Up @@ -6,9 +6,10 @@ jackson-module-kotlin = "2.14.3"
jadb = "2531a28109"
kotlin-reflect = "1.9.0"
kotlin-test = "1.8.20-RC"
kotlinx-coroutines-core = "1.7.1"
kotlinx-coroutines-core = "1.7.3"
picocli = "4.7.3"
revanced-patcher = "15.0.0-dev.2"
revanced-patcher = "15.0.0"
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" }
52 changes: 52 additions & 0 deletions revanced-cli/build.gradle.kts
@@ -0,0 +1,52 @@
plugins {
kotlin("jvm") version "1.9.0"
alias(libs.plugins.shadow)
}

dependencies {
implementation(project(":revanced-lib"))
implementation(libs.revanced.patcher)
implementation(libs.kotlinx.coroutines.core)
implementation(libs.picocli)

testImplementation(libs.kotlin.test)
}

kotlin { jvmToolchain(11) }

tasks {
test {
useJUnitPlatform()
testLogging {
events("PASSED", "SKIPPED", "FAILED")
}
}

processResources {
expand("projectVersion" to project.version)
}

shadowJar {
manifest {
attributes("Main-Class" to "app.revanced.cli.command.MainCommandKt")
}
minimize {
exclude(dependency("org.jetbrains.kotlin:.*"))
exclude(dependency("org.bouncycastle:.*"))
exclude(dependency("app.revanced:.*"))
}
}

build {
dependsOn(shadowJar)
}

// Dummy task to fix the Gradle semantic-release plugin.
// Remove this if you forked it to support building only.
// Tracking issue: https://github.com/KengoTODA/gradle-semantic-release-plugin/issues/435
register<DefaultTask>("publish") {
group = "publish"
description = "Dummy task"
dependsOn(build)
}
}
1 change: 1 addition & 0 deletions revanced-cli/settings.gradle.kts
@@ -0,0 +1 @@
rootProject.name = "revanced-cli"
@@ -0,0 +1,39 @@
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.*


fun main(args: Array<String>) {
Logger.setDefault()
CommandLine(MainCommand).execute(*args)
}

private object CLIVersionProvider : IVersionProvider {
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(
name = "revanced-cli",
description = ["Command line application to use ReVanced"],
mixinStandardHelpOptions = true,
versionProvider = CLIVersionProvider::class,
subcommands = [
ListPatchesCommand::class,
PatchCommand::class,
OptionsCommand::class,
UtilityCommand::class,
]
)
private object MainCommand
@@ -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()
}

0 comments on commit 157278c

Please sign in to comment.