mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-06-12 05:07:45 +02:00
Make config.prop optional
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
|
||||
import org.gradle.api.GradleException
|
||||
import org.eclipse.jgit.api.Git
|
||||
import org.eclipse.jgit.internal.storage.file.FileRepository
|
||||
import org.gradle.api.Plugin
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.kotlin.dsl.provideDelegate
|
||||
@ -7,19 +8,33 @@ import java.io.File
|
||||
import java.util.*
|
||||
|
||||
private val props = Properties()
|
||||
private lateinit var commitHash: String
|
||||
private var commitCount = 0
|
||||
|
||||
object Config {
|
||||
operator fun get(key: String) = props[key] as? String
|
||||
fun contains(key: String) = props.containsKey(key)
|
||||
operator fun get(key: String) : String? {
|
||||
val v = props[key] as? String ?: return null
|
||||
return if (v.isBlank()) null else v
|
||||
}
|
||||
fun contains(key: String) = get(key) != null
|
||||
|
||||
val appVersion: String get() = get("appVersion") ?: commitHash
|
||||
val appVersionCode: Int get() = get("appVersionCode")?.toInt() ?: commitCount
|
||||
val magiskVersionCode: Int get() = get("versionCode")?.toInt() ?: Int.MAX_VALUE
|
||||
}
|
||||
|
||||
class MagiskPlugin : Plugin<Project> {
|
||||
override fun apply(project: Project) {
|
||||
val configPath: String? by project
|
||||
val file = configPath?.let { File(it) } ?: project.file("config.prop")
|
||||
if (!file.exists())
|
||||
throw GradleException("Please setup config.prop")
|
||||
val config = configPath?.let { File(it) } ?: project.file("config.prop")
|
||||
if (config.exists())
|
||||
config.inputStream().use { props.load(it) }
|
||||
|
||||
file.inputStream().use { props.load(it) }
|
||||
if (!Config.contains("appVersion") || !Config.contains("appVersionCode")) {
|
||||
val repo = FileRepository(project.rootProject.file(".git"))
|
||||
val refId = repo.refDatabase.exactRef("refs/heads/master").objectId
|
||||
commitHash = repo.newObjectReader().abbreviate(refId, 8).name()
|
||||
commitCount = Git(repo).log().add(refId).call().count()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user