|
33 | 33 | import java.time.*;
|
34 | 34 | import java.util.*;
|
35 | 35 | import java.util.ResourceBundle.Control;
|
| 36 | +import java.util.regex.Pattern; |
36 | 37 | import java.util.stream.Collectors;
|
37 | 38 | import java.util.stream.IntStream;
|
38 | 39 | import java.util.stream.Stream;
|
@@ -1242,7 +1243,8 @@ private static Stream<String> zidMapEntry() {
|
1242 | 1243 | private static Stream<String> tzDataLinkEntry() {
|
1243 | 1244 | try {
|
1244 | 1245 | return Files.walk(Paths.get(tzDataDir), 1)
|
1245 |
| - .filter(p -> !Files.isDirectory(p)) |
| 1246 | + .filter(p -> p.toFile().isFile()) |
| 1247 | + .filter(p -> p.getFileName().toString().matches("africa|antarctica|asia|australasia|backward|etcetera|europe|northamerica|southamerica")) |
1246 | 1248 | .flatMap(CLDRConverter::extractLinks)
|
1247 | 1249 | .sorted();
|
1248 | 1250 | } catch (IOException e) {
|
@@ -1273,8 +1275,27 @@ private static Stream<String> extractLinks(Path tzFile) {
|
1273 | 1275 | // Note: the entries are alphabetically sorted, *except* the "world" region
|
1274 | 1276 | // code, i.e., "001". It should be the last entry for the same windows time
|
1275 | 1277 | // zone name entries. (cf. TimeZone_md.c)
|
| 1278 | + // |
| 1279 | + // The default entries from CLDR's windowsZones.xml file can be modified |
| 1280 | + // with <tzDataDir>/tzmappings.override where mapping overrides |
| 1281 | + // can be specified. |
| 1282 | + private static Pattern OVERRIDE_PATTERN = Pattern.compile("(?<win>([^:]+:[^:]+)):(?<java>[^:]+):"); |
1276 | 1283 | private static void generateWindowsTZMappings() throws Exception {
|
1277 | 1284 | Files.createDirectories(Paths.get(DESTINATION_DIR, "windows", "conf"));
|
| 1285 | + var override = Path.of(tzDataDir, "tzmappings.override"); |
| 1286 | + if (override.toFile().exists()) { |
| 1287 | + Files.readAllLines(override).stream() |
| 1288 | + .map(String::trim) |
| 1289 | + .filter(o -> !o.isBlank() && !o.startsWith("#")) |
| 1290 | + .forEach(o -> { |
| 1291 | + var m = OVERRIDE_PATTERN.matcher(o); |
| 1292 | + if (m.matches()) { |
| 1293 | + handlerWinZones.put(m.group("win"), m.group("java")); |
| 1294 | + } else { |
| 1295 | + System.out.printf("Unrecognized tzmappings override: %s. Ignored%n", o); |
| 1296 | + } |
| 1297 | + }); |
| 1298 | + } |
1278 | 1299 | Files.write(Paths.get(DESTINATION_DIR, "windows", "conf", "tzmappings"),
|
1279 | 1300 | handlerWinZones.keySet().stream()
|
1280 | 1301 | .filter(k -> k.endsWith(":001") ||
|
|
0 commit comments