-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
moved message bundle tasks to separate gradle build file
- Loading branch information
1 parent
e5e1abc
commit 2a401dd
Showing
3 changed files
with
60 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<String> 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<String> 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!") | ||
} | ||
} | ||
} |