up build.gradle.kts

This commit is contained in:
2026-05-07 02:22:42 +03:00
parent 08368afbc5
commit 4e60a78fbd

View File

@@ -1,5 +1,7 @@
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import org.gradle.api.tasks.testing.logging.TestLogEvent.*
import java.nio.file.Files
import java.nio.file.Paths
plugins {
java
@@ -142,3 +144,50 @@ tasks.register("collectAllDependencies") {
}
}
tasks.register("countCodeLines") {
group = "project"
description = "Подсчитывает количество строк кода"
doLast {
val extensions = listOf("java", "kts", "xml", "json", "yaml", "properties", "html", "css", "js", "ts", "vue", "sql")
val excludeDirs = listOf("build", "out", "gradle", ".idea", "dist", "package-lock")
val counts = mutableMapOf<String, Int>()
fileTree(".").forEach { file ->
val ext = file.extension
if (ext in extensions && excludeDirs.none { file.path.contains(it) }) {
try {
val lines = Files.readAllLines(Paths.get(file.path))
.map { it.trim() }
.filter { it.isNotEmpty() && !it.startsWith("//") && !it.startsWith("#") && !it.startsWith("*") && !it.startsWith("<!--") }
.size
counts[ext] = counts.getOrDefault(ext, 0) + lines
} catch (_: Exception) {
}
}
}
val total = counts.values.sum()
val report = buildString {
appendLine("Подсчёт строк кода:")
appendLine("=".repeat(55))
counts.toSortedMap().forEach { (ext, lines) ->
val percent = (lines * 100.0 / total).let { "%.2f".format(it) }
appendLine(" - ${ext.padEnd(10)} : ${lines.toString().padStart(6)} строк (${percent}%)")
}
appendLine("=".repeat(55))
appendLine("Всего строк кода: $total")
}
println(report)
val reportFile = file("build/reports/lineCount.txt")
reportFile.parentFile.mkdirs()
reportFile.writeText(report)
println("\nОтчёт сохранён в: ${reportFile.absolutePath}")
}
}