From b183f2688074376cab5f2c4af0d76d7320373073 Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Mon, 2 Oct 2023 13:03:55 -0700 Subject: [PATCH] CLDR-17137 Add --skip-license to Ldml2Json --- .../unicode/cldr/json/Ldml2JsonConverter.java | 40 ++++++++++++++----- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/json/Ldml2JsonConverter.java b/tools/cldr-code/src/main/java/org/unicode/cldr/json/Ldml2JsonConverter.java index 0dae63558d1..f9d12a4791c 100644 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/json/Ldml2JsonConverter.java +++ b/tools/cldr-code/src/main/java/org/unicode/cldr/json/Ldml2JsonConverter.java @@ -237,7 +237,13 @@ private class AvailableLocales { 'M', "(true|false)", "true", - "Whether to include the -modern tier"); + "Whether to include the -modern tier") + .add( + "skip-license", + null, + "(true|false)", + "false", + "Whether to include a copy of the Unicode License in the readme"); public static void main(String[] args) throws Exception { System.out.println(GEAR_ICON + " " + Ldml2JsonConverter.class.getName() + " options:"); @@ -288,7 +294,8 @@ static void processType(final String runType) throws Exception { Boolean.parseBoolean(options.get("bcp47").getValue()), Boolean.parseBoolean(options.get("bcp47-no-subtags").getValue()), Boolean.parseBoolean(options.get("Modern").getValue()), - Boolean.parseBoolean(options.get("Redundant").getValue())); + Boolean.parseBoolean(options.get("Redundant").getValue())), + Boolean.parseBoolean(options.get("skip-license").getValue()) DraftStatus status = DraftStatus.valueOf(options.get("draftstatus").getValue()); l2jc.processDirectory(runType, status); @@ -331,6 +338,7 @@ public int compareTo(JSONSection other) { private final String pkgVersion; private final boolean strictBcp47; private final boolean writeModernPackage; + private final boolean skipLicense; private final boolean skipBcp47LocalesWithSubtags; private LdmlConfigFileReader configFileReader; @@ -348,7 +356,8 @@ public Ldml2JsonConverter( boolean strictBcp47, boolean skipBcp47LocalesWithSubtags, boolean writeModernPackage, - boolean includeRedundant) { + boolean includeRedundant, + boolean skipLicense) { this.writeModernPackage = writeModernPackage; this.strictBcp47 = strictBcp47; this.skipBcp47LocalesWithSubtags = strictBcp47 && skipBcp47LocalesWithSubtags; @@ -376,6 +385,7 @@ public Ldml2JsonConverter( this.sections = configFileReader.getSections(); this.packages = new TreeSet<>(); this.includeRedundant = includeRedundant; + this.skipLicense = skipLicense; } /** @@ -1187,10 +1197,18 @@ public void writePackagingFiles(String outputDir, String packageName) throws IOE /** Write the ## License section */ public void writeCopyrightSection(PrintWriter out) { - out.println( - CldrUtility.getCopyrightMarkdown() - + "\n" - + "A copy of the license is included as [LICENSE](./LICENSE)."); + if (skipLicense) { + out.println( + CldrUtility.getCopyrightMarkdown() + + "\n" + + "A copy of the license is not included; please do not distribute."); + + } else { + out.println( + CldrUtility.getCopyrightMarkdown() + + "\n" + + "A copy of the license is included as [LICENSE](./LICENSE)."); + } } /** @@ -1230,9 +1248,11 @@ public void writeReadme(String outputDir, String packageName) throws IOException outf.println(); writeReadmeSection(outf); } - try (PrintWriter outf = - FileUtilities.openUTF8Writer(outputDir + "/" + packageName, "LICENSE"); ) { - FileCopier.copy(CldrUtility.getUTF8Data(CldrUtility.LICENSE), outf); + if (!skipLicense) { + try (PrintWriter outf = + FileUtilities.openUTF8Writer(outputDir + "/" + packageName, "LICENSE"); ) { + FileCopier.copy(CldrUtility.getUTF8Data(CldrUtility.LICENSE), outf); + } } }