1
0
Fork 0

when a language is updated only that language will be validated upon build time, instead of all of them

This commit is contained in:
sspanak 2024-04-14 12:13:40 +03:00 committed by Dimo Karaivanov
parent 2418c9c4c3
commit 39183369cf
3 changed files with 18 additions and 9 deletions

View file

@ -9,11 +9,11 @@ apply from: 'version-tools.gradle'
tasks.register('validateLanguages') { tasks.register('validateLanguages') {
inputs.dir fileTree(dir: LANGUAGES_INPUT_DIR) inputs.dir LANGUAGES_INPUT_DIR
outputs.file layout.buildDirectory.file("lang.validation.txt") outputs.dir LANGUAGE_VALIDATION_DIR
doLast { doLast {
validateLanguageFiles(DEFINITIONS_INPUT_DIR, DICTIONARIES_INPUT_DIR, outputs.files.singleFile) validateLanguageFiles(DEFINITIONS_INPUT_DIR, DICTIONARIES_INPUT_DIR, LANGUAGE_VALIDATION_DIR.get().asFile)
} }
} }

View file

@ -17,6 +17,8 @@ ext.LANGUAGES_OUTPUT_DIR = "${ASSETS_DIR}/${LANGUAGES_DIR_NAME}"
ext.DEFINITIONS_OUTPUT_DIR = "${LANGUAGES_OUTPUT_DIR}/${DEFINITIONS_DIR_NAME}" ext.DEFINITIONS_OUTPUT_DIR = "${LANGUAGES_OUTPUT_DIR}/${DEFINITIONS_DIR_NAME}"
ext.DICTIONARIES_OUTPUT_DIR = "${LANGUAGES_OUTPUT_DIR}/${DICTIONARIES_DIR_NAME}" ext.DICTIONARIES_OUTPUT_DIR = "${LANGUAGES_OUTPUT_DIR}/${DICTIONARIES_DIR_NAME}"
ext.LANGUAGE_VALIDATION_DIR = layout.buildDirectory.dir("langValidation")
ext.CSV_DELIMITER = ' ' // TAB ext.CSV_DELIMITER = ' ' // TAB
ext.MAX_WORD_FREQUENCY = 255 ext.MAX_WORD_FREQUENCY = 255
ext.MAX_ERRORS = 50 ext.MAX_ERRORS = 50

View file

@ -188,12 +188,19 @@ static def parseDictionaryFile(String alphabet, File dictionaryFile, int MAX_ERR
} }
ext.validateLanguageFiles = { definitionsDir, dictionariesDir, outputFile -> ext.validateLanguageFiles = { definitionsDir, dictionariesDir, validationDir ->
int errorCount = 0 int errorCount = 0
def errorStream = fileTree(definitionsDir).getFiles().parallelStream().map { File languageFile ->
def contentHash = languageFile.text.digest("SHA-1")
def outputFile = new File("${validationDir}/${languageFile.name.replace(".yml", "")}.txt")
if (outputFile.exists() && outputFile.text == "${contentHash} OK") {
return ""
}
outputFile.text = "" outputFile.text = ""
def errorStream = fileTree(definitionsDir).getFiles().parallelStream().map { File languageFile ->
if (errorCount >= MAX_ERRORS) { if (errorCount >= MAX_ERRORS) {
return "Too many errors! Skipping: ${languageFile}\n" return "Too many errors! Skipping: ${languageFile}\n"
} }
@ -201,18 +208,18 @@ ext.validateLanguageFiles = { definitionsDir, dictionariesDir, outputFile ->
def (alphabet, dictionaryFile, langFileErrorCount, langFileErrorMsg) = parseLanguageFile(languageFile, dictionariesDir) def (alphabet, dictionaryFile, langFileErrorCount, langFileErrorMsg) = parseLanguageFile(languageFile, dictionariesDir)
errorCount += langFileErrorCount errorCount += langFileErrorCount
if (!langFileErrorMsg.isEmpty()) { if (!langFileErrorMsg.isEmpty()) {
outputFile.text += "${languageFile.name} INVALID \n" outputFile.text += "${contentHash} INVALID"
return langFileErrorMsg return langFileErrorMsg
} }
def (dictionaryErrorMsg, dictionaryErrorCount) = parseDictionaryFile(alphabet, dictionaryFile, MAX_ERRORS, CSV_DELIMITER, MAX_WORD_FREQUENCY) def (dictionaryErrorMsg, dictionaryErrorCount) = parseDictionaryFile(alphabet, dictionaryFile, MAX_ERRORS, CSV_DELIMITER, MAX_WORD_FREQUENCY)
errorCount += dictionaryErrorCount errorCount += dictionaryErrorCount
if (!dictionaryErrorMsg.isEmpty()) { if (!dictionaryErrorMsg.isEmpty()) {
outputFile.text += "${languageFile.name} INVALID \n" outputFile.text += "${contentHash} INVALID"
return dictionaryErrorMsg return dictionaryErrorMsg
} }
outputFile.text += "${languageFile.name} OK\n" outputFile.text += "${contentHash} OK"
return "" return ""
} }