feat: 完善远程构建恢复、工程同步与变体选择
增加持久化构建记录、历史 APK 恢复、断点下载、Gradle 缓存复用、系统代理与按工程选择服务端 JDK。 支持已有工程目录、Git 状态检查、原生忽略规则和文本换行等价比较,修复干净检出与历史同步快照不一致时的误拦截。 优化插件设备可选构建、侧栏滚动、左右日志布局、时间显示和构建变体快速选择,并补充部署与协议文档。 验证:17 项 Go 测试、22 项插件测试及 HTTP/HTTPS 两条端到端测试通过;Linux/macOS 服务端交叉编译通过。
This commit is contained in:
1 parent
2203afde3c
commit
2cb70beb69
44 files changed
+3310
-236
No files matched your search
@@ -0,0 +1,73 @@
|
||||
package studio.tongtong.remotecompile
|
||||
|
||||
import java.nio.file.*
|
||||
import java.nio.file.attribute.BasicFileAttributes
|
||||
|
||||
/** Read common literal Gradle declarations; never execute Gradle merely to populate the selector. */
|
||||
object BuildTasks {
|
||||
private val name = Regex("[A-Za-z0-9_]+")
|
||||
fun valid(task: String) = Regex(":?[A-Za-z0-9_]+(:[A-Za-z0-9_]+)*").matches(task)
|
||||
private data class Token(val value: String, val string: Boolean = false)
|
||||
private fun tokens(text: String): List<Token> {
|
||||
val result = mutableListOf<Token>(); var i = 0
|
||||
while (i < text.length) {
|
||||
val c = text[i]
|
||||
when {
|
||||
c.isWhitespace() -> i++
|
||||
text.startsWith("//", i) -> { i = text.indexOf('\n', i).let { if (it < 0) text.length else it } }
|
||||
text.startsWith("/*", i) -> { i = text.indexOf("*/", i + 2).let { if (it < 0) text.length else it + 2 } }
|
||||
c == '\'' || c == '"' -> {
|
||||
val triple = text.startsWith("$c$c$c", i); val quote = if (triple) "$c$c$c" else "$c"
|
||||
i += quote.length; val value = StringBuilder()
|
||||
while (i < text.length && !text.startsWith(quote, i)) {
|
||||
if (text[i] == '\\' && i + 1 < text.length) i++
|
||||
value.append(text[i++])
|
||||
}
|
||||
i = minOf(text.length, i + quote.length); result.add(Token(value.toString(), true))
|
||||
}
|
||||
c.isLetterOrDigit() || c == '_' -> { val start = i++; while (i < text.length && (text[i].isLetterOrDigit() || text[i] == '_')) i++; result.add(Token(text.substring(start, i))) }
|
||||
else -> { result.add(Token(c.toString())); i++ }
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
fun fromScript(module: String, text: String): List<String> {
|
||||
if (!module.split(':').filter { it.isNotEmpty() }.all { name.matches(it) }) return emptyList()
|
||||
val tokens = tokens(text)
|
||||
if (tokens.none { it.string && it.value == "com.android.application" }) return emptyList()
|
||||
val types = linkedSetOf("debug", "release")
|
||||
var i = 0
|
||||
while (i < tokens.size - 1) {
|
||||
if (tokens[i].string || tokens[i].value != "buildTypes" || tokens[i + 1].value != "{") { i++; continue }
|
||||
var depth = 1; i += 2
|
||||
while (i < tokens.size && depth > 0) {
|
||||
val t = tokens[i]
|
||||
if (depth == 1 && !t.string) {
|
||||
val next = tokens.getOrNull(i + 1)?.value
|
||||
if (name.matches(t.value) && (next == "{" || (next == "." && tokens.getOrNull(i + 2)?.value == "initWith"))) types.add(t.value)
|
||||
if (t.value in setOf("create", "register", "maybeCreate", "getByName", "named") && next == "(") {
|
||||
tokens.getOrNull(i + 2)?.takeIf { it.string && name.matches(it.value) }?.let { types.add(it.value) }
|
||||
}
|
||||
}
|
||||
if (!t.string) { if (t.value == "{") depth++; if (t.value == "}") depth-- }
|
||||
i++
|
||||
}
|
||||
}
|
||||
return types.map { "$module:assemble${it.replaceFirstChar(Char::uppercaseChar)}" }.distinct()
|
||||
}
|
||||
fun discover(root: Path): List<String> {
|
||||
val result = linkedSetOf<String>()
|
||||
Files.walkFileTree(root, emptySet(), 5, object : SimpleFileVisitor<Path>() {
|
||||
override fun preVisitDirectory(dir: Path, attrs: BasicFileAttributes) =
|
||||
if (dir != root && SourceFiles.reserved(root.relativize(dir).joinToString("/"))) FileVisitResult.SKIP_SUBTREE else FileVisitResult.CONTINUE
|
||||
override fun visitFile(file: Path, attrs: BasicFileAttributes): FileVisitResult {
|
||||
if (file.fileName.toString() in setOf("build.gradle", "build.gradle.kts") && attrs.isRegularFile && attrs.size() <= 2 * 1024 * 1024) {
|
||||
val relative = root.relativize(file.parent).joinToString(":")
|
||||
result.addAll(fromScript(if (relative.isEmpty()) "" else ":$relative", Files.readString(file)))
|
||||
}
|
||||
return FileVisitResult.CONTINUE
|
||||
}
|
||||
})
|
||||
return result.toList()
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user