[8u] 8177472: Remove hard-coded IANA Subtag Registry map in LocaleEquivalentMap.java

Hohensee, Paul hohensee at amazon.com
Fri Jun 28 17:17:34 UTC 2019


Looks good.

Paul

On 6/28/19, 6:25 AM, "jdk8u-dev on behalf of Andrew John Hughes" <jdk8u-dev-bounces at openjdk.java.net on behalf of gnu.andrew at redhat.com> wrote:

    Bug: https://bugs.openjdk.java.net/browse/JDK-8177472
    Webrev: https://cr.openjdk.java.net/~andrew/openjdk8/8177472/webrev.01/
    
    This change gets rid of the generated file
    src/share/classes/sun/util/locale/LocaleEquivalentMaps.java and instead
    generates it during the build. Backporting this is necessary to simplify
    later IANA LSR data updates (e.g. JDK-8191404, JDK-8203872, JDK-8213294
    & JDK-8214935)
    
    The backport differs from the original change in the Makefile changes
    being altered to match the structure and style of build tool rules in 8u:
    
    -diff --git a/make/Tools.gmk b/make/Tools.gmk
    +diff -r cb372d34618e make/Tools.gmk
     --- a/make/Tools.gmk
     +++ b/make/Tools.gmk
    -@@ -116,6 +116,9 @@
    - TOOL_CLDRCONVERTER = $(JAVA_SMALL) -cp
    $(BUILDTOOLS_OUTPUTDIR)/jdk_tools_classes \
    +@@ -123,6 +123,9 @@
    + TOOL_CLDRCONVERTER = $(JAVA_SMALL) -cp $(JDK_OUTPUTDIR)/btclasses \
          build.tools.cldrconverter.CLDRConverter
    
    -+TOOL_GENERATELSREQUIVMAPS = $(JAVA_SMALL) -cp
    $(BUILDTOOLS_OUTPUTDIR)/jdk_tools_classes \
    ++TOOL_GENERATELSREQUIVMAPS = $(JAVA_SMALL) -cp $(JDK_OUTPUTDIR)/btclasses \
     +    build.tools.generatelsrequivmaps.EquivMapsGenerator
     +
    - TOOL_GENMODULESXML = $(JAVA_SMALL) $(INTERIM_LANGTOOLS_BOOTCLASSPATH) \
    -     -cp $(call PathList, $(BUILDTOOLS_OUTPUTDIR)/jdk_tools_classes) \
    -     build.tools.module.GenJdepsModulesXml
    
    
    +diff -r cb372d34618e make/gensrc/GensrcLocaleDataMetaInfo.gmk
    +--- a/make/gensrc/GensrcLocaleDataMetaInfo.gmk
    ++++ b/make/gensrc/GensrcLocaleDataMetaInfo.gmk
    -@@ -63,6 +63,16 @@
    +@@ -125,3 +125,13 @@
    + GENSRC_LOCALEDATAMETAINFO += $(GENSRC_CRBC_DST)
    
    -
    ################################################################################
    -
    -+GENSRC_LSREQUIVMAPS :=
    $(SUPPORT_OUTPUTDIR)/gensrc/java.base/sun/util/locale/LocaleEquivalentMaps.java
    + ###
     +
    -+$(GENSRC_LSREQUIVMAPS):
    $(JDK_TOPDIR)/make/data/lsrdata/language-subtag-registry.txt
    $(BUILD_TOOLS_JDK)
    -+      $(call MakeDir, $(@D))
    -+      $(TOOL_GENERATELSREQUIVMAPS) $< $@
    ++GENSRC_LSREQUIVMAPS_DST :=
    $(JDK_OUTPUTDIR)/gensrc/sun/util/locale/LocaleEquivalentMaps.java
     +
    -+GENSRC_JAVA_BASE += $(GENSRC_LSREQUIVMAPS)
    ++$(GENSRC_LSREQUIVMAPS_DST):
    $(JDK_TOPDIR)/make/data/lsrdata/language-subtag-registry.txt
    ++      $(MKDIR) -p $(@D)
    ++      $(TOOL_GENERATELSREQUIVMAPS) $< $@
     +
    -+################################################################################
    ++GENSRC_LOCALEDATAMETAINFO += $(GENSRC_LSREQUIVMAPS_DST)
     +
    - java.base: $(GENSRC_JAVA_BASE)
    -
    - all: java.base
    
    A couple of changes are also made to
    make/src/classes/build/tools/generatelsrequivmaps/EquivMapsGenerator.java so
    it remains possible to bootstrap the JDK using a Java 7 JDK.
    
    Java 7 does not have the java.time API, so we use java.util.Calendar and
    java.util.TimeZone to obtain the current year instead. Java 7 doesn't
    have Files.newBufferedWriter(Path), but this is simply a shorthand for
    Files.newBufferedWriter(Path, StandardCharsets.UTF_8), so we just
    explicitly specify the second argument.
    
    +diff -r cb372d34618e
    make/src/classes/build/tools/generatelsrequivmaps/EquivMapsGenerator.java
     --- /dev/null
     +++
    b/make/src/classes/build/tools/generatelsrequivmaps/EquivMapsGenerator.java
    -@@ -0,0 +1,281 @@
    +@@ -0,0 +1,282 @@
     +/*
     + * Copyright (c) 2012, 2017, Oracle and/or its affiliates. All rights
    reserved.
     + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    @@ -47183,14 +47168,15 @@
     +import java.io.BufferedWriter;
     +import java.io.IOException;
     +import java.nio.charset.Charset;
    ++import java.nio.charset.StandardCharsets;
     +import java.nio.file.Files;
     +import java.nio.file.Paths;
    -+import java.time.ZoneId;
    -+import java.time.ZonedDateTime;
     +import java.util.ArrayList;
    ++import java.util.Calendar;
     +import java.util.List;
     +import java.util.Locale;
     +import java.util.Map;
    ++import java.util.TimeZone;
     +import java.util.TreeMap;
     +
     +/**
    @@ -47380,8 +47366,8 @@
     +        + "}";
     +
     +    private static String getOpenJDKCopyright() {
    -+        int year = ZonedDateTime.now(ZoneId
    -+                .of("America/Los_Angeles")).getYear();
    ++        int year = Calendar.getInstance(TimeZone
    ++                .getTimeZone("America/Los_Angeles")).get(Calendar.YEAR);
     +        return String.format(Locale.US, COPYRIGHT, year);
     +    }
     +
    @@ -47394,7 +47380,7 @@
     +    private static void generateSourceCode(String fileName) {
     +
     +        try (BufferedWriter writer = Files.newBufferedWriter(
    -+                Paths.get(fileName))) {
    ++                Paths.get(fileName), StandardCharsets.UTF_8)) {
     +            writer.write(getOpenJDKCopyright());
     +            writer.write(headerText
     +                + "        //   LSR Revision: " + LSRrevisionDate);
    @@ -47436,8 +47422,7 @@
     +    }
     +
     +}
    
    
    The generated version of LocaleEquivalentMaps.java looks little
    different to the original:
    
    --- src/share/classes/sun/util/locale/LocaleEquivalentMaps.java
    2019-06-28 13:52:32.872368928 +0100
    +++ /mnt/builder/8u/jdk/gensrc/sun/util/locale/LocaleEquivalentMaps.java
           2019-06-28 05:44:39.955656054 +0100
    @@ -1,5 +1,5 @@
     /*
    - * Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights
    reserved.
    + * Copyright (c) 2012, 2019, 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
    @@ -21,16 +21,13 @@
      * 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.
    - */
    +*/
    
     package sun.util.locale;
    
     import java.util.HashMap;
     import java.util.Map;
    
    -/**
    - * Locale equivalent map for BCP47 Locale matching
    - */
     final class LocaleEquivalentMaps {
    
         static final Map<String, String> singleEquivMap;
    @@ -253,4 +250,4 @@
             regionVariantEquivMap.put("-zr", "-cd");
         }
    
    -}
    +}
    
    The tests in java/util/Locale still pass after the patch.
    
    Ok for 8u222?
    
    Thanks,
    -- 
    Andrew :)
    
    Senior Free Java Software Engineer
    Red Hat, Inc. (http://www.redhat.com)
    
    PGP Key: ed25519/0xCFDA0F9B35964222 (hkp://keys.gnupg.net)
    Fingerprint = 5132 579D D154 0ED2 3E04  C5A0 CFDA 0F9B 3596 4222
    https://keybase.io/gnu_andrew
    
    



More information about the jdk8u-dev mailing list