Browse Source

Fixed a few findbugs warnings and added a build rule to generate metadata for JavaScript.

pull/567/head
Nikolaos Trogkanis 15 years ago
committed by Mihaela Rosca
parent
commit
2980262b6d
25 changed files with 105 additions and 119 deletions
  1. +30
    -6
      java/build.xml
  2. +0
    -2
      java/pom.xml
  3. +1
    -1
      java/src/com/google/i18n/phonenumbers/AsYouTypeFormatter.java
  4. +1
    -1
      java/src/com/google/i18n/phonenumbers/CountryCodeToRegionCodeMap.java
  5. +2
    -2
      java/src/com/google/i18n/phonenumbers/PhoneNumberUtil.java
  6. +1
    -1
      java/src/com/google/i18n/phonenumbers/RegexCache.java
  7. +1
    -1
      java/src/com/google/i18n/phonenumbers/geocoding/AreaCodeMap.java
  8. +1
    -1
      java/src/com/google/i18n/phonenumbers/geocoding/AreaCodeMapStorageStrategy.java
  9. +1
    -1
      java/test/com/google/i18n/phonenumbers/CountryCodeToRegionCodeMapForTesting.java
  10. +1
    -1
      java/test/com/google/i18n/phonenumbers/PhoneNumberMatcherTest.java
  11. +5
    -14
      javascript/README
  12. +2
    -2
      javascript/i18n/phonenumbers/metadata.js
  13. +2
    -2
      javascript/i18n/phonenumbers/metadatalite.js
  14. +3
    -48
      tools/java/common/pom.xml
  15. +0
    -1
      tools/java/common/src/com/google/i18n/phonenumbers/tools/BuildMetadataFromXml.java
  16. +27
    -5
      tools/java/common/src/com/google/i18n/phonenumbers/tools/CopyrightNotice.java
  17. +6
    -8
      tools/java/common/test/com/google/i18n/phonenumbers/tools/BuildMetadataFromXmlTest.java
  18. +1
    -1
      tools/java/cpp-build/pom.xml
  19. +5
    -3
      tools/java/cpp-build/src/com/google/i18n/phonenumbers/tools/BuildMetadataCppFromXml.java
  20. BIN
      tools/java/cpp-build/target/cpp-build-1.0-SNAPSHOT-jar-with-dependencies.jar
  21. +1
    -1
      tools/java/java-build/pom.xml
  22. +4
    -2
      tools/java/java-build/src/com/google/i18n/phonenumbers/tools/BuildMetadataJsonFromXml.java
  23. +5
    -4
      tools/java/java-build/src/com/google/i18n/phonenumbers/tools/BuildMetadataProtoFromXml.java
  24. +5
    -11
      tools/java/java-build/src/com/google/i18n/phonenumbers/tools/GenerateAreaCodeData.java
  25. BIN
      tools/java/java-build/target/java-build-1.0-SNAPSHOT-jar-with-dependencies.jar

+ 30
- 6
java/build.xml View File

