Building aborts after 50 dictionary validation errors, otherwise it keeps going forever
This commit is contained in:
parent
70a6fb49ea
commit
ff1c832a5a
1 changed files with 17 additions and 0 deletions
17
build.gradle
17
build.gradle
|
|
@ -144,8 +144,13 @@ task validateDictionaries {
|
||||||
outputs.file "t9build.properties"
|
outputs.file "t9build.properties"
|
||||||
doLast {
|
doLast {
|
||||||
String errors = ""
|
String errors = ""
|
||||||
|
int errorCount = 0
|
||||||
|
final MAX_ERRORS = 50
|
||||||
|
|
||||||
inputs.getFiles().each {File file ->
|
inputs.getFiles().each {File file ->
|
||||||
|
if (errorCount >= MAX_ERRORS) {
|
||||||
|
return
|
||||||
|
}
|
||||||
println "Validating dictionary: " + file.name
|
println "Validating dictionary: " + file.name
|
||||||
|
|
||||||
def geographicalName = ~"[A-Z]\\w+-[^\\n]+"
|
def geographicalName = ~"[A-Z]\\w+-[^\\n]+"
|
||||||
|
|
@ -153,25 +158,37 @@ task validateDictionaries {
|
||||||
|
|
||||||
int lineNumber = 0
|
int lineNumber = 0
|
||||||
file.eachLine {line ->
|
file.eachLine {line ->
|
||||||
|
if (errorCount >= MAX_ERRORS) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
lineNumber++
|
lineNumber++
|
||||||
if (line.matches("\\d")) {
|
if (line.matches("\\d")) {
|
||||||
|
errorCount++
|
||||||
errors += "Dictionary '" + file.name + "' is invalid. Found numbers on line " + lineNumber + ". Please, remove all numbers.\n"
|
errors += "Dictionary '" + file.name + "' is invalid. Found numbers on line " + lineNumber + ". Please, remove all numbers.\n"
|
||||||
}
|
}
|
||||||
|
|
||||||
if (line.matches("^\\P{L}+\$")) {
|
if (line.matches("^\\P{L}+\$")) {
|
||||||
|
errorCount++
|
||||||
errors += "Dictionary '" + file.name + "' is invalid. Found a garbage word: '" + line + "' on line " + lineNumber + ".\n"
|
errors += "Dictionary '" + file.name + "' is invalid. Found a garbage word: '" + line + "' on line " + lineNumber + ".\n"
|
||||||
}
|
}
|
||||||
|
|
||||||
if (line.matches("^.\$")) {
|
if (line.matches("^.\$")) {
|
||||||
|
errorCount++
|
||||||
errors += "Dictionary '" + file.name + "' is invalid. Found a single letter: '" + line + "' on line " + lineNumber + ". Remove all single letters. The alphabet will be added automatically.\n"
|
errors += "Dictionary '" + file.name + "' is invalid. Found a single letter: '" + line + "' on line " + lineNumber + ". Remove all single letters. The alphabet will be added automatically.\n"
|
||||||
}
|
}
|
||||||
|
|
||||||
String uniqueWordKey = line ==~ geographicalName ? line : line.toLowerCase()
|
String uniqueWordKey = line ==~ geographicalName ? line : line.toLowerCase()
|
||||||
if (uniqueWords[uniqueWordKey] != null && uniqueWords[uniqueWordKey] == true) {
|
if (uniqueWords[uniqueWordKey] != null && uniqueWords[uniqueWordKey] == true) {
|
||||||
|
errorCount++
|
||||||
errors += "Dictionary '" + file.name + "' is invalid. Found a repeating word: '" + line + "' on line " + lineNumber + ". Ensure all words appear only once.\n"
|
errors += "Dictionary '" + file.name + "' is invalid. Found a repeating word: '" + line + "' on line " + lineNumber + ". Ensure all words appear only once.\n"
|
||||||
} else {
|
} else {
|
||||||
uniqueWords[uniqueWordKey] = true
|
uniqueWords[uniqueWordKey] = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (errorCount >= MAX_ERRORS ) {
|
||||||
|
errors += "Too many errors! Aborting.\n"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue