Skip to content

Commit

Permalink
Updates per review comments
Browse files Browse the repository at this point in the history
- typo/tab fixes
- add a unit test for Settings.UnicodeTools.DataDir
- Apply other suggestions from code review

Co-authored-by: Markus Scherer <[email protected]>
  • Loading branch information
srl295 and markusicu committed Jul 21, 2021
1 parent c9461c5 commit 933d2b8
Show file tree
Hide file tree
Showing 8 changed files with 88 additions and 57 deletions.
3 changes: 1 addition & 2 deletions UnicodeJsps/src/main/java/org/unicode/jsp/ScriptTester.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import java.util.Set;
import java.util.TreeMap;
import java.util.TreeSet;
import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.logging.Logger;
Expand Down Expand Up @@ -81,7 +80,7 @@ public static String getScriptName(int extendedScriptCode, int choice) {
if (extendedScriptCode >= LIMIT) {
return EXTENDED_NAME[extendedScriptCode - LIMIT][choice];
} else {
for (Entry<String, Integer> e : extraScripts.entrySet()) {
for (Map.Entry<String, Integer> e : extraScripts.entrySet()) {
if(e.getValue() == extendedScriptCode) {
if(choice == 0) {
return e.getKey();
Expand Down
3 changes: 2 additions & 1 deletion docs/unicodejsps/index.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
git # Building UnicodeJsp
# Building UnicodeJsp

## Compiling
### Prerequisites
Expand Down Expand Up @@ -50,6 +50,7 @@ within eclipse. It is unknown whether this has been attempted with the UnicodeJ

This will copy a number of files from the unicodetools to the Jsp directory.
The items it doesn't cover are discussed below.

### Other

`{$workspace}/unicodetools/data/emoji/\<VERSION\>`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public static void main(String[] args) throws IOException {
IndexUnicodeProperties latest = IndexUnicodeProperties.make();
VersionInfo ucdVersion = latest.getUcdVersion();
System.out.println("Copying Props for " + ucdVersion + " into JSP");
String fromDir = Settings.Output.BIN_DIR + ucdVersion + "/";
String fromDir = Settings.Output.BIN_DIR + ucdVersion + "/";
String toDir = Settings.UnicodeTools.UNICODEJSPS_DIR + "src/main/resources/org/unicode/jsp/props/";
//overwrite existing file, if exists
CopyOption[] options = new CopyOption[] {StandardCopyOption.REPLACE_EXISTING, StandardCopyOption.COPY_ATTRIBUTES};
Expand Down
2 changes: 1 addition & 1 deletion unicodetools/org/unicode/propstest/ListProps.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
public class ListProps {

private static final String BIN_PROPS = Settings.Output.BIN_DIR;
private static final UcdProperty DEBUG_LIST_VALUES = null ; // UcdProperty.Confusable_MA;
private static final UcdProperty DEBUG_LIST_VALUES = null ; // UcdProperty.Confusable_MA;
private static String ONLY_PROP = null; // "Emoji";
static final boolean ONLY_JSP = true;

Expand Down
65 changes: 33 additions & 32 deletions unicodetools/org/unicode/text/tools/GenerateSubtagNames.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,61 +18,62 @@

public class GenerateSubtagNames {
public static void main(String[] args) {
int n = generate(System.out);
System.err.println("# Generated " + n + " entries");
int n = generate(System.out);
System.err.println("# Generated " + n + " entries");
}

public static int generate(OutputStream toStream) {
try (PrintWriter pw = new PrintWriter(toStream)) {
return generate(pw);
}
try (PrintWriter pw = new PrintWriter(toStream)) {
return generate(pw);
}
}

public static int generate(PrintWriter toStream) {
Map<String, String> seen = generate();
toStream.append("# GenerateSubtagNames\n");
for (Entry<String, String> entry2 : seen.entrySet()) {
toStream.append(entry2.getKey() + ";" + entry2.getValue() + "\n");
toStream.append(entry2.getKey() + ";" + entry2.getValue() + "\n");
}
return seen.size();
}

private static Map<String, String> generate() {
Map<String,String> seen = new TreeMap();
private static Map<String, String> generate() {
Map<String, String> seen = new TreeMap();
CLDRConfig config = CLDRConfig.getInstance();
SupplementalDataInfo sdi = config.getSupplementalDataInfo();
StandardCodes sc = StandardCodes.make();
CLDRFile english = config.getEnglish();
Set<String> CODE_OK = new HashSet(Arrays.asList("QO", "UK", "ZZ"));
for (Entry<LstrType, Map<String, Map<LstrField, String>>> entry : StandardCodes
.getEnumLstreg().entrySet()) {
for (Entry<LstrType, Map<String, Map<LstrField, String>>> entry : StandardCodes.getEnumLstreg().entrySet()) {
LstrType type = entry.getKey();
int cldrType = -1;
switch(type) {
case language: cldrType = CLDRFile.LANGUAGE_NAME; break;
case script: cldrType = CLDRFile.SCRIPT_NAME; break;
case region: cldrType = CLDRFile.TERRITORY_NAME; break;
case variant:
break;
case extlang:
case redundant:
case legacy:
continue;
switch (type) {
case language:
cldrType = CLDRFile.LANGUAGE_NAME;
break;
case script:
cldrType = CLDRFile.SCRIPT_NAME;
break;
case region:
cldrType = CLDRFile.TERRITORY_NAME;
break;
case variant:
break;
case extlang:
case redundant:
case legacy:
continue;
}

for (Entry<String, Map<LstrField, String>> entry2 : entry.getValue().entrySet()) {
String code = entry2.getKey();
final Map<LstrField, String> fieldToValue = entry2.getValue();
String scope = fieldToValue.get(LstrField.Scope);
if (scope != null
&& scope.equals("private-use")
&& !CODE_OK.contains(code)) {
if (scope != null && scope.equals("private-use") && !CODE_OK.contains(code)) {
continue;
}
String description = fieldToValue.get(LstrField.Description);
if (description != null
&& description.equalsIgnoreCase("Private use")
&& !CODE_OK.contains(code)) {
if (description != null && description.equalsIgnoreCase("Private use") && !CODE_OK.contains(code)) {
continue;
}
if (seen.containsKey(code)) {
Expand All @@ -88,8 +89,8 @@ private static Map<String, String> generate() {
seen.put(code, name);
}
}
return seen;
}
return seen;
}

public static final String SUBTAG_NAMES_TXT = "subtagNames.txt";
public static final String SUBTAG_NAMES_TXT = "subtagNames.txt";
}
21 changes: 12 additions & 9 deletions unicodetools/org/unicode/text/utility/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,25 +76,28 @@ public static final class UnicodeTools {
public static final String UNICODETOOLS_DIR = UNICODETOOLS_REPO_DIR + "unicodetools/";
public static final String UNICODEJSPS_DIR = UNICODETOOLS_REPO_DIR + "UnicodeJsps/";
public static final String DATA_DIR = UNICODETOOLS_DIR + "data/";
public static final Path DATA_FILE = Paths.get(DATA_DIR);
public static final Path DATA_PATH = Paths.get(DATA_DIR);
public static final String UCD_DIR = DATA_DIR + "ucd/";
// TODO: IDN_DIR is used, but there is no .../data/IDN/ folder. Should this be .../data/idna/ ?
public static final String IDN_DIR = DATA_DIR + "IDN/";
// TODO: DICT_DIR is used, but there is no .../data/dict/ folder. ??
public static final String DICT_DIR = DATA_DIR + "dict/";

/**
* Constants representing data subdirectories
*/
public enum DataDir {
security,
ucd,
idna,
emoji;
SECURITY,
UCD,
IDNA,
EMOJI;

/**
* This dir as a Path
* @return
*/
public Path asPath() {
return DATA_FILE.resolve(name());
return DATA_PATH.resolve(name().toLowerCase());
}
/**
* This dir as a Path to the version subdir
Expand All @@ -103,7 +106,7 @@ public Path asPath() {
*/
public Path asPath(VersionInfo forVersion) {
String versionString = versionToString(forVersion);
if (this == ucd) {
if (this == UCD) {
// For some reason, these have -Update
return asPath().resolve(versionString + "-Update");
} else {
Expand All @@ -120,10 +123,10 @@ public String versionToString(VersionInfo version) {
sb.append(version.getMajor())
.append(".")
.append(version.getMinor());
if (this != emoji) {
if (this != EMOJI) {
// 13.1, 14.0
sb.append(".")
.append(version.getMicro());
.append(version.getMilli());
} // else: 14.0.0
return sb.toString();
}
Expand Down
12 changes: 6 additions & 6 deletions unicodetools/org/unicode/tools/UpdateJspFiles.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public static void main(String args[]) throws IOException {
System.out.println("Sublaunching ListProps..");
ListProps.main(args);

// Sublaunch listProps
// Sublaunch CopyPropsToUnicodeJsp
System.out.println("Sublaunching CopyPropsToUnicodeJsp");
CopyPropsToUnicodeJsp.main(args);

Expand All @@ -56,18 +56,18 @@ public static void main(String args[]) throws IOException {

private static void copyTextFiles(VersionInfo fromVersion) throws IOException {
System.out.println("1. Copying text files from " + fromVersion);
copyTextFiles(fromVersion, Settings.UnicodeTools.DataDir.security,
copyTextFiles(fromVersion, Settings.UnicodeTools.DataDir.SECURITY,
"confusables.txt",
"IdentifierStatus.txt",
"IdentifierType.txt");
copyTextFiles(fromVersion, Settings.UnicodeTools.DataDir.ucd,
copyTextFiles(fromVersion, Settings.UnicodeTools.DataDir.UCD,
"NameAliases.txt",
"NamesList.txt",
"ScriptExtensions.txt",
"StandardizedVariants.txt");
copyTextFiles(fromVersion, Settings.UnicodeTools.DataDir.idna,
copyTextFiles(fromVersion, Settings.UnicodeTools.DataDir.IDNA,
"IdnaMappingTable.txt");
copyTextFiles(fromVersion, Settings.UnicodeTools.DataDir.emoji,
copyTextFiles(fromVersion, Settings.UnicodeTools.DataDir.EMOJI,
"emoji-sequences.txt",
"emoji-zwj-sequences.txt");
System.err.println("TODO: <emoji-variants>");
Expand Down Expand Up @@ -134,7 +134,7 @@ private static void copyOtherProps(VersionInfo fromVersion) throws IOException {
"ExtraPropertyValueAliases.txt");

// Nota Bene! These aren't in the earlier list, becaause they are in the /data and not /ucd dir
copyTextFiles(JSP_RESOURCE_DATA.resolve("data"), fromVersion, Settings.UnicodeTools.DataDir.ucd,
copyTextFiles(JSP_RESOURCE_DATA.resolve("data"), fromVersion, Settings.UnicodeTools.DataDir.UCD,
"PropertyAliases.txt",
"PropertyValueAliases.txt");

Expand Down
37 changes: 32 additions & 5 deletions unicodetools/org/unicode/unittest/TestSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.io.File;
import java.lang.reflect.Field;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
Expand All @@ -13,23 +14,24 @@
import org.unicode.text.utility.Utility;

import com.ibm.icu.dev.test.TestFmwk;
import com.ibm.icu.util.VersionInfo;

public class TestSettings extends TestFmwk{

static final Set<String> Settings_to_skip = new HashSet(Arrays.asList(
"latestVersion",
"latestVersion",
"lastVersion"
));

static final Set<String> CLDRPaths_to_skip = new HashSet(Arrays.asList(
"COMPARE_PROGRAM",
"COMPARE_PROGRAM",
"UNICODE_VERSION"
));

public static void main(String[] args) {
new TestSettings().run(args);
}

public void TestDirs() throws IllegalArgumentException, IllegalAccessException {
checkDirs(Settings.class, Settings_to_skip);
checkDirs(CLDRPaths.class, CLDRPaths_to_skip);
Expand Down Expand Up @@ -66,4 +68,29 @@ private void checkDirs(Class<?> class1, Set<String> skips) throws IllegalAccessE
}
}
}

public void TestDataDirVersion() {
assertEquals("Emoji 1.2", "1.2",
Settings.UnicodeTools.DataDir.EMOJI.versionToString(VersionInfo.getInstance(1, 2, 3, 4)));
assertEquals("UCD 1.2.3", "1.2.3",
Settings.UnicodeTools.DataDir.UCD.versionToString(VersionInfo.getInstance(1, 2, 3, 4)));
assertEquals("Emoji 1.0", "1.0",
Settings.UnicodeTools.DataDir.EMOJI.versionToString(VersionInfo.getInstance(1, 0, 0, 0)));
assertEquals("UCD 1.0.0", "1.0.0",
Settings.UnicodeTools.DataDir.UCD.versionToString(VersionInfo.getInstance(1, 0, 0, 0)));
}

public void TestDataDirPath() {
assertEquals("Emoji 1.2", Settings.UnicodeTools.DATA_PATH.resolve("emoji/1.2"),
Settings.UnicodeTools.DataDir.EMOJI.asPath(VersionInfo.getInstance(1, 2, 3, 4)));
assertEquals("UCD 1.2.3", Settings.UnicodeTools.DATA_PATH.resolve("ucd/1.2.3-Update"),
Settings.UnicodeTools.DataDir.UCD.asPath(VersionInfo.getInstance(1, 2, 3, 4)));
assertEquals("Security 1.0.0", Settings.UnicodeTools.DATA_PATH.resolve("security/1.0.0"),
Settings.UnicodeTools.DataDir.SECURITY.asPath(VersionInfo.getInstance(1, 0, 0, 0)));
assertEquals("Emoji 1.0", Settings.UnicodeTools.DATA_PATH.resolve("emoji/1.0"),
Settings.UnicodeTools.DataDir.EMOJI.asPath(VersionInfo.getInstance(1, 0, 0, 0)));
assertEquals("UCD 1.0.0", Settings.UnicodeTools.DATA_PATH.resolve("ucd/1.0.0-Update"),
Settings.UnicodeTools.DataDir.UCD.asPath(VersionInfo.getInstance(1, 0, 0, 0)));
}

}

0 comments on commit 933d2b8

Please sign in to comment.