lexy

支持开源,尊重他人的劳动!

  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  17 随笔 :: 0 文章 :: 9 评论 :: 0 Trackbacks

<?xml version="1.0" encoding="GB2312" ?>

<!-- 一个项目,可包含很多任务组(target) -->
<project default="gen-report-coverage" basedir=".">

    <!--设置Java类被注入字节码后存放的路径-->
    <property name="bin.instrument.dir" value="${basedir}/out/instrbin"/>
    <!--设置覆盖率元数据和报告的路径-->
    <property name="coverage.dir" value="${basedir}/out/coverage"/>
    <!--设置junit报告的路径 -->
    <property name="junitReport.dir" value="${basedir}/out/junitReport"/>
    <!--设置主题代码源路径-->
    <property name="src.main.dir" value="${basedir}/../src/mcc">
    </property>
    <!--设置测试代码源路径-->
    <property name="src.test.dir" value="${basedir}/java">
    </property>
    <!--设置主题代码bin路径-->
    <property name="bin.main.dir" value="${basedir}/out/srcbin">
    </property>
    <!--设置测试代码bin路径-->
    <property name="bin.test.dir" value="${basedir}/out/testbin">
    </property>

    <property name="lib.dir" value="${basedir}/lib">
    </property>

    <path id="compile.path">
        <pathelement location="${bin.main.dir}"/>
        <pathelement location="${basedir}\..\lib\ganymed.jar"/>
        <pathelement location="${basedir}\..\lib\junit-3.8.1.jar"/>
        <pathelement location="${basedir}\..\lib\svnClientAdapter1.3.jar"/>
        <pathelement location="${basedir}\..\lib\svnjavahl.jar"/>
        <pathelement location="${basedir}\..\lib\svnkit.jar"/>
    </path>

    <!--指示 emma.jar 和emma_ant.jar 的路径-->
    <path id="emma.lib">
        <pathelement location="${lib.dir}/emma.jar"/>
        <pathelement location="${lib.dir}/emma_ant.jar"/>
    </path>

    <path id="compile.classes">
        <pathelement path="${bin.main.dir}"/>
    </path>

    <!--允许emma-->
    <property name="emma.enabled" value="true"/>

    <taskdef resource="emma_ant.properties" classpathref="emma.lib"/>

    <!-- 项目中的一个任务组,可包含很多任务(task:javac,java...) -->
    <target name="init">
        <delete dir="${bin.main.dir}"/>
        <delete dir="${bin.test.dir}"/>
        <delete dir="${bin.instrument.dir}"/>
        <delete dir="${coverage.dir}"/>
        <delete dir="${junitReport.dir}"/>
        <mkdir dir="${bin.main.dir}"/>
        <mkdir dir="${bin.test.dir}"/>
        <mkdir dir="${bin.instrument.dir}"/>
        <mkdir dir="${coverage.dir}"/>
        <mkdir dir="${junitReport.dir}"/>
    </target>

    <!--编译源代码-->
    <target name="compile-src.main" depends="init">
        <javac destdir="${bin.main.dir}" debug="on">
            <src path="${src.main.dir}"></src>
            <classpath refid="compile.path"></classpath>
        </javac>
        <copy todir="${bin.main.dir}">
            <fileset dir="${src.main.dir}">
                <exclude name="**/*.java"/>
            </fileset>
        </copy>
    </target>

    <!--编译测试代码-->
    <target name="compile-src.test" depends="compile-src.main">
        <javac destdir="${bin.test.dir}" debug="on">
            <src path="${src.test.dir}"/>
            <classpath refid="compile.path"></classpath>
        </javac>
        <copy todir="${bin.test.dir}">
            <fileset dir="${src.test.dir}">
                <exclude name="**/*.java"/>
            </fileset>
        </copy>
    </target>

    <!--对编译在路径bin.main.dir中的Java类注入字节码,
    并且把注入字节码的新Java类存放到路径bin.instrument.dir-->
    <!--覆盖率的元数据存放在路径coverage.dir中-->

    <target name="instrument" depends="compile-src.test">
        <emma enabled="${emma.enabled}" verbosity="info">
            <instr instrpathref="compile.classes"
                   destdir="${bin.instrument.dir}"
                   metadatafile="${coverage.dir}/metadata.emma"
                   merge="true">
            </instr>
        </emma>
        <!--<copy todir="${bin.instrument.dir}">-->
        <!--<fileset dir="${bin.main.dir}">-->
        <!--<exclude name="**/*.java"/>-->
        <!--</fileset>-->
        <!--</copy>-->
    </target>

    <!--执行测试用例同时生成junit测试报告和emma代码覆盖率报告-->
    <target name="test" depends="instrument">
        <junit fork="true" forkmode="once"
               printsummary="withOutAndErr"
               errorproperty="test.error"
               showoutput="on">
            <!--指明代码覆盖率的元数据的存放位置-->
            <jvmarg
                    value="-Demma.coverage.out.file=${coverage.dir}/metadata.emma"/>
            <jvmarg value="-Demma.coverage.out.merge=true"/>

            <classpath location="${bin.instrument.dir}"/>
            <classpath location="${bin.test.dir}"/>
            <classpath refid="emma.lib"/>
            <classpath refid="compile.path"/>

            <formatter type="xml"/>
            <!--执行所有以TestSuite结尾的junit测试用例-->
            <batchtest todir="${junitReport.dir}" haltonfailure="no">
                <fileset dir="${bin.test.dir}">
                    <include name="**/*TestSuite.class"/>
                </fileset>
            </batchtest>
        </junit>
    </target>

    <target name="gen-report-junit" depends="test">
        <!--生成junit测试报告-->
        <junitreport todir="${junitReport.dir}">
            <fileset dir="${junitReport.dir}">
                <include name="*"/>
            </fileset>
            <report format="frames" todir="${junitReport.dir}"/>
        </junitreport>
    </target>

    <!--生成代码覆盖率报告-->
    <target name="gen-report-coverage" depends="test">
        <!--如果属性emma.enabled的值是true,就生成代码覆盖率报告 -->
        <emma enabled="${emma.enabled}">
            <report sourcepath="${src.main.dir}"
                    sort="+line,+block,+name,+method,+class"
                    metrics="method:100,block:90,line:90,class:100">
                <fileset dir="${coverage.dir}">
                    <include name="metadata.emma"/>
                </fileset>
                <html outfile="${coverage.dir}/coverage.html"
                      depth="method"/>
            </report>
        </emma>
    </target>
</project>

posted on 2007-10-25 17:18 lexy 阅读(489) 评论(0)  编辑  收藏

只有注册用户登录后才能发表评论。


网站导航: