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