diff --git a/app/build.gradle b/app/build.gradle index 28ef4eac..00cbdf80 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -9,11 +9,11 @@ apply from: 'version-tools.gradle' tasks.register('validateLanguages') { - inputs.dir fileTree(dir: LANGUAGES_INPUT_DIR) - outputs.file layout.buildDirectory.file("lang.validation.txt") + inputs.dir LANGUAGES_INPUT_DIR + outputs.dir LANGUAGE_VALIDATION_DIR doLast { - validateLanguageFiles(DEFINITIONS_INPUT_DIR, DICTIONARIES_INPUT_DIR, outputs.files.singleFile) + validateLanguageFiles(DEFINITIONS_INPUT_DIR, DICTIONARIES_INPUT_DIR, LANGUAGE_VALIDATION_DIR.get().asFile) } } diff --git a/app/constants.gradle b/app/constants.gradle index 8bfe5eee..31afbc89 100644 --- a/app/constants.gradle +++ b/app/constants.gradle @@ -17,6 +17,8 @@ ext.LANGUAGES_OUTPUT_DIR = "${ASSETS_DIR}/${LANGUAGES_DIR_NAME}" ext.DEFINITIONS_OUTPUT_DIR = "${LANGUAGES_OUTPUT_DIR}/${DEFINITIONS_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.MAX_WORD_FREQUENCY = 255 ext.MAX_ERRORS = 50 diff --git a/app/validate-languages.gradle b/app/validate-languages.gradle index a7023924..37a95def 100644 --- a/app/validate-languages.gradle +++ b/app/validate-languages.gradle @@ -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 - outputFile.text = "" - 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 = "" + if (errorCount >= MAX_ERRORS) { return "Too many errors! Skipping: ${languageFile}\n" } @@ -201,18 +208,18 @@ ext.validateLanguageFiles = { definitionsDir, dictionariesDir, outputFile -> def (alphabet, dictionaryFile, langFileErrorCount, langFileErrorMsg) = parseLanguageFile(languageFile, dictionariesDir) errorCount += langFileErrorCount if (!langFileErrorMsg.isEmpty()) { - outputFile.text += "${languageFile.name} INVALID \n" + outputFile.text += "${contentHash} INVALID" return langFileErrorMsg } def (dictionaryErrorMsg, dictionaryErrorCount) = parseDictionaryFile(alphabet, dictionaryFile, MAX_ERRORS, CSV_DELIMITER, MAX_WORD_FREQUENCY) errorCount += dictionaryErrorCount if (!dictionaryErrorMsg.isEmpty()) { - outputFile.text += "${languageFile.name} INVALID \n" + outputFile.text += "${contentHash} INVALID" return dictionaryErrorMsg } - outputFile.text += "${languageFile.name} OK\n" + outputFile.text += "${contentHash} OK" return "" }