Commit 75f97ae2 authored by 王品堯's avatar 王品堯

add properties files check

parent 4be171ae
......@@ -4,6 +4,8 @@ import com.fasterxml.jackson.databind.node.ObjectNode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.FileInputStream;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
......@@ -23,11 +25,11 @@ public class JsonFileCompare {
addKeys("", twJson, originSet, new ArrayList<>());
IntStream.range(1, args.length).forEach(i -> findMissingKeys(Paths.get(args[i]), originSet));
} catch (Exception e) {
log.error("{} is not exists or not json files.", args[0], e);
System.exit(1);
}
checkProperties();
}
private static void addKeys(
......@@ -78,4 +80,64 @@ public class JsonFileCompare {
System.exit(1);
}
}
private static void checkProperties() {
String path = "./src/main/resources/i18n/";
String extension = ".properties";
Map<String, List<String>> map =
Arrays.stream(
Optional.ofNullable(
Paths.get(path).toFile().list((dir, name) -> name.endsWith(extension)))
.orElse(new String[0]))
.map(s -> s.split(extension)[0])
.collect(
Collectors.groupingBy(
filename -> filename.split("_")[0],
Collectors.mapping(l -> path + l + extension, Collectors.toList())));
for (Map.Entry<String, List<String>> entry : map.entrySet()) {
List<String> twList =
entry
.getValue()
.stream()
.filter(fileName -> fileName.contains("zh_TW"))
.collect(Collectors.toList());
List<String> otherList =
entry
.getValue()
.stream()
.filter(fileName -> !fileName.contains("zh_TW"))
.collect(Collectors.toList());
if (twList.isEmpty() || otherList.isEmpty()) continue;
try {
Set<String> originKeySet = getKeys(twList.get(0));
for (String target : otherList) {
Set<String> targetKeySet = getKeys(target);
Set<String> missingSet =
originKeySet
.parallelStream()
.filter(k -> !targetKeySet.contains(k))
.collect(Collectors.toSet());
if (!missingSet.isEmpty()) {
log.error(
"Missing Key on {} \nMissing Keys: {}",
Paths.get(target).getFileName(),
missingSet);
System.exit(1);
}
}
} catch (Exception e) {
log.error("check i18n properties error.", e);
System.exit(1);
}
}
}
private static Set<String> getKeys(String fileName) throws IOException {
Properties properties = new Properties();
properties.load(new FileInputStream(fileName));
return new HashSet(Collections.list(properties.propertyNames()));
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment