diff --git a/build.gradle b/build.gradle index 8dd7f56d0..ecd6d2325 100644 --- a/build.gradle +++ b/build.gradle @@ -11,6 +11,7 @@ plugins { apply from: 'eclipse.gradle' apply from: 'maven-central.gradle' apply from: 'code-quality.gradle' +apply from: 'message-bundle.gradle' sourceCompatibility = 1.8 targetCompatibility = 1.8 diff --git a/code-quality.gradle b/code-quality.gradle index 1cada9943..974fc9e48 100644 --- a/code-quality.gradle +++ b/code-quality.gradle @@ -97,61 +97,4 @@ dependencyCheck { // xml.enabled = false // html.enabled = true // } -//} - -import java.util.Map.Entry; -task checkMessageBundle(){ - description "Checks the message bundles(which are used for language translation) that all entries are used, " + - "and that there are no duplicates." - group "Verification" - inputs.files(fileTree(dir: "src/main/resources", include: "**/MessageBundle*.properties")) - outputs.dir("$buildDir/checkMessageBundle") //hack: define a output dir so gradle will check if up-to-date - - doLast{ - Set messageKeys = new HashSet<>() - - inputs.getFiles().each{File file -> - file.eachLine {String line -> - if(line && !line.trim().startsWith('#')){ - String[] keyValue = checkMessageBundleLineIsCorrectlyFormatted(line, file) - - if(messageKeys.contains(keyValue[0])){ - throw new GradleException("Internationalization message bundle contains duplicate key [${keyValue[0]}]!") - } - messageKeys.add(keyValue[0]) - } - } - } - - checkAllMessageKeysAreUsed(messageKeys) - } -} -check.dependsOn checkMessageBundle - -String[] checkMessageBundleLineIsCorrectlyFormatted(String line, File file){ - String[] keyValue = line.split("=", 2) - - if(keyValue.size() != 2 || keyValue[1].isEmpty()){ - throw new GradleException("Line [${line}] in file [${file}] is not a valid entry for the internationalization message bundle!") - } - - return keyValue -} - -void checkAllMessageKeysAreUsed(Set messageKeys){ - sourceSets.main.allJava.each { File file -> - file.eachLine{ String line -> - for(String key : messageKeys.clone()){ - if(line.contains(key)){ - messageKeys.remove(key) - } - } - } - } - - if(messageKeys.size() > 0){ - messageKeys.each{String key -> - throw new GradleException("[${key}] is listed in the internationalization message bundle but never actually used!") - } - } -} \ No newline at end of file +//} \ No newline at end of file diff --git a/message-bundle.gradle b/message-bundle.gradle new file mode 100644 index 000000000..54db47403 --- /dev/null +++ b/message-bundle.gradle @@ -0,0 +1,58 @@ +//this build file is responsible for all the tasks related to internationalization messages +import java.util.Map.Entry; + +task checkMessageBundle(){ + description "Checks the message bundles(which are used for language translation) that all entries are used, " + + "and that there are no duplicates." + group "Verification" + inputs.files(fileTree(dir: "src/main/resources", include: "**/MessageBundle*.properties")) + outputs.dir("$buildDir/checkMessageBundle") //hack: define a output dir so gradle will check if up-to-date + + doLast{ + Set messageKeys = new HashSet<>() + + inputs.getFiles().each{File file -> + file.eachLine {String line -> + if(line && !line.trim().startsWith('#')){ + String[] keyValue = checkMessageBundleLineIsCorrectlyFormatted(line, file) + + if(messageKeys.contains(keyValue[0])){ + throw new GradleException("Internationalization message bundle contains duplicate key [${keyValue[0]}]!") + } + messageKeys.add(keyValue[0]) + } + } + } + + checkAllMessageKeysAreUsed(messageKeys) + } +} +check.dependsOn checkMessageBundle + +String[] checkMessageBundleLineIsCorrectlyFormatted(String line, File file){ + String[] keyValue = line.split("=", 2) + + if(keyValue.size() != 2 || keyValue[1].isEmpty()){ + throw new GradleException("Line [${line}] in file [${file}] is not a valid entry for the internationalization message bundle!") + } + + return keyValue +} + +void checkAllMessageKeysAreUsed(Set messageKeys){ + sourceSets.main.allJava.each { File file -> + file.eachLine{ String line -> + for(String key : messageKeys.clone()){ + if(line.contains(key)){ + messageKeys.remove(key) + } + } + } + } + + if(messageKeys.size() > 0){ + messageKeys.each{String key -> + throw new GradleException("[${key}] is listed in the internationalization message bundle but never actually used!") + } + } +} \ No newline at end of file