Home | History | Annotate | Download | only in robolectric
      1 <?xml version="1.0" encoding="UTF-8"?>
      2 <project name="robolectric" default="test">
      3 
      4     <!-- The build.properties file can be created by you and is never touched
      5          by the 'android' tool. This is the place to change some of the default property values
      6          used by the Ant rules.
      7          Here are some properties you may want to change/update:
      8 
      9          application.package
     10              the name of your application package as defined in the manifest. Used by the
     11              'uninstall' rule.
     12          source.dir
     13              the name of the source directory. Default is 'src'.
     14          out.dir
     15              the name of the output directory. Default is 'bin'.
     16 
     17          Properties related to the SDK location or the project target should be updated
     18           using the 'android' tool with the 'update' action.
     19 
     20          This file is an integral part of the build system for your application and
     21          should be checked in in Version Control Systems.
     22 
     23          -->
     24     <property file="build.properties"/>
     25 
     26     <!-- The default.properties file is created and updated by the 'android' tool, as well
     27          as ADT.
     28          This file is an integral part of the build system for your application and
     29          should be checked in in Version Control Systems. -->
     30     <property file="default.properties"/>
     31 
     32     <condition property="isWindows"> <os family="windows" /> </condition>
     33 
     34     <target name="findAndroidWindows" if="isWindows">
     35         <echo message="Finding the Android version in windows"/>
     36         <exec executable="./find-android.bat"/>
     37     </target>
     38     <target name="findAndroidUnix" unless="isWindows">
     39         <echo message="Finding the Android version in *nix"/>
     40         <exec executable="./find-android.sh"/>
     41     </target>
     42     <property file="local.properties"/>
     43 
     44     <!-- Custom Android task to deal with the project target, and import the proper rules.
     45          This requires ant 1.6.0 or above. -->
     46     <path id="android.antlibs">
     47         <pathelement path="${sdk.dir}/tools/lib/anttasks.jar"/>
     48         <pathelement path="${sdk.dir}/tools/lib/sdklib.jar"/>
     49         <pathelement path="${sdk.dir}/tools/lib/androidprefs.jar"/>
     50         <pathelement path="${sdk.dir}/tools/lib/apkbuilder.jar"/>
     51         <pathelement path="${sdk.dir}/tools/lib/jarutils.jar"/>
     52     </path>
     53 
     54     <path id="android.target.classpath">
     55         <pathelement path="${sdk.dir}/platforms/android-16/android.jar"/>
     56         <pathelement path="${sdk.dir}/add-ons/addon_google_apis_google_inc_16/libs/maps.jar"/>
     57         <pathelement path="${sdk.dir}/add-ons/addon-google_apis-google_inc_-16/libs/maps.jar"/>
     58         <pathelement path="${sdk.dir}/add-ons/addon-google_apis-google-16/libs/maps.jar"/>
     59         <pathelement path="${sdk.dir}/extras/android/support/v4/android-support-v4.jar"/>
     60         <pathelement path="${sdk.dir}/android-compatibility/v4/android-support-v4.jar"/>
     61     </path>
     62 
     63     <property name="main.absolute.dir" location="${main.dir}"/>
     64     <property name="out.main.dir" value="${out.absolute.dir}/mainClasses"/>
     65     <property name="out.main.absolute.dir" value="${out.main.dir}"/>
     66     <property name="main.external.libs.dir" value="lib/main"/>
     67     <property name="main.external.libs.absolute.dir" location="${main.external.libs.dir}"/>
     68 
     69     <property name="test.absolute.dir" location="${test.dir}"/>
     70     <property name="out.test.dir" value="${out.absolute.dir}/testClasses"/>
     71     <property name="out.test.absolute.dir" value="${out.test.dir}"/>
     72     <property name="test.external.libs.dir" value="lib/test"/>
     73     <property name="test.external.libs.absolute.dir" location="${test.external.libs.dir}"/>
     74 
     75     <property name="publish.dir" location="${out.absolute.dir}/publish"/>
     76 
     77     <property name="pages.dir" value="pages"/>
     78     <property name="downloads.dir" value="${pages.dir}/downloads"/>
     79     <property name="javadoc.out.dir" value="${pages.dir}/javadoc"/>
     80 
     81     <property name="base.package" value="com.xtremelabs.robolectric"/>
     82 
     83     <property environment="env"/>
     84     <condition property="build.number" value="${env.BUILD_NUMBER}" else="unknown">
     85         <isset property="env.BUILD_NUMBER"/>
     86     </condition>
     87 
     88     <target name="compile"
     89             description="compile module source"
     90             depends="findAndroidUnix, findAndroidWindows">
     91         <mkdir dir="${out.main.absolute.dir}"/>
     92 
     93         <javac encoding="ascii" source="1.6" target="1.6" debug="true" extdirs=""
     94                destdir="${out.main.absolute.dir}"
     95                verbose="${verbose}"
     96                classpath="${extensible.classpath}"
     97                includeantruntime="false">
     98             <src path="${main.absolute.dir}"/>
     99             <classpath>
    100                 <pathelement path="${out.main.absolute.dir}"/>
    101                 <path refid="android.target.classpath"/>
    102                 <fileset dir="${main.external.libs.absolute.dir}" includes="*.jar"/>
    103             </classpath>
    104         </javac>
    105     </target>
    106 
    107     <target name="jar" description="create the robolectric jar" depends="compile">
    108         <mkdir dir="${target.dir}"/>
    109         <jar destfile="${target.dir}/robolectric.jar">
    110             <fileset dir="${out.main.absolute.dir}" includes="**/*.class"/>
    111         </jar>
    112     </target>
    113 
    114     <target name="jar-all" description="create the robolectric jar including all dependencies" depends="jar">
    115         <mkdir dir="${target.dir}/staging"/>
    116         <unjar dest="${target.dir}/staging" >
    117             <fileset dir="${main.external.libs.absolute.dir}" >
    118                  <exclude name="*src.jar" />
    119                  <exclude name="junit*.jar" />
    120                  <exclude name="hamcrest*.jar" />
    121             </fileset>
    122         </unjar>
    123         <unjar dest="${target.dir}/staging" src="${target.dir}/robolectric.jar"/>
    124         <jar destfile="${target.dir}/robolectric-all.jar" basedir="${target.dir}/staging"/>
    125         <delete dir="${target.dir}/staging"/>
    126     </target>
    127 
    128     <target name="source-jar" description="create a jar file that includes all of the source code">
    129         <mkdir dir="${target.dir}"/>
    130         <jar destfile="${target.dir}/robolectric-src.jar" basedir="${main.absolute.dir}"/>
    131     </target>
    132 
    133     <target name="compile.tests" depends="compile"
    134     description="compile module source; test classes" unless="skip.tests">
    135         <mkdir dir="${out.test.absolute.dir}"/>
    136 
    137         <javac encoding="ascii" source="1.6" target="1.6" debug="true" extdirs=""
    138         destdir="${out.test.absolute.dir}"
    139         verbose="${verbose}"
    140         classpath="${extensible.classpath}"
    141         includeantruntime="false">
    142             <src path="${test.absolute.dir}"/>
    143             <classpath>
    144                 <pathelement path="${out.main.absolute.dir}"/>
    145                 <pathelement path="${out.test.absolute.dir}"/>
    146                 <path refid="android.target.classpath"/>
    147                 <fileset dir="${main.external.libs.absolute.dir}" includes="*.jar"/>
    148                 <fileset dir="${test.external.libs.absolute.dir}" includes="*.jar"/>
    149             </classpath>
    150         </javac>
    151     </target>
    152 
    153     <target name="clean" description="cleanup module">
    154         <delete dir="${out.absolute.dir}"/>
    155         <delete dir="${out.test.absolute.dir}"/>
    156         <delete dir="${tmp.dir}"/>
    157         <delete dir="${target.dir}"/>
    158     </target>
    159 
    160     <target name="test" depends="compile.tests" description="test all">
    161         <mkdir dir="${basedir}/out/reports/tests"/>
    162         <junit showoutput="true" failureproperty="junit.failure">
    163             <formatter type="plain" usefile="false" if="junit.console.out"/>
    164             <formatter type="plain"/>
    165             <formatter type="xml"/>
    166             <batchtest todir="${basedir}/out/reports/tests">
    167                 <fileset dir="${test.absolute.dir}">
    168                     <include name="**/*Test.java"/>
    169                 </fileset>
    170             </batchtest>
    171             <classpath>
    172                 <pathelement path="${out.main.absolute.dir}"/>
    173                 <pathelement path="${out.test.absolute.dir}"/>
    174                 <fileset dir="${main.external.libs.dir}" includes="*.jar"/>
    175                 <fileset dir="${test.external.libs.dir}" includes="*.jar"/>
    176                 <path refid="android.target.classpath"/>
    177             </classpath>
    178         </junit>
    179         <fail if="junit.failure" message="Unit test(s) failed.  See reports!"/>
    180     </target>
    181 
    182     <target name="check-for-pages-dir-setup">
    183         <condition property="pages.dir.exists">
    184             <available file="${pages.dir}" type="dir"/>
    185         </condition>
    186     </target>
    187 
    188     <target name="check-for-pages-dir" depends="check-for-pages-dir-setup" unless="pages.dir.exists">
    189         <echo message="do you need a 'pages' symlink?"/>
    190     </target>
    191 
    192     <target name="snapshot" description="update most recent version of robolectric as jars" depends="clean, test, jar-all, source-jar, check-for-pages-dir" if="pages.dir.exists">
    193         <copy todir="${downloads.dir}">
    194             <fileset dir="${target.dir}" includes="robolectric*.jar"/>
    195         </copy>
    196         <exec executable="./update-downloads.rb"/>
    197     </target>
    198 
    199     <target name="gen-javadoc" description="generate javadoc for the public API" depends="check-for-pages-dir" if="pages.dir.exists">
    200         <mkdir dir="${javadoc.out.dir}" />
    201         <javadoc
    202                 packagenames="${base.package}.*"
    203                 access="protected"
    204                 defaultexcludes="yes"
    205                 windowtitle="Robolectric API"
    206                 sourcepath="${main.absolute.dir}"
    207                 overview="${main.absolute.dir}/overview.html"
    208                 destdir="${javadoc.out.dir}">
    209             <classpath>
    210                 <pathelement path="${out.main.absolute.dir}"/>
    211                 <path refid="android.target.classpath"/>
    212                 <fileset dir="${main.external.libs.absolute.dir}" includes="*.jar"/>
    213             </classpath>
    214             <doctitle><![CDATA[<h1>Robolectric<br/>API Documentation</h1>]]></doctitle>
    215         </javadoc>
    216     </target>
    217 
    218     <target name="maven-install-jars" description="Install the jar files that Maven can't find for itself">
    219         <exec executable="mvn">
    220             <arg line="install:install-file -DgroupId=com.google.android.maps -DartifactId=maps -Dversion=10_r2 -Dpackaging=jar -Dfile=${sdk.dir}/add-ons/addon_google_apis_google_inc_10/libs/maps.jar" />
    221         </exec>
    222         <exec executable="mvn">
    223             <arg line="install:install-file -DgroupId=com.google.android.maps -DartifactId=maps -Dversion=10_r2 -Dpackaging=jar -Dfile=${sdk.dir}/add-ons/addon-google_apis-google_inc_-10/libs/maps.jar" />
    224         </exec>
    225         <exec executable="mvn">
    226             <arg line="install:install-file -DgroupId=com.google.android.maps -DartifactId=maps -Dversion=10_r2 -Dpackaging=jar -Dfile=${sdk.dir}/add-ons/addon-google_apis-google-10/libs/maps.jar" />
    227         </exec>
    228     </target>
    229 
    230     <!-- used by travis-ci -->
    231     <target name="prepare-travis-ci" description="Prepare for travis ci build">
    232       <mkdir dir="tmp"/>
    233       <get src="http://dl.google.com/android/android-sdk_r20.0.3-linux.tgz" dest="tmp" skipexisting="true"/>
    234       <untar src="tmp/android-sdk_r20.0.3-linux.tgz" compression="gzip" dest="tmp/sdk"/>
    235       <echo file="tmp/install-sdk">#!/bin/sh -e
    236           ANDROID="tmp/sdk/android-sdk-linux/tools/android"
    237           chmod +x $ANDROID
    238           SDKS=$($ANDROID list sdk --all | awk \
    239                     '/SDK Platform.* API 10/ || /Google APIs, Android API 10, revision 2/ \
    240                     { s=s "," int($1) } \
    241                     END { print substr(s, 2, length(s)) }' \
    242                 )
    243           $ANDROID update sdk --no-ui --all --filter $SDKS
    244       </echo>
    245       <chmod file="tmp/install-sdk" perm="u+x"/>
    246       <exec executable="tmp/install-sdk"/>
    247       <propertyfile file="local.properties">
    248         <entry key="sdk.dir" value="${basedir}/tmp/sdk/android-sdk-linux/"/>
    249       </propertyfile>
    250       <exec executable="mvn">
    251           <arg line="install:install-file -DgroupId=com.google.android.maps -DartifactId=maps -Dversion=10_r2 -Dpackaging=jar -Dfile=tmp/sdk/android-sdk-linux/add-ons/addon-google_apis-google-10/libs/maps.jar"/>
    252       </exec>
    253     </target>
    254 </project>
    255