mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-28 15:24:43 +02:00
8343788: Provide means to alter lib/tzmappings entries on Windows
Reviewed-by: joehw
This commit is contained in:
parent
29c57e8b34
commit
352201ddec
2 changed files with 54 additions and 1 deletions
|
@ -33,6 +33,7 @@ import java.nio.file.*;
|
|||
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 @@ public class CLDRConverter {
|
|||
private static Stream<String> 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 @@ public class CLDRConverter {
|
|||
// 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 <tzDataDir>/tzmappings.override where mapping overrides
|
||||
// can be specified.
|
||||
private static Pattern OVERRIDE_PATTERN = Pattern.compile("(?<win>([^:]+:[^:]+)):(?<java>[^:]+):");
|
||||
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") ||
|
||||
|
|
32
src/java.base/share/data/tzdata/tzmappings.override
Normal file
32
src/java.base/share/data/tzdata/tzmappings.override
Normal file
|
@ -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:
|
Loading…
Add table
Add a link
Reference in a new issue