Source

libphonenumber-csharp / java / build.xml

Full commit
<?xml version="1.0" ?>

<project name="libphonenumber" default="compile">
  <property name="libphonenumber.src.dir" value="libphonenumber/src"/>
  <property name="libphonenumber.test.dir" value="libphonenumber/test"/>
  <property name="geocoder.src.dir" value="geocoder/src"/>
  <property name="geocoder.test.dir" value="geocoder/test"/>
  <property name="build.dir" value="build"/>
  <property name="classes.dir" value="${build.dir}/classes"/>
  <property name="jar.dir" value="${build.dir}/jar"/>
  <property name="lib.dir" value="lib"/>
  <property name="report.dir" value="${build.dir}/junitreport"/>
  <property name="resources.dir" value="../resources"/>
  <property name="javascript.dir" value="../javascript"/>
  <property name="build.tools.jar"
      value="../tools/java/java-build/target/java-build-1.0-SNAPSHOT-jar-with-dependencies.jar"/>

  <path id="classpath">
    <fileset dir="${lib.dir}" includes="**/*.jar"/>
  </path>
  <path id="test.classpath">
    <pathelement location="${classes.dir}"/>
    <pathelement location="${lib.dir}/junit/junit-4.8.1.jar"/>
    <pathelement location="${jar.dir}/${ant.project.name}-test.jar"/>
    <fileset dir="${lib.dir}">
      <include name="**/*.jar"/>
    </fileset>
  </path>

  <target name="build-metadata">
    <exec executable="java">
      <arg value="-jar" />
      <arg value="${build.tools.jar}"/>
      <arg value="BuildMetadataProtoFromXml"/>
      <arg value="--input-file=${resources.dir}/PhoneNumberMetaData.xml"/>
      <arg value="--output-dir=${libphonenumber.src.dir}/com/google/i18n/phonenumbers"/>
      <arg value="--data-prefix=data/PhoneNumberMetadataProto"/>
      <arg value="--mapping-class=CountryCodeToRegionCodeMap"/>
      <arg value="--copyright=2010"/>
      <arg value="--lite-build=false"/>
    </exec>
  </target>

  <target name="build-test-metadata">
    <exec executable="java">
      <arg value="-jar" />
      <arg value="${build.tools.jar}"/>
      <arg value="BuildMetadataProtoFromXml"/>
      <arg value="--input-file=${resources.dir}/PhoneNumberMetaDataForTesting.xml"/>
      <arg value="--output-dir=${libphonenumber.test.dir}/com/google/i18n/phonenumbers"/>
      <arg value="--data-prefix=data/PhoneNumberMetadataProtoForTesting"/>
      <arg value="--mapping-class=CountryCodeToRegionCodeMapForTesting"/>
      <arg value="--copyright=2010"/>
      <arg value="--lite-build=false"/>
    </exec>
  </target>

  <target name="build-alternate-metadata">
    <exec executable="java">
      <arg value="-jar" />
      <arg value="${build.tools.jar}"/>
      <arg value="BuildMetadataProtoFromXml"/>
      <arg value="--input-file=${resources.dir}/PhoneNumberAlternateFormats.xml"/>
      <arg value="--output-dir=${libphonenumber.src.dir}/com/google/i18n/phonenumbers"/>
      <arg value="--data-prefix=data/PhoneNumberAlternateFormatsProto"/>
      <arg value="--mapping-class=AlternateFormatsCountryCodeSet"/>
      <arg value="--copyright=2012"/>
      <arg value="--lite-build=false"/>
    </exec>
  </target>

  <target name="build-geo-data">
    <exec executable="java">
      <arg value="-jar" />
      <arg value="${build.tools.jar}"/>
      <arg value="GenerateAreaCodeData"/>
      <arg value="${resources.dir}/geocoding/"/>
      <arg value="geocoder/src/com/google/i18n/phonenumbers/geocoding/data"/>
    </exec>
  </target>

  <target name="build-geo-test-data">
    <exec executable="java">
      <arg value="-jar" />
      <arg value="${build.tools.jar}"/>
      <arg value="GenerateAreaCodeData"/>
      <arg value="${resources.dir}/test/geocoding/"/>
      <arg value="geocoder/test/com/google/i18n/phonenumbers/geocoding/testing_data"/>
    </exec>
  </target>

  <target name="build-js-metadata">
    <exec executable="java">
      <arg value="-jar" />
      <arg value="${build.tools.jar}"/>
      <arg value="BuildMetadataJsonFromXml"/>
      <arg value="${resources.dir}/PhoneNumberMetaData.xml"/>
      <arg value="${javascript.dir}/i18n/phonenumbers/metadata.js"/>
    </exec>
    <exec executable="java">
      <arg value="-jar" />
      <arg value="${build.tools.jar}"/>
      <arg value="BuildMetadataJsonFromXml"/>
      <arg value="${resources.dir}/PhoneNumberMetaData.xml"/>
      <arg value="${javascript.dir}/i18n/phonenumbers/metadatalite.js"/>
      <arg value="true"/> <!-- Lite metadata. -->
    </exec>
    <exec executable="java">
      <arg value="-jar" />
      <arg value="${build.tools.jar}"/>
      <arg value="BuildMetadataJsonFromXml"/>
      <arg value="${resources.dir}/PhoneNumberMetaDataForTesting.xml"/>
      <arg value="${javascript.dir}/i18n/phonenumbers/metadatafortesting.js"/>
    </exec>
  </target>

  <target name="compile" description="Compile Java source."
          depends="build-metadata,build-alternate-metadata,build-geo-data">
    <mkdir dir="${classes.dir}"/>
    <javac srcdir="${libphonenumber.src.dir};${geocoder.src.dir}"
           destdir="${classes.dir}" classpathref="classpath" includeAntRuntime="false"/>
    <javac srcdir="${libphonenumber.test.dir};${geocoder.test.dir}"
           destdir="${classes.dir}" classpathref="classpath" debug="on"
           includeAntRuntime="false"/>
  </target>

  <target name="jar" depends="compile">
    <mkdir dir="${jar.dir}"/>
    <jar destfile="${jar.dir}/${ant.project.name}.jar">
      <fileset dir="${classes.dir}">
        <include name="**/*.class"/>
        <exclude name="**/*Test*"/>
        <exclude name="**/BuildMetadata*"/>
        <exclude name="**/geocoding/*"/>
      </fileset>
      <fileset dir="${libphonenumber.src.dir}">
        <include name="**/PhoneNumberMetadataProto*"/>
        <include name="**/PhoneNumberAlternateFormatsProto*"/>
      </fileset>
    </jar>
    <jar destfile="${jar.dir}/offline-geocoder.jar">
      <fileset dir="${classes.dir}">
        <include name="**/geocoding/*.class"/>
        <exclude name="**/*Test*"/>
        <exclude name="**/geocoding/GenerateAreaCodeData*"/>
      </fileset>
      <fileset dir="${geocoder.src.dir}">
        <include name="**/geocoding/data/*"/>
      </fileset>
    </jar>
  </target>

  <target name="test-jar"
          depends="compile,build-test-metadata,build-geo-test-data">
    <mkdir dir="${jar.dir}"/>
    <jar destfile="${jar.dir}/${ant.project.name}-test.jar">
      <fileset dir="${classes.dir}">
        <include name="**/*.class"/>
        <exclude name="**/*Test*"/>
      </fileset>
      <fileset dir="${libphonenumber.src.dir}">
        <include name="**/PhoneNumberMetadataProto*"/>
        <include name="**/PhoneNumberAlternateFormatsProto*"/>
      </fileset>
      <fileset dir="${libphonenumber.test.dir}">
        <include name="**/PhoneNumberMetadataProtoForTesting*"/>
      </fileset>
      <fileset dir="${geocoder.test.dir}">
        <include name="**/geocoding/testing_data/*"/>
      </fileset>
    </jar>
  </target>

  <target name="junit" depends="test-jar">
    <mkdir dir="${report.dir}"/>
    <junit printsummary="yes"
        failureProperty="test.failed" errorProperty="test.failed">
      <classpath refid="test.classpath"/>
      <formatter type="xml"/>
      <batchtest fork="no" todir="${report.dir}">
        <fileset dir="${libphonenumber.test.dir}" includes="**/*Test.java"/>
      </batchtest>
      <batchtest fork="no" todir="${report.dir}">
        <fileset dir="${geocoder.test.dir}" includes="**/*Test.java"/>
      </batchtest>
    </junit>
    <fail message="Tests failed. Run 'ant junitreport' for more info."
        if="test.failed"/>
  </target>

  <target name="junitreport">
    <junitreport todir="${report.dir}">
      <fileset dir="${report.dir}" includes="TEST-*.xml"/>
        <report todir="${report.dir}"/>
    </junitreport>
  </target>

  <target name="testname" unless="test">
    <fail message="You must run this target with -Dtest=TestName"/>
  </target>

  <target name="test" depends="test-jar, testname">
    <junit printsummary="withOutAndErr">
      <classpath refid="test.classpath"/>
      <formatter type="plain" usefile="false"/>
      <batchtest fork="no">
        <fileset dir="${libphonenumber.test.dir}" includes="**/*${test}.java"/>
        <fileset dir="${geocoder.test.dir}" includes="**/*${test}.java"/>
      </batchtest>
    </junit>
  </target>

  <target name="clean" description="Remove generated files.">
    <delete dir="${build.dir}"/>
  </target>

  <target name="clean-build" depends="clean,jar"/>
</project>