2021-01-27 10:36:32 +00:00
|
|
|
|
2020-12-24 12:46:31 +00:00
|
|
|
import org.eclipse.jgit.internal.storage.file.FileRepository
|
2020-07-04 13:53:31 +00:00
|
|
|
import org.gradle.api.Plugin
|
|
|
|
import org.gradle.api.Project
|
2020-08-15 12:43:28 +00:00
|
|
|
import org.gradle.kotlin.dsl.provideDelegate
|
2020-07-04 13:53:31 +00:00
|
|
|
import java.io.File
|
|
|
|
import java.util.*
|
|
|
|
|
|
|
|
private val props = Properties()
|
2021-01-27 10:36:32 +00:00
|
|
|
private var commitHash = ""
|
2020-07-04 13:53:31 +00:00
|
|
|
|
|
|
|
object Config {
|
2021-01-25 15:33:09 +00:00
|
|
|
operator fun get(key: String): String? {
|
2020-12-24 12:46:31 +00:00
|
|
|
val v = props[key] as? String ?: return null
|
|
|
|
return if (v.isBlank()) null else v
|
|
|
|
}
|
2021-01-25 15:33:09 +00:00
|
|
|
|
2020-12-24 12:46:31 +00:00
|
|
|
fun contains(key: String) = get(key) != null
|
|
|
|
|
2021-01-25 15:33:09 +00:00
|
|
|
val version: String get() = get("version") ?: commitHash
|
2021-01-22 10:28:53 +00:00
|
|
|
val versionCode: Int get() = get("magisk.versionCode")!!.toInt()
|
2021-01-23 04:45:37 +00:00
|
|
|
val stubVersion: String get() = get("magisk.stubVersion")!!
|
2020-07-04 13:53:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
class MagiskPlugin : Plugin<Project> {
|
2021-01-27 10:36:32 +00:00
|
|
|
override fun apply(project: Project) = project.applyPlugin()
|
|
|
|
|
|
|
|
private fun Project.applyPlugin() {
|
2021-09-03 04:31:33 +00:00
|
|
|
initRandom(rootProject.file("dict.txt"))
|
2021-01-27 10:36:32 +00:00
|
|
|
props.clear()
|
|
|
|
rootProject.file("gradle.properties").inputStream().use { props.load(it) }
|
|
|
|
val configPath: String? by this
|
|
|
|
val config = configPath?.let { File(it) } ?: rootProject.file("config.prop")
|
2020-12-25 21:03:25 +00:00
|
|
|
if (config.exists())
|
|
|
|
config.inputStream().use { props.load(it) }
|
2020-12-25 13:34:15 +00:00
|
|
|
|
2021-01-27 10:36:32 +00:00
|
|
|
val repo = FileRepository(rootProject.file(".git"))
|
2020-12-25 13:34:15 +00:00
|
|
|
val refId = repo.refDatabase.exactRef("HEAD").objectId
|
|
|
|
commitHash = repo.newObjectReader().abbreviate(refId, 8).name()
|
2020-07-04 13:53:31 +00:00
|
|
|
}
|
|
|
|
}
|