Skip to content

Commit

Permalink
CLDR-18053 fix ConsoleCheckCLDR threading issue (#4156)
Browse files Browse the repository at this point in the history
  • Loading branch information
srl295 authored Oct 23, 2024
1 parent c697120 commit 8641978
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import org.unicode.cldr.util.CLDRConfig.Environment;
import org.unicode.cldr.util.CLDRFile;
import org.unicode.cldr.util.CLDRFile.Status;
import org.unicode.cldr.util.CLDRLocale;
import org.unicode.cldr.util.CLDRPaths;
import org.unicode.cldr.util.CLDRTool;
import org.unicode.cldr.util.CldrUtility;
Expand All @@ -51,7 +52,6 @@
import org.unicode.cldr.util.Factory;
import org.unicode.cldr.util.LanguageTagParser;
import org.unicode.cldr.util.Level;
import org.unicode.cldr.util.LocaleIDParser;
import org.unicode.cldr.util.LogicalGrouping;
import org.unicode.cldr.util.Organization;
import org.unicode.cldr.util.Pair;
Expand Down Expand Up @@ -270,15 +270,12 @@ private static Set<String> parse(String[] args, boolean showArguments) {
UOption.create("singleThread", '1', UOption.NO_ARG)
};

private static final Comparator<String> baseFirstCollator =
private static final Comparator<CLDRLocale> baseFirstCollator =
new Comparator<>() {
LanguageTagParser languageTagParser1 = new LanguageTagParser();
LanguageTagParser languageTagParser2 = new LanguageTagParser();

@Override
public int compare(String o1, String o2) {
String ls1 = languageTagParser1.set(o1).getLanguageScript();
String ls2 = languageTagParser2.set(o2).getLanguageScript();
public int compare(CLDRLocale o1, CLDRLocale o2) {
String ls1 = o1.getLanguageScript();
String ls2 = o2.getLanguageScript();
int result = ls1.compareTo(ls2);
if (result != 0) return result;
return o1.compareTo(o2);
Expand Down Expand Up @@ -501,16 +498,15 @@ public static void main(String[] args) throws Throwable {
PathShower pathShower = new PathShower();

// call on the files
Set<String> locales = new TreeSet<>(baseFirstCollator);
locales.addAll(cldrFactory.getAvailable());
Set<CLDRLocale> locales = new TreeSet<>(baseFirstCollator);
locales.addAll(cldrFactory.getAvailableCLDRLocales());

Set<String> fatalErrors = new TreeSet<>();
Set<CLDRLocale> fatalErrors = new TreeSet<>(baseFirstCollator);

showHeaderLine();

supplementalDataInfo = SupplementalDataInfo.getInstance(CLDRPaths.SUPPLEMENTAL_DIRECTORY);

LocaleIDParser localeIDParser = new LocaleIDParser();
PathHeader.Factory pathHeaderFactory = PathHeader.getFactory(english);

final Map<String, Level> locale_status =
Expand All @@ -534,7 +530,7 @@ public static void main(String[] args) throws Throwable {
// final Set<String> englishPaths = Collections.unmodifiableSet(ep); // for robustness

// Set up our stream to use. It will be parallel usually, or sequential for HTML.
Stream<String> stream;
Stream<CLDRLocale> stream;

if (sequential) {
System.err.println("# Note: running in sequential mode.");
Expand All @@ -545,10 +541,11 @@ public static void main(String[] args) throws Throwable {

// now, run it
stream.forEach(
localeID -> {
locale -> {
if (ErrorFile.writeError != null) {
return; // get out, it's an error.
}
final String localeID = locale.toString();

Set<PathHeader> paths = new TreeSet<>(); // CLDRFile.ldmlComparator);
Map<String, String> m = new TreeMap<>();
Expand All @@ -567,9 +564,7 @@ public static void main(String[] args) throws Throwable {
System.out.println("# Skipping special purpose locale: " + localeID);
return;
}

boolean isLanguageLocale =
localeID.equals(localeIDParser.set(localeID).getLanguageScript());
final boolean isLanguageLocale = locale.isLanguageLocale();
options.clear();

if (MyOptions.exemplarError.option.doesOccur()) {
Expand Down Expand Up @@ -612,12 +607,12 @@ public static void main(String[] args) throws Throwable {
if (ErrorFile.voteFactory != null) {
ErrorFile.voteFile = ErrorFile.voteFactory.make(localeID, true);
}
final String parentID = LocaleIDParser.getParent(localeID);
final CLDRLocale parentID = locale.getParent();
if (parentID != null) {
parent = cldrFactory.make(parentID, true);
parent = cldrFactory.make(parentID.toString(), true);
}
} catch (RuntimeException e) {
fatalErrors.add(localeID);
fatalErrors.add(locale);
System.out.println("FATAL ERROR: " + localeID);
e.printStackTrace(System.out);
return;
Expand All @@ -627,7 +622,7 @@ public static void main(String[] args) throws Throwable {

// generate HTML if asked for
if (ErrorFile.generated_html_directory != null) {
String baseLanguage = localeIDParser.set(localeID).getLanguageScript();
String baseLanguage = locale.getLanguageScript();

if (!baseLanguage.equals(ErrorFile.lastBaseLanguage)) {
ErrorFile.lastBaseLanguage = baseLanguage;
Expand Down Expand Up @@ -1958,8 +1953,8 @@ public static class PathShower {
public void set(String localeID) {
this.localeID = localeID;
newLocale = true;
LocaleIDParser localeIDParser = new LocaleIDParser();
showEnglish = !localeIDParser.set(localeID).getLanguageScript().equals("en");
CLDRLocale locale = CLDRLocale.getInstance(localeID);
showEnglish = !locale.getLanguage().equals("en");
lastPath = null;
lastSplitPath = null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,13 @@ public String getBaseName() {
return basename;
}

/**
* @return the language-script (or language) part of a tag.
*/
public String getLanguageScript() {
return parts == null ? fullname : parts.getLanguageScript();
}

/**
* internal: process a string from ICU to CLDR form. For now, just collapse double underscores.
*
Expand Down

0 comments on commit 8641978

Please sign in to comment.