buildframework/helium/external/helium-antlib/macros.ant.xml
author wbernard
Wed, 23 Dec 2009 19:29:07 +0200
changeset 179 d8ac696cc51f
parent 1 be27ed110b50
permissions -rw-r--r--
helium_7.0-r14027

<?xml version="1.0"?>
<!-- 
============================================================================ 
Name        : macros.xml 
Part of     : Helium AntLib

Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
All rights reserved.
This component and the accompanying materials are made available
under the terms of the License "Eclipse Public License v1.0"
which accompanies this distribution, and is available
at the URL "http://www.eclipse.org/legal/epl-v10.html".

Initial Contributors:
Nokia Corporation - initial contribution.

Contributors:

Description:

============================================================================
-->
<project name="build-macros" xmlns:au="org.apache.ant.antunit">
    <description>Helium Antlib build macro.</description>
    
    <dirname property="helium.antlib.root.dir" file="${ant.file.build-macros}" />
    <property name="build.temp.dir" location="${helium.antlib.root.dir}/../build" />
    <property name="bin.dir" location="${basedir}/../bin" />

    <path id="helium.antlib.classpath">
        <fileset dir="${helium.antlib.root.dir}/lib" includes="*.jar" />
        <fileset dir="${helium.antlib.root.dir}/antlibs" includes="*.jar" />
    </path>
    
    <taskdef resource="net/sf/antcontrib/antlib.xml" classpathref="helium.antlib.classpath"/>
    <taskdef resource="org/apache/ant/antunit/antlib.xml" uri="org.apache.ant.antunit" classpathref="helium.antlib.classpath"/>
    
    
    <presetdef name="subantPreset">
        <subant failonerror="true">
            <resources refid="subant.build.files"/>
        </subant>
    </presetdef>
    
    
    <macrodef name="compileModule">
        <attribute name="name" />
        <attribute name="dir" default="${helium.antlib.root.dir}" />
        <sequential>
            <mkdir dir="${build.temp.dir}/@{name}/classes" />
            <javac srcdir="${basedir}/src" destdir="${build.temp.dir}/@{name}/classes"
                   debug="true" source="1.6" target="1.6">
                <classpath refid="helium.antlib.classpath" />
                <classpath refid="helium.@{name}.classpath" />
                <include name="**/*.java" />
                <compilerarg value="-Xlint:unchecked" />
                <compilerarg value="-Xlint:deprecation" />
            </javac>
        </sequential>
    </macrodef>

    
    <macrodef name="jarModule">
        <attribute name="name" />
        <attribute name="dir" default="${helium.antlib.root.dir}" />
        <attribute name="bindir" default="${bin.dir}" />
        <sequential>
            <echo>Packaging module @{name}</echo>
            <mkdir dir="@{bindir}" />
            <jar destfile="@{bindir}/helium-@{name}.jar">
                <fileset dir="${build.temp.dir}/@{name}/classes" />
                <fileset dir="${basedir}/src" includes="**/*.xml" />
                <fileset dir="${basedir}/src" includes="**/*.*ftl" />
                <fileset dir="${basedir}/src" includes="**/*.vm" />
                
                <manifest>
                    <section name="common">
                        <attribute name="Implementation-Title" value="@{name}" />
                        <attribute name="Implementation-Vendor" value="Nokia" />
                    </section>
                </manifest>
            </jar>
        </sequential>
    </macrodef>
    

    <macrodef name="testModule">
        <attribute name="name" />
        <attribute name="dir" default="${helium.antlib.root.dir}" />
        <attribute name="bindir" default="${bin.dir}" />
        <sequential>
            <mkdir dir="${build.temp.dir}" />
            <if>
                <available type="dir" file="${basedir}/tests"/>
                <then>
                    <trycatch>
                        <try>
                            <!-- Temporarly replacing the jar file
                                 with an instrumented one to do the 
                                 actual coverage measurment
                             -->
                            <mkdir dir="${build.temp.dir}/@{name}/backup" />
                            <delete>
                                <fileset dir="${build.temp.dir}" includes="@{name}/**/*_antunit.emma" />
                            </delete>
                            <copy file="@{bindir}/helium-@{name}.jar" todir="${build.temp.dir}/@{name}/backup/" />
                            <emma enabled="true">
                                <instr destdir="@{bindir}/" metadatafile="${build.temp.dir}/@{name}/metadata_antunit.emma" merge="true" mode="overwrite">
                                    <instrpath>
                                        <fileset dir="@{bindir}" includes="helium-@{name}.jar" />
                                    </instrpath>
                                </instr>
                            </emma>
                            <exec osfamily="windows" executable="cmd" dir="${basedir}/tests">
                                <env key="ANT_LIB_HOME" path="${helium.antlib.root.dir}" />
                                <arg line="/c build.bat unittest" />
                            </exec>
                            <exec osfamily="unix" executable="./bld.sh" dir="${basedir}/tests">
                                <env key="ANT_LIB_HOME" path="${helium.antlib.root.dir}" />
                                <arg line="unittest" />
                            </exec>
                            <move todir="${build.temp.dir}/@{name}">
                                <fileset dir="${basedir}/tests" includes="**/coverage.ec" />
                                <chainedmapper>
                                    <filtermapper>
                                        <replacestring from="/" to="_" />
                                    </filtermapper>
                                    <regexpmapper from="^(.*)\.ec$$" to="\1_antunit.emma" />
                                </chainedmapper>
                            </move>
                            <emma enabled="true">
                                <report>
                                    <infileset dir="${build.temp.dir}/@{name}/" includes="*_antunit.emma" />
                                    <txt outfile="${build.temp.dir}/@{name}/coverage_antunit.txt" />
                                    <html outfile="${build.temp.dir}/@{name}/coverage_antunit.html" />
                                    <xml outfile="${build.temp.dir}/@{name}/coverage_antunit.xml" />
                                </report>
                            </emma>
                            <if>
                                <available file="${build.temp.dir}/@{name}/coverage_antunit.txt" />
                                <then>
                                    <loadfile property="message" srcFile="${build.temp.dir}/@{name}/coverage_antunit.txt" />
                                    <echo message="${message}" />
                                </then>
                            </if>
                        </try>
                        <finally>
                            <copy file="${build.temp.dir}/@{name}/backup/helium-@{name}.jar" todir="@{bindir}" overwrite="true" />
                        </finally>
                    </trycatch>
                </then>
            </if>
        </sequential>
    </macrodef>
    
    
    <path id="emma.classpath">
        <fileset dir="${helium.antlib.root.dir}\antlibs">
            <include name="**/*.jar" />
        </fileset>
    </path>
    <taskdef classpathref="emma.classpath" resource="emma_ant.properties" />
 
    
    <macrodef name="junitModule">
        <attribute name="name" />
        <attribute name="dir" default="${helium.antlib.root.dir}" />
        <attribute name="bindir" default="${bin.dir}" />
        <sequential>
            <mkdir dir="${build.temp.dir}" />
            <if>
                <available type="dir" file="${basedir}/tests/src"/>
                <then>
                    <echo>JUnit test module @{name}</echo>
                    <delete dir="${build.temp.dir}/@{name}/junit_classes"/>
                    <delete>
                        <fileset dir="${build.temp.dir}" includes="@{name}/**/*_junit.emma" />
                    </delete>
                    <mkdir dir="${build.temp.dir}/@{name}/junit_classes" />
                    <javac srcdir="${basedir}/tests/src" destdir="${build.temp.dir}/@{name}/junit_classes" debug="true" source="1.5" target="1.5">
                        <classpath refid="helium.antlib.classpath" />
                        <classpath refid="helium.@{name}.classpath" />
                        <classpath>
                            <fileset dir="@{bindir}" includes="*-@{name}.jar" />
                        </classpath>
                        <include name="**/*.java" />
                    </javac>
            
                    <copy file="@{bindir}/helium-@{name}.jar" todir="${build.temp.dir}/@{name}/" overwrite="true"/>
                    <emma enabled="true">
                        <instr destdir="${build.temp.dir}/@{name}/" metadatafile="${build.temp.dir}/@{name}/metadata_junit.emma" merge="true" mode="overwrite">
                            <instrpath>
                                <fileset dir="${build.temp.dir}/@{name}/" includes="helium-@{name}.jar" />
                            </instrpath>
                        </instr>
                    </emma>
                    
                    <delete file="${build.temp.dir}/@{name}/coverage.emma" failonerror="false" />
                    <junit fork="yes" printsummary="yes" haltonfailure="yes" showoutput="yes">
                        <formatter type="brief" usefile="false"/>
                        <jvmarg value="-Demma.coverage.out.file=${build.temp.dir}/@{name}/coverage_junit.emma" />
                        <jvmarg value="-Demma.coverage.out.merge=true" />
                        <jvmarg value="-Dtestdir=${basedir}" />
                        <classpath>
                            <pathelement path="${build.temp.dir}/@{name}/helium-@{name}.jar"/>
                            <pathelement path="${helium.antlib.root.dir}/antlibs/*.jar"/>
                            <pathelement path="${build.temp.dir}/@{name}/junit_classes" />
                        </classpath>
                        <classpath refid="helium.antlib.classpath" />
                        <classpath refid="helium.@{name}.classpath" />
                        <batchtest fork="yes" todir="${build.temp.dir}/@{name}/junit_test">
                            <fileset dir="${basedir}/tests/src">
                                <include name="**/*Test*.java"/>
                            </fileset>
                        </batchtest>
                    </junit>
                    <delete file="${build.temp.dir}/@{name}/helium-@{name}.jar" failonerror="false" />
                    
                    <emma enabled="true" >
                        <report>
                            <infileset dir="${build.temp.dir}/@{name}" includes="*_junit.emma" />
                            <txt outfile="${build.temp.dir}/@{name}/coverage.txt" />
                            <html outfile="${build.temp.dir}/@{name}/coverage.html" />
                            <xml outfile="${build.temp.dir}/@{name}/coverage.xml" />
                        </report>
                    </emma>
                    <if>
                        <available file="${build.temp.dir}/@{name}/coverage.txt" />
                        <then>
                            <loadfile property="message" srcFile="${build.temp.dir}/@{name}/coverage.txt"/>
                            <echo message="${message}"/>
                        </then>
                    </if>
                </then>
            </if>
        </sequential>
    </macrodef>
    
    
    <target name="compile">
        <echo>Compiling ${ant.project.name}</echo>
        <compileModule name="${name}"/>
    </target>
    
    
    <target name="jar">
        <echo>Creating jar for ${ant.project.name}</echo>
        <jarModule name="${name}"/>
    </target>
    
    
    <target name="build" depends="compile,jar">
        <echo>${ant.project.name} is built.</echo>
    </target>
    
    
    <target name="clean">
        <echo>Cleaning ${ant.project.name}</echo>
        <delete dir="${build.temp.dir}/${name}/classes"/>
        <delete file="${bin.dir}/helium-${name}.jar"/>
    </target>
    
    
    <target name="junit">
        <junitModule name="${name}"/>
    </target>
    
    
    <target name="unittest">
        <testModule name="${name}"/>
    </target>
    
    
    <target name="test" depends="junit,unittest">
        <echo>${ant.project.name} tested.</echo>
    </target>
</project>