mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2024-12-23 00:24:11 -08:00
Cache CLDRReader data between builds
This commit is contained in:
parent
6817618b4e
commit
2a07e67423
|
@ -48,7 +48,7 @@ public class JCLPlugin implements TeaVMPlugin {
|
||||||
JavacSupport javacSupport = new JavacSupport();
|
JavacSupport javacSupport = new JavacSupport();
|
||||||
host.add(javacSupport);
|
host.add(javacSupport);
|
||||||
|
|
||||||
host.registerService(CLDRReader.class, new CLDRReader(host.getProperties(), host.getClassLoader()));
|
host.registerService(CLDRReader.class, CLDRReader.getInstance(host.getProperties(), host.getClassLoader()));
|
||||||
|
|
||||||
host.add(new ClassForNameTransformer());
|
host.add(new ClassForNameTransformer());
|
||||||
host.add(new AnnotationDependencyListener());
|
host.add(new AnnotationDependencyListener());
|
||||||
|
|
|
@ -35,7 +35,8 @@ import java.util.zip.ZipEntry;
|
||||||
import java.util.zip.ZipInputStream;
|
import java.util.zip.ZipInputStream;
|
||||||
|
|
||||||
public class CLDRReader {
|
public class CLDRReader {
|
||||||
private static String[] weekdayKeys = { "sun", "mon", "tue", "wed", "thu", "fri", "sat" };
|
private static final String[] weekdayKeys = { "sun", "mon", "tue", "wed", "thu", "fri", "sat" };
|
||||||
|
private static CLDRReader lastInstance;
|
||||||
private Map<String, CLDRLocale> knownLocales = new LinkedHashMap<>();
|
private Map<String, CLDRLocale> knownLocales = new LinkedHashMap<>();
|
||||||
private Map<String, Integer> minDaysMap = new LinkedHashMap<>();
|
private Map<String, Integer> minDaysMap = new LinkedHashMap<>();
|
||||||
private Map<String, Integer> firstDayMap = new LinkedHashMap<>();
|
private Map<String, Integer> firstDayMap = new LinkedHashMap<>();
|
||||||
|
@ -44,24 +45,32 @@ public class CLDRReader {
|
||||||
private Set<String> availableLanguages = new LinkedHashSet<>();
|
private Set<String> availableLanguages = new LinkedHashSet<>();
|
||||||
private Set<String> availableCountries = new LinkedHashSet<>();
|
private Set<String> availableCountries = new LinkedHashSet<>();
|
||||||
private boolean initialized;
|
private boolean initialized;
|
||||||
private Properties properties;
|
|
||||||
private ClassLoader classLoader;
|
private ClassLoader classLoader;
|
||||||
|
private String availableLocalesString;
|
||||||
|
|
||||||
public CLDRReader(Properties properties, ClassLoader classLoader) {
|
private CLDRReader(ClassLoader classLoader, String availableLocalesString) {
|
||||||
this.properties = properties;
|
|
||||||
this.classLoader = classLoader;
|
this.classLoader = classLoader;
|
||||||
|
this.availableLocalesString = availableLocalesString;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static CLDRReader getInstance(Properties properties, ClassLoader classLoader) {
|
||||||
|
String availableLocalesString = properties.getProperty("java.util.Locale.available", "en_EN").trim();
|
||||||
|
if (lastInstance == null || !lastInstance.availableLocalesString.equals(availableLocalesString)
|
||||||
|
|| lastInstance.classLoader != classLoader) {
|
||||||
|
lastInstance = new CLDRReader(classLoader, availableLocalesString);
|
||||||
|
}
|
||||||
|
return lastInstance;
|
||||||
}
|
}
|
||||||
|
|
||||||
private synchronized void ensureInitialized() {
|
private synchronized void ensureInitialized() {
|
||||||
if (!initialized) {
|
if (!initialized) {
|
||||||
initialized = true;
|
initialized = true;
|
||||||
findAvailableLocales(properties);
|
findAvailableLocales();
|
||||||
readCLDR(classLoader);
|
readCLDR(classLoader);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void findAvailableLocales(Properties properties) {
|
private void findAvailableLocales() {
|
||||||
String availableLocalesString = properties.getProperty("java.util.Locale.available", "en_EN").trim();
|
|
||||||
for (String locale : Arrays.asList(availableLocalesString.split(" *, *"))) {
|
for (String locale : Arrays.asList(availableLocalesString.split(" *, *"))) {
|
||||||
int countryIndex = locale.indexOf('_');
|
int countryIndex = locale.indexOf('_');
|
||||||
if (countryIndex > 0) {
|
if (countryIndex > 0) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user