@ -52,7 +52,6 @@
<arg value="GenerateAreaCodeData"/> <arg value="GenerateAreaCodeData"/>
<arg value="../resources/geocoding/"/> <arg value="../resources/geocoding/"/>
<arg value="src/com/google/i18n/phonenumbers/geocoding/data"/> <arg value="src/com/google/i18n/phonenumbers/geocoding/data"/>
<arg value="false"/> <!-- Not for testing. -->
</exec> </exec>
</target> </target>
@ -63,15 +62,41 @@
<arg value="GenerateAreaCodeData"/> <arg value="GenerateAreaCodeData"/>
<arg value="../resources/test/geocoding/"/> <arg value="../resources/test/geocoding/"/>
<arg value="test/com/google/i18n/phonenumbers/geocoding/testing_data"/> <arg value="test/com/google/i18n/phonenumbers/geocoding/testing_data"/>
<arg value="false"/> <!-- Not for testing. -->
</exec>
</target>
<target name="build-js-metadata">
<exec executable="java">
<arg value="-jar" />
<arg value="../tools/java/java-build/target/java-build-1.0-SNAPSHOT-jar-with-dependencies.jar"/>
<arg value="BuildMetadataJsonFromXml"/>
<arg value="../resources/PhoneNumberMetaData.xml"/>
<arg value="../javascript/i18n/phonenumbers/metadata.js"/>
</exec>
<exec executable="java">
<arg value="-jar" />
<arg value="../tools/java/java-build/target/java-build-1.0-SNAPSHOT-jar-with-dependencies.jar"/>
<arg value="BuildMetadataJsonFromXml"/>
<arg value="../resources/PhoneNumberMetaData.xml"/>
<arg value="../javascript/i18n/phonenumbers/metadatalite.js"/>
<arg value="true"/> <!-- Lite metadata. -->
</exec>
<exec executable="java">
<arg value="-jar" />
<arg value="../tools/java/java-build/target/java-build-1.0-SNAPSHOT-jar-with-dependencies.jar"/>
<arg value="BuildMetadataJsonFromXml"/>
<arg value="../resources/PhoneNumberMetaDataForTesting.xml"/>
<arg value="../javascript/i18n/phonenumbers/metadatafortesting.js"/>
</exec> </exec>
</target> </target>
<target name="compile" description="Compile Java source." <target name="compile" description="Compile Java source."
depends="build-metadata,build-geo-data"> depends="build-metadata,build-geo-data">
<mkdir dir="${classes.dir}"/> <mkdir dir="${classes.dir}"/>
<javac srcdir="${src.dir}" destdir="${classes.dir}" classpathref="classpath"/>
<javac srcdir="${test.dir}" destdir="${classes.dir}" classpathref="classpath" debug="on"/>
<javac srcdir="${src.dir}" destdir="${classes.dir}"
classpathref="classpath" includeAntRuntime="false"/>
<javac srcdir="${test.dir}" destdir="${classes.dir}"
classpathref="classpath" debug="on" includeAntRuntime="false"/>
</target> </target>
<target name="jar" depends="compile"> <target name="jar" depends="compile">
@ -81,7 +106,6 @@
<include name="**/*.class"/> <include name="**/*.class"/>
<exclude name="**/*Test*"/> <exclude name="**/*Test*"/>
<exclude name="**/BuildMetadata*"/> <exclude name="**/BuildMetadata*"/>
<exclude name="**/JSArrayBuilder*"/>
<exclude name="**/geocoding/*"/> <exclude name="**/geocoding/*"/>
</fileset> </fileset>
<fileset dir="${src.dir}"> <fileset dir="${src.dir}">
@ -125,7 +149,7 @@
<junit printsummary="yes"> <junit printsummary="yes">
<classpath refid="test.classpath"/> <classpath refid="test.classpath"/>
<formatter type="xml"/> <formatter type="xml"/>
<batchtest fork="no" todir="${report.dir}">
<batchtest fork="yes" todir="${report.dir}">
<fileset dir="${test.dir}" includes="**/*Test.java"/> <fileset dir="${test.dir}" includes="**/*Test.java"/>
</batchtest> </batchtest>
</junit> </junit>


+ 0
- 2
java/pom.xml View File

@ -245,7 +245,6 @@
<argument>GenerateAreaCodeData</argument> <argument>GenerateAreaCodeData</argument>
<argument>../resources/geocoding</argument> <argument>../resources/geocoding</argument>
<argument>src/com/google/i18n/phonenumbers/geocoding/data</argument> <argument>src/com/google/i18n/phonenumbers/geocoding/data</argument>
<argument>false</argument> <!-- Not for testing. -->
</arguments> </arguments>
</configuration> </configuration>
</execution> </execution>
@ -263,7 +262,6 @@
<argument>GenerateAreaCodeData</argument> <argument>GenerateAreaCodeData</argument>
<argument>../resources/test/geocoding</argument> <argument>../resources/test/geocoding</argument>
<argument>test/com/google/i18n/phonenumbers/geocoding/testing_data</argument> <argument>test/com/google/i18n/phonenumbers/geocoding/testing_data</argument>
<argument>true</argument> <!-- For testing. -->
</arguments> </arguments>
</configuration> </configuration>
</execution> </execution>


+ 1
- 1
java/src/com/google/i18n/phonenumbers/AsYouTypeFormatter.java View File

