Gradle script to enforce dependencies order
Signed-off-by: Aayush Gupta <aayushgupta219@gmail.com>
This commit is contained in:
parent
2e79d7387d
commit
7be0c63773
2 changed files with 62 additions and 1 deletions
|
|
@ -12,6 +12,8 @@ plugins {
|
||||||
checkstyle
|
checkstyle
|
||||||
}
|
}
|
||||||
|
|
||||||
|
apply(from = "check-dependencies.gradle.kts")
|
||||||
|
|
||||||
val gitWorkingBranch = providers.exec {
|
val gitWorkingBranch = providers.exec {
|
||||||
commandLine("git", "rev-parse", "--abbrev-ref", "HEAD")
|
commandLine("git", "rev-parse", "--abbrev-ref", "HEAD")
|
||||||
}.standardOutput.asText.map { it.trim() }
|
}.standardOutput.asText.map { it.trim() }
|
||||||
|
|
@ -180,7 +182,7 @@ afterEvaluate {
|
||||||
if (!System.getProperties().containsKey("skipFormatKtlint")) {
|
if (!System.getProperties().containsKey("skipFormatKtlint")) {
|
||||||
dependsOn("formatKtlint")
|
dependsOn("formatKtlint")
|
||||||
}
|
}
|
||||||
dependsOn("runCheckstyle", "runKtlint")
|
dependsOn("runCheckstyle", "runKtlint", "checkDependenciesOrder")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
59
app/check-dependencies.gradle.kts
Normal file
59
app/check-dependencies.gradle.kts
Normal file
|
|
@ -0,0 +1,59 @@
|
||||||
|
/*
|
||||||
|
* SPDX-FileCopyrightText: 2024 NewPipe contributors <https://newpipe.net>
|
||||||
|
* SPDX-FileCopyrightText: 2025 NewPipe e.V. <https://newpipe-ev.de>
|
||||||
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
*/
|
||||||
|
|
||||||
|
tasks.register("checkDependenciesOrder") {
|
||||||
|
group = "verification"
|
||||||
|
description = "Checks that each section in libs.versions.toml is sorted alphabetically"
|
||||||
|
|
||||||
|
val tomlFile = file("../gradle/libs.versions.toml")
|
||||||
|
|
||||||
|
doLast {
|
||||||
|
if (!tomlFile.exists()) {
|
||||||
|
throw GradleException("TOML file not found")
|
||||||
|
}
|
||||||
|
|
||||||
|
val lines = tomlFile.readLines()
|
||||||
|
val nonSortedBlocks = mutableListOf<List<String>>()
|
||||||
|
var currentBlock = mutableListOf<String>()
|
||||||
|
var prevLine = ""
|
||||||
|
var prevIndex = 0
|
||||||
|
|
||||||
|
lines.forEachIndexed { lineIndex, line ->
|
||||||
|
if (line.trim().isNotEmpty() && !line.startsWith("#")) {
|
||||||
|
if (line.startsWith("[")) {
|
||||||
|
prevLine = ""
|
||||||
|
} else {
|
||||||
|
val currIndex = lineIndex + 1
|
||||||
|
if (prevLine > line) {
|
||||||
|
if (currentBlock.isNotEmpty() && currentBlock.last() == "$prevIndex: $prevLine") {
|
||||||
|
currentBlock.add("$currIndex: $line")
|
||||||
|
} else {
|
||||||
|
if (currentBlock.isNotEmpty()) {
|
||||||
|
nonSortedBlocks.add(currentBlock)
|
||||||
|
currentBlock = mutableListOf()
|
||||||
|
}
|
||||||
|
currentBlock.add("$prevIndex: $prevLine")
|
||||||
|
currentBlock.add("$currIndex: $line")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
prevLine = line
|
||||||
|
prevIndex = lineIndex + 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (currentBlock.isNotEmpty()) {
|
||||||
|
nonSortedBlocks.add(currentBlock)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (nonSortedBlocks.isNotEmpty()) {
|
||||||
|
throw GradleException(
|
||||||
|
"The following lines were not sorted:\n" +
|
||||||
|
nonSortedBlocks.joinToString("\n\n") { it.joinToString("\n") }
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue