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", 33 "1.1.1", 34 "1.2", 35 "1.3", 36 "1.4", 37 "1.4.1", 38 "1.5.0.1", 39 "1.5.1", 40 "1.6.1", 41 "1.7.2", 42 "1.8.1", 43 "1.9.1", 44 "2.0.1", 45 "21.0", 46 "22.1", 47 "23.1", 48 "24.0", 49 "25.0", 50 "26.0", 51 "27.0", 52 "28.0", 53 "29.0", 54 "30.0", 55 "31.0", 56 "32.0", 57 "33.0", 58 "33.1", 59 "34.0", 60 "35.0", 61 "35.1", 62 "36.0", 63 "36.1", 64 "37.0", 65 "38.0", 66 "38.1", 67 "39.0", 68 "40.0", 69 "41.0" 70 // add to this once the release is final! 71 ); 72 public static final Set<VersionInfo> CLDR_VERSIONS_VI = ImmutableSet.copyOf(CLDR_VERSIONS.stream() 73 .map(x -> VersionInfo.getInstance(x)) 74 .collect(Collectors.toList())); 75 76 public static final String DEV_VERSION = "42"; 77 public static final VersionInfo DEV_VERSION_VI = VersionInfo.getInstance(DEV_VERSION); 78 79 public static final Set<String> CLDR_RELEASE_VERSION_SET = ImmutableSet.copyOf(ToolConstants.CLDR_VERSIONS); 80 public static final Set<String> CLDR_RELEASE_AND_DEV_VERSION_SET = ImmutableSet.<String>builder().addAll(CLDR_RELEASE_VERSION_SET).add(DEV_VERSION).build(); 81 previousVersion(VersionInfo version)82 public static VersionInfo previousVersion(VersionInfo version) { 83 VersionInfo last = null; 84 for (VersionInfo current : CLDR_VERSIONS_VI) { 85 if (current.equals(version)) { 86 break; 87 } 88 last = current; 89 } 90 return last; 91 } previousVersion(String version, int minFields)92 public static String previousVersion(String version, int minFields) { 93 VersionInfo result = previousVersion(VersionInfo.getInstance(version)); 94 return result.getVersionString(minFields, 2); 95 } previousVersion(String version)96 public static String previousVersion(String version) { 97 return previousVersion(version, 2); 98 } 99 getBaseDirectory(VersionInfo vi)100 public static String getBaseDirectory(VersionInfo vi) { 101 if (vi.equals(DEV_VERSION_VI)) { 102 return CLDRPaths.BASE_DIRECTORY; 103 } else if (CLDR_VERSIONS_VI.contains(vi)) { 104 return CLDRPaths.ARCHIVE_DIRECTORY + "cldr-" + vi.getVersionString(2, 3) + "/"; 105 } else { 106 throw new IllegalArgumentException("not a known version: " + vi.getVersionString(2, 2) 107 + ", must be in: " + CLDR_VERSIONS_VI); 108 } 109 } getBaseDirectory(String version)110 public static String getBaseDirectory(String version) { 111 VersionInfo vi = VersionInfo.getInstance(version); 112 return getBaseDirectory(vi); 113 } 114 115 // allows overriding with -D 116 public static final VersionInfo CHART_VI = VersionInfo.getInstance(CldrUtility.getProperty("CHART_VERSION", DEV_VERSION)); 117 public static final String CHART_VERSION = CHART_VI.getVersionString(1, 2); 118 119 public static final String PREV_CHART_VERSION_RAW = CldrUtility.getProperty("PREV_CHART_VERSION", previousVersion(CHART_VERSION)); 120 public static final VersionInfo PREV_CHART_VI = VersionInfo.getInstance(PREV_CHART_VERSION_RAW); 121 public static final String PREV_CHART_VERSION = PREV_CHART_VI.getVersionString(1, 2); 122 public static final String PREV_CHART_VERSION_WITH0 = PREV_CHART_VI.getVersionString(2, 2); // must have 1 decimal 123 124 public static final ChartStatus CHART_STATUS = ChartStatus.valueOf(CldrUtility.getProperty("CHART_STATUS", 125 CLDR_VERSIONS_VI.contains(CHART_VI) 126 ? "release" 127 : "beta")); 128 public static final boolean BETA = CHART_STATUS == ChartStatus.beta; 129 130 // DON'T CHANGE ANY OF THE FOLLOWING DEFINITIONS; THEY ARE DRIVEN BY THE ABOVE 131 132 public static final String CHART_DISPLAY_VERSION = CHART_VI.getVersionString(2, 2) + (BETA ? "β" : ""); 133 134 public static final String LAST_RELEASE_VERSION = CLDR_VERSIONS.get(CLDR_VERSIONS.size()-1); 135 public static final VersionInfo LAST_RELEASE_VI = VersionInfo.getInstance(LAST_RELEASE_VERSION); 136 public static final String LAST_RELEASE_VERSION_WITH0 = LAST_RELEASE_VI.getVersionString(2, 2); // must have 1 decimal 137 138 139 //public static final String CHART_SOURCE_DIRECTORY = CLDR_VERSIONS.contains(CHART_VERSION) ? "" 140 141 public static final String CHART_SOURCE = "http://unicode.org/repos/cldr/" 142 + (CHART_STATUS != ChartStatus.release ? "trunk/" : "tags/release-" + CHART_VERSION + "/"); 143 144 } 145