@ -470,7 +470,7 @@ public class AsYouTypeFormatter {
nationalNumber.setLength(0); nationalNumber.setLength(0);
nationalNumber.append(numberWithoutCountryCallingCode); nationalNumber.append(numberWithoutCountryCallingCode);
String newRegionCode = phoneUtil.getRegionCodeForCountryCode(countryCode); String newRegionCode = phoneUtil.getRegionCodeForCountryCode(countryCode);
if (newRegionCode != defaultCountry) {
if (!newRegionCode.equals(defaultCountry)) {
currentMetaData = getMetadataForRegion(newRegionCode); currentMetaData = getMetadataForRegion(newRegionCode);
} }
String countryCodeString = Integer.toString(countryCode); String countryCodeString = Integer.toString(countryCode);


+ 1
- 1
java/src/com/google/i18n/phonenumbers/CountryCodeToRegionCodeMap.java View File

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2011 Google Inc.
* Copyright (C) 2010 Google Inc.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.


+ 2
- 2
java/src/com/google/i18n/phonenumbers/PhoneNumberUtil.java View File

@ -2346,7 +2346,7 @@ public class PhoneNumberUtil {
* @param secondNumber second number to compare. Can contain formatting, and can have country * @param secondNumber second number to compare. Can contain formatting, and can have country
* calling code specified with + at the start. * calling code specified with + at the start.
* @return NOT_A_NUMBER, NO_MATCH, SHORT_NSN_MATCH, NSN_MATCH, EXACT_MATCH. See * @return NOT_A_NUMBER, NO_MATCH, SHORT_NSN_MATCH, NSN_MATCH, EXACT_MATCH. See
* isNumberMatch(PhoneNumber firstNumber, PhoneNumber secondNumber) for more details.
* {@link #isNumberMatch(PhoneNumber, PhoneNumber)} for more details.
*/ */
public MatchType isNumberMatch(String firstNumber, String secondNumber) { public MatchType isNumberMatch(String firstNumber, String secondNumber) {
try { try {
@ -2384,7 +2384,7 @@ public class PhoneNumberUtil {
* @param secondNumber second number to compare. Can contain formatting, and can have country * @param secondNumber second number to compare. Can contain formatting, and can have country
* calling code specified with + at the start. * calling code specified with + at the start.
* @return NOT_A_NUMBER, NO_MATCH, SHORT_NSN_MATCH, NSN_MATCH, EXACT_MATCH. See * @return NOT_A_NUMBER, NO_MATCH, SHORT_NSN_MATCH, NSN_MATCH, EXACT_MATCH. See
* isNumberMatch(PhoneNumber firstNumber, PhoneNumber secondNumber) for more details.
* {@link #isNumberMatch(PhoneNumber, PhoneNumber)} for more details.
*/ */
public MatchType isNumberMatch(PhoneNumber firstNumber, String secondNumber) { public MatchType isNumberMatch(PhoneNumber firstNumber, String secondNumber) {
// First see if the second number has an implicit country calling code, by attempting to parse // First see if the second number has an implicit country calling code, by attempting to parse


+ 1
- 1
java/src/com/google/i18n/phonenumbers/RegexCache.java View File

@ -46,7 +46,7 @@ public class RegexCache {
return cache.containsKey(regex); return cache.containsKey(regex);
} }
private class LRUCache<K, V> {
private static class LRUCache<K, V> {
// LinkedHashMap offers a straightforward implementation of LRU cache. // LinkedHashMap offers a straightforward implementation of LRU cache.
private LinkedHashMap<K, V> map; private LinkedHashMap<K, V> map;
private int size; private int size;


+ 1
- 1
java/src/com/google/i18n/phonenumbers/geocoding/AreaCodeMap.java View File

@ -185,7 +185,7 @@ public class AreaCodeMap implements Externalizable {
private int binarySearch(int start, int end, long value) { private int binarySearch(int start, int end, long value) {
int current = 0; int current = 0;
while (start <= end) { while (start <= end) {
current = (start + end) / 2;
current = (start + end) >>> 1;
int currentValue = areaCodeMapStorage.getPrefix(current); int currentValue = areaCodeMapStorage.getPrefix(current);
if (currentValue == value) { if (currentValue == value) {
return current; return current;


+ 1
- 1
java/src/com/google/i18n/phonenumbers/geocoding/AreaCodeMapStorageStrategy.java View File

@ -40,7 +40,7 @@ abstract class AreaCodeMapStorageStrategy {
* *
* @param countryCallingCode the country calling code of the number prefixes contained in the map * @param countryCallingCode the country calling code of the number prefixes contained in the map
* @param isLeadingZeroPossible whether the phone number prefixes belong to a region which * @param isLeadingZeroPossible whether the phone number prefixes belong to a region which
* {@link PhoneNumberUtil#isLeadingZeroPossible isLeadingZeroPossible}
* {@link com.google.i18n.phonenumbers.PhoneNumberUtil#isLeadingZeroPossible}
*/ */
public AreaCodeMapStorageStrategy(int countryCallingCode, boolean isLeadingZeroPossible) { public AreaCodeMapStorageStrategy(int countryCallingCode, boolean isLeadingZeroPossible) {
this.countryCallingCode = countryCallingCode; this.countryCallingCode = countryCallingCode;


+ 1
- 1
java/test/com/google/i18n/phonenumbers/CountryCodeToRegionCodeMapForTesting.java View File

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2011 Google Inc.
* Copyright (C) 2010 Google Inc.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.


+ 1
- 1
java/test/com/google/i18n/phonenumbers/PhoneNumberMatcherTest.java View File

@ -702,7 +702,7 @@ public class PhoneNumberMatcherTest extends TestCase {
* Small class that holds the context of the number we are testing against. The test will * Small class that holds the context of the number we are testing against. The test will
* insert the phone number to be found between leadingText and trailingText. * insert the phone number to be found between leadingText and trailingText.
*/ */
private class NumberContext {
private static class NumberContext {
final String leadingText; final String leadingText;
final String trailingText; final String trailingText;


+ 5
- 14
javascript/README View File

@ -33,26 +33,17 @@ project:
have changed: have changed:
a. Manually update the .pb.js files with the changes of the .proto files. a. Manually update the .pb.js files with the changes of the .proto files.
b. Manually update the toJsArray() Java methods in b. Manually update the toJsArray() Java methods in
java/resources/com/google/i18n/phonenumbers/BuildMetadataJsonFromXml.java
tools/java/java-build/src/com/google/i18n/phonenumbers/tools/BuildMetadataJsonFromXml.java
c. Build tools/java/java-build/target/java-build-1.0-SNAPSHOT-jar-with-dependencies.jar
by running:
mvn -f tools/java/java-build/pom.xml package
2. If the phone number metadata in the XML format has changed 2. If the phone number metadata in the XML format has changed
(resources/PhoneNumberMetaData.xml) (resources/PhoneNumberMetaData.xml)
run the following commands to regenerate metadata.js and run the following commands to regenerate metadata.js and
metadatafortesting.js: metadatafortesting.js:
ant -f java/build.xml
java -cp java/build/classes \
com.google.i18n.phonenumbers.BuildMetadataJsonFromXml \
resources/PhoneNumberMetaData.xml \
javascript/i18n/phonenumbers/metadata.js false
java -cp java/build/classes \
com.google.i18n.phonenumbers.BuildMetadataJsonFromXml \
resources/PhoneNumberMetaData.xml \
javascript/i18n/phonenumbers/metadatalite.js true
java -cp java/build/classes \
com.google.i18n.phonenumbers.BuildMetadataJsonFromXml \
resources/PhoneNumberMetaDataForTesting.xml \
javascript/i18n/phonenumbers/metadatafortesting.js false
ant -f java/build.xml build-js-metadata
3. Manually port any changes of the Java code to the JavaScript code: 3. Manually port any changes of the Java code to the JavaScript code:
PhoneNumberUtil.java => phonenumberutil.js PhoneNumberUtil.java => phonenumberutil.js


+ 2
- 2
javascript/i18n/phonenumbers/metadata.js View File

@ -2315,9 +2315,9 @@ i18n.phonenumbers.metadata.countryToMetadata = {
,[,,"NA","NA"] ,[,,"NA","NA"]
,[,,"NA","NA"] ,[,,"NA","NA"]
,"KW",965,"00",,,,,,,,[[,"(\\d{4})(\\d{3,4})","$1 $2",["[1269]"] ,"KW",965,"00",,,,,,,,[[,"(\\d{4})(\\d{3,4})","$1 $2",["[1269]"]
,"",""]
,"$1",""]
,[,"(5[05]\\d)(\\d{5})","$1 $2",["5"] ,[,"(5[05]\\d)(\\d{5})","$1 $2",["5"]
,"",""]
,"$1",""]
] ]
,,[,,"NA","NA"] ,,[,,"NA","NA"]
,,,[,,"NA","NA"] ,,,[,,"NA","NA"]


+ 2
- 2
javascript/i18n/phonenumbers/metadatalite.js View File

@ -2315,9 +2315,9 @@ i18n.phonenumbers.metadata.countryToMetadata = {
,[,,"NA","NA"] ,[,,"NA","NA"]
,[,,"NA","NA"] ,[,,"NA","NA"]
,"KW",965,"00",,,,,,,,[[,"(\\d{4})(\\d{3,4})","$1 $2",["[1269]"] ,"KW",965,"00",,,,,,,,[[,"(\\d{4})(\\d{3,4})","$1 $2",["[1269]"]
,"",""]
,"$1",""]
,[,"(5[05]\\d)(\\d{5})","$1 $2",["5"] ,[,"(5[05]\\d)(\\d{5})","$1 $2",["5"]
,"",""]
,"$1",""]
] ]
,,[,,"NA","NA"] ,,[,,"NA","NA"]
,,,[,,"NA","NA"] ,,,[,,"NA","NA"]


+ 3
- 48
tools/java/common/pom.xml View File

@ -27,26 +27,8 @@
<target>1.5</target> <target>1.5</target>
</configuration> </configuration>
</plugin> </plugin>
<!-- Create a directory called 'generated'. -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>create-generated-directory</id>
<phase>generate-sources</phase>
<configuration>
<tasks>
<mkdir dir="generated"/>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- Add generated/ to the source directories. -->
<!-- Add ../../../java/src/ to make Phonemetadata.java available to the source
directories. -->
<plugin> <plugin>
<groupId>org.codehaus.mojo</groupId> <groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId> <artifactId>build-helper-maven-plugin</artifactId>
@ -60,34 +42,12 @@
</goals> </goals>
<configuration> <configuration>
<sources> <sources>
<source>generated/</source>
<source>../../../java/src/</source>
</sources> </sources>
</configuration> </configuration>
</execution> </execution>
</executions> </executions>
</plugin> </plugin>
<!-- Invoke Protocol Buffers compiler to generate PhoneMetadata.java. -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<executable>protoc</executable>
<arguments>
<argument>--java_out=generated</argument>
<argument>../../../resources/phonemetadata.proto</argument>
<argument>--proto_path=../../../resources</argument>
</arguments>
</configuration>
</plugin>
</plugins> </plugins>
</build> </build>
@ -98,11 +58,6 @@
<version>4.8.1</version> <version>4.8.1</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
<version>2.4.0a</version>
</dependency>
</dependencies> </dependencies>
</project> </project>

+ 0
- 1
tools/java/common/src/com/google/i18n/phonenumbers/tools/BuildMetadataFromXml.java View File

@ -32,7 +32,6 @@ import java.util.Map;
import java.util.TreeMap; import java.util.TreeMap;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import java.util.logging.Logger;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilder;


+ 27
- 5
tools/java/common/src/com/google/i18n/phonenumbers/tools/CopyrightNotice.java View File

@ -16,7 +16,9 @@
package com.google.i18n.phonenumbers.tools; package com.google.i18n.phonenumbers.tools;
import java.util.Calendar;
import java.io.IOException;
import java.io.Writer;
import java.util.Formatter;
/** /**
* Class containing the Apache copyright notice used by code generators. * Class containing the Apache copyright notice used by code generators.
@ -25,9 +27,15 @@ import java.util.Calendar;
*/ */
public class CopyrightNotice { public class CopyrightNotice {
public static final String TEXT =
"/*\n" +
" * Copyright (C) " + Calendar.getInstance().get(Calendar.YEAR) + " Google Inc.\n" +
private static final String TEXT_OPENING =
"/*\n";
private static final String TEXT_OPENING_FOR_JAVASCRIPT =
"/**\n" +
" * @license\n";
private static final String TEXT =
" * Copyright (C) %d Google Inc.\n" +
" *\n" + " *\n" +
" * Licensed under the Apache License, Version 2.0 (the \"License\");\n" + " * Licensed under the Apache License, Version 2.0 (the \"License\");\n" +
" * you may not use this file except in compliance with the License.\n" + " * you may not use this file except in compliance with the License.\n" +
@ -40,5 +48,19 @@ public class CopyrightNotice {
" * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n" + " * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n" +
" * See the License for the specific language governing permissions and\n" + " * See the License for the specific language governing permissions and\n" +
" * limitations under the License.\n" + " * limitations under the License.\n" +
" */\n";
" */\n\n";
static final void writeTo(Writer writer, int year) throws IOException {
writeTo(writer, year, false);
}
static final void writeTo(Writer writer, int year, boolean isJavascript) throws IOException {
if (isJavascript) {
writer.write(TEXT_OPENING_FOR_JAVASCRIPT);
} else {
writer.write(TEXT_OPENING);
}
Formatter formatter = new Formatter(writer);
formatter.format(TEXT, year);
}
} }

+ 6
- 8
tools/java/common/test/com/google/i18n/phonenumbers/tools/BuildMetadataFromXmlTest.java View File

@ -18,7 +18,6 @@ package com.google.i18n.phonenumbers.tools;
import com.google.i18n.phonenumbers.Phonemetadata.NumberFormat; import com.google.i18n.phonenumbers.Phonemetadata.NumberFormat;
import com.google.i18n.phonenumbers.Phonemetadata.PhoneMetadata; import com.google.i18n.phonenumbers.Phonemetadata.PhoneMetadata;
import com.google.i18n.phonenumbers.Phonemetadata.PhoneMetadataCollection;
import com.google.i18n.phonenumbers.Phonemetadata.PhoneNumberDesc; import com.google.i18n.phonenumbers.Phonemetadata.PhoneNumberDesc;
import junit.framework.TestCase; import junit.framework.TestCase;
@ -115,7 +114,7 @@ public class BuildMetadataFromXmlTest extends TestCase {
assertEquals("0", phoneMetadata.getNationalPrefix()); assertEquals("0", phoneMetadata.getNationalPrefix());
assertEquals(" x", phoneMetadata.getPreferredExtnPrefix()); assertEquals(" x", phoneMetadata.getPreferredExtnPrefix());
assertTrue(phoneMetadata.getMainCountryForCode()); assertTrue(phoneMetadata.getMainCountryForCode());
assertTrue(phoneMetadata.getLeadingZeroPossible());
assertTrue(phoneMetadata.isLeadingZeroPossible());
} }
public void testLoadTerritoryTagMetadataSetsBooleanFieldsToFalseByDefault() public void testLoadTerritoryTagMetadataSetsBooleanFieldsToFalseByDefault()
@ -125,7 +124,7 @@ public class BuildMetadataFromXmlTest extends TestCase {
PhoneMetadata.Builder phoneMetadata = PhoneMetadata.Builder phoneMetadata =
BuildMetadataFromXml.loadTerritoryTagMetadata("33", territoryElement, "", ""); BuildMetadataFromXml.loadTerritoryTagMetadata("33", territoryElement, "", "");
assertFalse(phoneMetadata.getMainCountryForCode()); assertFalse(phoneMetadata.getMainCountryForCode());
assertFalse(phoneMetadata.getLeadingZeroPossible());
assertFalse(phoneMetadata.isLeadingZeroPossible());
} }
public void testLoadTerritoryTagMetadataSetsNationalPrefixForParsingByDefault() public void testLoadTerritoryTagMetadataSetsNationalPrefixForParsingByDefault()
@ -144,8 +143,7 @@ public class BuildMetadataFromXmlTest extends TestCase {
String xmlInput = "<territory countryCode='33' internationalPrefix='00'/>"; String xmlInput = "<territory countryCode='33' internationalPrefix='00'/>";
Element territoryElement = parseXmlString(xmlInput); Element territoryElement = parseXmlString(xmlInput);
// Should not throw any exception. // Should not throw any exception.
PhoneMetadata.Builder phoneMetadata =
BuildMetadataFromXml.loadTerritoryTagMetadata("33", territoryElement, "", "");
BuildMetadataFromXml.loadTerritoryTagMetadata("33", territoryElement, "", "");
} }
// Tests loadInternationalFormat(). // Tests loadInternationalFormat().
@ -310,7 +308,7 @@ public class BuildMetadataFromXmlTest extends TestCase {
Element element = parseXmlString(xmlInput); Element element = parseXmlString(xmlInput);
PhoneMetadata.Builder metadata = PhoneMetadata.newBuilder(); PhoneMetadata.Builder metadata = PhoneMetadata.newBuilder();
BuildMetadataFromXml.loadAvailableFormats(metadata, "AE", element, "0", "($1)"); BuildMetadataFromXml.loadAvailableFormats(metadata, "AE", element, "0", "($1)");
assertEquals(0, metadata.getIntlNumberFormatCount());
assertEquals(0, metadata.intlNumberFormatSize());
} }
public void testLoadAvailableFormatsHandlesMultipleNumberFormats() public void testLoadAvailableFormatsHandlesMultipleNumberFormats()
@ -337,7 +335,7 @@ public class BuildMetadataFromXmlTest extends TestCase {
String nationalFormat = "$1 $2"; String nationalFormat = "$1 $2";
BuildMetadataFromXml.loadInternationalFormat(metadata, numberFormatElement, nationalFormat); BuildMetadataFromXml.loadInternationalFormat(metadata, numberFormatElement, nationalFormat);
assertEquals(0, metadata.getIntlNumberFormatCount());
assertEquals(0, metadata.intlNumberFormatSize());
} }
// Tests setLeadingDigitsPatterns(). // Tests setLeadingDigitsPatterns().
@ -484,7 +482,7 @@ public class BuildMetadataFromXmlTest extends TestCase {
PhoneMetadata.Builder metadata = PhoneMetadata.newBuilder(); PhoneMetadata.Builder metadata = PhoneMetadata.newBuilder();
// Should set sameMobileAndFixedPattern to true. // Should set sameMobileAndFixedPattern to true.
BuildMetadataFromXml.loadGeneralDesc(metadata, territoryElement); BuildMetadataFromXml.loadGeneralDesc(metadata, territoryElement);
assertTrue(metadata.getSameMobileAndFixedLinePattern());
assertTrue(metadata.isSameMobileAndFixedLinePattern());
} }
public void testLoadGeneralDescSetsAllDescriptions() public void testLoadGeneralDescSetsAllDescriptions()


+ 1
- 1
tools/java/cpp-build/pom.xml View File

@ -72,7 +72,7 @@
</execution> </execution>
</executions> </executions>
</plugin> </plugin>
<!-- Invoke Protocol Buffers compiler to generate PhoneMetadata.java. -->
<!-- Invoke Protocol Buffers compiler to generate Phonemetadata.java. -->
<plugin> <plugin>
<groupId>org.codehaus.mojo</groupId> <groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId> <artifactId>exec-maven-plugin</artifactId>


+ 5
- 3
tools/java/cpp-build/src/com/google/i18n/phonenumbers/tools/BuildMetadataCppFromXml.java View File

@ -53,6 +53,8 @@ public class BuildMetadataCppFromXml extends Command {
private static final Set<String> METADATA_TYPES = private static final Set<String> METADATA_TYPES =
new HashSet<String>(Arrays.asList("metadata", "test_metadata", "lite_metadata")); new HashSet<String>(Arrays.asList("metadata", "test_metadata", "lite_metadata"));
private static final int COPYRIGHT_YEAR = 2011;
/** /**
* Package private setter used to inject the binary stream for testing purpose. * Package private setter used to inject the binary stream for testing purpose.
*/ */
@ -124,9 +126,9 @@ public class BuildMetadataCppFromXml extends Command {
* const void* metadata_get(); * const void* metadata_get();
* </pre> * </pre>
*/ */
private void emitHeader() {
private void emitHeader() throws IOException {
final PrintWriter pw = new PrintWriter(headerFileOutputStream); final PrintWriter pw = new PrintWriter(headerFileOutputStream);
pw.write(CopyrightNotice.TEXT);
CopyrightNotice.writeTo(pw, COPYRIGHT_YEAR);
final String guardName = "I18N_PHONENUMBERS_METADATA_H_"; final String guardName = "I18N_PHONENUMBERS_METADATA_H_";
pw.println("#ifndef " + guardName); pw.println("#ifndef " + guardName);
pw.println("#define " + guardName); pw.println("#define " + guardName);
@ -179,7 +181,7 @@ public class BuildMetadataCppFromXml extends Command {
*/ */
private void emitImplementation() throws IOException { private void emitImplementation() throws IOException {
final PrintWriter pw = new PrintWriter(implFileOutputStream); final PrintWriter pw = new PrintWriter(implFileOutputStream);
pw.write(CopyrightNotice.TEXT);
CopyrightNotice.writeTo(pw, COPYRIGHT_YEAR);
pw.println("#include \"phonenumbers/metadata.h\""); pw.println("#include \"phonenumbers/metadata.h\"");
pw.println(); pw.println();


BIN
tools/java/cpp-build/target/cpp-build-1.0-SNAPSHOT-jar-with-dependencies.jar View File


+ 1
- 1
tools/java/java-build/pom.xml View File

@ -49,7 +49,7 @@
<target>1.5</target> <target>1.5</target>
</configuration> </configuration>
</plugin> </plugin>
<!-- Add ../../../java/src/ to make PhoneMetadata.java available to the source
<!-- Add ../../../java/src/ to make Phonemetadata.java available to the source
directories. --> directories. -->
<plugin> <plugin>
<groupId>org.codehaus.mojo</groupId> <groupId>org.codehaus.mojo</groupId>


+ 4
- 2
tools/java/java-build/src/com/google/i18n/phonenumbers/tools/BuildMetadataJsonFromXml.java View File

@ -72,6 +72,8 @@ public class BuildMetadataJsonFromXml extends Command {
" * @type {Object.<string, Array>}\n" + " * @type {Object.<string, Array>}\n" +
" */\n"; " */\n";
private static final int COPYRIGHT_YEAR = 2010;
@Override @Override
public String getCommandName() { public String getCommandName() {
return "BuildMetadataJsonFromXml"; return "BuildMetadataJsonFromXml";
@ -97,7 +99,7 @@ public class BuildMetadataJsonFromXml extends Command {
BufferedWriter writer = new BufferedWriter(new FileWriter(outputFile)); BufferedWriter writer = new BufferedWriter(new FileWriter(outputFile));
writer.write(CopyrightNotice.TEXT);
CopyrightNotice.writeTo(writer, COPYRIGHT_YEAR, true);
Formatter formatter = new Formatter(writer); Formatter formatter = new Formatter(writer);
formatter.format(FILE_OVERVIEW, inputFile); formatter.format(FILE_OVERVIEW, inputFile);
@ -116,7 +118,7 @@ public class BuildMetadataJsonFromXml extends Command {
writer.flush(); writer.flush();
writer.close(); writer.close();
} catch (Exception e) { } catch (Exception e) {
System.err.println(HELP_MESSAGE);
e.printStackTrace();
return false; return false;
} }
return true; return true;


+ 5
- 4
tools/java/java-build/src/com/google/i18n/phonenumbers/tools/BuildMetadataProtoFromXml.java View File

@ -20,7 +20,6 @@ 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;
@ -71,7 +70,7 @@ public class BuildMetadataProtoFromXml extends Command {
private static final String GENERATION_COMMENT = private static final String GENERATION_COMMENT =
"/* This file is automatically generated by {@link BuildMetadataProtoFromXml}.\n" + "/* This file is automatically generated by {@link BuildMetadataProtoFromXml}.\n" +
" * Please don't modify it directly.\n" + " * Please don't modify it directly.\n" +
" */\n";
" */\n\n";
@Override @Override
public String getCommandName() { public String getCommandName() {
@ -116,7 +115,7 @@ public class BuildMetadataProtoFromXml extends Command {
writeCountryCallingCodeMappingToJavaFile(countryCodeToRegionCodeMap, outputDir, forTesting); writeCountryCallingCodeMappingToJavaFile(countryCodeToRegionCodeMap, outputDir, forTesting);
} catch (Exception e) { } catch (Exception e) {
System.err.println(HELP_MESSAGE);
e.printStackTrace();
return false; return false;
} }
System.out.println("Metadata code successfully generated."); System.out.println("Metadata code successfully generated.");
@ -137,6 +136,7 @@ public class BuildMetadataProtoFromXml extends Command {
private static final String MAPPING_COMMENT_2 = private static final String MAPPING_COMMENT_2 =
" // The capacity is set to %d as there are %d different country codes,\n" + " // The capacity is set to %d as there are %d different country codes,\n" +
" // and this offers a load factor of roughly " + MAPPING_LOAD_FACTOR + ".\n"; " // and this offers a load factor of roughly " + MAPPING_LOAD_FACTOR + ".\n";
private static final int COPYRIGHT_YEAR = 2010;
private static void writeCountryCallingCodeMappingToJavaFile( private static void writeCountryCallingCodeMappingToJavaFile(
Map<Integer, List<String>> countryCodeToRegionCodeMap, Map<Integer, List<String>> countryCodeToRegionCodeMap,
@ -152,7 +152,8 @@ public class BuildMetadataProtoFromXml extends Command {
BufferedWriter writer = new BufferedWriter(new FileWriter(mappingFile)); BufferedWriter writer = new BufferedWriter(new FileWriter(mappingFile));
writer.write(CopyrightNotice.TEXT + "\n" + GENERATION_COMMENT + "\n");
CopyrightNotice.writeTo(writer, COPYRIGHT_YEAR);
writer.write(GENERATION_COMMENT);
if (PACKAGE_NAME.length() > 0) { if (PACKAGE_NAME.length() > 0) {
writer.write("package " + PACKAGE_NAME.replaceAll("/", ".") + ";\n\n"); writer.write("package " + PACKAGE_NAME.replaceAll("/", ".") + ";\n\n");
} }


+ 5
- 11
tools/java/java-build/src/com/google/i18n/phonenumbers/tools/GenerateAreaCodeData.java View File

@ -57,8 +57,6 @@ public class GenerateAreaCodeData extends Command {
private final File inputPath; private final File inputPath;
// The path to the output directory. // The path to the output directory.
private final File outputPath; private final File outputPath;
// Whether the data is generated for testing.
private final boolean forTesting;
private static final Logger LOGGER = Logger.getLogger(GenerateAreaCodeData.class.getName()); private static final Logger LOGGER = Logger.getLogger(GenerateAreaCodeData.class.getName());
@ -68,10 +66,9 @@ public class GenerateAreaCodeData extends Command {
public GenerateAreaCodeData() { public GenerateAreaCodeData() {
inputPath = null; inputPath = null;
outputPath = null; outputPath = null;
forTesting = false;
} }
public GenerateAreaCodeData(File inputPath, File outputPath, boolean forTesting)
public GenerateAreaCodeData(File inputPath, File outputPath)
throws IOException { throws IOException {
if (!inputPath.isDirectory()) { if (!inputPath.isDirectory()) {
throw new IOException("The provided input path does not exist: " + throw new IOException("The provided input path does not exist: " +
@ -88,7 +85,6 @@ public class GenerateAreaCodeData extends Command {
} }
this.inputPath = inputPath; this.inputPath = inputPath;
this.outputPath = outputPath; this.outputPath = outputPath;
this.forTesting = forTesting;
} }
/** /**
@ -146,7 +142,7 @@ public class GenerateAreaCodeData extends Command {
objectOutputStream.flush(); objectOutputStream.flush();
} }
private class Pair<A, B> {
private static class Pair<A, B> {
public final A first; public final A first;
public final B second; public final B second;
@ -284,16 +280,14 @@ public class GenerateAreaCodeData extends Command {
public boolean start() { public boolean start() {
String[] args = getArgs(); String[] args = getArgs();
if (args.length != 4) {
if (args.length != 3) {
LOGGER.log(Level.SEVERE, LOGGER.log(Level.SEVERE,
"usage: GenerateAreaCodeData /path/to/input/directory /path/to/output/directory" +
" forTesting");
"usage: GenerateAreaCodeData /path/to/input/directory /path/to/output/directory");
return false; return false;
} }
try { try {
GenerateAreaCodeData generateAreaCodeData = GenerateAreaCodeData generateAreaCodeData =
new GenerateAreaCodeData(new File(args[1]), new File(args[2]),
Boolean.parseBoolean(args[3]));
new GenerateAreaCodeData(new File(args[1]), new File(args[2]));
generateAreaCodeData.run(); generateAreaCodeData.run();
} catch (IOException e) { } catch (IOException e) {
LOGGER.log(Level.SEVERE, e.getMessage()); LOGGER.log(Level.SEVERE, e.getMessage());


BIN
tools/java/java-build/target/java-build-1.0-SNAPSHOT-jar-with-dependencies.jar View File


Loading…
Cancel
Save