Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLDR-17346 ConsoleCheckCLDR fixes #3659

Merged
merged 2 commits into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 30 additions & 22 deletions tools/cldr-code/src/main/java/org/unicode/cldr/test/CheckCLDR.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@

package org.unicode.cldr.test;

import com.google.common.base.Supplier;
import com.google.common.base.Suppliers;
import com.google.common.collect.ComparisonChain;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.ibm.icu.dev.util.ElapsedTimer;
import com.ibm.icu.impl.Row.R3;
Expand Down Expand Up @@ -718,10 +721,9 @@ public CheckCLDR setCldrFileToCheck(
// we must load filters here, as they are used by check()

// Shortlist error filters for this locale.
loadFilters();
String locale = cldrFileToCheck.getLocaleID();
filtersForLocale.clear();
for (R3<Pattern, Subtype, Pattern> filter : allFilters) {
for (R3<Pattern, Subtype, Pattern> filter : getAllFilters()) {
if (filter.get0() == null || !filter.get0().matcher(locale).matches()) continue;
Subtype subtype = filter.get1();
List<Pattern> xpaths = filtersForLocale.get(subtype);
Expand Down Expand Up @@ -1563,26 +1565,32 @@ public void setPhase(Phase phase) {
}

/** A map of error/warning types to their filters. */
private static List<R3<Pattern, Subtype, Pattern>> allFilters;

/** Loads the set of filters used for CheckCLDR results. */
private void loadFilters() {
if (allFilters != null) return;
allFilters = new ArrayList<>();
RegexFileParser fileParser = new RegexFileParser();
fileParser.setLineParser(
new RegexLineParser() {
@Override
public void parse(String line) {
String[] fields = line.split("\\s*;\\s*");
Subtype subtype = Subtype.valueOf(fields[0]);
Pattern locale = PatternCache.get(fields[1]);
Pattern xpathRegex =
PatternCache.get(fields[2].replaceAll("\\[@", "\\\\[@"));
allFilters.add(new R3<>(locale, subtype, xpathRegex));
}
});
fileParser.parse(CheckCLDR.class, "/org/unicode/cldr/util/data/CheckCLDR-exceptions.txt");
private static Supplier<List<R3<Pattern, Subtype, Pattern>>> filterSupplier =
Suppliers.memoize(
() -> {
final List<R3<Pattern, Subtype, Pattern>> newFilters = new ArrayList<>();
RegexFileParser fileParser = new RegexFileParser();
fileParser.setLineParser(
new RegexLineParser() {
@Override
public void parse(String line) {
String[] fields = line.split("\\s*;\\s*");
Subtype subtype = Subtype.valueOf(fields[0]);
Pattern locale = PatternCache.get(fields[1]);
Pattern xpathRegex =
PatternCache.get(
fields[2].replaceAll("\\[@", "\\\\[@"));
newFilters.add(new R3<>(locale, subtype, xpathRegex));
}
});
fileParser.parse(
CheckCLDR.class,
"/org/unicode/cldr/util/data/CheckCLDR-exceptions.txt");
return ImmutableList.copyOf(newFilters);
});

private static final List<R3<Pattern, Subtype, Pattern>> getAllFilters() {
return filterSupplier.get();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1781,9 +1781,9 @@ private static String getIdString(String path, String value) {
private static void showValue(
CLDRFile cldrFile,
String prettyPath,
String localeID,
final String localeID,
String example,
String path,
final String path,
String value,
String fullPath,
String statusString,
Expand Down Expand Up @@ -2031,27 +2031,30 @@ private static String guessFilePath(Pair<String, String> locPath) {
final File base = new File(CLDRPaths.BASE_DIRECTORY);
final String loc = locPath.getFirst();
final String path = locPath.getSecond();
String subdir = "main";
if (path.startsWith("//ldml/annotations")) {
subdir = "annotations";
} else if (path.startsWith("//ldml/subdivisions")) {
subdir = "subdivisions";
}
File inCommon = new File(base, "common");
File subsub = new File(inCommon, subdir);
if (subsub.isDirectory()) {
File subFile = new File(subsub, loc + ".xml");
if (subFile.canRead())
return subFile.getAbsolutePath().substring(base.getAbsolutePath().length() + 1);
}
if (path != null) {
String subdir = "main";
if (path.startsWith("//ldml/annotations")) {
subdir = "annotations";
} else if (path.startsWith("//ldml/subdivisions")) {
subdir = "subdivisions";
}
File inCommon = new File(base, "common");
File subsub = new File(inCommon, subdir);
if (subsub.isDirectory()) {
File subFile = new File(subsub, loc + ".xml");
if (subFile.canRead())
return subFile.getAbsolutePath().substring(base.getAbsolutePath().length() + 1);
}

File inSeed = new File(base, "seed");
subsub = new File(inSeed, subdir);
if (subsub.isDirectory()) {
File subFile = new File(subsub, loc + ".xml");
if (subFile.canRead())
return subFile.getAbsolutePath().substring(base.getAbsolutePath().length() + 1);
File inSeed = new File(base, "seed");
subsub = new File(inSeed, subdir);
if (subsub.isDirectory()) {
File subFile = new File(subsub, loc + ".xml");
if (subFile.canRead())
return subFile.getAbsolutePath().substring(base.getAbsolutePath().length() + 1);
}
}
// no XPath - could be an entire-locale error.
return loc + ".xml";
}

Expand Down
Loading