Skip to content

Commit 352201d

Browse files
committed
8343788: Provide means to alter lib/tzmappings entries on Windows
Reviewed-by: joehw
1 parent 29c57e8 commit 352201d

File tree

2 files changed

+54
-1
lines changed

2 files changed

+54
-1
lines changed

make/jdk/src/classes/build/tools/cldrconverter/CLDRConverter.java

+22-1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import java.time.*;
3434
import java.util.*;
3535
import java.util.ResourceBundle.Control;
36+
import java.util.regex.Pattern;
3637
import java.util.stream.Collectors;
3738
import java.util.stream.IntStream;
3839
import java.util.stream.Stream;
@@ -1242,7 +1243,8 @@ private static Stream<String> zidMapEntry() {
12421243
private static Stream<String> tzDataLinkEntry() {
12431244
try {
12441245
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"))
12461248
.flatMap(CLDRConverter::extractLinks)
12471249
.sorted();
12481250
} catch (IOException e) {
@@ -1273,8 +1275,27 @@ private static Stream<String> extractLinks(Path tzFile) {
12731275
// Note: the entries are alphabetically sorted, *except* the "world" region
12741276
// code, i.e., "001". It should be the last entry for the same windows time
12751277
// 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>[^:]+):");
12761283
private static void generateWindowsTZMappings() throws Exception {
12771284
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+
}
12781299
Files.write(Paths.get(DESTINATION_DIR, "windows", "conf", "tzmappings"),
12791300
handlerWinZones.keySet().stream()
12801301
.filter(k -> k.endsWith(":001") ||
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#
2+
# Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
3+
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
#
5+
# This code is free software; you can redistribute it and/or modify it
6+
# under the terms of the GNU General Public License version 2 only, as
7+
# published by the Free Software Foundation. Oracle designates this
8+
# particular file as subject to the "Classpath" exception as provided
9+
# by Oracle in the LICENSE file that accompanied this code.
10+
#
11+
# This code is distributed in the hope that it will be useful, but WITHOUT
12+
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+
# version 2 for more details (a copy is included in the LICENSE file that
15+
# accompanied this code).
16+
#
17+
# You should have received a copy of the GNU General Public License version
18+
# 2 along with this work; if not, write to the Free Software Foundation,
19+
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+
#
21+
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22+
# or visit www.oracle.com if you need additional information or have any
23+
# questions.
24+
#
25+
26+
# Extra definitions for Windows /lib/tzmappings file. These entries
27+
# replace the existing (Windows Zone Name):(REGION) entries, or are added
28+
# as new entries
29+
30+
# Example entries
31+
# Foo Standard Time:US:America/Los_Angeles:
32+
# Bar Standard Time:001:Asia/Tokyo:

0 commit comments

Comments
 (0)