lexy

          支持開(kāi)源,尊重他人的勞動(dòng)!

            BlogJava :: 首頁(yè) :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
            17 隨筆 :: 0 文章 :: 9 評(píng)論 :: 0 Trackbacks

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

          <!-- 一個(gè)項(xiàng)目,可包含很多任務(wù)組(target) -->
          <project default="gen-report-coverage" basedir=".">

              <!--設(shè)置Java類被注入字節(jié)碼后存放的路徑-->
              <property name="bin.instrument.dir" value="${basedir}/out/instrbin"/>
              <!--設(shè)置覆蓋率元數(shù)據(jù)和報(bào)告的路徑-->
              <property name="coverage.dir" value="${basedir}/out/coverage"/>
              <!--設(shè)置junit報(bào)告的路徑 -->
              <property name="junitReport.dir" value="${basedir}/out/junitReport"/>
              <!--設(shè)置主題代碼源路徑-->
              <property name="src.main.dir" value="${basedir}/../src/mcc">
              </property>
              <!--設(shè)置測(cè)試代碼源路徑-->
              <property name="src.test.dir" value="${basedir}/java">
              </property>
              <!--設(shè)置主題代碼bin路徑-->
              <property name="bin.main.dir" value="${basedir}/out/srcbin">
              </property>
              <!--設(shè)置測(cè)試代碼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"/>

              <!-- 項(xiàng)目中的一個(gè)任務(wù)組,可包含很多任務(wù)(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>

              <!--編譯測(cè)試代碼-->
              <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>

              <!--對(duì)編譯在路徑bin.main.dir中的Java類注入字節(jié)碼,
              并且把注入字節(jié)碼的新Java類存放到路徑bin.instrument.dir-->
              <!--覆蓋率的元數(shù)據(jù)存放在路徑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>

              <!--執(zhí)行測(cè)試用例同時(shí)生成junit測(cè)試報(bào)告和emma代碼覆蓋率報(bào)告-->
              <target name="test" depends="instrument">
                  <junit fork="true" forkmode="once"
                         printsummary="withOutAndErr"
                         errorproperty="test.error"
                         showoutput="on">
                      <!--指明代碼覆蓋率的元數(shù)據(jù)的存放位置-->
                      <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"/>
                      <!--執(zhí)行所有以TestSuite結(jié)尾的junit測(cè)試用例-->
                      <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測(cè)試報(bào)告-->
                  <junitreport todir="${junitReport.dir}">
                      <fileset dir="${junitReport.dir}">
                          <include name="*"/>
                      </fileset>
                      <report format="frames" todir="${junitReport.dir}"/>
                  </junitreport>
              </target>

              <!--生成代碼覆蓋率報(bào)告-->
              <target name="gen-report-coverage" depends="test">
                  <!--如果屬性emma.enabled的值是true,就生成代碼覆蓋率報(bào)告 -->
                  <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 閱讀(498) 評(píng)論(0)  編輯  收藏

          只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 措美县| 长寿区| 莫力| 桦川县| 镇远县| 武强县| 北安市| 化德县| 厦门市| 庄河市| 板桥市| 增城市| 方正县| 香格里拉县| 南江县| 宣威市| 洮南市| 稻城县| 余庆县| 松溪县| 德钦县| 丹阳市| 永顺县| 双江| 综艺| 花莲市| 定襄县| 兴和县| 泗阳县| 鹤壁市| 双牌县| 惠来县| 汉川市| 平原县| 武陟县| 洞头县| 元朗区| 新化县| 上虞市| 安西县| 青州市|