Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.unicode.cldr.util.UnitConverter.UnitSystem;

public class ChartUnitConversions extends Chart {
private static final boolean DUMP_UNIT_TABLE_TO_STDOUT = false;

public static final String QUANTITY_MSG =
"The units are grouped and ordered by Quantity (which are based on the NIST quantities, see "
Expand Down Expand Up @@ -170,10 +171,12 @@ public void writeContents(FormattedFileWriter pw) throws IOException {
.finishRow();
}
pw.write(tablePrinter.toTable());
PrintWriter pw2 = new PrintWriter(System.out);
tablePrinter.toTsv(pw2);
pw2.flush();
pw2.close();
if (DUMP_UNIT_TABLE_TO_STDOUT) {
PrintWriter pw2 = new PrintWriter(System.out);
tablePrinter.toTsv(pw2);
pw2.flush();
pw2.close();
}
// for (R4<UnitId, UnitSystem, Rational, String> sk : all) {
// System.out.println(String.format("%s\t%s\t%s\t%s", sk.get0(), sk.get1(),
// sk.get2(), sk.get3()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
import com.ibm.icu.text.Collator;
import com.ibm.icu.util.ICUUncheckedIOException;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Date;
import java.util.Set;
Expand All @@ -16,6 +14,7 @@
import org.unicode.cldr.util.CLDRPaths;
import org.unicode.cldr.util.CldrUtility;
import org.unicode.cldr.util.CollatorHelper;
import org.unicode.cldr.util.TempPrintWriter;

public class FormattedFileWriter extends java.io.Writer {
public static final String CHART_TARGET_DIR = CLDRPaths.CHART_DIRECTORY + "/supplemental/";
Expand Down Expand Up @@ -188,13 +187,10 @@ public static void writeTargetWithReplacements(
String targetFileName,
final String templateFileName,
String[] replacements) {
try {
PrintWriter pw2 =
org.unicode.cldr.draft.FileUtilities.openUTF8Writer(targetdir, targetFileName);
System.err.println("Writing: " + Paths.get(targetdir, targetFileName));
try (final TempPrintWriter pw2 = new TempPrintWriter(targetdir, targetFileName)) {
pw2.noDiff();
FileUtilities.appendBufferedReader(
ToolUtilities.getUTF8Data(templateFileName), pw2, replacements);
pw2.close();
ToolUtilities.getUTF8Data(templateFileName), pw2.asPrintWriter(), replacements);
} catch (IOException e) {
throw new ICUUncheckedIOException(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.unicode.cldr.util.CldrUtility;
import org.unicode.cldr.util.DateTimeFormats;
import org.unicode.cldr.util.FileCopier;
import org.unicode.cldr.util.StackTracker;
import org.unicode.cldr.util.VerifyCompactNumbers;
import org.unicode.cldr.util.VerifyZones;

Expand All @@ -18,14 +19,26 @@
* @author markdavis
*/
public class GenerateAllCharts {
/** print an eyecatcher with the line number of this stage of GenerateAllCharts */
private static void headline(String str) {
StackTraceElement caller = StackTracker.currentElement(0);
System.out.println();
System.out.println("---------------------------");
System.out.println(caller.getFileName() + ":" + caller.getLineNumber() + " " + str);
}

public static void main(String[] args) throws Exception {
headline("Setting Up");
final File mainDir = new File(CLDRPaths.CHART_DIRECTORY);
System.out.println("Writing to " + mainDir.getAbsolutePath());
if (mainDir.mkdirs()) {
System.err.println("Created: " + mainDir);
}
if (!mainDir.isDirectory()) {
throw new IOException("Main dir doesn't exist: " + mainDir);
}

headline("Copying LICENSE, README.md, css, etc.");
FileCopier.copy(CldrUtility.class, "data/LICENSE", CLDRPaths.CHART_DIRECTORY, "LICENSE");
FileCopier.copy(
GenerateAllCharts.class,
Expand All @@ -39,30 +52,49 @@ public static void main(String[] args) throws Exception {
"main-index.html",
CLDRPaths.CHART_DIRECTORY,
"index.html");

headline("Setting Up include htmls");
FormattedFileWriter.copyIncludeHtmls(CLDRPaths.CHART_DIRECTORY);

if (ToolConstants.CHART_VERSION.compareTo("37") >= 0) {
headline("ChartGrammaticalForms");
new ChartGrammaticalForms().writeChart(null);
}

headline("ShowLanguages");
ShowLanguages.main(args);

headline("ChartAnnotations");
new ChartAnnotations().writeChart(null);
headline("ChartSubdivisionNames");
new ChartSubdivisionNames().writeChart(null);
headline("GenerateBcp47Text");
GenerateBcp47Text.main(args);
headline("GenerateSidewaysView");
GenerateSidewaysView.main(args);
headline("ShowData");
ShowData.main(args);

// headline("GenerateTransformCharts");
// GenerateTransformCharts.main(args);
headline("ChartDelta");
ChartDelta.main(args);
headline("ChartDelta - high level");
ChartDelta.main(args, true); // churn
headline("ChartCollation");
ChartCollation.main(args);

headline("VerifyCompactNumbers");
VerifyCompactNumbers.main(args);
headline("VerifyZones");
VerifyZones.main(args);
headline("DateTimeFormats");
DateTimeFormats.main(args);
headline("ChartPersonNames");
new ChartPersonNames().writeChart(null);

headline("GenerateKeyboardCharts");
GenerateKeyboardCharts.main(args);
headline("DONE");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
public class GenerateKeyboardCharts {

static final String SUBDIR = "keyboards";
static IOException copyErr = null;

public static void main(String args[]) throws IOException {
final File mainDir = new File(CLDRPaths.CHART_DIRECTORY);
Expand Down Expand Up @@ -62,8 +63,12 @@ public static void main(String args[]) throws IOException {
} catch (IOException e) {
e.printStackTrace();
System.err.println("Error copying " + path);
System.exit(1);
// will overwrite if more than one- but at least one will be
// thrown.
copyErr = new IOException("Error copying " + path, e);
}
});
// rethrow any error
if (copyErr != null) throw copyErr;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@
@CLDRTool(alias = "showlanguages", description = "Generate Language info charts")
public class ShowLanguages {
private static final boolean SHOW_NATIVE = true;
private static final boolean SHOW_SKIPPED = false;
private static int skipped = 0;

static Comparator col =
new org.unicode.cldr.util.MultiComparator(
Expand All @@ -110,6 +112,12 @@ public static void main(String[] args) throws IOException {
// cldrFactory = Factory.make(Utility.COMMON_DIRECTORY + "../dropbox/extra2/", ".*");
// printLanguageData(cldrFactory, "language_info2.txt");
System.out.println("Done - wrote into " + FormattedFileWriter.CHART_TARGET_DIR);
if (skipped > 0) {
System.err.println(
"*** WARNING ***\nTODO CLDR-1129: "
+ skipped
+ " skipped xpath(s) - set SHOW_SKIPPED=true to debug.");
}
}

/** */
Expand Down Expand Up @@ -920,28 +928,28 @@ public LanguageInfo(Factory cldrFactory) throws IOException {
deprecatedItems.add(parts.findAttributes("deprecatedItems"));
continue;
}
if (path.indexOf("/calendarData") >= 0) {
Map<String, String> attributes = parts.findAttributes("calendar");
if (path.indexOf("/calendarPreferenceData/calendarPreference") >= 0) {
Map<String, String> attributes = parts.findAttributes("calendarPreference");
if (attributes == null) {
System.err.println(
"Err: on path "
+ fullPath
+ " , no attributes on 'calendar'. Probably, this tool is out of date.");
+ " , no attributes on 'calendarPreference'. Probably, this tool is out of date.");
} else {
String type = attributes.get("type");
String ordering = attributes.get("ordering");
String territories = attributes.get("territories");
if (territories == null) {
System.err.println(
"Err: on path "
+ fullPath
+ ", missing territories. Probably, this tool is out of date.");
} else if (type == null) {
} else if (ordering == null) {
System.err.println(
"Err: on path "
+ fullPath
+ ", missing type. Probably, this tool is out of date.");
+ ", missing ordering. Probably, this tool is out of date.");
} else {
addTerritoryInfo(territories, "calendar", type);
addTerritoryInfo(territories, "Preferred Calendar", ordering);
}
}
}
Expand Down Expand Up @@ -985,7 +993,10 @@ public LanguageInfo(Factory cldrFactory) throws IOException {
}
}
if (path.indexOf("/generation") >= 0 || path.indexOf("/version") >= 0) continue;
System.out.println("Skipped Element: " + path);
skipped++;
if (SHOW_SKIPPED) {
System.out.println("Skipped Element: " + path);
}
}

for (String territory : supplementalDataInfo.getTerritoriesWithPopulationData()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ private static void showCoverage(

System.out.println(Joiner.on("\n").join(languageToRegion.asMap().entrySet()));

System.out.println("# Checking: " + availableLanguages);
System.out.println("# Writing coverage: " + availableLanguages);

NumberFormat percentFormat = NumberFormat.getPercentInstance(Locale.ENGLISH);
percentFormat.setMaximumFractionDigits(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ private void calculateCoverage(final String only) {

logger.info(Joiner.on("\n").join(languageToRegion.asMap().entrySet()));

logger.info("# Checking: " + availableLanguages);
logger.info("# Calculating locale coverage: " + availableLanguages);

NumberFormat percentFormat = NumberFormat.getPercentInstance(Locale.ENGLISH);
percentFormat.setMaximumFractionDigits(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public class TempPrintWriter extends Writer {
final String filename;
boolean noReplace = false;
boolean skipCopyright = false;
boolean noDiff = false;

public TempPrintWriter skipCopyright(boolean newSkipCopyright) {
skipCopyright = newSkipCopyright;
Expand All @@ -37,6 +38,15 @@ public PrintWriter asPrintWriter() {
return tempPrintWriter;
}

/**
* turn off the file difference print. Good if you expect a lot of changes, such as with a
* chart.
*/
public TempPrintWriter noDiff() {
noDiff = true;
return this;
}

public static TempPrintWriter openUTF8Writer(String filename) {
return new TempPrintWriter(new File(filename));
}
Expand Down Expand Up @@ -77,7 +87,7 @@ public void close() {
if (noReplace) {
new File(tempName).delete();
} else {
replaceDifferentOrDelete(filename, tempName, skipCopyright);
replaceDifferentOrDelete(filename, tempName);
}
} catch (IOException e) {
throw new ICUUncheckedIOException(e);
Expand Down Expand Up @@ -129,8 +139,7 @@ public void printlnWithTabs(int desiredCount, String textToPrint) {
* If contents(newFile) ≠ contents(oldFile), rename newFile to old. Otherwise delete newfile.
* Return true if replaced. *
*/
private static boolean replaceDifferentOrDelete(
String oldFile, String newFile, boolean skipCopyright) throws IOException {
private boolean replaceDifferentOrDelete(String oldFile, String newFile) throws IOException {
final File oldFile2 = new File(oldFile);
if (oldFile2.exists()) {
final String lines[] = new String[2];
Expand All @@ -139,20 +148,24 @@ private static boolean replaceDifferentOrDelete(
new File(newFile).delete();
return false;
}
System.out.println("Found difference in : " + oldFile + ", " + newFile);
final int diff = compare(lines[0], lines[1]);
System.out.println(
" File1: '"
+ lines[0].substring(0, diff)
+ "', '"
+ lines[0].substring(diff)
+ "'");
System.out.println(
" File2: '"
+ lines[1].substring(0, diff)
+ "', '"
+ lines[1].substring(diff)
+ "'");
if (noDiff) {
System.out.println("Writing: " + oldFile);
} else {
System.out.println("Found difference in : " + oldFile + ", " + newFile);
final int diff = compare(lines[0], lines[1]);
System.out.println(
" File1: '"
+ lines[0].substring(0, diff)
+ "', '"
+ lines[0].substring(diff)
+ "'");
System.out.println(
" File2: '"
+ lines[1].substring(0, diff)
+ "', '"
+ lines[1].substring(diff)
+ "'");
}
}
Files.move(Path.of(newFile), oldFile2.toPath(), StandardCopyOption.REPLACE_EXISTING);
return true;
Expand Down
Loading