Skip to content

Commit 2a401dd

Browse files
committed
moved message bundle tasks to separate gradle build file
1 parent e5e1abc commit 2a401dd

File tree

3 files changed

+60
-58
lines changed

3 files changed

+60
-58
lines changed

build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ plugins {
1111
apply from: 'eclipse.gradle'
1212
apply from: 'maven-central.gradle'
1313
apply from: 'code-quality.gradle'
14+
apply from: 'message-bundle.gradle'
1415

1516
sourceCompatibility = 1.8
1617
targetCompatibility = 1.8

code-quality.gradle

Lines changed: 1 addition & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -97,61 +97,4 @@ dependencyCheck {
9797
// xml.enabled = false
9898
// html.enabled = true
9999
// }
100-
//}
101-
102-
import java.util.Map.Entry;
103-
task checkMessageBundle(){
104-
description "Checks the message bundles(which are used for language translation) that all entries are used, " +
105-
"and that there are no duplicates."
106-
group "Verification"
107-
inputs.files(fileTree(dir: "src/main/resources", include: "**/MessageBundle*.properties"))
108-
outputs.dir("$buildDir/checkMessageBundle") //hack: define a output dir so gradle will check if up-to-date
109-
110-
doLast{
111-
Set<String> messageKeys = new HashSet<>()
112-
113-
inputs.getFiles().each{File file ->
114-
file.eachLine {String line ->
115-
if(line && !line.trim().startsWith('#')){
116-
String[] keyValue = checkMessageBundleLineIsCorrectlyFormatted(line, file)
117-
118-
if(messageKeys.contains(keyValue[0])){
119-
throw new GradleException("Internationalization message bundle contains duplicate key [${keyValue[0]}]!")
120-
}
121-
messageKeys.add(keyValue[0])
122-
}
123-
}
124-
}
125-
126-
checkAllMessageKeysAreUsed(messageKeys)
127-
}
128-
}
129-
check.dependsOn checkMessageBundle
130-
131-
String[] checkMessageBundleLineIsCorrectlyFormatted(String line, File file){
132-
String[] keyValue = line.split("=", 2)
133-
134-
if(keyValue.size() != 2 || keyValue[1].isEmpty()){
135-
throw new GradleException("Line [${line}] in file [${file}] is not a valid entry for the internationalization message bundle!")
136-
}
137-
138-
return keyValue
139-
}
140-
141-
void checkAllMessageKeysAreUsed(Set<String> messageKeys){
142-
sourceSets.main.allJava.each { File file ->
143-
file.eachLine{ String line ->
144-
for(String key : messageKeys.clone()){
145-
if(line.contains(key)){
146-
messageKeys.remove(key)
147-
}
148-
}
149-
}
150-
}
151-
152-
if(messageKeys.size() > 0){
153-
messageKeys.each{String key ->
154-
throw new GradleException("[${key}] is listed in the internationalization message bundle but never actually used!")
155-
}
156-
}
157-
}
100+
//}

message-bundle.gradle

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
//this build file is responsible for all the tasks related to internationalization messages
2+
import java.util.Map.Entry;
3+
4+
task checkMessageBundle(){
5+
description "Checks the message bundles(which are used for language translation) that all entries are used, " +
6+
"and that there are no duplicates."
7+
group "Verification"
8+
inputs.files(fileTree(dir: "src/main/resources", include: "**/MessageBundle*.properties"))
9+
outputs.dir("$buildDir/checkMessageBundle") //hack: define a output dir so gradle will check if up-to-date
10+
11+
doLast{
12+
Set<String> messageKeys = new HashSet<>()
13+
14+
inputs.getFiles().each{File file ->
15+
file.eachLine {String line ->
16+
if(line && !line.trim().startsWith('#')){
17+
String[] keyValue = checkMessageBundleLineIsCorrectlyFormatted(line, file)
18+
19+
if(messageKeys.contains(keyValue[0])){
20+
throw new GradleException("Internationalization message bundle contains duplicate key [${keyValue[0]}]!")
21+
}
22+
messageKeys.add(keyValue[0])
23+
}
24+
}
25+
}
26+
27+
checkAllMessageKeysAreUsed(messageKeys)
28+
}
29+
}
30+
check.dependsOn checkMessageBundle
31+
32+
String[] checkMessageBundleLineIsCorrectlyFormatted(String line, File file){
33+
String[] keyValue = line.split("=", 2)
34+
35+
if(keyValue.size() != 2 || keyValue[1].isEmpty()){
36+
throw new GradleException("Line [${line}] in file [${file}] is not a valid entry for the internationalization message bundle!")
37+
}
38+
39+
return keyValue
40+
}
41+
42+
void checkAllMessageKeysAreUsed(Set<String> messageKeys){
43+
sourceSets.main.allJava.each { File file ->
44+
file.eachLine{ String line ->
45+
for(String key : messageKeys.clone()){
46+
if(line.contains(key)){
47+
messageKeys.remove(key)
48+
}
49+
}
50+
}
51+
}
52+
53+
if(messageKeys.size() > 0){
54+
messageKeys.each{String key ->
55+
throw new GradleException("[${key}] is listed in the internationalization message bundle but never actually used!")
56+
}
57+
}
58+
}

0 commit comments

Comments
 (0)