|
|
@ -20,6 +20,7 @@ import com.google.i18n.phonenumbers.Phonemetadata.PhoneMetadata; |
|
|
import com.google.i18n.phonenumbers.Phonemetadata.PhoneMetadataCollection; |
|
|
import com.google.i18n.phonenumbers.Phonemetadata.PhoneMetadataCollection; |
|
|
|
|
|
|
|
|
import java.io.BufferedWriter; |
|
|
import java.io.BufferedWriter; |
|
|
|
|
|
import java.io.File; |
|
|
import java.io.FileOutputStream; |
|
|
import java.io.FileOutputStream; |
|
|
import java.io.FileWriter; |
|
|
import java.io.FileWriter; |
|
|
import java.io.IOException; |
|
|
import java.io.IOException; |
|
|
@ -38,7 +39,7 @@ public class BuildMetadataProtoFromXml extends Command { |
|
|
private static final String META_DATA_FILE_PREFIX = |
|
|
private static final String META_DATA_FILE_PREFIX = |
|
|
"/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto"; |
|
|
"/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto"; |
|
|
private static final String TEST_META_DATA_FILE_PREFIX = |
|
|
private static final String TEST_META_DATA_FILE_PREFIX = |
|
|
"/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProtoForTesting"; |
|
|
|
|
|
|
|
|
"/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProtoForTesting"; |
|
|
private static final String TEST_COUNTRY_CODE_TO_REGION_CODE_MAP_CLASS_NAME = |
|
|
private static final String TEST_COUNTRY_CODE_TO_REGION_CODE_MAP_CLASS_NAME = |
|
|
"CountryCodeToRegionCodeMapForTesting"; |
|
|
"CountryCodeToRegionCodeMapForTesting"; |
|
|
private static final String COUNTRY_CODE_TO_REGION_CODE_MAP_CLASS_NAME = |
|
|
private static final String COUNTRY_CODE_TO_REGION_CODE_MAP_CLASS_NAME = |
|
|
@ -50,7 +51,7 @@ public class BuildMetadataProtoFromXml extends Command { |
|
|
"\n" + |
|
|
"\n" + |
|
|
"where:\n" + |
|
|
"where:\n" + |
|
|
" inputFile The input file containing phone number metadata in XML format.\n" + |
|
|
" inputFile The input file containing phone number metadata in XML format.\n" + |
|
|
" outputDir The output directory to store phone number metadata in proto\n" + |
|
|
|
|
|
|
|
|
" outputDir The output source directory to store phone number metadata in proto\n" + |
|
|
" format (one file per region) and the country code to region code\n" + |
|
|
" format (one file per region) and the country code to region code\n" + |
|
|
" mapping file.\n" + |
|
|
" mapping file.\n" + |
|
|
" forTesting Flag whether to generate metadata for testing purposes or not.\n" + |
|
|
" forTesting Flag whether to generate metadata for testing purposes or not.\n" + |
|
|
@ -67,6 +68,11 @@ public class BuildMetadataProtoFromXml extends Command { |
|
|
"Example command line invocation:\n" + |
|
|
"Example command line invocation:\n" + |
|
|
"BuildMetadataProtoFromXml PhoneNumberMetadata.xml src false false\n"; |
|
|
"BuildMetadataProtoFromXml PhoneNumberMetadata.xml src false false\n"; |
|
|
|
|
|
|
|
|
|
|
|
private static final String GENERATION_COMMENT = |
|
|
|
|
|
"/* This file is automatically generated by {@link BuildMetadataProtoFromXml}.\n" + |
|
|
|
|
|
" * Please don't modify it directly.\n" + |
|
|
|
|
|
" */\n"; |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public String getCommandName() { |
|
|
public String getCommandName() { |
|
|
return "BuildMetadataProtoFromXml"; |
|
|
return "BuildMetadataProtoFromXml"; |
|
|
@ -84,6 +90,12 @@ public class BuildMetadataProtoFromXml extends Command { |
|
|
boolean forTesting = args[3].equals("true"); |
|
|
boolean forTesting = args[3].equals("true"); |
|
|
boolean liteBuild = args.length > 4 && args[4].equals("true"); |
|
|
boolean liteBuild = args.length > 4 && args[4].equals("true"); |
|
|
|
|
|
|
|
|
|
|
|
if (!FileUtils.isGenerationRequired( |
|
|
|
|
|
new File(inputFile), |
|
|
|
|
|
new File(outputDir, new File(META_DATA_FILE_PREFIX).getParent()))) { |
|
|
|
|
|
System.out.println("Metadata code up-to-date."); |
|
|
|
|
|
return true; |
|
|
|
|
|
} |
|
|
String filePrefix; |
|
|
String filePrefix; |
|
|
if (forTesting) { |
|
|
if (forTesting) { |
|
|
filePrefix = outputDir + TEST_META_DATA_FILE_PREFIX; |
|
|
filePrefix = outputDir + TEST_META_DATA_FILE_PREFIX; |
|
|
@ -113,6 +125,7 @@ public class BuildMetadataProtoFromXml extends Command { |
|
|
System.err.println(HELP_MESSAGE); |
|
|
System.err.println(HELP_MESSAGE); |
|
|
return false; |
|
|
return false; |
|
|
} |
|
|
} |
|
|
|
|
|
System.out.println("Metadata code successfully generated."); |
|
|
return true; |
|
|
return true; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -140,15 +153,14 @@ public class BuildMetadataProtoFromXml extends Command { |
|
|
} else { |
|
|
} else { |
|
|
mappingClassName = COUNTRY_CODE_TO_REGION_CODE_MAP_CLASS_NAME; |
|
|
mappingClassName = COUNTRY_CODE_TO_REGION_CODE_MAP_CLASS_NAME; |
|
|
} |
|
|
} |
|
|
String mappingFile = |
|
|
|
|
|
outputDir + "/" + PACKAGE_NAME.replaceAll("\\.", "/") + "/" + mappingClassName + ".java"; |
|
|
|
|
|
|
|
|
String mappingFile = outputDir + "/" + PACKAGE_NAME + "/" + mappingClassName + ".java"; |
|
|
int capacity = (int) (countryCodeToRegionCodeMap.size() / MAPPING_LOAD_FACTOR); |
|
|
int capacity = (int) (countryCodeToRegionCodeMap.size() / MAPPING_LOAD_FACTOR); |
|
|
|
|
|
|
|
|
BufferedWriter writer = new BufferedWriter(new FileWriter(mappingFile)); |
|
|
BufferedWriter writer = new BufferedWriter(new FileWriter(mappingFile)); |
|
|
|
|
|
|
|
|
writer.write(CopyrightNotice.TEXT); |
|
|
|
|
|
|
|
|
writer.write(CopyrightNotice.TEXT + "\n" + GENERATION_COMMENT + "\n"); |
|
|
if (PACKAGE_NAME.length() > 0) { |
|
|
if (PACKAGE_NAME.length() > 0) { |
|
|
writer.write("package " + PACKAGE_NAME + ";\n\n"); |
|
|
|
|
|
|
|
|
writer.write("package " + PACKAGE_NAME.replaceAll("/", ".") + ";\n\n"); |
|
|
} |
|
|
} |
|
|
writer.write(MAPPING_IMPORTS); |
|
|
writer.write(MAPPING_IMPORTS); |
|
|
writer.write("\n"); |
|
|
writer.write("\n"); |
|
|
|