• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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", "45.0"
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 = "46";
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 
65     /** Version prior to the current DEV version */
previousVersion()66     public static VersionInfo previousVersion() {
67         return previousVersion(DEV_VERSION_VI);
68     }
69 
previousVersion(String version, int minFields)70     public static String previousVersion(String version, int minFields) {
71         VersionInfo result = previousVersion(VersionInfo.getInstance(version));
72         return result.getVersionString(minFields, 2);
73     }
74 
previousVersion(String version)75     public static String previousVersion(String version) {
76         return previousVersion(version, 2);
77     }
78 
getBaseDirectory(VersionInfo vi)79     public static String getBaseDirectory(VersionInfo vi) {
80         if (vi.equals(DEV_VERSION_VI)) {
81             return CLDRPaths.BASE_DIRECTORY;
82         } else if (CLDR_VERSIONS_VI.contains(vi)) {
83             return CLDRPaths.ARCHIVE_DIRECTORY + "cldr-" + vi.getVersionString(2, 3) + "/";
84         } else {
85             throw new IllegalArgumentException(
86                     "not a known version: "
87                             + vi.getVersionString(2, 2)
88                             + ", must be in: "
89                             + CLDR_VERSIONS_VI);
90         }
91     }
92 
getBaseDirectory(String version)93     public static String getBaseDirectory(String version) {
94         VersionInfo vi = VersionInfo.getInstance(version);
95         return getBaseDirectory(vi);
96     }
97 
98     // allows overriding with -D
99     public static final VersionInfo CHART_VI =
100             VersionInfo.getInstance(CldrUtility.getProperty("CHART_VERSION", DEV_VERSION));
101     public static final String CHART_VERSION = CHART_VI.getVersionString(1, 2);
102 
103     public static final String PREV_CHART_VERSION_RAW =
104             CldrUtility.getProperty("PREV_CHART_VERSION", previousVersion(CHART_VERSION));
105     public static final VersionInfo PREV_CHART_VI = VersionInfo.getInstance(PREV_CHART_VERSION_RAW);
106     public static final String PREV_CHART_VERSION = PREV_CHART_VI.getVersionString(1, 2);
107     public static final String PREV_CHART_VERSION_WITH0 =
108             PREV_CHART_VI.getVersionString(2, 2); // must have 1 decimal
109 
110     public static final ChartStatus CHART_STATUS =
111             ChartStatus.valueOf(
112                     CldrUtility.getProperty(
113                             "CHART_STATUS",
114                             CLDR_VERSIONS_VI.contains(CHART_VI) ? "release" : "beta"));
115     public static final boolean BETA = CHART_STATUS == ChartStatus.beta;
116 
117     // DON'T CHANGE ANY OF THE FOLLOWING DEFINITIONS; THEY ARE DRIVEN BY THE ABOVE
118 
119     public static final String CHART_DISPLAY_VERSION =
120             CHART_VI.getVersionString(2, 2) + (BETA ? "β" : "");
121 
122     public static final String LAST_RELEASE_VERSION = CLDR_VERSIONS.get(CLDR_VERSIONS.size() - 1);
123     public static final VersionInfo LAST_RELEASE_VI = VersionInfo.getInstance(LAST_RELEASE_VERSION);
124     public static final String LAST_RELEASE_VERSION_WITH0 =
125             LAST_RELEASE_VI.getVersionString(2, 2); // must have 1 decimal
126 
127     // public static final String CHART_SOURCE_DIRECTORY = CLDR_VERSIONS.contains(CHART_VERSION) ?
128     // ""
129 
130     public static final String CHART_SOURCE =
131             "http://unicode.org/repos/cldr/"
132                     + (CHART_STATUS != ChartStatus.release
133                             ? "trunk/"
134                             : "tags/release-" + CHART_VERSION + "/");
135 }
136