8174269: Remove COMPAT locale data provider from JDK

Reviewed-by: ihse, joehw
This commit is contained in:
Naoto Sato 2024-03-05 19:32:29 +00:00
parent c6641c7d2d
commit 809995b526
565 changed files with 1106 additions and 67327 deletions

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 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
@ -28,6 +28,8 @@ package sun.util.cldr;
import static sun.util.locale.provider.LocaleProviderAdapter.Type;
import java.text.MessageFormat;
import java.time.Duration;
import java.time.Instant;
import java.util.Arrays;
import java.util.Locale;
import java.util.Objects;
@ -154,10 +156,15 @@ public class CLDRTimeZoneNameProviderImpl extends TimeZoneNameProviderImpl {
var cands = ((CLDRLocaleProviderAdapter)LocaleProviderAdapter.forType(Type.CLDR))
.getCandidateLocales("", locale);
for (int i = 1; i < cands.size() ; i++) {
String[] parentNames = super.getDisplayNameArray(id, cands.get(i));
var loc = cands.get(i);
String[] parentNames = super.getDisplayNameArray(id, loc);
if (parentNames != null && !parentNames[index].isEmpty()) {
names[index] = parentNames[index];
return;
// Long names in ROOT locale should not be copied, as they can be generated
// with the fallback mechanisms below
if (!loc.equals(Locale.ROOT) || index % 2 == 0) {
names[index] = parentNames[index];
return;
}
}
}
}
@ -167,19 +174,6 @@ public class CLDRTimeZoneNameProviderImpl extends TimeZoneNameProviderImpl {
return;
}
// Check if COMPAT can substitute the name
if (!exists(names, index) &&
LocaleProviderAdapter.getAdapterPreference().contains(Type.JRE)) {
String[] compatNames = (String[])LocaleProviderAdapter.forJRE()
.getLocaleResources(mapChineseLocale(locale))
.getTimeZoneNames(id);
if (compatNames != null) {
// Assumes COMPAT has no empty slots
names[index] = compatNames[index];
return;
}
}
// Region Fallback
if (regionFormatFallback(names, index, locale)) {
return;
@ -270,8 +264,18 @@ public class CLDRTimeZoneNameProviderImpl extends TimeZoneNameProviderImpl {
}
private String toGMTFormat(String id, boolean daylight, Locale l) {
TimeZone tz = ZoneInfoFile.getZoneInfo(id);
int offset = (tz.getRawOffset() + (daylight ? tz.getDSTSavings() : 0)) / 60000;
var zr = ZoneInfoFile.getZoneInfo(id).toZoneId().getRules();
var now = Instant.now();
var saving = zr.getTransitions().reversed().stream()
.dropWhile(zot -> zot.getInstant().isAfter(now))
.filter(zot -> zr.isDaylightSavings(zot.getInstant()))
.findFirst()
.map(zot -> zr.getDaylightSavings(zot.getInstant()))
.map(Duration::getSeconds)
.map(Long::intValue)
.orElse(0);
int offset = (zr.getStandardOffset(now).getTotalSeconds() +
(daylight ? saving : 0)) / 60;
LocaleResources lr = LocaleProviderAdapter.forType(Type.CLDR).getLocaleResources(l);
ResourceBundle fd = lr.getJavaTimeFormatData();
@ -294,33 +298,4 @@ public class CLDRTimeZoneNameProviderImpl extends TimeZoneNameProviderImpl {
String.format(l, hourFormat, offset / 60, offset % 60));
}
}
// Mapping CLDR's Simplified/Traditional Chinese resources
// to COMPAT's zh-CN/TW
private Locale mapChineseLocale(Locale locale) {
if (locale.getLanguage() == "zh") {
switch (locale.getScript()) {
case "Hans":
return Locale.CHINA;
case "Hant":
return Locale.TAIWAN;
case "":
// no script, guess from country code.
switch (locale.getCountry()) {
case "":
case "CN":
case "SG":
return Locale.CHINA;
case "HK":
case "MO":
case "TW":
return Locale.TAIWAN;
}
break;
}
}
// no need to map
return locale;
}
}

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2005, 2014, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 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
@ -23,58 +23,49 @@
* questions.
*/
#warn This file is preprocessed before being compiled
/*
* This class contains a map which records the locale list string for
* each resource in sun.util.resources & sun.text.resources.
* It is used to avoid loading non-existent localized resources so that
* jar files won't be opened unnecessary to look up them.
* jar files won't be opened unnecessarily to look up them.
*/
package #Package#;
package sun.util.locale.provider;
import java.util.HashMap;
import java.util.Map;
import sun.util.locale.provider.LocaleDataMetaInfo;
import static sun.util.locale.provider.LocaleProviderAdapter.Type;
public class #Lang#LocaleDataMetaInfo implements LocaleDataMetaInfo {
public class BaseLocaleDataMetaInfo implements LocaleDataMetaInfo {
private static final Map<String, String> resourceNameToLocales = new HashMap<>(9);
private static final Map<String, String> resourceNameToLocales = HashMap.newHashMap(9);
static {
/* During JDK build time, #XXX_YYY# will be replaced by a string contain all the locales
supported by the resource.
Don't remove the space character between " and #. That is put there purposely so that
look up locale string such as "en" could be based on if it contains " en ".
*/
resourceNameToLocales.put("FormatData",
" #FormatData_Locales# ");
" en en-US ");
resourceNameToLocales.put("CollationData",
" #CollationData_Locales# ");
" ");
resourceNameToLocales.put("BreakIteratorInfo",
" #BreakIteratorInfo_Locales# ");
" ");
resourceNameToLocales.put("BreakIteratorRules",
" #BreakIteratorRules_Locales# ");
" ");
resourceNameToLocales.put("TimeZoneNames",
" #TimeZoneNames_Locales# ");
" en ");
resourceNameToLocales.put("LocaleNames",
" #LocaleNames_Locales# ");
" en ");
resourceNameToLocales.put("CurrencyNames",
" #CurrencyNames_Locales# ");
" en-US ");
resourceNameToLocales.put("CalendarData",
" #CalendarData_Locales# ");
" en ");
resourceNameToLocales.put("AvailableLocales",
" #AvailableLocales_Locales# ");
" en en-US ");
}
/*
@ -91,7 +82,7 @@ public class #Lang#LocaleDataMetaInfo implements LocaleDataMetaInfo {
@Override
public Type getType() {
return Type.JRE;
}
}
@Override
public String availableLanguageTags(String category) {

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 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
@ -84,29 +84,17 @@ public class CalendarNameProviderImpl extends CalendarNameProvider implements Av
Era[] jeras = CalendarSystem.forName("japanese").getEras();
if (value <= jeras.length) {
// Localized era name could not be retrieved from this provider.
// This can occur either for Reiwa or SupEra.
//
// If it's CLDR provider, try COMPAT first, which is guaranteed to have
// the name for Reiwa.
if (type == LocaleProviderAdapter.Type.CLDR) {
lr = LocaleProviderAdapter.forJRE().getLocaleResources(locale);
key = getResourceKeyFor(LocaleProviderAdapter.Type.JRE,
calendarType, field, style, javatime);
strings =
javatime ? lr.getJavaTimeNames(key) : lr.getCalendarNames(key);
}
if (strings == null || value >= strings.length) {
// Get the default name for SupEra
Era supEra = jeras[value - 1]; // 0-based index
if (javatime) {
return getBaseStyle(style) == NARROW_FORMAT ?
supEra.getAbbreviation() :
supEra.getName();
} else {
return (style & LONG) != 0 ?
supEra.getName() :
supEra.getAbbreviation();
}
// This can occur for SupEra.
// Get the default name for SupEra
Era supEra = jeras[value - 1]; // 0-based index
if (javatime) {
return getBaseStyle(style) == NARROW_FORMAT ?
supEra.getAbbreviation() :
supEra.getName();
} else {
return (style & LONG) != 0 ?
supEra.getName() :
supEra.getAbbreviation();
}
} else {
return null;
@ -314,7 +302,7 @@ public class CalendarNameProviderImpl extends CalendarNameProvider implements Av
// JRE and CLDR use different resource key conventions
// due to historical reasons. (JRE DateFormatSymbols.getEras returns
// abbreviations while other getShort*() return abbreviations.)
if (adapterType == LocaleProviderAdapter.Type.JRE) {
if (adapterType == LocaleProviderAdapter.Type.FALLBACK) {
if (javatime) {
if (baseStyle == LONG) {
key.append("long.");

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 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
@ -25,29 +25,30 @@
package sun.util.locale.provider;
import java.util.Collections;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.text.spi.BreakIteratorProvider;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Locale;
import java.util.Set;
import java.util.stream.Stream;
/**
* FallbackProviderAdapter implementation.
/*
* FallbackProviderAdapter implementation. Fallback provider serves the
* following purposes:
*
* @author Naoto Sato
* - Locale data for ROOT, in case CLDR provider is absent.
* - Locale data for BreakIterator/Collator resources for all locales.
* - "Gan-nen" support for SimpleDateFormat (provides "FirstYear" for
* Japanese locales).
*/
public class FallbackLocaleProviderAdapter extends JRELocaleProviderAdapter {
// Required locales/langtags
private static final Locale[] AVAILABLE_LOCS = {Locale.US, Locale.ENGLISH, Locale.ROOT};
private static final Set<String> AVAILABLE_LANGTAGS = Set.of("en-US", "en", "und");
/**
* Supported language tag set.
*/
private static final Set<String> rootTagSet =
Collections.singleton(Locale.ROOT.toLanguageTag());
/**
* Fallback provider only provides the ROOT locale data.
*/
@SuppressWarnings("this-escape")
private final LocaleResources rootLocaleResources =
new LocaleResources(this, Locale.ROOT);
private volatile BreakIteratorProvider breakIteratorProvider;
/**
* Returns the type of this LocaleProviderAdapter
@ -58,17 +59,45 @@ public class FallbackLocaleProviderAdapter extends JRELocaleProviderAdapter {
}
@Override
public LocaleResources getLocaleResources(Locale locale) {
return rootLocaleResources;
public Locale[] getAvailableLocales() {
return Stream.concat(Arrays.stream(super.getAvailableLocales()), Stream.of(AVAILABLE_LOCS))
.distinct().toArray(Locale[]::new);
}
@Override
protected Set<String> createLanguageTagSet(String category) {
return rootTagSet;
var s = new HashSet<>(super.createLanguageTagSet(category));
s.addAll(AVAILABLE_LANGTAGS);
return s;
}
@Override
public boolean isSupportedProviderLocale(Locale locale, Set<String>langtags) {
return Locale.ROOT.equals(locale);
public boolean isSupportedProviderLocale(Locale locale, Set<String> langtags) {
if (Locale.ROOT.equals(locale)) {
return true;
}
locale = locale.stripExtensions();
return langtags.contains(locale.toLanguageTag());
}
@Override
// In order to correctly report supported locales
public BreakIteratorProvider getBreakIteratorProvider() {
if (breakIteratorProvider == null) {
@SuppressWarnings("removal")
BreakIteratorProvider provider = AccessController.doPrivileged(
(PrivilegedAction<BreakIteratorProvider>) () ->
new BreakIteratorProviderImpl(
getAdapterType(),
getLanguageTagSet("BreakIteratorRules")));
synchronized (this) {
if (breakIteratorProvider == null) {
breakIteratorProvider = provider;
}
}
}
return breakIteratorProvider;
}
}

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 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
@ -470,7 +470,7 @@ public class JRELocaleProviderAdapter extends LocaleProviderAdapter implements R
if (ldmi.getType() == LocaleProviderAdapter.Type.JRE) {
String t = ldmi.availableLanguageTags(category);
if (t != null) {
if (tags.length() > 0) {
if (!tags.isEmpty()) {
tags.append(' ');
}
tags.append(t);

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 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
@ -126,8 +126,7 @@ public abstract class LocaleProviderAdapter {
for (String type : types) {
type = type.trim().toUpperCase(Locale.ROOT);
if (type.equals("COMPAT") || type.equals("JRE")) {
compatWarningMessage = "COMPAT locale provider will be removed in a future release";
type = "JRE";
compatWarningMessage = "COMPAT locale provider has been removed";
}
try {
Type aType = Type.valueOf(type.trim().toUpperCase(Locale.ROOT));
@ -141,17 +140,14 @@ public abstract class LocaleProviderAdapter {
}
}
if (!typeList.isEmpty()) {
// bona fide preference exists
if (!(typeList.contains(Type.CLDR) || typeList.contains(Type.JRE))) {
// Append FALLBACK as the last resort when no ResourceBundleBasedAdapter is available.
typeList.add(Type.FALLBACK);
}
} else {
if (typeList.isEmpty()) {
// Default preference list.
typeList.add(Type.CLDR);
typeList.add(Type.JRE);
}
// always append FALLBACK
typeList.add(Type.FALLBACK);
adapterPreference = Collections.unmodifiableList(typeList);
// Emit logs, if any, after 'adapterPreference' is initialized which is needed
@ -307,14 +303,13 @@ public abstract class LocaleProviderAdapter {
public static Locale[] toLocaleArray(Set<String> tags) {
return tags.stream()
.map(t -> {
return switch (t) {
case "ja-JP-JP" -> JRELocaleConstants.JA_JP_JP;
case "no-NO-NY" -> JRELocaleConstants.NO_NO_NY;
case "th-TH-TH" -> JRELocaleConstants.TH_TH_TH;
default -> Locale.forLanguageTag(t);
};
.map(t -> switch (t) {
case "ja-JP-JP" -> JRELocaleConstants.JA_JP_JP;
case "no-NO-NY" -> JRELocaleConstants.NO_NO_NY;
case "th-TH-TH" -> JRELocaleConstants.TH_TH_TH;
default -> Locale.forLanguageTag(t);
})
.distinct()
.toArray(Locale[]::new);
}

View file

@ -1,43 +0,0 @@
#
# Copyright (c) 2005, 2012, 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.
#
# (C) Copyright Taligent, Inc. 1996, 1997 - All Rights Reserved
# (C) Copyright IBM Corp. 1996 - 1999 - All Rights Reserved
#
# The original version of this source code and documentation
# is copyrighted and owned by Taligent, Inc., a wholly-owned
# subsidiary of IBM. These materials are provided under terms
# of a License Agreement between Taligent and Sun. This technology
# is protected by multiple US and International patents.
#
# This notice and attribution to Taligent may not be removed.
# Taligent is a registered trademark of Taligent, Inc.
# This bundle is empty because the data of the base bundle
# is adequate for this locale.
# The bundle is necessary to prevent the resource
# bundle lookup from falling back to the default
# locale.

View file

@ -1,38 +0,0 @@
#
# Copyright (c) 2005, 2012, 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.
#
# (C) Copyright Taligent, Inc. 1996, 1997 - All Rights Reserved
# (C) Copyright IBM Corp. 1996 - 1999 - All Rights Reserved
#
# The original version of this source code and documentation
# is copyrighted and owned by Taligent, Inc., a wholly-owned
# subsidiary of IBM. These materials are provided under terms
# of a License Agreement between Taligent and Sun. This technology
# is protected by multiple US and International patents.
#
# This notice and attribution to Taligent may not be removed.
# Taligent is a registered trademark of Taligent, Inc.
USD=$

View file

@ -1,41 +0,0 @@
# Copyright (c) 2005, 2012, 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.
#
# (C) Copyright Taligent, Inc. 1996, 1997 - All Rights Reserved
# (C) Copyright IBM Corp. 1996 - 1999 - All Rights Reserved
#
# The original version of this source code and documentation
# is copyrighted and owned by Taligent, Inc., a wholly-owned
# subsidiary of IBM. These materials are provided under terms
# of a License Agreement between Taligent and Sun. This technology
# is protected by multiple US and International patents.
#
# This notice and attribution to Taligent may not be removed.
# Taligent is a registered trademark of Taligent, Inc.
# This bundle is empty because the data of the base bundle
# is adequate for this locale.
# The bundle is necessary to prevent the resource
# bundle lookup from falling back to the default
# locale.

View file

@ -1,58 +0,0 @@
/*
* Copyright (c) 1997, 2012, 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.
*/
/*
* (C) Copyright Taligent, Inc. 1996, 1997 - All Rights Reserved
* (C) Copyright IBM Corp. 1996 - 1998 - All Rights Reserved
*
* The original version of this source code and documentation
* is copyrighted and owned by Taligent, Inc., a wholly-owned
* subsidiary of IBM. These materials are provided under terms
* of a License Agreement between Taligent and Sun. This technology
* is protected by multiple US and International patents.
*
* This notice and attribution to Taligent may not be removed.
* Taligent is a registered trademark of Taligent, Inc.
*
*/
package sun.util.resources;
import sun.util.resources.TimeZoneNamesBundle;
public final class TimeZoneNames_en extends TimeZoneNamesBundle {
// This bundle is empty because the root bundle's content
// is adequate for this locale.
// The bundle is necessary to prevent the resource
// bundle lookup from falling back to the default
// locale.
protected final Object[][] getContents() {
return new Object[][] {
};
}
}