mirror of
https://github.com/TeamNewPipe/NewPipe
synced 2024-12-22 16:10:31 +00:00
48 lines
1.7 KiB
Groovy
48 lines
1.7 KiB
Groovy
|
tasks.register('checkDependenciesOrder') {
|
||
|
group = 'verification'
|
||
|
description = 'Checks that each section in libs.versions.toml is sorted alphabetically'
|
||
|
|
||
|
def tomlFile = file('../gradle/libs.versions.toml')
|
||
|
|
||
|
doLast {
|
||
|
if (!tomlFile.exists()) {
|
||
|
throw new GradleException('TOML file not found')
|
||
|
}
|
||
|
|
||
|
def lines = tomlFile.readLines()
|
||
|
def nonSortedBlocks = []
|
||
|
def currentBlock = []
|
||
|
def prevLine = ''
|
||
|
def prevIndex = 0
|
||
|
|
||
|
lines.eachWithIndex { line, lineIndex ->
|
||
|
if (line.trim() && !line.startsWith('#')) {
|
||
|
if (line.startsWith('[')) {
|
||
|
prevLine = ''
|
||
|
} else {
|
||
|
def currIndex = lineIndex + 1
|
||
|
if (prevLine > line) {
|
||
|
if (currentBlock && currentBlock[-1] == "${prevIndex}: ${prevLine}") {
|
||
|
currentBlock.add("${currIndex}: ${line}")
|
||
|
} else {
|
||
|
if (!currentBlock.isEmpty()) {
|
||
|
nonSortedBlocks.add(currentBlock)
|
||
|
currentBlock = []
|
||
|
}
|
||
|
currentBlock.add("${prevIndex}: ${prevLine}")
|
||
|
currentBlock.add("${currIndex}: ${line}")
|
||
|
}
|
||
|
}
|
||
|
prevLine = line
|
||
|
prevIndex = lineIndex + 1
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if (!currentBlock.isEmpty()) {
|
||
|
nonSortedBlocks.add(currentBlock)
|
||
|
throw new GradleException("The following lines were not sorted:\n" +
|
||
|
nonSortedBlocks.collect { it.join("\n") }.join("\n\n"))
|
||
|
}
|
||
|
}
|
||
|
}
|