Home | History | Annotate | Download | only in hamcrest
      1 <project name="hamcrest" default="all">
      2 
      3     <property name="version" value="SNAPSHOT" description="Version number to use in build files"/>
      4     <property name="haltonfailure" value="true" description="Whether to halt the build if the tests fail"/>
      5     <property name="debug" value="true" description="Whether to build with debug information"/>
      6     <property name="javaversion" value="1.5" description="Java version to target"/>
      7     <tstamp><format property="build.timestamp" pattern="yyyy-MM-dd HH:mm:ss" timezone="GMT"/></tstamp>
      8     <taskdef name="junit" classname="org.apache.tools.ant.taskdefs.optional.junit.JUnitTask" classpath="lib/integration/ant-junit-1.8.4.jar"/>
      9 
     10 
     11     <target name="all" depends="clean, bigjar, javadoc" description="Performs clean build, runs tests and packages for distribution"/>
     12 
     13     <target name="clean" description="Clean up all built files">
     14         <delete dir="build"/>
     15     </target>
     16 
     17     <target name="api" description="Build Hamcrest APIs">
     18         <path id="cp-hamcrest-api-main" path=""/>
     19         <path id="cp-hamcrest-api-test" path=""/>
     20         <compile-module modulename="hamcrest-api"/>
     21         <jar-module modulename="hamcrest-api"/>
     22         <test-module modulename="hamcrest-api"/>
     23     </target>
     24 
     25     <target name="generator" depends="api" description="Build code generator tool">
     26         <path id="cp-hamcrest-generator-main" path="lib/generator/qdox-2.0-M2.jar;build/hamcrest-api-${version}.jar"/>
     27         <path id="cp-hamcrest-generator-test" path=""/>
     28         <compile-module modulename="hamcrest-generator"/>
     29         <jar-module modulename="hamcrest-generator"/>
     30         <test-module modulename="hamcrest-generator"/>
     31 
     32         <!-- Include QDox classes in hamcrest-generator.jar using JarJar to place classes under a different package -->
     33         <taskdef name="jarjar" classname="com.tonicsystems.jarjar.JarJarTask" classpath="lib/generator/jarjar-1.3.jar"/>
     34         <copy file="build/hamcrest-generator-${version}.jar" tofile="build/hamcrest-generator-${version}-nodep.jar"/>
     35         <jarjar jarfile="build/hamcrest-generator-${version}.jar">
     36             <zipfileset src="build/hamcrest-generator-${version}-nodep.jar"/>
     37             <zipfileset src="lib/generator/qdox-2.0-M2.jar"/>
     38             <rule pattern="com.thoughtworks.qdox.**" result="org.hamcrest.generator.qdox.@1"/>
     39         </jarjar>
     40     </target>
     41 
     42     <target name="core" depends="generator" description="Build core Hamcrest library">
     43         <path id="cp-hamcrest-core-main" path="build/hamcrest-api-${version}.jar"/>
     44         <path id="cp-hamcrest-core-test" path=""/>
     45         <compile-module modulename="hamcrest-core"/>
     46         <generate-module-factory modulename="hamcrest-core" configurationfile="hamcrest-core/core-matchers.xml" targetclass="org.hamcrest.CoreMatchers" sources="hamcrest-core/src/main/java"/>
     47         <jar-module modulename="hamcrest-core"/>
     48         <test-module modulename="hamcrest-core"/>
     49     </target>
     50 
     51     <target name="library" depends="core" description="Build library of matchers">
     52         <path id="cp-hamcrest-library-main" path="build/hamcrest-api-${version}.jar;build/hamcrest-core-${version}.jar"/>
     53         <path id="cp-hamcrest-library-test" path="build/hamcrest-core-${version}-tests.jar"/>
     54         <compile-module modulename="hamcrest-library"/>
     55         <generate-module-factory modulename="hamcrest-library" configurationfile="hamcrest-library/matchers.xml" targetclass="org.hamcrest.Matchers" sources="hamcrest-core/src/main/java,hamcrest-library/src/main/java"/>
     56         <jar-module modulename="hamcrest-library"/>
     57         <test-module modulename="hamcrest-library"/>
     58     </target>
     59 
     60     <target name="integration" depends="library" description="Build integration with external tools">
     61         <path id="cp-hamcrest-integration-main">
     62             <fileset file="build/hamcrest-api-${version}.jar"/>
     63             <fileset file="build/hamcrest-core-${version}.jar"/>
     64             <fileset file="build/hamcrest-library-${version}.jar"/>
     65             <fileset dir="lib/integration" includes="**/*.jar"/>
     66         </path>
     67         <path id="cp-hamcrest-integration-test" path="build/hamcrest-core-${version}-tests.jar"/>
     68         <compile-module modulename="hamcrest-integration"/>
     69         <jar-module modulename="hamcrest-integration"/>
     70         <test-module modulename="hamcrest-integration"/>
     71     </target>
     72 
     73     <target name="examples" depends="core, library, integration" description="Build and run unit tests.">
     74         <path id="cp-hamcrest-examples-main">
     75             <fileset file="build/hamcrest-api-${version}.jar"/>
     76             <fileset file="build/hamcrest-core-${version}.jar"/>
     77             <fileset file="build/hamcrest-library-${version}.jar"/>
     78             <fileset file="build/hamcrest-integration-${version}.jar"/>
     79             <fileset dir="lib/integration" includes="**/*.jar"/>
     80         </path>
     81         <compile-module modulename="hamcrest-examples"/>
     82         <jar-module modulename="hamcrest-examples"/>
     83     </target>
     84 
     85     <target name="bigjar" depends="core,library,integration,generator" description="Build composite jars">
     86         <!-- Bundle api into core jar -->
     87         <copy todir="build/temp/hamcrest-core-${version}.jar.contents">
     88             <fileset dir="build/temp/hamcrest-api-${version}.jar.contents"/>
     89         </copy>
     90         <copy todir="build/temp/hamcrest-core-${version}-sources.jar.contents">
     91             <fileset dir="build/temp/hamcrest-api-${version}-sources.jar.contents"/>
     92         </copy>
     93         <jar-module modulename="hamcrest-core"/>
     94 
     95         <!-- Bundle core, library, integration, and generator into all jar-->
     96         <copy todir="build/temp/hamcrest-all-${version}.jar.contents">
     97             <fileset dir="build/temp/hamcrest-core-${version}.jar.contents"/>
     98             <fileset dir="build/temp/hamcrest-library-${version}.jar.contents"/>
     99             <fileset dir="build/temp/hamcrest-integration-${version}.jar.contents"/>
    100             <fileset dir="build/temp/hamcrest-generator-${version}.jar.contents"/>
    101         </copy>
    102         <copy todir="build/temp/hamcrest-all-${version}-sources.jar.contents">
    103             <fileset dir="build/temp/hamcrest-core-${version}-sources.jar.contents"/>
    104             <fileset dir="build/temp/hamcrest-library-${version}-sources.jar.contents"/>
    105             <fileset dir="build/temp/hamcrest-integration-${version}-sources.jar.contents"/>
    106             <fileset dir="build/temp/hamcrest-generator-${version}-sources.jar.contents"/>
    107         </copy>
    108         <path id="cp-hamcrest-all-main">
    109             <path refid="cp-hamcrest-core-main"/>
    110             <path refid="cp-hamcrest-library-main"/>
    111             <path refid="cp-hamcrest-integration-main"/>
    112             <path refid="cp-hamcrest-generator-main"/>
    113         </path>
    114         <jar-module modulename="hamcrest-all"/>
    115     </target>
    116 
    117     <target name="javadoc" depends="bigjar" description="build javadoc jars">
    118         <javadoc-module modulename="hamcrest-generator"/>
    119         <javadoc-module modulename="hamcrest-core"/>
    120         <javadoc-module modulename="hamcrest-library"/>
    121         <javadoc-module modulename="hamcrest-integration"/>
    122         <javadoc-module modulename="hamcrest-all"/>
    123     </target>
    124 
    125     <target name="bundle" description="Create a release bundle for deployment to maven central" depends="clean, javadoc">
    126         <copy todir="build">
    127             <fileset dir="pom" includes="*.pom"/>
    128             <filterset><filter token="VERSION" value="${version}"/></filterset>
    129             <mapper type="regexp" from="(.*)\.pom" to="\1-${version}.pom"/>
    130         </copy>
    131 
    132         <sign target="hamcrest-parent-${version}.pom"/>
    133         <jar-bundle modulename="hamcrest-parent"/>
    134 
    135         <bundle-module modulename="hamcrest-core"/>
    136         <bundle-module modulename="hamcrest-generator"/>
    137         <bundle-module modulename="hamcrest-library"/>
    138         <bundle-module modulename="hamcrest-integration"/>
    139         <bundle-module modulename="hamcrest-all"/>
    140     </target>
    141 
    142     <macrodef name="make-manifest">
    143         <attribute name="modulename" description="Name of the module"/>
    144         <sequential>
    145             <mkdir dir="build/temp/@{modulename}-${version}.jar.manifest"/>
    146             <manifest file="build/temp/@{modulename}-${version}.jar.manifest/MANIFEST.MF">
    147                <attribute name="Implementation-Title" value="@{modulename}"/>
    148                <attribute name="Implementation-Vendor" value="hamcrest.org"/>
    149                <attribute name="Implementation-Version" value="${version}"/>
    150                <attribute name="Built-By" value="${user.name}"/>
    151                <attribute name="Built-Date" value="${build.timestamp}"/>
    152            </manifest>
    153         </sequential>
    154     </macrodef>
    155 
    156     <macrodef name="compile-module">
    157         <attribute name="modulename" description="Name of the module to jar"/>
    158         <sequential>
    159             <compile-content srcdir="@{modulename}/src/main/java" jarname="@{modulename}-${version}" classpathref="cp-@{modulename}-main" />
    160             <path id="cp-@{modulename}-test-complete">
    161                 <path path="lib/integration/junit-dep-4.11.jar"/>
    162                 <path refid="cp-@{modulename}-main"/>
    163                 <path refid="cp-@{modulename}-test"/>
    164                 <path path="build/temp/@{modulename}-${version}.jar.contents"/>
    165             </path>
    166             <compile-content srcdir="@{modulename}/src/test/java" jarname="@{modulename}-${version}-tests" classpathref="cp-@{modulename}-test-complete" />
    167         </sequential>
    168     </macrodef>
    169 
    170     <macrodef name="compile-content">
    171         <attribute name="srcdir"/>
    172         <attribute name="jarname" description="Name of the jar whose content is being compiled (without .jar suffix)"/>
    173         <attribute name="classpathref"/>
    174         <sequential>
    175             <mkdir dir="build/temp/@{jarname}-sources.jar.contents"/>
    176             <copy failonerror="false" todir="build/temp/@{jarname}-sources.jar.contents">
    177                 <fileset dir="@{srcdir}"/>
    178             </copy>
    179             <mkdir dir="build/temp/@{jarname}.jar.contents"/>
    180             <javac srcdir="build/temp/@{jarname}-sources.jar.contents"
    181                    destdir="build/temp/@{jarname}.jar.contents"
    182                    debug="${debug}" source="${javaversion}" target="${javaversion}" includeantruntime="false">
    183                 <classpath refid="@{classpathref}"/>
    184             </javac>
    185         </sequential>
    186     </macrodef>
    187 
    188     <macrodef name="jar-module">
    189         <attribute name="modulename" description="Name of the module to jar"/>
    190         <sequential>
    191             <make-manifest modulename="@{modulename}"/>
    192             <jar-module-component modulename="@{modulename}"/>
    193             <jar-module-component modulename="@{modulename}" suffix="-tests"/>
    194             <jar-module-component modulename="@{modulename}" suffix="-sources"/>
    195         </sequential>
    196     </macrodef>
    197 
    198     <macrodef name="jar-module-component">
    199         <attribute name="modulename" description="Name of the module to jar"/>
    200         <attribute name="suffix" default="" description="Name of the module to jar"/>
    201         <sequential>
    202             <copy file="LICENSE.txt" todir="build/temp/@{modulename}-${version}@{suffix}.jar.contents/META-INF"/>
    203             <jar jarfile="build/@{modulename}-${version}@{suffix}.jar" manifest="build/temp/@{modulename}-${version}.jar.manifest/MANIFEST.MF">
    204                 <fileset dir="build/temp/@{modulename}-${version}@{suffix}.jar.contents"/>
    205             </jar>
    206         </sequential>
    207     </macrodef>
    208 
    209     <macrodef name="generate-module-factory" description="Generate one class with all static imports">
    210         <attribute name="modulename" description="Name of the module to jar"/>
    211         <attribute name="configurationfile" description="xml configuration file"/>
    212         <attribute name="targetclass" description="factory class to generate"/>
    213         <attribute name="sources" description="comma-separated source directories"/>
    214         <sequential>
    215             <mkdir dir="build/temp/@{modulename}/generated-code"/>
    216             <java classname="org.hamcrest.generator.config.XmlConfigurator" fork="yes" failonerror="yes">
    217                 <classpath path="build/hamcrest-generator-${version}.jar"/>
    218                 <classpath refid="cp-@{modulename}-main"/>
    219                 <classpath path="build/temp/@{modulename}-${version}.jar.contents"/>
    220                 <arg value="@{configurationfile}"/>
    221                 <arg value="@{sources}"/>
    222                 <arg value="@{targetclass}"/>
    223                 <arg value="build/temp/@{modulename}/generated-code"/>
    224             </java>
    225 
    226             <copy todir="build/temp/@{modulename}-${version}-sources.jar.contents">
    227                 <fileset dir="build/temp/@{modulename}/generated-code"/>
    228             </copy>
    229             <compile-module modulename="@{modulename}"/>
    230         </sequential>
    231     </macrodef>
    232 
    233     <macrodef name="test-module" description="run unit tests.">
    234         <attribute name="modulename" description="Name of the module to test"/>
    235         <sequential>
    236             <mkdir dir="build/temp/@{modulename}/test-wrk"/>
    237             <junit printsummary="no" forkmode="once" tempdir="build/temp/@{modulename}/test-wrk" haltonfailure="${haltonfailure}" dir="@{modulename}">
    238                 <formatter type="brief" usefile="no"/>
    239                 <classpath refid="cp-@{modulename}-test-complete"/>
    240                 <classpath path="build/@{modulename}-${version}-tests.jar"/>
    241                 <batchtest fork="yes" todir="${build.dir}/testreport">
    242                     <zipfileset src="build/@{modulename}-${version}-tests.jar">
    243                         <include name="org/hamcrest/**/*Test.class"/>
    244                         <exclude name="**/Abstract*.class"/>
    245                     </zipfileset>
    246                 </batchtest>
    247             </junit>
    248         </sequential>
    249     </macrodef>
    250 
    251     <macrodef name="javadoc-module" description="Generate javadoc for a module and build a Jar">
    252         <attribute name="modulename" description="Name of the module to document"/>
    253         <sequential>
    254             <javadoc packagenames="org.hamcrest.*" sourcepath="build/temp/@{modulename}-${version}-sources.jar.contents"
    255                      destdir="build/temp/@{modulename}-${version}-javadoc.jar.contents" author="true" version="true"
    256                      use="true" windowtitle="Hamcrest" source="${javaversion}" failonerror="yes" defaultexcludes="yes">
    257                 <classpath refid="cp-@{modulename}-main"/>
    258             </javadoc>
    259             <jar-module-component modulename="@{modulename}" suffix="-javadoc"/>
    260         </sequential>
    261     </macrodef>
    262 
    263     <macrodef name="bundle-module" description="Generate maven bundle jar for a module">
    264         <attribute name="modulename" description="Name of the module to bundle"/>
    265         <sequential>
    266             <sign target="@{modulename}-${version}.pom"/>
    267             <sign target="@{modulename}-${version}.jar"/>
    268             <sign target="@{modulename}-${version}-javadoc.jar"/>
    269             <sign target="@{modulename}-${version}-sources.jar"/>
    270             <jar-bundle modulename="@{modulename}"/>
    271         </sequential>
    272     </macrodef>
    273 
    274     <macrodef name="jar-bundle" description="Jar maven bundle contents">
    275         <attribute name="modulename" description="Name of the module to create bundle jar for"/>
    276         <sequential>
    277             <jar destfile="build/maven-bundle-@{modulename}.jar">
    278                 <fileset dir="build"><include name="@{modulename}-${version}*"/></fileset>
    279             </jar>
    280         </sequential>
    281     </macrodef>
    282 
    283     <macrodef name="sign" description="Sign a file with a gpg key">
    284         <attribute name="target" description="Name of the resource to sign"/>
    285         <sequential>
    286             <exec executable="gpg" dir="build"><arg value="-ab"/><arg value="@{target}"/></exec>
    287         </sequential>
    288     </macrodef>
    289 </project>
    290