Skip to content

Commit

Permalink
CLDR-17137 Add --skip-license to Ldml2Json
Browse files Browse the repository at this point in the history
  • Loading branch information
Manishearth committed Oct 2, 2023
1 parent fadf398 commit b183f26
Showing 1 changed file with 30 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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:");
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;

Expand All @@ -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;
Expand Down Expand Up @@ -376,6 +385,7 @@ public Ldml2JsonConverter(
this.sections = configFileReader.getSections();
this.packages = new TreeSet<>();
this.includeRedundant = includeRedundant;
this.skipLicense = skipLicense;
}

/**
Expand Down Expand Up @@ -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).");
}
}

/**
Expand Down Expand Up @@ -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);
}
}
}

Expand Down

0 comments on commit b183f26

Please sign in to comment.