xref: /aosp_15_r20/external/cldr/tools/cldr-code/src/main/java/org/unicode/cldr/tool/ToolConstants.java (revision 912701f9769bb47905792267661f0baf2b85bed5)
1 package org.unicode.cldr.tool;
2 
3 import com.google.common.collect.ImmutableList;
4 import com.google.common.collect.ImmutableSet;
5 import com.ibm.icu.util.VersionInfo;
6 import java.util.List;
7 import java.util.Set;
8 import java.util.stream.Collectors;
9 import org.unicode.cldr.util.CLDRPaths;
10 import org.unicode.cldr.util.CldrUtility;
11 
12 /**
13  * Constants specific to CLDR tools. Not to be used with the Survey Tool. Moved here from
14  * CldrUtilities
15  *
16  * @author srl
17  */
18 public class ToolConstants {
19 
20     // We are now having charts point to the appropriate source, so this may take some tweaking!
21     public enum ChartStatus {
22         beta, // at the start of the release
23         trunk, // before the release is tagged
24         release // for release version
25     }
26 
27     // TODO change this to CldrVersion, add add in the ShowLocaleCoverage years.
28     public static final List<String> CLDR_VERSIONS =
29             ImmutableList.of(
30                     "1.1", "1.1.1", "1.2", "1.3", "1.4", "1.4.1", "1.5.0.1", "1.5.1", "1.6.1",
31                     "1.7.2", "1.8.1", "1.9.1", "2.0.1", "21.0", "22.1", "23.1", "24.0", "25.0",
32                     "26.0", "27.0", "28.0", "29.0", "30.0", "31.0", "32.0", "33.0", "33.1", "34.0",
33                     "35.0", "35.1", "36.0", "36.1", "37.0", "38.0", "38.1", "39.0", "40.0", "41.0",
34                     "42.0", "43.0", "44.0", "44.1"
35                     // add to this once the release is final!
36                     );
37     public static final Set<VersionInfo> CLDR_VERSIONS_VI =
38             ImmutableSet.copyOf(
39                     CLDR_VERSIONS.stream()
40                             .map(x -> VersionInfo.getInstance(x))
41                             .collect(Collectors.toList()));
42 
43     public static final String DEV_VERSION = "45";
44     public static final VersionInfo DEV_VERSION_VI = VersionInfo.getInstance(DEV_VERSION);
45 
46     public static final Set<String> CLDR_RELEASE_VERSION_SET =
47             ImmutableSet.copyOf(ToolConstants.CLDR_VERSIONS);
48     public static final Set<String> CLDR_RELEASE_AND_DEV_VERSION_SET =
49             ImmutableSet.<String>builder()
50                     .addAll(CLDR_RELEASE_VERSION_SET)
51                     .add(DEV_VERSION)
52                     .build();
53 
previousVersion(VersionInfo version)54     public static VersionInfo previousVersion(VersionInfo version) {
55         VersionInfo last = null;
56         for (VersionInfo current : CLDR_VERSIONS_VI) {
57             if (current.equals(version)) {
58                 break;
59             }
60             last = current;
61         }
62         return last;
63     }
64 
previousVersion(String version, int minFields)65     public static String previousVersion(String version, int minFields) {
66         VersionInfo result = previousVersion(VersionInfo.getInstance(version));
67         return result.getVersionString(minFields, 2);
68     }
69 
previousVersion(String version)70     public static String previousVersion(String version) {
71         return previousVersion(version, 2);
72     }
73 
getBaseDirectory(VersionInfo vi)74     public static String getBaseDirectory(VersionInfo vi) {
75         if (vi.equals(DEV_VERSION_VI)) {
76             return CLDRPaths.BASE_DIRECTORY;
77         } else if (CLDR_VERSIONS_VI.contains(vi)) {
78             return CLDRPaths.ARCHIVE_DIRECTORY + "cldr-" + vi.getVersionString(2, 3) + "/";
79         } else {
80             throw new IllegalArgumentException(
81                     "not a known version: "
82                             + vi.getVersionString(2, 2)
83                             + ", must be in: "
84                             + CLDR_VERSIONS_VI);
85         }
86     }
87 
getBaseDirectory(String version)88     public static String getBaseDirectory(String version) {
89         VersionInfo vi = VersionInfo.getInstance(version);
90         return getBaseDirectory(vi);
91     }
92 
93     // allows overriding with -D
94     public static final VersionInfo CHART_VI =
95             VersionInfo.getInstance(CldrUtility.getProperty("CHART_VERSION", DEV_VERSION));
96     public static final String CHART_VERSION = CHART_VI.getVersionString(1, 2);
97 
98     public static final String PREV_CHART_VERSION_RAW =
99             CldrUtility.getProperty("PREV_CHART_VERSION", previousVersion(CHART_VERSION));
100     public static final VersionInfo PREV_CHART_VI = VersionInfo.getInstance(PREV_CHART_VERSION_RAW);
101     public static final String PREV_CHART_VERSION = PREV_CHART_VI.getVersionString(1, 2);
102     public static final String PREV_CHART_VERSION_WITH0 =
103             PREV_CHART_VI.getVersionString(2, 2); // must have 1 decimal
104 
105     public static final ChartStatus CHART_STATUS =
106             ChartStatus.valueOf(
107                     CldrUtility.getProperty(
108                             "CHART_STATUS",
109                             CLDR_VERSIONS_VI.contains(CHART_VI) ? "release" : "beta"));
110     public static final boolean BETA = CHART_STATUS == ChartStatus.beta;
111 
112     // DON'T CHANGE ANY OF THE FOLLOWING DEFINITIONS; THEY ARE DRIVEN BY THE ABOVE
113 
114     public static final String CHART_DISPLAY_VERSION =
115             CHART_VI.getVersionString(2, 2) + (BETA ? "β" : "");
116 
117     public static final String LAST_RELEASE_VERSION = CLDR_VERSIONS.get(CLDR_VERSIONS.size() - 1);
118     public static final VersionInfo LAST_RELEASE_VI = VersionInfo.getInstance(LAST_RELEASE_VERSION);
119     public static final String LAST_RELEASE_VERSION_WITH0 =
120             LAST_RELEASE_VI.getVersionString(2, 2); // must have 1 decimal
121 
122     // public static final String CHART_SOURCE_DIRECTORY = CLDR_VERSIONS.contains(CHART_VERSION) ?
123     // ""
124 
125     public static final String CHART_SOURCE =
126             "http://unicode.org/repos/cldr/"
127                     + (CHART_STATUS != ChartStatus.release
128                             ? "trunk/"
129                             : "tags/release-" + CHART_VERSION + "/");
130 }
131