diff --git a/make/jdk/src/classes/build/tools/cldrconverter/CLDRConverter.java b/make/jdk/src/classes/build/tools/cldrconverter/CLDRConverter.java index 8865e3908ae6b..55dd6a8d6ad5b 100644 --- a/make/jdk/src/classes/build/tools/cldrconverter/CLDRConverter.java +++ b/make/jdk/src/classes/build/tools/cldrconverter/CLDRConverter.java @@ -33,6 +33,7 @@ import java.time.*; import java.util.*; import java.util.ResourceBundle.Control; +import java.util.regex.Pattern; import java.util.stream.Collectors; import java.util.stream.IntStream; import java.util.stream.Stream; @@ -1242,7 +1243,8 @@ private static Stream zidMapEntry() { private static Stream tzDataLinkEntry() { try { return Files.walk(Paths.get(tzDataDir), 1) - .filter(p -> !Files.isDirectory(p)) + .filter(p -> p.toFile().isFile()) + .filter(p -> p.getFileName().toString().matches("africa|antarctica|asia|australasia|backward|etcetera|europe|northamerica|southamerica")) .flatMap(CLDRConverter::extractLinks) .sorted(); } catch (IOException e) { @@ -1273,8 +1275,27 @@ private static Stream extractLinks(Path tzFile) { // Note: the entries are alphabetically sorted, *except* the "world" region // code, i.e., "001". It should be the last entry for the same windows time // zone name entries. (cf. TimeZone_md.c) + // + // The default entries from CLDR's windowsZones.xml file can be modified + // with /tzmappings.override where mapping overrides + // can be specified. + private static Pattern OVERRIDE_PATTERN = Pattern.compile("(?([^:]+:[^:]+)):(?[^:]+):"); private static void generateWindowsTZMappings() throws Exception { Files.createDirectories(Paths.get(DESTINATION_DIR, "windows", "conf")); + var override = Path.of(tzDataDir, "tzmappings.override"); + if (override.toFile().exists()) { + Files.readAllLines(override).stream() + .map(String::trim) + .filter(o -> !o.isBlank() && !o.startsWith("#")) + .forEach(o -> { + var m = OVERRIDE_PATTERN.matcher(o); + if (m.matches()) { + handlerWinZones.put(m.group("win"), m.group("java")); + } else { + System.out.printf("Unrecognized tzmappings override: %s. Ignored%n", o); + } + }); + } Files.write(Paths.get(DESTINATION_DIR, "windows", "conf", "tzmappings"), handlerWinZones.keySet().stream() .filter(k -> k.endsWith(":001") || diff --git a/src/java.base/share/data/tzdata/tzmappings.override b/src/java.base/share/data/tzdata/tzmappings.override new file mode 100644 index 0000000000000..0f0e0c1372c83 --- /dev/null +++ b/src/java.base/share/data/tzdata/tzmappings.override @@ -0,0 +1,32 @@ +# +# Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved. +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# This code is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License version 2 only, as +# published by the Free Software Foundation. Oracle designates this +# particular file as subject to the "Classpath" exception as provided +# by Oracle in the LICENSE file that accompanied this code. +# +# This code is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +# version 2 for more details (a copy is included in the LICENSE file that +# accompanied this code). +# +# You should have received a copy of the GNU General Public License version +# 2 along with this work; if not, write to the Free Software Foundation, +# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. +# +# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA +# or visit www.oracle.com if you need additional information or have any +# questions. +# + +# Extra definitions for Windows /lib/tzmappings file. These entries +# replace the existing (Windows Zone Name):(REGION) entries, or are added +# as new entries + +# Example entries +# Foo Standard Time:US:America/Los_Angeles: +# Bar Standard Time:001:Asia/Tokyo: